00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _CodaObject_hxx
00018 #define _CodaObject_hxx
00019
00020
00021 #include <cMsg.hxx>
00022 #include <CodaException.hxx>
00023 #include <iostream>
00024 #include <sstream>
00025 #include <iomanip>
00026 #include <stdio.h>
00027 #include <unistd.h>
00028 #include <pthread.h>
00029 #include <algorithm>
00030
00031
00032 #define MIN(a,b) ((a)<(b))?(a):(b)
00033 #define MAX(a,b) ((a)>(b))?(a):(b)
00034
00035
00036
00037 #define DALOG_INFO 1
00038 #define DALOG_WARN 5
00039 #define DALOG_ERROR 9
00040 #define DALOG_SEVERE 13
00041
00042
00046 namespace codaObject {
00047
00048 using namespace std;
00049 using namespace cmsg;
00050
00051
00082
00083
00084
00085
00092 template <class C, typename R, typename T> class pthreadDispatcher {
00093 public:
00094 C *c;
00095 R (C::*mfp)(T);
00096 T mfArg;
00105 pthreadDispatcher(C *c, R (C::*mfp)(T), T mfArg) : c(c), mfp(mfp), mfArg(mfArg) {}
00106
00107
00113 static void *dispatchIt(void *pthreadArg) {
00114 pthreadDispatcher *pd = static_cast<pthreadDispatcher*>(pthreadArg);
00115 pthread_exit((void*)(((pd->c)->*(pd->mfp))(pd->mfArg)));
00116 return(NULL);
00117 }
00118 };
00119
00120
00121
00122
00123
00124
00136 class CodaObject {
00137
00138 public:
00139 CodaObject(const string& UDL, const string& name, const string& descr, const string &codaClass = "user",
00140 const cMsgSubscriptionConfig *scfg = NULL, int connTimeout = 10) throw(CodaException);
00141 virtual ~CodaObject(void) throw();
00142
00143
00144 protected:
00145 virtual void sendResponse(const cMsgMessage *msg, const string& subject, const string& type,
00146 const string& text, int userInt) const throw(CodaException);
00147 virtual void userMsgHandler(cMsgMessage *msg, void *userArg) throw(CodaException);
00148 virtual string userStatus(void) const throw();
00149
00150
00151 public:
00152 int daLogMsg(const string& text, int sevid, const string& daLogSubj="") const throw(CodaException);
00153 virtual void startProcessing(void) throw(CodaException);
00154 virtual void stopProcessing(void) throw(CodaException);
00155
00156 string getObjectType(void) const throw();
00157 string getCodaClass(void) const throw();
00158 string getHostName(void) const throw();
00159 string getUserName(void) const throw();
00160 string getState(void) const throw();
00161 string getStatus(void) const throw();
00162 string getConfig(void) const throw();
00163
00164
00165 public:
00166 void changeState(const string& newState) throw(CodaException);
00167 void changeStatus(const string& newStatus) throw(CodaException);
00168
00169
00170 private:
00171 void codaObjectCallback(cMsgMessage *msg, void* userArg) throw(CodaException);
00172 string checkCodaClass(const string &cClass) const throw();
00173
00174
00175 protected:
00176 virtual void daLogMsgFill(cMsgMessage &msg) const throw(CodaException);
00177
00178
00179 protected:
00180 string UDL;
00181 string name;
00182 string descr;
00184 string objectType;
00185 string codaClass;
00186 string hostName;
00187 string userName;
00188 string state;
00189 string status;
00190 string config;
00192 const cMsgSubscriptionConfig *myscfg;
00195 public:
00196 cMsg *rcConn;
00199 private:
00200 cMsgCallback *codaCBD;
00201 int connTimeout;
00204 public:
00205 string CodaObjectDaLogSubject;
00206 static int debug;
00207 };
00208
00209
00210
00211
00212
00213
00214
00215 }
00216
00217 #endif