Skip to content
Snippets Groups Projects
Commit f06b5f57 authored by Ruud Overeem's avatar Ruud Overeem
Browse files

BugID: 679

Introduced 'ControllerDefines' containing a the controller-type definitions,
the Controller-errornumbers and a collection of handy routines for contructing
names and retrieving the controller properties from a name.
parent 0226b656
No related branches found
No related tags found
No related merge requests found
//# ControllerDefines.h: all kind of enumerations for controllers.
//#
//# Copyright (C) 2006
//# 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 APL_CONTROLLERDEFINES_H
#define APL_CONTROLLERDEFINES_H
namespace LOFAR {
namespace APLCommon {
// Define errornumbers the controller may return.
enum
{
CT_RESULT_NO_ERROR = 0,
CT_RESULT_UNSPECIFIED
};
// Define numbers for the controllertypes. These numbers are translated to names,
// execuables, etc in the class ControllerName.
enum {
CNTLRTYPE_NO_TYPE = 0, // no type defined yet
CNTLRTYPE_SCHEDULERCTRL, // MACscheduler
CNTLRTYPE_OBSERVATIONCTRL, // ObservationControl
CNTLRTYPE_BEAMDIRECTIONCTRL, // BeamDirectionControl
CNTLRTYPE_GROUPCTRL, // RingControl
CNTLRTYPE_STATIONCTRL, // StationControl
CNTLRTYPE_DIGITALBOARDCTRL, // DigitalBoardControl
CNTLRTYPE_BEAMCTRL, // BeamControl
CNTLRTYPE_CALIBRATIONCTRL, // CalibrationControl
CNTLRTYPE_STATIONINFRACTRL, // StationInfraControl
CNTLRTYPE_NR_TYPES // should always be the last
};
// Construct a uniq controllername from the controllerType, the instanceNr
// of the controller and the observationID.
// Note: the returned name is always the 'non-shared' name. To get the 'shared'
// name passed the result to 'sharedControllerName')
string controllerName (uint16 cntlrType,
uint16 instanceNr,
uint32 ObservationNr);
// Convert the 'non-shared controllername' to the 'shared controller' name.
string sharedControllerName (const string& controllerName);
// Return name of the executable
string getExecutable (uint16 cntlrType);
// return 'shared' bit of controllertype
bool isSharedController(uint16 cntrlType) ;
// Get the ObservationNr from the controllername.
uint32 getObservationNr (const string& ObservationName);
// Get the instanceNr from the controllername.
uint16 getInstanceNr (const string& ObservationName);
// Get the controllerType from the controllername.
int32 getControllerType (const string& ObservationName);
}; // APLCommon
}; // LOFAR
#endif
...@@ -5,6 +5,7 @@ pkginclude_HEADERS = \ ...@@ -5,6 +5,7 @@ pkginclude_HEADERS = \
APLCommonExceptions.h \ APLCommonExceptions.h \
APL_Defines.h \ APL_Defines.h \
APLUtilities.h \ APLUtilities.h \
ControllerDefines.h \
LogicalDeviceFactoryBase.h \ LogicalDeviceFactoryBase.h \
LogicalDeviceFactory.h \ LogicalDeviceFactory.h \
LogicalDevice.h \ LogicalDevice.h \
......
//# ControllerDefines.cc: Controller(name) related utilities
//#
//# Copyright (C) 2006
//# 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 <Common/LofarLogger.h>
#include <Common/StringUtil.h> // rtrim
#include <APS/ParameterSet.h> // indexValue
#include <APL/APLCommon/ControllerDefines.h>
namespace LOFAR {
namespace APLCommon {
typedef struct cntlrDefinition {
char* cntlrName;
bool shared;
} cntlrDefinition_t;
static cntlrDefinition_t controllerTable[] = {
{ "", false },
{ "MACScheduler", false },
{ "ObservationControl", false },
{ "BeamDirectionControl", true },
{ "RingControl", true },
{ "StationControl", false },
{ "DigitalBoardControl", false },
{ "BeamControl", true },
{ "CalibrationControl", true },
{ "StationInfraControl", true },
{ "", false }
};
// Construct a uniq controllername from the controllerType, the instanceNr
// of the controller and the observationID.
// Note: the returned name is always the 'non-shared' name. To get the 'shared'
// name passed the result to 'sharedControllerName')
string controllerName (uint16 cntlrType,
uint16 instanceNr,
uint32 ObservationNr)
{
ASSERTSTR (cntlrType != CNTLRTYPE_NO_TYPE && cntlrType < CNTLRTYPE_NR_TYPES,
"No controller defined with type: " << cntlrType);
return (formatString("%s(%d){%d}", controllerTable[cntlrType].cntlrName,
ObservationNr, instanceNr));
}
// Convert the 'non-shared controllername' to the 'shared controller' name.
string sharedControllerName (const string& controllerName)
{
string cName(controllerName); // destroyable copy
rtrim(cName, "{0123456789}");
return (cName);
}
// Return name of the executable
string getExecutable (uint16 cntlrType)
{
ASSERTSTR (cntlrType != CNTLRTYPE_NO_TYPE && cntlrType < CNTLRTYPE_NR_TYPES,
"No controller defined with type: " << cntlrType);
return (controllerTable[cntlrType].cntlrName);
}
// return 'shared' bit of controllertype
bool isSharedController(uint16 cntlrType)
{
ASSERTSTR (cntlrType != CNTLRTYPE_NO_TYPE && cntlrType < CNTLRTYPE_NR_TYPES,
"No controller defined with type: " << cntlrType);
return (controllerTable[cntlrType].shared);
}
// Get the ObservationNr from the controllername.
uint32 getObservationNr (const string& ObservationName)
{
return (ACC::APS::indexValue(sharedControllerName(ObservationName), "()"));
}
// Get the instanceNr from the controllername.
uint16 getInstanceNr (const string& ObservationName)
{
return (ACC::APS::indexValue(ObservationName, "{}"));
}
// Get the controllerType from the controllername.
int32 getControllerType (const string& controllerName)
{
string cntlrName(controllerName); // destroyable copy
rtrim(cntlrName, "(){}0123456789"); // cut down to executable name
uint32 idx = CNTLRTYPE_NO_TYPE + 1;
while (idx < CNTLRTYPE_NR_TYPES) {
if (!strcmp (controllerTable[idx].cntlrName, cntlrName.c_str())) {
return (idx);
}
idx++;
}
return (CNTLRTYPE_NO_TYPE);
}
} // namespace APLCommon
} // namespace LOFAR
...@@ -15,6 +15,7 @@ libaplcommon_la_CPPFLAGS = \ ...@@ -15,6 +15,7 @@ libaplcommon_la_CPPFLAGS = \
libaplcommon_la_SOURCES = \ libaplcommon_la_SOURCES = \
$(DOCHDRS) \ $(DOCHDRS) \
APLUtilities.cc \ APLUtilities.cc \
ControllerDefines.cc \
LogicalDevice.cc \ LogicalDevice.cc \
PropertySetAnswer.cc \ PropertySetAnswer.cc \
ResourceAllocator.cc \ ResourceAllocator.cc \
......
check_PROGRAMS = tControllerDefines
tControllerDefines_SOURCES = tControllerDefines.cc
tControllerDefines_LDADD = ../src/libaplcommon.la
tControllerDefines_DEPENCIES= ../src/libaplcommon.la $(LOFAR_DEPEND)
TESTSCRIPTS = tControllerDefines_test.sh
TESTS_ENVIRONMENT = lofar_sharedir=$(lofar_sharedir) \
LOFARROOT=$(LOFARROOT)
TESTS = $(TESTSCRIPTS)
EXTRA_DIST = tControllerDefines.log_prop \
ResourceAllocatorTest.log_prop \
$(TESTSCRIPTS)
noinst_PROGRAMS = \ noinst_PROGRAMS = \
ResourceAllocatorTest ResourceAllocatorTest
...@@ -22,10 +39,6 @@ INSTHDRS = ...@@ -22,10 +39,6 @@ INSTHDRS =
pkginclude_HEADERS = $(NOINSTHDRS) $(INSTHDRS) pkginclude_HEADERS = $(NOINSTHDRS) $(INSTHDRS)
sysconf_DATA = \
ResourceAllocatorTest.log_prop
EXTRA_DIST = $(BUILT_SOURCES) $(sysconf_data)
%.log_prop: %.log_prop.in %.log_prop: %.log_prop.in
cp $< $@ cp $< $@
......
//# tControllerDefines.cc
//#
//# 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 <Common/LofarLogger.h>
#include <APL/APLCommon/ControllerDefines.h>
using namespace LOFAR;
using namespace LOFAR::APLCommon;
int main (int argc, char* argv[])
{
INIT_LOGGER(argv[0]);
uint16 cntlrType(CNTLRTYPE_STATIONCTRL);
uint16 instanceNr(8);
uint32 obsNr(123);
string cntlrName = controllerName(cntlrType, instanceNr, obsNr);
LOG_INFO_STR("Controllername = " << cntlrName);
ASSERTSTR (cntlrName == "StationControl(123){8}",
"Expecting cntlrName 'StationControl(123){8}' in stead of " << cntlrName);
string sharedName = sharedControllerName(cntlrName);
LOG_INFO_STR("SharedName = " << sharedName);
ASSERTSTR (sharedName == "StationControl(123)",
"Expecting sharedName 'StationControl(123)' in stead of " << sharedName);
string execName = getExecutable(cntlrType);
LOG_INFO_STR("Executable = " << execName);
ASSERTSTR (execName == "StationControl",
"Expecting executable 'StationControl' in stead of " << execName);
ASSERTSTR (isSharedController(CNTLRTYPE_GROUPCTRL),
"Expected group controller to be shared.");
uint32 retrievedObsNr = getObservationNr(cntlrName);
LOG_INFO_STR("ObservationNr = " << retrievedObsNr);
ASSERTSTR (retrievedObsNr == obsNr,
"Expected observationNr " << obsNr << " in stead of " << retrievedObsNr);
uint32 retrievedInstanceNr = getInstanceNr(cntlrName);
LOG_INFO_STR("InstanceNr = " << retrievedInstanceNr);
ASSERTSTR (retrievedInstanceNr == instanceNr,
"Expected instanceNr " << instanceNr << " in stead of "
<< retrievedInstanceNr);
uint16 retrievedCntlrType = getControllerType(cntlrName);
LOG_INFO_STR("ControllerType = " << cntlrType);
ASSERTSTR (retrievedCntlrType == cntlrType,
"Expected controllerType " << cntlrType << " in stead of "
<< retrievedCntlrType);
LOG_INFO_STR("ObservationNr of shared name= " << getObservationNr(sharedName));
LOG_INFO_STR("InstanceNr of shared name = " << getInstanceNr(sharedName));
LOG_INFO_STR("CntlrType of shared name = " << getControllerType(sharedName));
LOG_INFO_STR("Sharedname of shared name = " << sharedControllerName(sharedName));
return (0);
}
# Configure the rootLogger
log4cplus.rootLogger=DEBUG, STDOUT
# Define the STDOUT appender
log4cplus.appender.STDOUT=log4cplus::ConsoleAppender
log4cplus.appender.STDOUT.layout=log4cplus::PatternLayout
log4cplus.appender.STDOUT.layout.ConversionPattern=%-5p [%x]%c{3} - %m%n
log4cplus.appender.STDOUT.ImmediateFlush=true
#!/bin/sh
$lofar_sharedir/runtest.sh tControllerDefines 2>&1 > tControllerDefines_test.log
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