00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00033 #ifndef ALP_IPC_MESSAGE_H
00034 #define ALP_IPC_MESSAGE_H
00035
00036
00037 #include <stdint.h>
00038 #include <string>
00039
00040 #include <hiker/ipc.h>
00041 #include <hiker/types.h>
00042
00043
00044
00045 namespace alp {
00046
00047 class string;
00048
00049 namespace ipc {
00050
00051 struct Array
00052 {
00053 unsigned char* array;
00054 uint32_t len;
00055
00056 Array() : array(NULL), len(0) {;}
00057 Array(unsigned char* a, uint32_t l)
00058 : array(a), len(l)
00059 {;}
00060 };
00061
00062 class Message
00063 {
00064 public:
00065 enum PackMode { none, send, receive };
00066
00067 Message();
00068 Message(AlpMessage* msg);
00069 Message(int what);
00070 Message(const Message& rhs);
00071 ~Message();
00072
00073 Message& operator=(const Message&);
00074
00075 inline alp_status_t Status() const { return fStatus; }
00076 inline PackMode Mode() const { return fMode; }
00077 inline int What() const { return fWhat; }
00078
00079 alp_status_t AddInt32(int32_t i);
00080 alp_status_t AddUInt32(uint32_t i);
00081 alp_status_t AddBool(bool b);
00082 alp_status_t AddFloat(float f);
00083 alp_status_t AddString(const char* s);
00084 alp_status_t AddString(const std::string& s);
00085 alp_status_t AddString(const alp::string& s);
00086 alp_status_t AddByteArray(const unsigned char* a, uint32_t len);
00087
00088 alp_status_t GetInt32(int32_t& i);
00089 alp_status_t GetUInt32(uint32_t& i);
00090 alp_status_t GetBool(bool& b);
00091 alp_status_t GetFloat(float& f);
00092 alp_status_t GetString(char*& s);
00093 alp_status_t GetString(std::string& s);
00094 alp_status_t GetString(alp::string& s);
00095 alp_status_t GetByteArray(unsigned char*& a, uint32_t& len);
00096
00097 private:
00098 AlpMessage* GetMessage();
00099 alp_status_t Send(AlpConnection* channel);
00100
00101 class MessageSharedPtr;
00102
00103 MessageSharedPtr* fMessage;
00104 PackMode fMode;
00105 alp_status_t fStatus;
00106 int fWhat;
00107
00108 friend class Server;
00109 friend class Client;
00110 };
00111
00112
00113
00114 Message& operator<<(Message& ipc, const int32_t i);
00115 Message& operator<<(Message& ipc, const uint32_t i);
00116 Message& operator<<(Message& ipc, const bool b);
00117 Message& operator<<(Message& ipc, const float f);
00118 Message& operator<<(Message& ipc, const char* s);
00119 Message& operator<<(Message& ipc, const std::string& s);
00120 Message& operator<<(Message& ipc, const Array& a);
00121
00122 Message& operator>>(Message& ipc, int32_t& i);
00123 Message& operator>>(Message& ipc, uint32_t& i);
00124 Message& operator>>(Message& ipc, bool& b);
00125 Message& operator>>(Message& ipc, float& f);
00126 Message& operator>>(Message& ipc, char*& s);
00127 Message& operator>>(Message& ipc, std::string& s);
00128 Message& operator>>(Message& ipc, Array& a);
00129
00130 }
00131
00132 }
00133
00134
00135
00136 #endif // ALP_IPC_MESSAGE_H