Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

acsServiceController.h

Go to the documentation of this file.
00001 #ifndef _ACS_SERVICE_CONTROLLER_H_ 00002 #define _ACS_SERVICE_CONTROLLER_H_ 00003 00004 /******************************************************************************* 00005 * ALMA - Atacama Large Millimiter Array 00006 * (c) European Southern Observatory, 2002 00007 * Copyright by ESO (in the framework of the ALMA collaboration) 00008 * and Cosylab 2002, All rights reserved 00009 * 00010 * This library is free software; you can redistribute it and/or 00011 * modify it under the terms of the GNU Lesser General Public 00012 * License as published by the Free Software Foundation; either 00013 * version 2.1 of the License, or (at your option) any later version. 00014 * 00015 * This library is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 * Lesser General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU Lesser General Public 00021 * License along with this library; if not, write to the Free Software 00022 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00023 * 00024 * "@(#) $Id: acsServiceController.h,v 1.2 2008/11/10 20:04:46 msekoran Exp $" 00025 * 00026 * who when what 00027 * -------- -------- ---------------------------------------------- 00028 * azagar 2008-10-21 created 00029 */ 00030 00031 #include "acsRequest.h" 00032 #include <acsThreadManager.h> 00033 #include <map> 00034 00035 const ACE_Time_Value TIME_PERIOD(60); 00036 00037 class ControllerThread : public ACS::Thread { 00038 private: 00039 ACSDaemonContext *context; 00040 ACE_Thread_Mutex *m_mutex; 00041 ACE_Condition<ACE_Thread_Mutex> *m_wait; 00042 volatile bool running; 00043 public: 00044 ControllerThread(const ACE_CString &name, 00045 const ACS::TimeInterval& responseTime = ThreadBase::defaultResponseTime, 00046 const ACS::TimeInterval& sleepTime = ThreadBase::defaultSleepTime); 00047 ~ControllerThread(); 00048 void setContext(ACSDaemonContext *icontext) { context = icontext; } 00049 void onStart(); 00050 void stop(); 00051 void exit(); 00052 void runLoop() ACE_THROW_SPEC ((CORBA::SystemException, ::ACSErrTypeCommon::BadParameterEx)); 00053 }; 00054 00055 class ControlledServiceRequest; 00056 00057 class ServiceController { 00058 protected: 00059 ACSDaemonContext *context; 00060 bool autorestart; 00061 ACE_Thread_Mutex *m_mutex; 00062 acsdaemon::ServiceState state; 00063 bool active; 00064 Request *startreq, *stopreq; // last request in queue (either start or stop, not both) 00065 00066 friend class ControlledServiceRequest; 00067 // called once the request returned by createControlledServiceRequest begins stopping the service 00068 void stopping(); 00069 // called once the request returned by createControlledServiceRequest is complete 00070 void requestComplete(Request *request); 00071 virtual bool setState(acsdaemon::ServiceState istate); 00072 protected: 00073 virtual ControlledServiceRequest *createControlledServiceRequest(ACSServiceRequestType itype, acsdaemon::DaemonCallback_ptr callback = NULL) = 0; 00074 virtual acsdaemon::ServiceState getActualState() = 0; 00075 virtual void fireAlarm(acsdaemon::ServiceState state) = 0; 00076 public: 00077 ServiceController(ACSDaemonContext *icontext, bool iautorestart); 00078 virtual ~ServiceController(); 00079 ACSDaemonContext *getContext() { return context; } 00080 void restart(); 00081 bool start(acsdaemon::DaemonCallback_ptr callback = NULL) ACE_THROW_SPEC ((acsdaemonErrType::ServiceAlreadyRunningEx)); 00082 void stop(acsdaemon::DaemonCallback_ptr callback = NULL) ACE_THROW_SPEC ((acsdaemonErrType::ServiceNotRunningEx)); 00083 acsdaemon::ServiceState getLastState() { return state; } 00084 }; 00085 00086 class ControlledServiceRequest : public Request { 00087 private: 00088 ServiceController *controller; 00089 Request *request; 00090 bool delreq; 00091 bool isstopping; 00092 protected: 00093 void abort(); 00094 bool execute(); 00095 public: 00096 ControlledServiceRequest(ServiceController *icontroller, Request *irequest, bool iisstopping); 00097 ~ControlledServiceRequest(); 00098 }; 00099 00100 class ImpController; 00101 00102 class ImpRequest : public Request { 00103 private: 00104 ImpController *controller; 00105 ACE_CString command; 00106 protected: 00107 void abort() {} 00108 bool execute(); 00109 public: 00110 ImpRequest(ImpController *icontroller, ACSServiceRequestType itype, ACSServiceType iservice); 00111 }; 00112 00113 class ImpController : public ServiceController { 00114 private: 00115 ACSServiceType service; 00116 ACE_CString corbaloc; 00117 protected: 00118 ControlledServiceRequest *createControlledServiceRequest(ACSServiceRequestType itype, acsdaemon::DaemonCallback_ptr callback = NULL); 00119 acsdaemon::ServiceState getActualState(); 00120 void fireAlarm(acsdaemon::ServiceState state) {} 00121 public: 00122 ImpController(ACSDaemonContext *icontext, ACSServiceType iservice, bool iautostart = true); 00123 ACSServiceType getACSService() { return service; } 00124 void setManagerReference(const char * ref); 00125 }; 00126 00127 class ACSServiceController : public ServiceController { 00128 private: 00129 ACSServiceRequestDescription *desc; 00130 ACE_CString corbaloc; 00131 bool alarmSystemInitialized; 00132 protected: 00133 ControlledServiceRequest *createControlledServiceRequest(ACSServiceRequestType itype, acsdaemon::DaemonCallback_ptr callback = NULL); 00134 acsdaemon::ServiceState getActualState(); 00135 virtual bool setState(acsdaemon::ServiceState istate); 00136 void fireAlarm(acsdaemon::ServiceState state); 00137 public: 00138 ACSServiceController(ACSDaemonContext *icontext, ACSServiceRequestDescription *idesc, bool iautostart); 00139 ~ACSServiceController(); 00140 }; 00141 00142 class ACSDaemonContext { 00143 private: 00144 CORBA::ORB_ptr orb; 00145 ACS::ThreadManager tm; 00146 RequestProcessorThread *reqproc; 00147 ControllerThread *ctrl; 00148 ACE_Thread_Mutex *m_mutex; 00149 ServiceController **impcontrollers; 00150 ServiceController **acsservicecontrollers; 00151 std::map<const char *, ServiceController **> acsservicecontrollersmap; 00152 ServiceController *getImpController(ACSServiceType service); 00153 ServiceController *getACSServiceController(ACSServiceRequestDescription *desc); 00154 ACE_CString managerReference; 00155 void setImpControllersManagerReference(const char * ref); 00156 public: 00157 ACSDaemonContext(std::string name); 00158 ~ACSDaemonContext(); 00159 void initialize(CORBA::ORB_ptr iorb); 00160 void dispose(CORBA::ORB_ptr iorb); 00161 void processRequest(ACSServiceRequestTarget target, ACSServiceRequestType type, ACSServiceRequestDescription *desc, acsdaemon::DaemonCallback_ptr callback = NULL) ACE_THROW_SPEC ((acsdaemonErrType::ServiceAlreadyRunningEx, acsdaemonErrType::ServiceNotRunningEx)); 00162 RequestProcessorThread *getRequestProcessor() { return reqproc; } 00163 CORBA::ORB_ptr getORB() { return orb; } 00164 void checkControllers(); 00165 acsdaemon::ServiceState getACSServiceState(int instance_number, const char *name = NULL); 00166 void setManagerReference(const char * ref) { managerReference = ref; setImpControllersManagerReference(ref); }; 00167 const char * getManagerReference() const { return managerReference.is_empty() ? NULL : managerReference.c_str(); } 00168 }; 00169 00170 00171 #endif

Generated on Thu Apr 30 02:30:49 2009 for ACS C++ API by doxygen 1.3.8