00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef _cMsg_hxx
00028 #define _cMsg_hxx
00029
00030
00031 #include <cMsg.h>
00032 #include <string>
00033 #include <exception>
00034 #include <vector>
00035 #include <map>
00036
00037
00041 namespace cmsg {
00042
00043 using namespace std;
00044
00045
00046
00047
00048
00049
00053 class cMsgException : public std::exception {
00054
00055 public:
00056 cMsgException(void);
00057 cMsgException(const string &descr);
00058 cMsgException(const string &descr, int code);
00059 cMsgException(const cMsgException &e);
00060 virtual ~cMsgException(void) throw();
00061
00062 virtual string toString(void) const throw();
00063 virtual const char *what(void) const throw();
00064
00065
00066 public:
00067 string descr;
00068 int returnCode;
00069 };
00070
00071
00072
00073
00074
00075
00079 class cMsgMessage {
00080
00081 friend class cMsg;
00084 public:
00085 cMsgMessage(void) throw(cMsgException);
00086 cMsgMessage(const cMsgMessage &m) throw(cMsgException);
00087 cMsgMessage(void *msgPointer) throw(cMsgException);
00088 virtual ~cMsgMessage(void);
00089
00090 virtual string getSubject(void) const throw(cMsgException);
00091 virtual void setSubject(const string &subject) throw(cMsgException);
00092 virtual string getType(void) const throw(cMsgException);
00093 virtual void setType(const string &type) throw(cMsgException);
00094 virtual string getText(void) const throw(cMsgException);
00095 virtual void setText(const string &text) throw(cMsgException);
00096
00097 virtual void setByteArrayLength(int length) throw(cMsgException);
00098 virtual void resetByteArrayLength();
00099 virtual int getByteArrayLength(void);
00100 virtual int getByteArrayLengthFull(void);
00101 virtual void setByteArrayOffset(int offset) throw(cMsgException);
00102 virtual int getByteArrayOffset(void);
00103 virtual int getByteArrayEndian(void);
00104 virtual void setByteArrayEndian(int endian) throw(cMsgException);
00105 virtual bool needToSwap(void) const throw(cMsgException);
00106 virtual char* getByteArray(void);
00107 virtual void setByteArray(char *array, int length) throw(cMsgException);
00108 virtual void setByteArrayNoCopy(char* array, int length) throw(cMsgException);
00109
00110 virtual int getUserInt(void) const throw(cMsgException);
00111 virtual void setUserInt(int i) throw(cMsgException);
00112 virtual struct timespec getUserTime(void) const throw(cMsgException);
00113 virtual void setUserTime(const struct timespec &userTime) throw(cMsgException);
00114 virtual int getVersion(void) const throw(cMsgException);
00115 virtual string getDomain(void) const throw(cMsgException);
00116 virtual string getReceiver(void) const throw(cMsgException);
00117 virtual string getReceiverHost(void) const throw(cMsgException);
00118 virtual string getSender(void) const throw(cMsgException);
00119 virtual string getSenderHost(void) const throw(cMsgException);
00120 virtual struct timespec getReceiverTime(void) const throw(cMsgException);
00121 virtual struct timespec getSenderTime(void) const throw(cMsgException);
00122 virtual bool isGetRequest(void) const throw(cMsgException);
00123 virtual bool isGetResponse(void) const throw(cMsgException);
00124 virtual bool isNullGetResponse(void) const throw(cMsgException);
00125
00126 virtual void makeNullResponse(const cMsgMessage &msg) throw(cMsgException);
00127 virtual void makeNullResponse(const cMsgMessage *msg) throw(cMsgException);
00128 virtual void makeResponse(const cMsgMessage &msg) throw(cMsgException);
00129 virtual void makeResponse(const cMsgMessage *msg) throw(cMsgException);
00130
00131 virtual void setGetResponse(bool b) throw(cMsgException);
00132 virtual void setNullGetResponse(bool b) throw(cMsgException);
00133 virtual string toString(void) const throw(cMsgException);
00134 virtual cMsgMessage *copy(void) const throw(cMsgException);
00135 virtual cMsgMessage *nullResponse(void) const throw(cMsgException);
00136 virtual cMsgMessage *response(void) const throw(cMsgException);
00137 virtual string getSubscriptionDomain() const throw(cMsgException);
00138 virtual string getSubscriptionSubject() const throw(cMsgException);
00139 virtual string getSubscriptionType() const throw(cMsgException);
00140 virtual string getSubscriptionUDL() const throw(cMsgException);
00141 virtual int getSubscriptionCueSize(void) const throw(cMsgException);
00142 virtual bool getReliableSend(void) const throw(cMsgException);
00143 virtual void setReliableSend(bool b) throw(cMsgException);
00144
00145
00146
00147
00148
00149
00150
00151
00152 public:
00153
00154 virtual bool hasPayload() const;
00155
00156 virtual void payloadClear(void);
00157 virtual void payloadReset(void);
00158 virtual void payloadPrint(void) const;
00159 virtual void payloadCopy(const cMsgMessage &msg) throw(cMsgException);
00160
00161 virtual bool payloadRemoveField(const string &name);
00162 virtual string payloadGetText() const;
00163 virtual void payloadSetFromText(const string &txt) throw(cMsgException);
00164 virtual string payloadGetFieldDescription(const string &name) const throw(cMsgException);
00165
00166 virtual map<string,int> *payloadGet() const throw(cMsgException);
00167 virtual int payloadGetCount() const;
00168 virtual bool payloadContainsName (const string &name) const;
00169 virtual int payloadGetType (const string &name) const throw(cMsgException);
00170 virtual void setHistoryLengthMax (int len) const throw(cMsgException);
00171
00172
00173
00174
00175
00176 virtual void getBinary(const string &name, const char **val, int &len, int &endian)
00177 const throw(cMsgException);
00178 virtual void getBinaryArray(const string &name, const char ***vals, int **lens, int **endians, int &count)
00179 const throw(cMsgException);
00180
00181 virtual cMsgMessage *getMessage(const string &name) const throw(cMsgException);
00182 virtual vector<cMsgMessage> *getMessageVector(const string &name) const throw(cMsgException);
00183 virtual vector<cMsgMessage*> *getMessagePVector(const string &name) const throw(cMsgException);
00184 virtual cMsgMessage *getMessageArray (const string &name) const throw(cMsgException);
00185 virtual cMsgMessage* *getMessagePArray (const string &name) const throw(cMsgException);
00186
00187 virtual string getString(const string &name) const throw(cMsgException);
00188 virtual vector<string> *getStringVector(const string &name) const throw(cMsgException);
00189 virtual string *getStringArray(const string &name) const throw(cMsgException);
00190
00191 virtual float getFloat(const string &name) const throw(cMsgException);
00192 virtual vector<float> *getFloatVector(const string &name) const throw(cMsgException);
00193 virtual float *getFloatArray(const string &name) const throw(cMsgException);
00194
00195 virtual double getDouble(const string &name) const throw(cMsgException);
00196 virtual vector<double> *getDoubleVector(const string &name) const throw(cMsgException);
00197 virtual double *getDoubleArray(const string &name) const throw(cMsgException);
00198
00199 virtual int8_t getInt8 (const string &name) const throw(cMsgException);
00200 virtual int16_t getInt16 (const string &name) const throw(cMsgException);
00201 virtual int32_t getInt32 (const string &name) const throw(cMsgException);
00202 virtual int64_t getInt64 (const string &name) const throw(cMsgException);
00203
00204 virtual vector<int8_t> *getInt8Vector (const string &name) const throw(cMsgException);
00205 virtual vector<int16_t> *getInt16Vector(const string &name) const throw(cMsgException);
00206 virtual vector<int32_t> *getInt32Vector(const string &name) const throw(cMsgException);
00207 virtual vector<int64_t> *getInt64Vector(const string &name) const throw(cMsgException);
00208
00209 virtual int8_t *getInt8Array (const string &name) const throw(cMsgException);
00210 virtual int16_t *getInt16Array (const string &name) const throw(cMsgException);
00211 virtual int32_t *getInt32Array (const string &name) const throw(cMsgException);
00212 virtual int64_t *getInt64Array (const string &name) const throw(cMsgException);
00213
00214
00215 virtual uint8_t getUint8 (const string &name) const throw(cMsgException);
00216 virtual uint16_t getUint16(const string &name) const throw(cMsgException);
00217 virtual uint32_t getUint32(const string &name) const throw(cMsgException);
00218 virtual uint64_t getUint64(const string &name) const throw(cMsgException);
00219
00220 virtual vector<uint8_t> *getUint8Vector (const string &name) const throw(cMsgException);
00221 virtual vector<uint16_t> *getUint16Vector(const string &name) const throw(cMsgException);
00222 virtual vector<uint32_t> *getUint32Vector(const string &name) const throw(cMsgException);
00223 virtual vector<uint64_t> *getUint64Vector(const string &name) const throw(cMsgException);
00224
00225 virtual uint8_t *getUint8Array (const string &name) const throw(cMsgException);
00226 virtual uint16_t *getUint16Array (const string &name) const throw(cMsgException);
00227 virtual uint32_t *getUint32Array (const string &name) const throw(cMsgException);
00228 virtual uint64_t *getUint64Array (const string &name) const throw(cMsgException);
00229
00230
00231
00232
00233
00234
00235 virtual void add(const string &name, const char *src, int size, int endian);
00236 virtual void add(const string &name, const char **srcs, int number,
00237 const int sizes[], const int endians[]);
00238
00239 virtual void add(const string &name, const string &s);
00240 virtual void add(const string &name, const string *s);
00241 virtual void add(const string &name, const char **strs, int len);
00242 virtual void add(const string &name, const string *strs, int len);
00243 virtual void add(const string &name, const vector<string> &strs);
00244 virtual void add(const string &name, const vector<string> *strs);
00245
00246 virtual void add(const string &name, const cMsgMessage &msg);
00247 virtual void add(const string &name, const cMsgMessage *msg);
00248 virtual void add(const string &name, const cMsgMessage *msg, int len);
00249 virtual void add(const string &name, const cMsgMessage* *msg, int len);
00250 virtual void add(const string &name, const vector<cMsgMessage> &msgVec);
00251 virtual void add(const string &name, const vector<cMsgMessage> *msgVec);
00252 virtual void add(const string &name, const vector<cMsgMessage*> &msgPVec);
00253 virtual void add(const string &name, const vector<cMsgMessage*> *msgPVec);
00254
00255 virtual void add(const string &name, float val);
00256 virtual void add(const string &name, double val);
00257 virtual void add(const string &name, const float *vals, int len);
00258 virtual void add(const string &name, const double *vals, int len);
00259 virtual void add(const string &name, const vector<float> &vals);
00260 virtual void add(const string &name, const vector<float> *vals);
00261 virtual void add(const string &name, const vector<double> &vals);
00262 virtual void add(const string &name, const vector<double> *vals);
00263
00264 virtual void add(const string &name, int8_t val);
00265 virtual void add(const string &name, int16_t val);
00266 virtual void add(const string &name, int32_t val);
00267 virtual void add(const string &name, int64_t val);
00268
00269 virtual void add(const string &name, uint8_t val);
00270 virtual void add(const string &name, uint16_t val);
00271 virtual void add(const string &name, uint32_t val);
00272 virtual void add(const string &name, uint64_t val);
00273
00274 virtual void add(const string &name, const int8_t *vals, int len);
00275 virtual void add(const string &name, const int16_t *vals, int len);
00276 virtual void add(const string &name, const int32_t *vals, int len);
00277 virtual void add(const string &name, const int64_t *vals, int len);
00278
00279 virtual void add(const string &name, const uint8_t *vals, int len);
00280 virtual void add(const string &name, const uint16_t *vals, int len);
00281 virtual void add(const string &name, const uint32_t *vals, int len);
00282 virtual void add(const string &name, const uint64_t *vals, int len);
00283
00284 virtual void add(const string &name, const vector<int8_t> &vals);
00285 virtual void add(const string &name, const vector<int8_t> *vals);
00286 virtual void add(const string &name, const vector<int16_t> &vals);
00287 virtual void add(const string &name, const vector<int16_t> *vals);
00288 virtual void add(const string &name, const vector<int32_t> &vals);
00289 virtual void add(const string &name, const vector<int32_t> *vals);
00290 virtual void add(const string &name, const vector<int64_t> &vals);
00291 virtual void add(const string &name, const vector<int64_t> *vals);
00292
00293 virtual void add(const string &name, const vector<uint8_t> &vals);
00294 virtual void add(const string &name, const vector<uint8_t> *vals);
00295 virtual void add(const string &name, const vector<uint16_t> &vals);
00296 virtual void add(const string &name, const vector<uint16_t> *vals);
00297 virtual void add(const string &name, const vector<uint32_t> &vals);
00298 virtual void add(const string &name, const vector<uint32_t> *vals);
00299 virtual void add(const string &name, const vector<uint64_t> &vals);
00300 virtual void add(const string &name, const vector<uint64_t> *vals);
00301
00302
00303 public:
00304 void *myMsgPointer;
00305 };
00306
00307
00308
00309
00310
00311
00315 class cMsgCallback {
00316
00317 public:
00318 virtual void callback(cMsgMessage *msg, void *userObject) = 0;
00319 virtual ~cMsgCallback() {};
00320 };
00321
00322
00323
00324
00325
00326
00330 class cMsgSubscriptionConfig {
00331
00332 public:
00333 cMsgSubscriptionConfig(void);
00334 virtual ~cMsgSubscriptionConfig(void);
00335
00336 virtual int getMaxCueSize(void) const;
00337 virtual void setMaxCueSize(int size);
00338 virtual int getSkipSize(void) const;
00339 virtual void setSkipSize(int size);
00340 virtual bool getMaySkip(void) const;
00341 virtual void setMaySkip(bool maySkip);
00342 virtual bool getMustSerialize(void) const;
00343 virtual void setMustSerialize(bool mustSerialize);
00344 virtual int getMaxThreads(void) const;
00345 virtual void setMaxThreads(int max);
00346 virtual int getMessagesPerThread(void) const;
00347 virtual void setMessagesPerThread(int mpt);
00348 virtual size_t getStackSize(void) const;
00349 virtual void setStackSize(size_t size);
00350
00351 public:
00352 cMsgSubscribeConfig *config;
00353 };
00354
00355
00356
00357
00358
00359
00363 class cMsg {
00364
00365 public:
00366 cMsg(const string &UDL, const string &name, const string &descr);
00367 virtual ~cMsg(void);
00368 virtual void connect() throw(cMsgException);
00369 virtual void disconnect(void) throw(cMsgException);
00370 virtual void send(cMsgMessage &msg) throw(cMsgException);
00371 virtual void send(cMsgMessage *msg) throw(cMsgException);
00372 virtual int syncSend(cMsgMessage &msg, const struct timespec *timeout = NULL) throw(cMsgException);
00373 virtual int syncSend(cMsgMessage *msg, const struct timespec *timeout = NULL) throw(cMsgException);
00374 virtual void *subscribe(const string &subject, const string &type, cMsgCallback *cb, void *userArg,
00375 const cMsgSubscriptionConfig *cfg = NULL) throw(cMsgException);
00376 virtual void *subscribe(const string &subject, const string &type, cMsgCallback &cb, void *userArg,
00377 const cMsgSubscriptionConfig *cfg = NULL) throw(cMsgException);
00378 virtual void unsubscribe(void *handle) throw(cMsgException);
00379 virtual void subscriptionPause(void *handle) throw(cMsgException);
00380 virtual void subscriptionResume(void *handle) throw(cMsgException);
00381 virtual void subscriptionQueueClear(void *handle) throw(cMsgException);
00382 virtual int subscriptionQueueCount(void *handle) throw(cMsgException);
00383 virtual bool subscriptionQueueIsFull(void *handle) throw(cMsgException);
00384 virtual int subscriptionMessagesTotal(void *handle) throw(cMsgException);
00385 virtual cMsgMessage *sendAndGet(cMsgMessage &sendMsg, const struct timespec *timeout = NULL)
00386 throw(cMsgException);
00387 virtual cMsgMessage *sendAndGet(cMsgMessage *sendMsg, const struct timespec *timeout = NULL)
00388 throw(cMsgException);
00389 virtual cMsgMessage *subscribeAndGet(const string &subject, const string &type, const struct timespec *timeout = NULL)
00390 throw(cMsgException);
00391 virtual void flush(const struct timespec *timeout = NULL) throw(cMsgException);
00392 virtual void start(void) throw(cMsgException);
00393 virtual void stop(void) throw(cMsgException);
00394 virtual void setUDL(const string &udl) throw(cMsgException);
00395 virtual string getUDL(void) const;
00396 virtual string getCurrentUDL(void) const throw(cMsgException);
00397 virtual string getName(void) const;
00398 virtual string getDescription(void) const;
00399 virtual bool isConnected(void) const throw(cMsgException);
00400 virtual bool isReceiving(void) const throw(cMsgException);
00401 virtual void setShutdownHandler(cMsgShutdownHandler *handler, void* userArg) throw(cMsgException);
00402 virtual void shutdownClients(const string &client, int flag) throw(cMsgException);
00403 virtual void shutdownServers(const string &server, int flag) throw(cMsgException);
00404 virtual cMsgMessage *monitor(const string &monString) throw(cMsgException);
00405
00406
00407 private:
00408 void *myDomainId;
00409 string myUDL;
00410 string myName;
00411 string myDescr;
00412 bool initialized;
00413 };
00414
00415
00416
00417
00418
00419 #include <cMsgPrivate.hxx>
00420
00421
00422 }
00423
00424 #endif
00425