/*----------------------------------------------------------------------------* * Copyright (c) 2005 Southeastern Universities Research Association, * * Thomas Jefferson National Accelerator Facility * * * * This software was developed under a United States Government license * * described in the NOTICE file included as part of this distribution. * * * * E.Wolin, 25-Feb-2005, Jefferson Lab * * * * Authors: Elliott Wolin * * wolin@jlab.org Jefferson Lab, MS-6B * * Phone: (757) 269-7365 12000 Jefferson Ave. * * Fax: (757) 269-5519 Newport News, VA 23606 * * *----------------------------------------------------------------------------*/ #ifndef _CodaObject_hxx #define _CodaObject_hxx #include #include #include #include #include #include #include #include #define MIN(a,b) ((a)<(b))?(a):(b) #define MAX(a,b) ((a)>(b))?(a):(b) // for daLogMsg #define DALOG_INFO 1 #define DALOG_WARN 5 #define DALOG_ERROR 9 #define DALOG_SEVERE 13 /** * The entire codaObject package resides in the codaObject namespace. */ namespace codaObject { using namespace std; using namespace cmsg; /** * @mainpage codaObject Package * @author Elliott Wolin * @version 0.9beta * @date 21-Feb-2007 * * @section intro Introduction. * The codaObject package is an object-oriented framework for building DAQ components that can interact with the * CODA run control facility. * * Software compontents participating in a run control session can be * built from one of a number of coda objects in an inheritance * hierarchy, depending on the functionality required. The hierarchy contains the following objects: * * CodaObject implements basic communications with run control, but cannot be owned or controlled. * As far as run control is concerned a CodaObject can only respond to queries. * * SessionObject adds the notion of session ownership and basic control to CodaObject. * * RunObject is a SessionObject that can participate in run control transitions. * * InterruptibleObject introduces interrupt capability to RunObject via an InterruptService object. A number of * kinds of InterrruptService classes are provided. * * No main program is provided. Developers write classes that extend the * classes in this package, and provide their own main program. * See the example programs in the test and exesrc directories. */ //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- /** * Allows pthread_create() to dispatch to an object member function that takes a single argument, used internally. * * Static function dispatchIt() is actually given to pthread_create(). The pthread_create() user arg is a pointer to * this dispatcher object, which contains all info needed to dispatch correctly. */ template class pthreadDispatcher { public: C *c; /**(pthreadArg); pthread_exit((void*)(((pd->c)->*(pd->mfp))(pd->mfArg))); return(NULL); } }; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- /** * Base class for all CODA objects implements standard functionality. * Connects to run control system, sets up basic callbacks, etc. * * CodaObjects have a state than can spontaneously change due to external causes. * * NOTE: CodaObjects are by design NOT controllable by the run control * system! Use SessionObject if you need to own and control the object. * As far as run control is concerned, a CodaObject can only respond * to queries. */ class CodaObject { public: CodaObject(const string& UDL, const string& name, const string& descr, const string &codaClass = "user", const cMsgSubscriptionConfig *scfg = NULL, int connTimeout = 10) throw(CodaException); virtual ~CodaObject(void) throw(); protected: virtual void sendResponse(const cMsgMessage *msg, const string& subject, const string& type, const string& text, int userInt) const throw(CodaException); virtual void userMsgHandler(const cMsgMessage *msg, void *userArg) throw(CodaException); virtual string userStatus(void) const throw(); public: void daLogMsg(const string& text, int sevid, const string& daLogSubj="") const throw(CodaException); virtual void startProcessing(void) throw(CodaException); virtual void stopProcessing(void) throw(CodaException); string getObjectType(void) const throw(); string getCodaClass(void) const throw(); string getEXPID(void) const throw(); string getHostName(void) const throw(); string getUserName(void) const throw(); string getState(void) const throw(); public: virtual string getStatus(void) const throw(); void changeState(const string& newState) throw(CodaException); private: void codaObjectCallback(cMsgMessage *msg, void* userArg) throw(CodaException); string checkCodaClass(const string &cClass) const throw(); protected: virtual void daLogMsgFill(cMsgMessage &msg, const string& text, int sevid) const throw(CodaException); protected: string UDL; /**