diff --git a/CEP/BB/BBSControl/include/BBSControl/CommandResult.h b/CEP/BB/BBSControl/include/BBSControl/CommandResult.h new file mode 100644 index 0000000000000000000000000000000000000000..a7f08ae528fe788bc1b738ed6051c13d69ef11b0 --- /dev/null +++ b/CEP/BB/BBSControl/include/BBSControl/CommandResult.h @@ -0,0 +1,97 @@ +//# CommandResult.h: Result of execution of a command by the local controller +//# +//# Copyright (C) 2002-2004 +//# ASTRON (Netherlands Foundation for Research in Astronomy) +//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl +//# +//# This program is free software; you can redistribute it and/or modify +//# it under the terms of the GNU General Public License as published by +//# the Free Software Foundation; either version 2 of the License, or +//# (at your option) any later version. +//# +//# This program is distributed in the hope that it will be useful, +//# but WITHOUT ANY WARRANTY; without even the implied warranty of +//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//# GNU General Public License for more details. +//# +//# You should have received a copy of the GNU General Public License +//# along with this program; if not, write to the Free Software +//# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//# +//# $Id$ + +#ifndef LOFAR_BBSCONTROL_COMMANDRESULT_H +#define LOFAR_BBSCONTROL_COMMANDRESULT_H + +// \file +// Result of execution of a command by the local controller + +//# Includes +#include <Common/lofar_string.h> +#include <Common/lofar_iosfwd.h> + +namespace LOFAR +{ + namespace BBS + { + + // \addtogroup BBSControl + // @{ + + // Class representing the result of the execution of a command by the + // local controller. It encapsulates the return value (an enumerated + // value), with its associated return value as a string, and an optional + // additional error message. + class CommandResult + { + public: + // Result values that can be set by the local controller. + enum Result { + UNKNOWN = -1, ///< An unknown error occurred. + OK, ///< No errors. + OUT_OF_DATA, ///< Local controller was "Out of data" + ERROR, ///< Something definitely went wrong. + //# Insert new return values HERE !! + N_Result ///< Number of result values. + }; + + // If \a result matches with one of the enumeration values in Result, + // then itsResult is set to \a result, else itsResult is set to \c + // UNKNOWN. The optional extra message can provide a more detailed + // description of the actual error. + CommandResult(Result result = UNKNOWN, const string& msg = string()); + + // Get the return value. + Result get() const + { return itsResult; } + + // Return the user-supplied message. + const string& message() const + { return itsMessage; } + + // Return the result as a string. + const string& asString() const; + + // Return \c true if result is OK, else return \c false. + operator bool() const + { return itsResult == OK; } + + private: + // The return result + Result itsResult; + + // User-supplied optional message. + string itsMessage; + + }; + + // Output in ASCII format. + ostream& operator<<(ostream& os, const CommandResult& result); + + // @} + + } // namespace BBS + +} // namespace LOFAR + +#endif diff --git a/CEP/BB/BBSControl/include/BBSControl/Makefile.am b/CEP/BB/BBSControl/include/BBSControl/Makefile.am index 913176a34302f1c8f6fe03d9e6af441f02b681c1..90fa835aee530d19dccae20908239bf22b7ce4fb 100644 --- a/CEP/BB/BBSControl/include/BBSControl/Makefile.am +++ b/CEP/BB/BBSControl/include/BBSControl/Makefile.am @@ -17,6 +17,7 @@ pkginclude_HEADERS = \ CommandQueue.h \ CommandQueueTrigger.h \ CommandQueueTransactors.h \ + CommandResult.h \ CommandVisitor.h \ DomainRegistrationRequest.h \ Exceptions.h \ diff --git a/CEP/BB/BBSControl/src/CommandResult.cc b/CEP/BB/BBSControl/src/CommandResult.cc new file mode 100644 index 0000000000000000000000000000000000000000..c3ab110e0491b50361f3a98b49bbd65557e1e696 --- /dev/null +++ b/CEP/BB/BBSControl/src/CommandResult.cc @@ -0,0 +1,66 @@ +//# CommandResult.cc: Result of execution of a command by the local controller +//# +//# Copyright (C) 2002-2004 +//# ASTRON (Netherlands Foundation for Research in Astronomy) +//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl +//# +//# This program is free software; you can redistribute it and/or modify +//# it under the terms of the GNU General Public License as published by +//# the Free Software Foundation; either version 2 of the License, or +//# (at your option) any later version. +//# +//# This program is distributed in the hope that it will be useful, +//# but WITHOUT ANY WARRANTY; without even the implied warranty of +//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//# GNU General Public License for more details. +//# +//# You should have received a copy of the GNU General Public License +//# along with this program; if not, write to the Free Software +//# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//# +//# $Id$ + +//# Always #include <lofar_config.h> first! +#include <lofar_config.h> + +//# Includes +#include <BBSControl/CommandResult.h> +#include <Common/lofar_iostream.h> + +namespace LOFAR +{ + namespace BBS + { + + CommandResult::CommandResult(Result result, const string& msg) : + itsMessage(msg) + { + if (UNKNOWN < result && result < N_Result) itsResult = result; + else itsResult = UNKNOWN; + } + + const string& CommandResult::asString() const + { + //# Caution: Always keep this array of strings in sync with the enum + //# Result that is defined in the header file! + static const string resultString[N_Result+1] = { + "Success", + "Out-of-data", + "Error", + "Unknown error" //# This line should ALWAYS be last! + }; + if (itsResult < 0) return resultString[N_Result]; + else return resultString[itsResult]; + } + + + ostream& operator<<(ostream& os, const CommandResult& result) + { + os << result.asString(); + if (!result.message().empty()) os << ": " << result.message(); + return os; + } + + } // namespace BBS + +} // namespace LOFAR diff --git a/CEP/BB/BBSControl/src/Makefile.am b/CEP/BB/BBSControl/src/Makefile.am index d7d2357f449c0939de1f5e00f083e2d93c851d5a..f5c152744367f5742a556de0a25be1afe826a166 100644 --- a/CEP/BB/BBSControl/src/Makefile.am +++ b/CEP/BB/BBSControl/src/Makefile.am @@ -19,6 +19,7 @@ libbbscontrol_la_SOURCES = \ CommandQueueTrigger.cc \ CommandQueueTransactors.cc \ CommandQueueTrigger.cc \ + CommandResult.cc \ DomainRegistrationRequest.cc \ FinalizeCommand.cc \ GlobalProcessControl.cc \ @@ -31,18 +32,18 @@ libbbscontrol_la_SOURCES = \ SolverProcessControl.cc \ QueryBuilder/AddCommand.cc -#bin_PROGRAMS = GlobalControl KernelControl SolverControl +bin_PROGRAMS = GlobalControl KernelControl SolverControl -#GlobalControl_SOURCES = GlobalControl.cc -#GlobalControl_LDADD = libbbscontrol.la -#GlobalControl_DEPENDENCIES = libbbscontrol.la $(LOFAR_DEPEND) +GlobalControl_SOURCES = GlobalControl.cc +GlobalControl_LDADD = libbbscontrol.la +GlobalControl_DEPENDENCIES = libbbscontrol.la $(LOFAR_DEPEND) -#KernelControl_SOURCES = KernelControl.cc -#KernelControl_LDADD = libbbscontrol.la -#KernelControl_DEPENDENCIES = libbbscontrol.la $(LOFAR_DEPEND) +KernelControl_SOURCES = KernelControl.cc +KernelControl_LDADD = libbbscontrol.la +KernelControl_DEPENDENCIES = libbbscontrol.la $(LOFAR_DEPEND) -#SolverControl_SOURCES = SolverControl.cc -#SolverControl_LDADD = libbbscontrol.la -#SolverControl_DEPENDENCIES = libbbscontrol.la $(LOFAR_DEPEND) +SolverControl_SOURCES = SolverControl.cc +SolverControl_LDADD = libbbscontrol.la +SolverControl_DEPENDENCIES = libbbscontrol.la $(LOFAR_DEPEND) include $(top_srcdir)/Makefile.common