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 SFriend
|
---|
12 | {
|
---|
13 | std::string id;
|
---|
14 | std::string name;
|
---|
15 | } SFriend;
|
---|
16 |
|
---|
17 | // for callback
|
---|
18 |
|
---|
19 | typedef struct SResultResponse
|
---|
20 | {
|
---|
21 | bool result;
|
---|
22 | bool isError;
|
---|
23 | } SResultResponse;
|
---|
24 |
|
---|
25 | typedef struct SReceivedMessage
|
---|
26 | {
|
---|
27 | std::string sessid;
|
---|
28 | std::string sender;
|
---|
29 | std::string message;
|
---|
30 | bool isError;
|
---|
31 | } SReceivedMessage;
|
---|
32 |
|
---|
33 | typedef int (* callback_onResultResponse)(SResultResponse &);
|
---|
34 | typedef int (* callback_onReceiveMessage)(SReceivedMessage &);
|
---|
35 |
|
---|
36 | typedef struct SCallback
|
---|
37 | {
|
---|
38 | callback_onResultResponse result;
|
---|
39 | callback_onReceiveMessage message;
|
---|
40 | } SCallback;
|
---|
41 |
|
---|
42 | class chev
|
---|
43 | {
|
---|
44 | private:
|
---|
45 | Message::Request request;
|
---|
46 | std::string error;
|
---|
47 | cf::network::tcp socket;
|
---|
48 | cf::task::thread listener;
|
---|
49 | SCallback callback;
|
---|
50 |
|
---|
51 | public:
|
---|
52 | chev();
|
---|
53 |
|
---|
54 | bool connect(const std::string & host, unsigned short port);
|
---|
55 |
|
---|
56 | bool sms();
|
---|
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 | bool sendMessage(const std::string & friendid, const std::string & sessionID, const std::string & message);
|
---|
67 |
|
---|
68 | // call once
|
---|
69 | bool runReceiver(const SCallback & cb);
|
---|
70 |
|
---|
71 | const std::string & getLastError();
|
---|
72 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.