From f06b5f572966d73849fa2190e7b3fdcfc5a0fc3d Mon Sep 17 00:00:00 2001 From: Ruud Overeem <overeem@astron.nl> Date: Tue, 13 Jun 2006 13:17:13 +0000 Subject: [PATCH] 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. --- .../include/APL/APLCommon/ControllerDefines.h | 82 +++++++++++ .../include/APL/APLCommon/Makefile.am | 1 + MAC/APL/APLCommon/src/ControllerDefines.cc | 127 ++++++++++++++++++ MAC/APL/APLCommon/src/Makefile.am | 1 + MAC/APL/APLCommon/test/Makefile.am | 21 ++- MAC/APL/APLCommon/test/tControllerDefines.cc | 83 ++++++++++++ .../test/tControllerDefines.log_prop | 9 ++ .../APLCommon/test/tControllerDefines_test.sh | 2 + 8 files changed, 322 insertions(+), 4 deletions(-) create mode 100644 MAC/APL/APLCommon/include/APL/APLCommon/ControllerDefines.h create mode 100644 MAC/APL/APLCommon/src/ControllerDefines.cc create mode 100644 MAC/APL/APLCommon/test/tControllerDefines.cc create mode 100644 MAC/APL/APLCommon/test/tControllerDefines.log_prop create mode 100755 MAC/APL/APLCommon/test/tControllerDefines_test.sh diff --git a/MAC/APL/APLCommon/include/APL/APLCommon/ControllerDefines.h b/MAC/APL/APLCommon/include/APL/APLCommon/ControllerDefines.h new file mode 100644 index 00000000000..b15a7b725d0 --- /dev/null +++ b/MAC/APL/APLCommon/include/APL/APLCommon/ControllerDefines.h @@ -0,0 +1,82 @@ +//# 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 diff --git a/MAC/APL/APLCommon/include/APL/APLCommon/Makefile.am b/MAC/APL/APLCommon/include/APL/APLCommon/Makefile.am index 015f9752d9e..6925693f360 100644 --- a/MAC/APL/APLCommon/include/APL/APLCommon/Makefile.am +++ b/MAC/APL/APLCommon/include/APL/APLCommon/Makefile.am @@ -5,6 +5,7 @@ pkginclude_HEADERS = \ APLCommonExceptions.h \ APL_Defines.h \ APLUtilities.h \ + ControllerDefines.h \ LogicalDeviceFactoryBase.h \ LogicalDeviceFactory.h \ LogicalDevice.h \ diff --git a/MAC/APL/APLCommon/src/ControllerDefines.cc b/MAC/APL/APLCommon/src/ControllerDefines.cc new file mode 100644 index 00000000000..1dc4bf0839b --- /dev/null +++ b/MAC/APL/APLCommon/src/ControllerDefines.cc @@ -0,0 +1,127 @@ +//# 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 + + + diff --git a/MAC/APL/APLCommon/src/Makefile.am b/MAC/APL/APLCommon/src/Makefile.am index cd4f7704f1c..cbf3828d049 100644 --- a/MAC/APL/APLCommon/src/Makefile.am +++ b/MAC/APL/APLCommon/src/Makefile.am @@ -15,6 +15,7 @@ libaplcommon_la_CPPFLAGS = \ libaplcommon_la_SOURCES = \ $(DOCHDRS) \ APLUtilities.cc \ + ControllerDefines.cc \ LogicalDevice.cc \ PropertySetAnswer.cc \ ResourceAllocator.cc \ diff --git a/MAC/APL/APLCommon/test/Makefile.am b/MAC/APL/APLCommon/test/Makefile.am index 5c056f6ecf2..86a34c47198 100755 --- a/MAC/APL/APLCommon/test/Makefile.am +++ b/MAC/APL/APLCommon/test/Makefile.am @@ -1,3 +1,20 @@ +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 = \ ResourceAllocatorTest @@ -22,10 +39,6 @@ INSTHDRS = pkginclude_HEADERS = $(NOINSTHDRS) $(INSTHDRS) -sysconf_DATA = \ - ResourceAllocatorTest.log_prop - -EXTRA_DIST = $(BUILT_SOURCES) $(sysconf_data) %.log_prop: %.log_prop.in cp $< $@ diff --git a/MAC/APL/APLCommon/test/tControllerDefines.cc b/MAC/APL/APLCommon/test/tControllerDefines.cc new file mode 100644 index 00000000000..a83ca3fd051 --- /dev/null +++ b/MAC/APL/APLCommon/test/tControllerDefines.cc @@ -0,0 +1,83 @@ +//# 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); +} + diff --git a/MAC/APL/APLCommon/test/tControllerDefines.log_prop b/MAC/APL/APLCommon/test/tControllerDefines.log_prop new file mode 100644 index 00000000000..15bfe2a4055 --- /dev/null +++ b/MAC/APL/APLCommon/test/tControllerDefines.log_prop @@ -0,0 +1,9 @@ +# 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 + diff --git a/MAC/APL/APLCommon/test/tControllerDefines_test.sh b/MAC/APL/APLCommon/test/tControllerDefines_test.sh new file mode 100755 index 00000000000..de0eddeb17b --- /dev/null +++ b/MAC/APL/APLCommon/test/tControllerDefines_test.sh @@ -0,0 +1,2 @@ +#!/bin/sh +$lofar_sharedir/runtest.sh tControllerDefines 2>&1 > tControllerDefines_test.log -- GitLab