• Classes
  • Modules
  • Namespaces
  • Files
  • Related Pages
  • File List
  • File Members

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.12 2012/05/17 09:24:30 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 #include <string>
00035 #include <AcsAlarmSystemC.h>
00036 #include <acsdaemonC.h>
00037 
00038 const ACE_Time_Value TIME_PERIOD(15);
00039 
00040 class DetailedServiceStateProvider {
00041   public:
00042     virtual ~DetailedServiceStateProvider() {};
00043     virtual acsdaemon::ServiceState getDetailedServiceState(ACSServiceRequestDescription *desc, CORBA::Object_ptr obj) = 0;
00044 };
00045 
00046 class ControllerThread : public ACS::Thread {
00047   private:
00048     ACSDaemonContext *context;
00049     ACE_Thread_Mutex *m_mutex;
00050     ACE_Condition<ACE_Thread_Mutex> *m_wait;
00051     volatile bool running;
00052   public:
00053     ControllerThread(const ACE_CString &name,
00054            const ACS::TimeInterval& responseTime = ThreadBase::defaultResponseTime, 
00055            const ACS::TimeInterval& sleepTime = ThreadBase::defaultSleepTime);
00056     ~ControllerThread();
00057     void setContext(ACSDaemonContext *icontext) { context = icontext; }
00058     void onStart();
00059     void stop();
00060     void exit();
00061     void runLoop() throw(CORBA::SystemException, ::ACSErrTypeCommon::BadParameterEx);
00062 };
00063 
00064 class ControlledServiceRequest;
00065 
00066 class ServiceController {
00067   protected:
00068     ACSDaemonContext *context;
00069     bool autorestart;
00070     ACE_Thread_Mutex *m_mutex;
00071     volatile acsdaemon::ServiceState state;
00072     volatile bool active;
00073     Request *startreq, *stopreq; // last request in queue (either start or stop, not both)
00074 
00075     friend class ControlledServiceRequest;
00076     // called once the request returned by createControlledServiceRequest begins stopping the service
00077     void stopping();
00078     // called once the request returned by createControlledServiceRequest is complete
00079     void requestComplete(Request *request);
00080     virtual bool setState(acsdaemon::ServiceState istate);
00081   protected:
00082     virtual ControlledServiceRequest *createControlledServiceRequest(ACSServiceRequestType itype, acsdaemon::DaemonCallback_ptr callback = NULL) = 0;
00083     virtual acsdaemon::ServiceState getActualState() = 0;
00084     virtual void fireAlarm(acsdaemon::ServiceState state) = 0;
00085   public:
00086     virtual ACE_CString getServiceName() = 0;
00087     ServiceController(ACSDaemonContext *icontext, bool iautorestart);
00088     virtual ~ServiceController();
00089     ACSDaemonContext *getContext() { return context; }
00090     void restart();
00091     bool start(acsdaemon::DaemonCallback_ptr callback = NULL) throw(acsdaemonErrType::ServiceAlreadyRunningEx);
00092     void stop(acsdaemon::DaemonCallback_ptr callback = NULL) throw(acsdaemonErrType::ServiceNotRunningEx);
00093     acsdaemon::ServiceState getLastState() { return state; }
00094 };
00095 
00096 class ControlledServiceRequest : public Request {
00097   private:
00098     ServiceController *controller;
00099     Request *request;
00100     bool delreq;
00101     bool isstopping;
00102   protected:
00103     void abort();
00104     bool execute();
00105   public:
00106     ControlledServiceRequest(ServiceController *icontroller, Request *irequest, bool iisstopping);
00107     ~ControlledServiceRequest();
00108 };
00109 
00110 class ImpController;
00111 
00112 class ImpRequest : public Request {
00113   private:
00114     ImpController *controller;
00115     ACE_CString command;
00116   protected:
00117     void abort() {}
00118     bool execute();
00119   public:
00120     ImpRequest(ImpController *icontroller, ACSServiceRequestType itype, ACSServiceType iservice);
00121 };
00122 
00123 class ImpController : public ServiceController {
00124   private:
00125     ACSServiceType service;
00126     ACE_CString corbaloc;
00127     bool firstCheck;
00128   protected:
00129     ControlledServiceRequest *createControlledServiceRequest(ACSServiceRequestType itype, acsdaemon::DaemonCallback_ptr callback = NULL);
00130     acsdaemon::ServiceState getActualState();
00131     void fireAlarm(acsdaemon::ServiceState state) {}
00132   public:
00133     ImpController(ACSDaemonContext *icontext, ACSServiceType iservice, bool iautostart = true);
00134     ACSServiceType getACSService() { return service; }
00135     virtual ACE_CString getServiceName();
00136     void setConfigurationReference(const short instance_number, const acsdaemon::ServiceInfoSeq & services_info);
00137 };
00138 
00139 class ACSServiceController : public ServiceController {
00140   private:
00141     ACSServiceRequestDescription *desc;
00142     ACE_CString corbaloc;
00143     bool alarmSystemInitialized;
00144     ::alarmsystem::AlarmService_var alarmService;
00145  protected:
00146     ControlledServiceRequest *createControlledServiceRequest(ACSServiceRequestType itype, acsdaemon::DaemonCallback_ptr callback = NULL);
00147     acsdaemon::ServiceState getActualState();
00148     virtual bool setState(acsdaemon::ServiceState istate);
00149     void fireAlarm(acsdaemon::ServiceState state);
00150   public:
00151     ACSServiceController(ACSDaemonContext *icontext, ACSServiceRequestDescription *idesc, bool iautostart);
00152     virtual ACE_CString getServiceName();
00153     ~ACSServiceController();
00154 };
00155 
00156 class ACSDaemonContext {
00157   private:
00158     CORBA::ORB_ptr orb;
00159     ACS::ThreadManager tm;
00160     RequestProcessorThread *reqproc;
00161     ControllerThread *ctrl;
00162     ACE_Thread_Mutex *m_mutex;
00163     ACE_Recursive_Thread_Mutex m_configMutex;
00164     ServiceController **impcontrollers;
00165     ServiceController **acsservicecontrollers;
00166     std::map<std::string, ServiceController **> acsservicecontrollersmap;
00167     ServiceController *getImpController(ACSServiceType service);
00168     ServiceController *getACSServiceController(ACSServiceRequestDescription *desc);
00169     std::map<short, ::acsdaemon::ServiceInfoSeq> configurationReferences;
00170     DetailedServiceStateProvider *detailedServiceStateProvider;
00171     void setImpControllersConfigurationReference(const short instance_number, const ::acsdaemon::ServiceInfoSeq & services_info);
00172   public:
00173     ACSDaemonContext(std::string name, DetailedServiceStateProvider *dssp = NULL);
00174     ~ACSDaemonContext();
00175     void initialize(CORBA::ORB_ptr iorb);
00176     void dispose(CORBA::ORB_ptr iorb);
00177     void processRequest(ACSServiceRequestTarget target, ACSServiceRequestType type, ACSServiceRequestDescription *desc, acsdaemon::DaemonCallback_ptr callback = NULL) throw(acsdaemonErrType::ServiceAlreadyRunningEx, acsdaemonErrType::ServiceNotRunningEx);
00178     RequestProcessorThread *getRequestProcessor() { return reqproc; }
00179     CORBA::ORB_ptr getORB() { return orb; }
00180     void checkControllers();
00181     acsdaemon::ServiceState getACSServiceState(int instance_number, const char *name = NULL);
00182     acsdaemon::ServiceState getDetailedServiceState(ACSServiceRequestDescription *desc, CORBA::Object_ptr obj) const {
00183         return detailedServiceStateProvider ? detailedServiceStateProvider->getDetailedServiceState(desc, obj) : acsdaemon::RUNNING; };
00184     void setConfigurationReference(const short instance_number, const ::acsdaemon::ServiceInfoSeq & services_info);
00185     ::acsdaemon::ServiceInfoSeq getConfigurationReference(const short instance_number);
00186     std::string getConfigurationReference(const short instance_number, const char* service_type);
00187     bool hasConfigurationReference(const short instance_number);
00188     bool hasConfigurationReference(const short instance_number, const char* service_type);
00189 };
00190 
00191 
00192 #endif

Generated on Mon May 4 2015 08:27:41 for ACS-2015.4 C++ API by  doxygen 1.7.0