diff --git a/LCS/ACC/PLC/include/PLC/ProcCtrlCmdLine.h b/LCS/ACC/PLC/include/PLC/ProcCtrlCmdLine.h index d08dd7501bce8b18abb8853183ec945f86273546..dfba4ff140672d7efe5ed2070728c10b56247790 100644 --- a/LCS/ACC/PLC/include/PLC/ProcCtrlCmdLine.h +++ b/LCS/ACC/PLC/include/PLC/ProcCtrlCmdLine.h @@ -44,7 +44,7 @@ namespace LOFAR public: // Constructor. The argument \a aProcCtrl is a pointer to the "real" // Process Control object. - ProcCtrlCmdLine(ProcessControl* aProcCtrl); + explicit ProcCtrlCmdLine(ProcessControl* aProcCtrl, const string& aUniqProcName = "localCmdLineProcess"); // Start the process controller. Make a predefined sequence of calls // to ProcessController's member functions; the number of times that diff --git a/LCS/ACC/PLC/include/PLC/ProcCtrlProxy.h b/LCS/ACC/PLC/include/PLC/ProcCtrlProxy.h index ab9d1498ea4c1c2024ae5cbb7c0f169a754053b7..6cb5228c239265bd0665c7f94dd92604fb977528 100644 --- a/LCS/ACC/PLC/include/PLC/ProcCtrlProxy.h +++ b/LCS/ACC/PLC/include/PLC/ProcCtrlProxy.h @@ -89,7 +89,7 @@ namespace LOFAR // \warning Make sure that the lifetime of the "real" Process Control // object exceeds that of the ProcCtrlProxy object. Otherwise, // ProcCtrlProxy will use a dangling pointer. - ProcCtrlProxy(ProcessControl* aProcCtrl); + ProcCtrlProxy(ProcessControl* aProcCtrl, const string& aUniqProcName); // Start the process controller. Arguments can be passed in a generic // way, using a ParameterSet. This method must be implemented by the diff --git a/LCS/ACC/PLC/include/PLC/ProcCtrlRemote.h b/LCS/ACC/PLC/include/PLC/ProcCtrlRemote.h index f663749adf5d915873fd8950ccc3c2c82c1ee468..3396b06eec986f47f1f4fa44afd8b57e95cf563a 100644 --- a/LCS/ACC/PLC/include/PLC/ProcCtrlRemote.h +++ b/LCS/ACC/PLC/include/PLC/ProcCtrlRemote.h @@ -43,7 +43,7 @@ class ProcCtrlRemote : public ProcCtrlProxy public: // Constructor. The argument \a aProcCtrl is a pointer to the "real" // Process Control object. - ProcCtrlRemote(ProcessControl* aProcCtrl); + ProcCtrlRemote(ProcessControl* aProcCtrl, const string& aUniqProcName); // Start the process controller. Let it run under control of a // ProcControlServer. @@ -52,10 +52,6 @@ public: // Send metadata to the server virtual void sendResultParameters(const string& aKVlist); - // Tell how to talk to the ApplController - void setServer(ProcControlServer* aControlServer) - { itsPCServer = aControlServer; } - private: // Pointer to the server so that sendResultParameters can use it. ProcControlServer* itsPCServer; diff --git a/LCS/ACC/PLC/include/PLC/ProcessControl.h b/LCS/ACC/PLC/include/PLC/ProcessControl.h index 89d242246b508db15e2d66bc754e5afbce6378d8..34481681400a1d8b0e8c34bf5a2c33674abd8da8 100644 --- a/LCS/ACC/PLC/include/PLC/ProcessControl.h +++ b/LCS/ACC/PLC/include/PLC/ProcessControl.h @@ -59,8 +59,8 @@ public: protected: // Default constructor - explicit ProcessControl(const string& theProcessID): - itsProcID(theProcessID), itsRunState(false), itsControlProxy(0) {} + explicit ProcessControl(): + itsRunState(false), itsControlProxy(0) {} // \name Commands to control the processes. // diff --git a/LCS/ACC/PLC/src/ACCmain.cc b/LCS/ACC/PLC/src/ACCmain.cc index f1614c1b9a42b19379da29eb1391fc2292a73add..26c6e3d63b98ee1af8aed0442831ed13f7f5ee82 100644 --- a/LCS/ACC/PLC/src/ACCmain.cc +++ b/LCS/ACC/PLC/src/ACCmain.cc @@ -89,7 +89,7 @@ int ACCmain (int argc, char* orig_argv[], ProcessControl* theProcess) { string programName(basename(argv[0])); bool ACCmode(true); - int result(0); + int result(0); // Check invocation syntax: [ACC] parsetfile UniqProcesName // When we are called by ACC the first argument is ACC. @@ -121,7 +121,7 @@ int ACCmain (int argc, char* orig_argv[], ProcessControl* theProcess) { // Create the correct ProcCtrlProxy and start it. if (ACCmode) { arg.add("ProcID", argv[3]); - result = (ProcCtrlRemote(theProcess))(arg); + result = (ProcCtrlRemote(theProcess, argv[3]))(arg); } else { if (argc > 1) { diff --git a/LCS/ACC/PLC/src/ProcCtrlCmdLine.cc b/LCS/ACC/PLC/src/ProcCtrlCmdLine.cc index fac64fb40dfab3aec6b7aa74756296143c5c858f..3356615cf9fdae74f49d66d33802738699d28ee5 100644 --- a/LCS/ACC/PLC/src/ProcCtrlCmdLine.cc +++ b/LCS/ACC/PLC/src/ProcCtrlCmdLine.cc @@ -39,8 +39,8 @@ namespace LOFAR //## -------- P u b l i c m e t h o d s -------- ##// - ProcCtrlCmdLine::ProcCtrlCmdLine(ProcessControl* aProcCtrl) : - ProcCtrlProxy(aProcCtrl) + ProcCtrlCmdLine::ProcCtrlCmdLine(ProcessControl* aProcCtrl, const string& aUniqProcName) : + ProcCtrlProxy(aProcCtrl, aUniqProcName) { LOG_TRACE_FLOW(AUTO_FUNCTION_NAME); } diff --git a/LCS/ACC/PLC/src/ProcCtrlProxy.cc b/LCS/ACC/PLC/src/ProcCtrlProxy.cc index f3b6946cdf4c72089b42497c09a676aff148fd8b..9c477747c76db6f5a2ffb89ef1fe7d97388b469f 100644 --- a/LCS/ACC/PLC/src/ProcCtrlProxy.cc +++ b/LCS/ACC/PLC/src/ProcCtrlProxy.cc @@ -114,12 +114,13 @@ void ProcCtrlProxy::clearRunState() //## -------- P r o t e c t e d m e t h o d s -------- ##// -ProcCtrlProxy::ProcCtrlProxy(ProcessControl* aProcCtrl) : +ProcCtrlProxy::ProcCtrlProxy(ProcessControl* aProcCtrl, const string& aUniqProcName) : itsProcCtrl(aProcCtrl) { LOG_TRACE_FLOW(AUTO_FUNCTION_NAME); itsProcCtrl->itsControlProxy = this; + itsProcCtrl->itsProcID = aUniqProcName; } void ProcCtrlProxy::sendResultParameters(const string& keyList) diff --git a/LCS/ACC/PLC/src/ProcCtrlRemote.cc b/LCS/ACC/PLC/src/ProcCtrlRemote.cc index e9d85f6cd89d3ed23b6a51e7afde9139387926ab..1894d6d414725b21ed28705a2edb0a8c461bf1db 100644 --- a/LCS/ACC/PLC/src/ProcCtrlRemote.cc +++ b/LCS/ACC/PLC/src/ProcCtrlRemote.cc @@ -37,8 +37,8 @@ using LOFAR::ParameterSet; // // ProcCtrlRemote(PC*) // -ProcCtrlRemote::ProcCtrlRemote(ProcessControl* aProcCtrl) : - ProcCtrlProxy(aProcCtrl), +ProcCtrlRemote::ProcCtrlRemote(ProcessControl* aProcCtrl, const string& aUniqProcName) : + ProcCtrlProxy(aProcCtrl, aUniqProcName), itsPCServer(0) { LOG_TRACE_FLOW(AUTO_FUNCTION_NAME); @@ -51,7 +51,7 @@ int ProcCtrlRemote::operator()(const ParameterSet& arg) { LOG_TRACE_LIFETIME(TRACE_LEVEL_FLOW, ""); - string prefix = globalParameterSet()->getString("_parsetPrefix"); + string prefix = globalParameterSet()->getString("_parsetPrefix"); // connect to Application Controller itsPCServer = new ProcControlServer(globalParameterSet()->getString(prefix+"_ACnode"), diff --git a/MAC/APL/CEPCU/test/ApplController/APCmdImpl.cc b/LCS/ACC/PLC/test/APCmdImpl.cc similarity index 97% rename from MAC/APL/CEPCU/test/ApplController/APCmdImpl.cc rename to LCS/ACC/PLC/test/APCmdImpl.cc index ff96d7ddfe7af4a097a2ed9ab25b8af967aecafc..90566b1977266d539de0c88d820b0910bd98560e 100644 --- a/MAC/APL/CEPCU/test/ApplController/APCmdImpl.cc +++ b/LCS/ACC/PLC/test/APCmdImpl.cc @@ -32,8 +32,8 @@ namespace LOFAR { namespace ACC { -APCmdImpl::APCmdImpl(const string& aProcessID) : - ProcessControl(aProcessID), +APCmdImpl::APCmdImpl() : + ProcessControl(), itsRunCounter(0) {} diff --git a/MAC/APL/CEPCU/test/ApplController/APCmdImpl.h b/LCS/ACC/PLC/test/APCmdImpl.h similarity index 97% rename from MAC/APL/CEPCU/test/ApplController/APCmdImpl.h rename to LCS/ACC/PLC/test/APCmdImpl.h index 51c38e1f4e899aaa58f48464bfa34c8f1c28fce3..bdaf177f7d4154375e1b70991016d17bedd0239f 100644 --- a/MAC/APL/CEPCU/test/ApplController/APCmdImpl.h +++ b/LCS/ACC/PLC/test/APCmdImpl.h @@ -40,7 +40,7 @@ class APCmdImpl : public ProcessControl { public: // Default constructable - explicit APCmdImpl(const string& aProcessID); + APCmdImpl(); // Destructor virtual ~APCmdImpl(); diff --git a/LCS/ACC/PLC/test/CMakeLists.txt b/LCS/ACC/PLC/test/CMakeLists.txt index 2252dbf9d887333afd3136412ff1536fe4213447..3484154b5c4b071b3e72474c895c7bf9915a658a 100644 --- a/LCS/ACC/PLC/test/CMakeLists.txt +++ b/LCS/ACC/PLC/test/CMakeLists.txt @@ -6,3 +6,4 @@ set(CHECK_PROGRAMS foreach(prog ${CHECK_PROGRAMS}) lofar_add_executable(${prog} ${prog}.cc) endforeach(prog ${CHECK_PROGRAMS}) +lofar_add_executable(tACCmain tACCmain.cc APCmdImpl.cc) diff --git a/LCS/ACC/PLC/test/Makefile.am b/LCS/ACC/PLC/test/Makefile.am index 7820a48a1796ed86de4829cf9bda35bb4c869db1..7504bd61bac8545d334306b42c20abd812c4082c 100644 --- a/LCS/ACC/PLC/test/Makefile.am +++ b/LCS/ACC/PLC/test/Makefile.am @@ -1,7 +1,9 @@ -check_PROGRAMS = tPCCmd +check_PROGRAMS = tPCCmd tACCmain tPCCmd_SOURCES = tPCCmd.cc +tACCmain_SOURCES = tACCmain.cc APCmdImpl.cc + LDADD = ../src/libplc.la DEPENDENCIES = ../src/libplc.la $(LOFAR_DEPEND) diff --git a/LCS/ACC/PLC/test/tACCmain.cc b/LCS/ACC/PLC/test/tACCmain.cc new file mode 100644 index 0000000000000000000000000000000000000000..0d2147712c72ad3ca5a2fbd9e05c8e36a5320112 --- /dev/null +++ b/LCS/ACC/PLC/test/tACCmain.cc @@ -0,0 +1,55 @@ +//# tACCMain.cc: testproces to test ACCmain +//# +//# 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> +#include <PLC/ACCmain.h> +#include <Common/LofarLogger.h> +#include <Common/LofarLocators.h> +#include "APCmdImpl.h" + +using namespace LOFAR; +using namespace LOFAR::ACC; +using namespace LOFAR::ACC::PLC; + +int main(int argc, char *argv[]) +{ + // Always bring up the logger first + ConfigLocator aCL; + string progName(basename(argv[0])); +#ifdef HAVE_LOG4CPLUS + string logPropFile(progName + ".log_prop"); + INIT_VAR_LOGGER (aCL.locate(logPropFile).c_str(), progName + "-" + argv[3]); +#else + string logPropFile(progName + ".debug"); + INIT_LOGGER (aCL.locate(logPropFile).c_str()); +#endif + + try { + LOFAR::ACC::APCmdImpl myProcessImpl; + return (LOFAR::ACC::PLC::ACCmain(argc, argv, &myProcessImpl)); + } //try + catch(...) { + std::cerr << "** PROBLEM **: Unhandled exception caught." << std::endl; + return -3; + } +} diff --git a/MAC/APL/CEPCU/test/ApplController/APTest.log_prop b/LCS/ACC/PLC/test/tACCmain.log_prop similarity index 100% rename from MAC/APL/CEPCU/test/ApplController/APTest.log_prop rename to LCS/ACC/PLC/test/tACCmain.log_prop diff --git a/MAC/APL/CEPCU/test/ApplController/APTest.cc b/MAC/APL/CEPCU/test/ApplController/APTest.cc deleted file mode 100644 index 13f56ded528ab58e76be526171344cdf0452b4a5..0000000000000000000000000000000000000000 --- a/MAC/APL/CEPCU/test/ApplController/APTest.cc +++ /dev/null @@ -1,189 +0,0 @@ -//# APTest.cc: Example program how a Application Process should respond. -//# -//# Copyright (C) 2002-2005 -//# 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 <time.h> -#include <libgen.h> -#include <stdlib.h> /// srand -#include <Common/LofarLogger.h> -#include <Common/LofarLocators.h> -#include <PLC/ProcControlServer.h> -#include <PLC/ProcCtrlRemote.h> -#include <Common/ParameterSet.h> -#include <APCmdImpl.h> - -using namespace LOFAR; -using namespace LOFAR::ACC; -using namespace LOFAR::ACC::PLC; - -// -// This program demonstrates how an Application Process should communicate -// with the Application Controller. It shows the minimal implementation possible: -// [A] Connect to the AC. -// [B] Register at the AC so we receive messages. -// [C] See if the are new messages arrived. -// [D] Dispatch the message to the right routine in our APCmdImpl. -// [E] Unregister at the AC. -// -// The places where other program code should be added are marked with -// IMPLEMENT. -// -// Note: The structure of the program is conform the MAIN.cc template. -// -// argv[0] : name executable. -// argv[1] : ACC. -// argv[2] : full name of parset file. -// argv[3] : uniq process-name. (equal to _processName key) -// -int main (int argc, char *argv[]) { - - // Always bring up the logger first - ConfigLocator aCL; - string progName(basename(argv[0])); -#ifdef HAVE_LOG4CPLUS - string logPropFile(progName + ".log_prop"); - INIT_VAR_LOGGER (aCL.locate(logPropFile).c_str(), progName + "-" + argv[3]); -#else - string logPropFile(progName + ".debug"); - INIT_LOGGER (aCL.locate(logPropFile).c_str()); -#endif - // Check invocation syntax - if (argc < 3) { - LOG_FATAL_STR("Invocation error, syntax: " << progName << - " ACC parameterfile"); - return (-1); - } - - LOG_INFO_STR("Starting up: " << argv[0] << "(" << argv[2] << ")"); - - try { - // --- begin of example code --- - - // Read in parameterfile and get my name - ParameterSet itsParamSet(argv[2]); // may throw - string itsProcID = itsParamSet.getString("_processName"); - string itsPrefix = itsParamSet.getString("_parsetPrefix"); - - // Create a APCmdImpl object. This object contains the real - // implementation of the commands we should support. - ProcessControl* itsAPCmdImpl = new APCmdImpl(itsProcID); - - // Create a proxy to talk to the ApplController. - ProcCtrlProxy* itsProxy = new ProcCtrlRemote(itsAPCmdImpl); - ASSERTSTR(itsProxy, "Unable to create a ProcessControlProxy"); - - // [A] Connect to the Application Controller - ProcControlServer itsPCcomm(itsParamSet.getString(itsPrefix+"_ACnode"), - itsParamSet.getUint16(itsPrefix+"_ACport"), - itsProxy); - - // Tell proxy how to talk to the ApplController. - ((ProcCtrlRemote*)(itsProxy))->setServer(&itsPCcomm); - - // IMPLEMENT: do other launch activities like processing the ParamSet - // TEST: init random generator with some value for testing - uint32 seed = 0; - for (uint16 i = 0; i < itsProcID.length(); ++i) { - seed += itsProcID.data()[i]; - } - srand(seed); - sleep(rand() % 5); // simulate we are busy - - // [B] Tell AC we are ready for commands - itsPCcomm.registerAtAC(itsProcID); - - // Main processing loop - bool quiting(false); - while (!quiting) { - // [C] scan AC port to see if a new command was sent. - if (itsPCcomm.pollForMessage()) { - // get pointer to received data - DH_ProcControl* newMsg = itsPCcomm.getDataHolder(); - - // we can update our runstate here if we like - quiting = (newMsg->getCommand() == PCCmdQuit); - - // TEST: simulate we are busy - sleep (rand()%4); - - // [D] let PCcomm dispatch and handle the message - itsPCcomm.handleMessage(newMsg); - } - else { - // no new message was received, do another run if we are in - // the run state - if (((APCmdImpl*)(itsAPCmdImpl))->inRunState()) { - itsPCcomm.handleMessage(&DH_ProcControl(PCCmdRun)); - } - } - - // TEST: once in a while report some intermediate results - if ((rand()%10) == 0) { - ParameterSet resultSet; - string resultBuffer; - resultSet.add(KVpair(itsProcID+".interimresult", - string("He where is my Apple?"), - true)); - resultSet.writeBuffer(resultBuffer); - itsPCcomm.sendResultParameters(resultBuffer); - } - - sleep(1); - - // IMPLEMENT: do other stuff - - } - - LOG_INFO_STR("Shutting down: " << argv[0]); - - // IMPLEMENT: do all neccesary shutdown actions. - - // [E] unregister at AC and send last results - // As an example only 1 KV pair is returned but it is allowed to pass - // a whole parameterset. - ParameterSet resultSet; - string resultBuffer; - resultSet.add(KVpair(itsProcID+".result", - string("IMPLEMENT useful information"), - true)); - resultSet.writeBuffer(resultBuffer); // convert to stringbuffer - itsPCcomm.unregisterAtAC(resultBuffer); // send to AC before quiting - - // TEST: simulate we are busy. - sleep (3); - - // --- end of example code --- - } - catch (Exception& ex) { - LOG_FATAL_STR("Caught exception: " << ex << endl); - LOG_FATAL_STR(argv[0] << " terminated by exception!"); - return(1); - } - - - LOG_INFO_STR(argv[0] << " terminated normally"); - return (0); -} - diff --git a/MAC/APL/CEPCU/test/ApplController/CMakeLists.txt b/MAC/APL/CEPCU/test/ApplController/CMakeLists.txt index d98a7c5b4f8d66cf9a690f9d1d996c73ac7d9778..8fcf46ab1c2113e5e10cd124c1c775580be8e3e3 100644 --- a/MAC/APL/CEPCU/test/ApplController/CMakeLists.txt +++ b/MAC/APL/CEPCU/test/ApplController/CMakeLists.txt @@ -20,4 +20,3 @@ include(LofarCTest) -lofar_add_test(APTest APTest.cc APCmdImpl.cc) diff --git a/MAC/APL/CEPCU/test/ApplController/Makefile.am b/MAC/APL/CEPCU/test/ApplController/Makefile.am index 0c035ecfc4557ae79471e07f2827e60f228e8975..d8abe58ef07a9bb0cb00b0afd6a01c77d624c154 100644 --- a/MAC/APL/CEPCU/test/ApplController/Makefile.am +++ b/MAC/APL/CEPCU/test/ApplController/Makefile.am @@ -1,12 +1,7 @@ -bin_PROGRAMS = APTest -sysconf_DATA = APTest.log_prop +bin_PROGRAMS = +sysconf_DATA = TESTS = -### APTest ### -APTest_SOURCES = APCmdImpl.cc APTest.cc -APTest_DEPENDENCIES = $(LOFAR_DEPEND) APCmdImpl.h -APTest_LDADD = - include $(top_srcdir)/Makefile.common