Changeset 6 in chevmsgr for trunk/msg.hpp
- Timestamp:
- 08/29/15 02:20:50 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/msg.hpp
r5 r6 8 8 #include <string> 9 9 #include <vector> 10 11 typedef struct SFriend 12 { 13 std::string id; 14 std::string name; 15 } SFriend; 16 17 // -------------------------------------------------------------- 18 19 namespace ProtocolType 20 { 21 #define DECLARE_KEY(_t) static const std::string _t = #_t 22 23 DECLARE_KEY(ID); 24 DECLARE_KEY(TYPE); 25 DECLARE_KEY(SMS); 26 DECLARE_KEY(PHONE); 27 DECLARE_KEY(JOIN); 28 DECLARE_KEY(PW); 29 DECLARE_KEY(LOGIN); 30 DECLARE_KEY(ADD_FRIEND); 31 DECLARE_KEY(OPEN_SESSION); 32 DECLARE_KEY(TO); 33 DECLARE_KEY(CHAT); 34 DECLARE_KEY(FROM); 35 DECLARE_KEY(SESSION_ID); 36 DECLARE_KEY(MESSAGE); 37 DECLARE_KEY(SENSITIVE); 38 DECLARE_KEY(GET_FRIEND_LIST); 39 DECLARE_KEY(RESULT); 40 } 41 42 namespace Protocol 43 { 44 class Message 45 { 46 private: 47 json::Object mObject; 48 49 public: 50 void parse(const std::string & message); 51 52 template<typename T> 53 inline T get(const std::string & key) const 54 { 55 return (T)mObject[key]; 56 } 57 58 std::string type() const; 59 }; 60 61 class IProtocol 62 { 63 public: 64 virtual void makeTemplate(json::Object & obj, const std::string & type) const = 0; 65 }; 66 67 class Request : public IProtocol 68 { 69 private: 70 std::string mID; 71 72 public: 73 void setUserID(const std::string & id); 74 75 const std::string & getUserID(); 76 77 void makeTemplate(json::Object & obj, const std::string & type) const; 78 79 std::string sms(const std::string & phone) const; 80 81 std::string join(const std::string & id, const std::string & pw, const std::string & sms); 82 83 std::string login(const std::string & pw) const; 84 85 std::string addFriend(const std::string & id) const; 86 87 std::string openSession(const std::string & to) const; 88 89 std::string chat(const std::string & sessid, const std::string & message, const int sensitive) const; 90 91 std::string getFriendList() const; 92 }; 93 94 class Response : public IProtocol 95 { 96 public: 97 void makeTemplate(json::Object & obj, const std::string & type) const; 98 99 std::string result(const std::string & requestType, const bool status) const; 100 101 std::string friendList(const std::vector<SFriend> & friendList) const; 102 103 std::string openSession(const std::vector<std::string> & idList) const; 104 }; 105 }; 106 107 // -------------------------------------------------------------- 10 108 11 109 #define LOG(message) log(__FILE__,__func__,__LINE__,message) … … 30 128 << message << std::endl; 31 129 } 32 33 // --------------------------------------------------------------34 namespace Message35 {36 class Parser37 {38 private:39 json::Object mObject;40 41 public:42 void parse(const std::string & message);43 44 template<typename T>45 inline T get(const std::string & key) const46 {47 return (T)mObject[key];48 }49 50 std::string type() const;51 };52 53 class IMessage54 {55 public:56 virtual void makeTemplate(json::Object & obj, const std::string & type) const = 0;57 };58 59 class Request : public IMessage60 {61 private:62 std::string mID;63 64 public:65 void setUserID(const std::string & id);66 67 const std::string & getUserID();68 69 void makeTemplate(json::Object & obj, const std::string & type) const;70 71 std::string command(const std::string & cmd) const;72 73 std::string sms(const std::string & phone) const;74 75 std::string Request::join(const std::string & id, const std::string & pw, const std::string & sms);76 77 std::string login(const std::string & pw) const;78 79 std::string Request::chat(const std::string & to, const std::string & sessid, const std::string & message) const;80 81 std::string friendList() const;82 };83 84 class Response : public IMessage85 {86 public:87 typedef struct friendInfo88 {89 std::string id;90 std::string name;91 } friendInfo;92 93 public:94 void makeTemplate(json::Object & obj, const std::string & type) const;95 96 std::string result(const bool status) const;97 };98 };
Note:
See TracChangeset
for help on using the changeset viewer.