Skip to content
Snippets Groups Projects
Commit ec7bb060 authored by Marcel Loose's avatar Marcel Loose :sunglasses:
Browse files

BugID: 991

Added CommandResult class.
parent 0ddc6376
No related branches found
No related tags found
No related merge requests found
//# 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
...@@ -17,6 +17,7 @@ pkginclude_HEADERS = \ ...@@ -17,6 +17,7 @@ pkginclude_HEADERS = \
CommandQueue.h \ CommandQueue.h \
CommandQueueTrigger.h \ CommandQueueTrigger.h \
CommandQueueTransactors.h \ CommandQueueTransactors.h \
CommandResult.h \
CommandVisitor.h \ CommandVisitor.h \
DomainRegistrationRequest.h \ DomainRegistrationRequest.h \
Exceptions.h \ Exceptions.h \
......
//# 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
...@@ -19,6 +19,7 @@ libbbscontrol_la_SOURCES = \ ...@@ -19,6 +19,7 @@ libbbscontrol_la_SOURCES = \
CommandQueueTrigger.cc \ CommandQueueTrigger.cc \
CommandQueueTransactors.cc \ CommandQueueTransactors.cc \
CommandQueueTrigger.cc \ CommandQueueTrigger.cc \
CommandResult.cc \
DomainRegistrationRequest.cc \ DomainRegistrationRequest.cc \
FinalizeCommand.cc \ FinalizeCommand.cc \
GlobalProcessControl.cc \ GlobalProcessControl.cc \
...@@ -31,18 +32,18 @@ libbbscontrol_la_SOURCES = \ ...@@ -31,18 +32,18 @@ libbbscontrol_la_SOURCES = \
SolverProcessControl.cc \ SolverProcessControl.cc \
QueryBuilder/AddCommand.cc QueryBuilder/AddCommand.cc
#bin_PROGRAMS = GlobalControl KernelControl SolverControl bin_PROGRAMS = GlobalControl KernelControl SolverControl
#GlobalControl_SOURCES = GlobalControl.cc GlobalControl_SOURCES = GlobalControl.cc
#GlobalControl_LDADD = libbbscontrol.la GlobalControl_LDADD = libbbscontrol.la
#GlobalControl_DEPENDENCIES = libbbscontrol.la $(LOFAR_DEPEND) GlobalControl_DEPENDENCIES = libbbscontrol.la $(LOFAR_DEPEND)
#KernelControl_SOURCES = KernelControl.cc KernelControl_SOURCES = KernelControl.cc
#KernelControl_LDADD = libbbscontrol.la KernelControl_LDADD = libbbscontrol.la
#KernelControl_DEPENDENCIES = libbbscontrol.la $(LOFAR_DEPEND) KernelControl_DEPENDENCIES = libbbscontrol.la $(LOFAR_DEPEND)
#SolverControl_SOURCES = SolverControl.cc SolverControl_SOURCES = SolverControl.cc
#SolverControl_LDADD = libbbscontrol.la SolverControl_LDADD = libbbscontrol.la
#SolverControl_DEPENDENCIES = libbbscontrol.la $(LOFAR_DEPEND) SolverControl_DEPENDENCIES = libbbscontrol.la $(LOFAR_DEPEND)
include $(top_srcdir)/Makefile.common include $(top_srcdir)/Makefile.common
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment