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

acsRequest.h

Go to the documentation of this file.
00001 #ifndef _ACS_REQUEST_H_ 00002 #define _ACS_REQUEST_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: acsRequest.h,v 1.3 2008/11/04 14:50:15 msekoran Exp $" 00025 * 00026 * who when what 00027 * -------- -------- ---------------------------------------------- 00028 * azagar 2008-08-12 created 00029 */ 00030 00031 #include "acsdaemonS.h" 00032 #include <acsThread.h> 00033 #include <acsutilPorts.h> 00034 #include <queue> 00035 #include <memory> 00036 00037 // callback call timeout 00038 #define CORBA_TIMEOUT 5000 00039 00040 /*** exit codes of startup/shutdown scripts ***/ 00041 // all fine 00042 #define EC_OK 0 00043 // can't create requested acs instance: already exists 00044 #define EC_CANNOTCREATE 40 00045 // can't use requested acs instance: doesn't exist or is owned by somebody else 00046 #define EC_CANNOTUSE 41 00047 // general failure, no details known 00048 #define EC_FAILURE 42 00049 // command line arguments wrong or missing 00050 #define EC_BADARGS 43 00051 // can't run requested servant: no port available 00052 #define EC_NOPORT 44 00053 // can't run requested servant: launch attempt timed out 00054 #define EC_TIMEOUT 45 00055 00056 struct ACSService { 00057 const char *xmltag; 00058 const char *script; 00059 const char *impname; // Name of services handler (used for logging purposes) 00060 const char *imptype; // CORBA-type for this services handler 00061 const char *impport; 00062 const char *impexec; 00063 const char *svccorbaurl; 00064 std::string (*svcport)(int); 00065 std::string (*namedsvcport)(int, const char *); 00066 bool autorestart; // Should ACS service automatically restart 00067 }; 00068 00069 enum ACSServiceType { 00070 NAMING_SERVICE = 0, 00071 NOTIFICATION_SERVICE, 00072 CDB, 00073 MANAGER, 00074 ACS_LOG_SERVICE, 00075 LOGGING_SERVICE, 00076 INTERFACE_REPOSITORY, 00077 UNKNOWN 00078 }; 00079 00080 #define ACS_SERVICE_TYPES UNKNOWN 00081 #define ACS_SERVICE_INSTANCES 10 00082 00083 const ACSService acsServices[] = { 00084 { 00085 "naming_service", 00086 "acsNamingService", 00087 "Naming Service Imp", 00088 "NamingServiceImp", 00089 "3015", 00090 "acsutilBlock -t 15 -s -k -b \"Imp is up and running...\" acsdaemonNamingServiceImp", 00091 "corbaloc::%s:%s/NameService", 00092 &ACSPorts::getNamingServicePort, 00093 NULL, 00094 false 00095 }, { 00096 "notification_service", 00097 "acsNotifyService", 00098 "Notification Service Imp", 00099 "NotificationServiceImp", 00100 "3016", 00101 "acsutilBlock -t 15 -s -k -b \"Imp is up and running...\" acsdaemonNotificationServiceImp", 00102 "corbaloc::%s:%s/%s", 00103 NULL, 00104 &ACSPorts::getNotifyServicePort, 00105 true 00106 }, { 00107 "cdb", 00108 "acsConfigurationDatabase", 00109 "CDB Imp", 00110 "ConfigurationDatabaseImp", 00111 "3017", 00112 "acsutilBlock -t 15 -s -k -b \"Imp is up and running...\" acsdaemonConfigurationDatabaseImp", 00113 "corbaloc::%s:%s/CDB", 00114 &ACSPorts::getCDBPort, 00115 NULL, 00116 false 00117 }, { 00118 "manager", 00119 "acsManager", 00120 "Manager Imp", 00121 "ManagerImp", 00122 "3018", 00123 "acsutilBlock -t 15 -s -k -b \"Imp is up and running...\" acsdaemonManagerImp", 00124 "corbaloc::%s:%s/Manager", 00125 &ACSPorts::getManagerPort, 00126 NULL, 00127 false 00128 }, { 00129 "acs_log", 00130 "acsACSLogService", 00131 "ACS Log Service Imp", 00132 "ACSLogServiceImp", 00133 "3019", 00134 "acsutilBlock -t 15 -s -k -b \"Imp is up and running...\" acsdaemonACSLogServiceImp", 00135 "corbaloc::%s:%s/ACSLogSvc", 00136 &ACSPorts::getLogPort, 00137 NULL, 00138 false 00139 }, { 00140 "logging_service", 00141 "acsLoggingService", 00142 "Logging Service Imp", 00143 "LoggingServiceImp", 00144 "3020", 00145 "acsutilBlock -t 15 -s -k -b \"Imp is up and running...\" acsdaemonLoggingServiceImp", 00146 "corbaloc::%s:%s/Log", 00147 &ACSPorts::getLoggingServicePort, 00148 NULL, 00149 true 00150 }, { 00151 "interface_repository", 00152 "acsInterfaceRepository", 00153 "Interface Repository Imp", 00154 "InterfaceRepositoryImp", 00155 "3021", 00156 "acsutilBlock -t 15 -s -k -b \"Imp is up and running...\" acsdaemonInterfaceRepositoryImp", 00157 "corbaloc::%s:%s/InterfaceRepository", 00158 &ACSPorts::getIRPort, 00159 NULL, 00160 false 00161 }, { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, false } 00162 }; 00163 00164 enum ACSServiceRequestType { 00165 START_SERVICE, 00166 STOP_SERVICE 00167 }; 00168 00169 enum ACSServiceRequestTarget { 00170 LOCAL, 00171 DAEMON, 00172 IMP 00173 }; 00174 00175 ACSServiceType acsServiceXMLTagToEnum(const char *service); 00176 00177 class RequestProcessorThread; 00178 00179 class Request { 00180 public: 00181 virtual ~Request() {}; 00182 virtual void abort() = 0; 00183 virtual bool execute() = 0; 00184 }; 00185 00186 class RequestProcessorThread : public ACS::Thread { 00187 private: 00188 ACE_Thread_Mutex *m_mutex; 00189 ACE_Condition<ACE_Thread_Mutex> *m_wait; 00190 std::queue<Request*> pending; 00191 volatile bool running; 00192 public: 00193 RequestProcessorThread(const ACE_CString &name, 00194 const ACS::TimeInterval& responseTime=ThreadBase::defaultResponseTime, 00195 const ACS::TimeInterval& sleepTime=ThreadBase::defaultSleepTime); 00196 ~RequestProcessorThread(); 00197 void onStart(); 00198 void stop(); 00199 void exit(); 00200 void runLoop() ACE_THROW_SPEC ((CORBA::SystemException, ::ACSErrTypeCommon::BadParameterEx)); 00201 void process(Request* r); 00202 }; 00203 00204 template <class R> class RequestChainContext; 00205 00206 template <class R> class ChainedRequest : public Request { 00207 private: 00208 RequestChainContext<R> *context; 00209 friend class RequestChainContext<R>; 00210 void process(RequestChainContext<R> *icontext); 00211 protected: 00212 virtual void complete(); 00213 public: 00214 ChainedRequest() : context(NULL) {} 00215 }; 00216 00217 template <class R> class RequestChainContext { 00218 private: 00219 RequestProcessorThread *rpt; 00220 std::deque<R*> requests; 00221 R *curreq; 00222 bool inprocess; 00223 protected: 00224 virtual bool requestDone(R *request) = 0; 00225 virtual void chainDone() = 0; 00226 virtual void chainAborted() = 0; 00227 public: 00228 RequestChainContext(RequestProcessorThread *irpt) : rpt(irpt), curreq(NULL), inprocess(false) {} 00229 virtual ~RequestChainContext() { 00230 while (!requests.empty()) { 00231 delete requests.front(); 00232 requests.pop_front(); 00233 } 00234 } 00235 RequestProcessorThread *getRequestProcessor() { return rpt; } 00236 void appendRequest(R *request) { requests.push_back(request); } 00237 void prependRequest(R *request) { requests.push_front(request); } 00238 void proceed(R *lastreq = NULL); 00239 }; 00240 00241 /*********************** ACS SERVICES SPECIFIC REQUESTS ***********************/ 00242 00243 class ACSServiceRequestChainContext; 00244 00245 class ACSServiceRequestDescription { 00246 private: 00247 ACSServiceType service; 00248 int instance_number; 00249 const char *host, *name, *domain, *cdbxmldir; 00250 bool loadir, wait, recovery; 00251 ACE_CString prepareCommand(ACSServiceRequestType request_type, bool log); 00252 public: 00253 ACSServiceRequestDescription(ACSServiceType iservice, int iinstance_number); 00254 ACSServiceRequestDescription(const ACSServiceRequestDescription &desc); 00255 ACSErr::Completion_var executeLocal(ACSServiceRequestType request_type); 00256 ACSErr::Completion_var executeRemote(ACSServiceRequestType request_type, CORBA::ORB_ptr orb, acsdaemon::DaemonCallback_ptr cbptr, const char *corbaloc); 00257 void setFromXMLAttributes(const char **atts); 00258 void setName(const char *iname) { name = iname == NULL ? NULL : strdup(iname); } 00259 void setDomain(const char *idomain) { domain = idomain == NULL ? NULL : strdup(idomain); } 00260 void setLoadIR(bool iloadir) { loadir = iloadir; } 00261 void setWaitLoadIR(bool iwait) { wait = iwait; } 00262 void setRecovery(bool irecovery) { recovery = irecovery; } 00263 void setCdbXMLDir(const char *icdbxmldir) { cdbxmldir = icdbxmldir == NULL ? NULL : strdup(icdbxmldir); } 00264 int getInstanceNumber() { return instance_number; } 00265 const char *getName() { return name; } 00266 const char *getHost() { return host == NULL ? ACSPorts::getIP() : host; } 00267 ACSServiceType getACSService() { return service; } 00268 const char *getACSServiceName() { return acsServices[service].xmltag; } 00269 }; 00270 00271 class ACSDaemonContext; 00272 00273 class ACSServiceRequest : public ChainedRequest<ACSServiceRequest>, POA_acsdaemon::DaemonCallback { 00274 private: 00275 ACSDaemonContext *context; 00276 ACSServiceRequestTarget target; 00277 ACSServiceRequestType request_type; 00278 ACSServiceRequestDescription *desc; 00279 acsdaemon::DaemonCallback_var callback; 00280 const ACSErr::Completion *completion; 00281 acsdaemon::DaemonCallback_var cbvar; 00282 acsdaemon::DaemonCallback_ptr cbptr(); 00283 void release(); 00284 protected: 00285 void complete(); 00286 void abort(); 00287 bool execute(); 00288 public: 00289 ACSServiceRequest(ACSDaemonContext *icontext, ACSServiceRequestTarget itarget, ACSServiceRequestType itype, ACSServiceRequestDescription *idesc, acsdaemon::DaemonCallback_ptr icallback = NULL); 00290 ~ACSServiceRequest(); 00291 void done(const ::ACSErr::Completion &comp); 00292 void working(const ::ACSErr::Completion &comp); 00293 const ACSErr::Completion *getCompletion() { return completion; } 00294 bool isErrorFree() { return completion == NULL || completion->previousError.length() == 0; } 00295 ACSServiceRequestTarget getRequestTarget() { return target; } 00296 ACSServiceRequestDescription *getDescription() { return desc; } 00297 const char *getACSServiceName() { return desc->getACSServiceName(); } 00298 int getInstanceNumber() { return desc->getInstanceNumber(); } 00299 const char *getHost() { return desc->getHost(); } 00300 }; 00301 00302 class ACSServiceRequestChainContext : public RequestChainContext<ACSServiceRequest> { 00303 private: 00304 ACSDaemonContext *context; 00305 ACSServiceRequestType request_type; 00306 bool reuse_services; 00307 acsdaemon::DaemonSequenceCallback_var callback; 00308 int instance_number; 00309 protected: 00310 bool requestDone(ACSServiceRequest *request); 00311 void chainDone(); 00312 void chainAborted(); 00313 public: 00314 ACSServiceRequestChainContext(ACSDaemonContext *icontext, ACSServiceRequestType itype, bool ireuse_services, acsdaemon::DaemonSequenceCallback_ptr icallback); 00315 ~ACSServiceRequestChainContext(); 00316 void addRequest(const char *iservice, const char **atts); 00317 void startProcessing() { proceed(); } 00318 }; 00319 00320 00321 #endif

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