00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef _cMsg_hxx
00019 #define _cMsg_hxx
00020
00021
00022 #include <cMsg.h>
00023 #include <string>
00024 #include <exception>
00025 #include <vector>
00026 #include <map>
00027
00028
00032 namespace cmsg {
00033
00034 using namespace std;
00035
00036
00037
00038
00039
00040
00044 class cMsgException : public exception {
00045
00046 public:
00047 cMsgException(void);
00048 cMsgException(const string &descr);
00049 cMsgException(const string &descr, int code);
00050 cMsgException(const cMsgException &e);
00051 virtual ~cMsgException(void) throw();
00052
00053 virtual string toString(void) const throw();
00054 virtual const char *what(void) const throw();
00055
00056
00057 public:
00058 string descr;
00059 int returnCode;
00060 };
00061
00062
00063
00064
00065
00066
00070 class cMsgMessage {
00071
00072 friend class cMsg;
00075 public:
00076 cMsgMessage(void) throw(cMsgException);
00077 cMsgMessage(const cMsgMessage &m) throw(cMsgException);
00078 cMsgMessage(void *msgPointer) throw(cMsgException);
00079 virtual ~cMsgMessage(void);
00080
00081 virtual string getSubject(void) const throw(cMsgException);
00082 virtual void setSubject(const string &subject) throw(cMsgException);
00083 virtual string getType(void) const throw(cMsgException);
00084 virtual void setType(const string &type) throw(cMsgException);
00085 virtual string getText(void) const throw(cMsgException);
00086 virtual void setText(const string &text) throw(cMsgException);
00087 virtual void setByteArrayLength(int length) throw(cMsgException);
00088 virtual int getByteArrayLength(void) const throw(cMsgException);
00089 virtual void setByteArrayOffset(int offset) throw(cMsgException);
00090 virtual int getByteArrayOffset(void) const throw(cMsgException);
00091 virtual int getByteArrayEndian(void) const throw(cMsgException);
00092 virtual void setByteArrayEndian(int endian) throw(cMsgException);
00093 virtual bool needToSwap(void) const throw(cMsgException);
00094 virtual void setByteArray(char *array) throw(cMsgException);
00095 virtual char* getByteArray(void) const throw(cMsgException);
00096 virtual void setByteArrayAndLimits(char *array, int offset, int length) throw(cMsgException);
00097 virtual void copyByteArray(char* array, int offset, int length) throw(cMsgException);
00098 virtual int getUserInt(void) const throw(cMsgException);
00099 virtual void setUserInt(int i) throw(cMsgException);
00100 virtual struct timespec getUserTime(void) const throw(cMsgException);
00101 virtual void setUserTime(const struct timespec &userTime) throw(cMsgException);
00102 virtual int getVersion(void) const throw(cMsgException);
00103 virtual string getDomain(void) const throw(cMsgException);
00104 virtual string getReceiver(void) const throw(cMsgException);
00105 virtual string getReceiverHost(void) const throw(cMsgException);
00106 virtual string getSender(void) const throw(cMsgException);
00107 virtual string getSenderHost(void) const throw(cMsgException);
00108 virtual struct timespec getReceiverTime(void) const throw(cMsgException);
00109 virtual struct timespec getSenderTime(void) const throw(cMsgException);
00110 virtual bool isGetRequest(void) const throw(cMsgException);
00111 virtual bool isGetResponse(void) const throw(cMsgException);
00112 virtual bool isNullGetResponse(void) const throw(cMsgException);
00113 virtual void makeNullResponse(cMsgMessage &msg) throw(cMsgException);
00114 virtual void makeNullResponse(cMsgMessage *msg) throw(cMsgException);
00115 virtual void makeResponse(cMsgMessage &msg) throw(cMsgException);
00116 virtual void makeResponse(cMsgMessage *msg) throw(cMsgException);
00117 virtual void setGetResponse(bool b) throw(cMsgException);
00118 virtual void setNullGetResponse(bool b) throw(cMsgException);
00119 virtual string toString(void) const throw(cMsgException);
00120 virtual cMsgMessage *copy(void) const throw(cMsgException);
00121 virtual cMsgMessage *nullResponse(void) const throw(cMsgException);
00122 virtual cMsgMessage *response(void) const throw(cMsgException);
00123 virtual string getSubscriptionDomain() const throw(cMsgException);
00124 virtual string getSubscriptionSubject() const throw(cMsgException);
00125 virtual string getSubscriptionType() const throw(cMsgException);
00126 virtual string getSubscriptionUDL() const throw(cMsgException);
00127 virtual int getSubscriptionCueSize(void) const throw(cMsgException);
00128 virtual bool getReliableSend(void) const throw(cMsgException);
00129 virtual void setReliableSend(bool b) throw(cMsgException);
00130
00131
00132
00133
00134
00135 virtual bool hasPayload() const;
00136
00137 virtual void payloadClear(void);
00138 virtual void payloadWipeout(void);
00139 virtual void payloadPrint(void) const;
00140 virtual void payloadCopy(cMsgMessage &msg) throw(cMsgException);
00141
00142 virtual bool payloadRemoveField(const string &name);
00143 virtual string payloadGetFieldDescription(const string &name) const throw(cMsgException);
00144
00145 virtual map<string,int> *payloadGet() const throw(cMsgException);
00146 virtual int payloadGetCount() const;
00147 virtual bool payloadContainsName (const string &name) const;
00148 virtual int payloadGetType (const string &name) const throw(cMsgException);
00149
00150
00151
00152
00153 virtual void getBinary(string name, const char **val, int &len, int &endian) const throw(cMsgException);
00154
00155 virtual const cMsgMessage *getMessage(string name) const throw(cMsgException);
00156 virtual vector<cMsgMessage> *getMessageVector(string name) const throw(cMsgException);
00157
00158 virtual string getString(string name) const throw(cMsgException);
00159 virtual vector<string> *getStringVector(string name) const throw(cMsgException);
00160
00161 virtual float getFloat(string name) const throw(cMsgException);
00162 virtual double getDouble(string name) const throw(cMsgException);
00163 virtual vector<float> *getFloatVector(string name) const throw(cMsgException);
00164 virtual vector<double> *getDoubleVector(string name) const throw(cMsgException);
00165
00166 virtual int8_t getInt8(string name) const throw(cMsgException);
00167 virtual int16_t getInt16(string name) const throw(cMsgException);
00168 virtual int32_t getInt32(string name) const throw(cMsgException);
00169 virtual int64_t getInt64(string name) const throw(cMsgException);
00170 virtual uint8_t getUint8(string name) const throw(cMsgException);
00171 virtual uint16_t getUint16(string name) const throw(cMsgException);
00172 virtual uint32_t getUint32(string name) const throw(cMsgException);
00173 virtual uint64_t getUint64(string name) const throw(cMsgException);
00174
00175 virtual vector<int8_t> *getInt8Vector (string name) const throw(cMsgException);
00176 virtual vector<int16_t> *getInt16Vector(string name) const throw(cMsgException);
00177 virtual vector<int32_t> *getInt32Vector(string name) const throw(cMsgException);
00178 virtual vector<int64_t> *getInt64Vector(string name) const throw(cMsgException);
00179
00180 virtual vector<uint8_t> *getUint8Vector (string name) const throw(cMsgException);
00181 virtual vector<uint16_t> *getUint16Vector(string name) const throw(cMsgException);
00182 virtual vector<uint32_t> *getUint32Vector(string name) const throw(cMsgException);
00183 virtual vector<uint64_t> *getUint64Vector(string name) const throw(cMsgException);
00184
00185
00186
00187
00188 virtual void addBinary(string name, const char *src, int size, int endian);
00189
00190 virtual void addString(string name, string s);
00191 virtual void addStringArray(string name, const char **strs, int len);
00192 virtual void addStringArray(string name, string *strs, int len);
00193 virtual void addStringVector(string name, vector<string> &strs);
00194
00195 virtual void addMessage(string name, cMsgMessage &msg);
00196 virtual void addMessageArray(string name, cMsgMessage *msg, int len);
00197 virtual void addMessageVector(string name, vector<cMsgMessage> &msg);
00198
00199 virtual void addFloat(string name, float val);
00200 virtual void addDouble(string name, double val);
00201 virtual void addFloatArray(string name, float *vals, int len);
00202 virtual void addDoubleArray(string name, double *vals, int len);
00203 virtual void addFloatVector(string name, vector<float> &vals);
00204 virtual void addDoubleVector(string name, vector<double> &vals);
00205
00206 virtual void addInt8 (string name, int8_t val);
00207 virtual void addInt16(string name, int16_t val);
00208 virtual void addInt32(string name, int32_t val);
00209 virtual void addInt64(string name, int64_t val);
00210
00211 virtual void addUint8 (string name, uint8_t val);
00212 virtual void addUint16(string name, uint16_t val);
00213 virtual void addUint32(string name, uint32_t val);
00214 virtual void addUint64(string name, uint64_t val);
00215
00216 virtual void addInt8Array (string name, int8_t *vals, int len);
00217 virtual void addInt16Array(string name, int16_t *vals, int len);
00218 virtual void addInt32Array(string name, int32_t *vals, int len);
00219 virtual void addInt64Array(string name, int64_t *vals, int len);
00220
00221 virtual void addUint8Array (string name, uint8_t *vals, int len);
00222 virtual void addUint16Array(string name, uint16_t *vals, int len);
00223 virtual void addUint32Array(string name, uint32_t *vals, int len);
00224 virtual void addUint64Array(string name, uint64_t *vals, int len);
00225
00226 virtual void addInt8Vector (string name, vector<int8_t> &vals);
00227 virtual void addInt16Vector(string name, vector<int16_t> &vals);
00228 virtual void addInt32Vector(string name, vector<int32_t> &vals);
00229 virtual void addInt64Vector(string name, vector<int64_t> &vals);
00230
00231 virtual void addUint8Vector (string name, vector<uint8_t> &vals);
00232 virtual void addUint16Vector(string name, vector<uint16_t> &vals);
00233 virtual void addUint32Vector(string name, vector<uint32_t> &vals);
00234 virtual void addUint64Vector(string name, vector<uint64_t> &vals);
00235
00236
00237
00238 void *myMsgPointer;
00239 };
00240
00241
00242
00243
00244
00245
00249 class cMsgCallback {
00250
00251 public:
00252 virtual void callback(cMsgMessage *msg, void *userObject) = 0;
00253
00254 };
00255
00256
00257
00258
00259
00260
00264 class cMsgSubscriptionConfig {
00265
00266 public:
00267 cMsgSubscriptionConfig(void);
00268 virtual ~cMsgSubscriptionConfig(void);
00269
00270 virtual int getMaxCueSize(void);
00271 virtual void setMaxCueSize(int size);
00272 virtual int getSkipSize(void);
00273 virtual void setSkipSize(int size);
00274 virtual bool getMaySkip(void);
00275 virtual void setMaySkip(bool maySkip);
00276 virtual bool getMustSerialize(void);
00277 virtual void setMustSerialize(bool mustSerialize);
00278 virtual int getMaxThreads(void);
00279 virtual void setMaxThreads(int max);
00280 virtual int getMessagesPerThread(void);
00281 virtual void setMessagesPerThread(int mpt);
00282 virtual size_t getStackSize(void);
00283 virtual void setStackSize(size_t size);
00284
00285 public:
00286 cMsgSubscribeConfig *config;
00287 };
00288
00289
00290
00291
00292
00293
00297 class cMsg {
00298
00299 public:
00300 cMsg(const string &UDL, const string &name, const string &descr);
00301 virtual ~cMsg(void);
00302 virtual void connect() throw(cMsgException);
00303 virtual void disconnect(void) throw(cMsgException);
00304 virtual void send(cMsgMessage &msg) throw(cMsgException);
00305 virtual void send(cMsgMessage *msg) throw(cMsgException);
00306 virtual int syncSend(cMsgMessage &msg, const struct timespec *timeout = NULL) throw(cMsgException);
00307 virtual int syncSend(cMsgMessage *msg, const struct timespec *timeout = NULL) throw(cMsgException);
00308 virtual void *subscribe(const string &subject, const string &type, cMsgCallback *cb, void *userArg,
00309 const cMsgSubscriptionConfig *cfg = NULL) throw(cMsgException);
00310 virtual void *subscribe(const string &subject, const string &type, cMsgCallback &cb, void *userArg,
00311 const cMsgSubscriptionConfig *cfg = NULL) throw(cMsgException);
00312 virtual void unsubscribe(void *handle) throw(cMsgException);
00313 virtual cMsgMessage *sendAndGet(cMsgMessage &sendMsg, const struct timespec *timeout = NULL)
00314 throw(cMsgException);
00315 virtual cMsgMessage *sendAndGet(cMsgMessage *sendMsg, const struct timespec *timeout = NULL)
00316 throw(cMsgException);
00317 virtual cMsgMessage *subscribeAndGet(const string &subject, const string &type, const struct timespec *timeout = NULL)
00318 throw(cMsgException);
00319 virtual void flush(const struct timespec *timeout = NULL) throw(cMsgException);
00320 virtual void start(void) throw(cMsgException);
00321 virtual void stop(void) throw(cMsgException);
00322 virtual string getUDL(void) const;
00323 virtual string getName(void) const;
00324 virtual string getDescription(void) const;
00325 virtual bool isConnected(void) const;
00326 virtual bool isReceiving(void) const;
00327 virtual void setShutdownHandler(cMsgShutdownHandler *handler, void* userArg) throw(cMsgException);
00328 virtual void shutdownClients(const string &client, int flag) throw(cMsgException);
00329 virtual void shutdownServers(const string &server, int flag) throw(cMsgException);
00330 virtual cMsgMessage *monitor(const string &monString) throw(cMsgException);
00331
00332
00333 private:
00334 void *myDomainId;
00335 string myUDL;
00336 string myName;
00337 string myDescr;
00338 bool initialized;
00339 };
00340
00341
00342
00343
00344
00345 #include <cMsgPrivate.hxx>
00346
00347
00348 }
00349
00350 #endif
00351