Last change
on this file since 6 was 6, checked in by cheese, 9 years ago |
modify client interface and message protocol
|
File size:
1.2 KB
|
Line | |
---|
1 | #pragma once
|
---|
2 |
|
---|
3 | #include <string>
|
---|
4 | #include <vector>
|
---|
5 |
|
---|
6 | #include "msg.hpp"
|
---|
7 |
|
---|
8 | #include "cf/network.h"
|
---|
9 | #include "cf/task.h"
|
---|
10 |
|
---|
11 | typedef struct SConversation
|
---|
12 | {
|
---|
13 | // tell and listen
|
---|
14 | std::string sessid;
|
---|
15 | std::string message;
|
---|
16 | int sensitive;
|
---|
17 | bool isError;
|
---|
18 |
|
---|
19 | // only for listen
|
---|
20 | std::string from;
|
---|
21 | } SConversation;
|
---|
22 |
|
---|
23 | class MessageQ
|
---|
24 | {
|
---|
25 | private:
|
---|
26 | cf::task::mutex mutex;
|
---|
27 | std::vector<Protocol::Message> messageQ;
|
---|
28 |
|
---|
29 | public:
|
---|
30 | void push(const Protocol::Message & parser);
|
---|
31 |
|
---|
32 | Protocol::Message pop(const std::string & requestType);
|
---|
33 | };
|
---|
34 |
|
---|
35 | class chev
|
---|
36 | {
|
---|
37 | private:
|
---|
38 | Protocol::Request request;
|
---|
39 | std::string error;
|
---|
40 | cf::network::tcp socket;
|
---|
41 | cf::task::thread listener;
|
---|
42 |
|
---|
43 | MessageQ messageQ;
|
---|
44 |
|
---|
45 | std::map<std::string, std::string> sessionMap;
|
---|
46 |
|
---|
47 | public:
|
---|
48 | chev();
|
---|
49 |
|
---|
50 | ~chev();
|
---|
51 |
|
---|
52 | const std::string & getLastError() const;
|
---|
53 |
|
---|
54 | bool connect(const std::string & host, unsigned short port);
|
---|
55 |
|
---|
56 | bool sms(const std::string & phone);
|
---|
57 |
|
---|
58 | bool join(const std::string & id, const std::string & pw, const std::string & sms);
|
---|
59 |
|
---|
60 | bool login(const std::string & id, const std::string & pw);
|
---|
61 |
|
---|
62 | bool addFriend(const std::string & id);
|
---|
63 |
|
---|
64 | std::vector<SFriend> getFriendList();
|
---|
65 |
|
---|
66 | std::string getSessionID(const std::vector<std::string> & idList);
|
---|
67 |
|
---|
68 | bool tell(const SConversation & conversation);
|
---|
69 |
|
---|
70 | SConversation listen();
|
---|
71 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.