source: chevmsgr/trunk/msgclnt.h@ 12

Last change on this file since 12 was 12, checked in by cheese, 9 years ago

add dialogs

File size: 1.5 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
11typedef 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
23typedef struct SOpenSession
24{
25 std::string sessid;
26 std::vector<std::string> idList;
27} SOpenSession;
28
29typedef struct SCallback
30{
31 int(*onChat)(SConversation &);
32 int(*onOpenSession)(SOpenSession &);
33} SCallback;
34
35class MessageQ
36{
37private:
38 cf::task::mutex mutex;
39 std::vector<Protocol::Message> messageQ;
40
41public:
42 void push(const Protocol::Message & message);
43
44 Protocol::Message pop(const std::string & requestType, bool isWait = true);
45};
46
47class chev
48{
49private:
50 Protocol::Request request;
51 std::string error;
52 cf::network::tcp socket;
53 cf::task::thread listener;
54 cf::task::thread caller;
55
56 MessageQ messageQ;
57
58 std::map<std::string, std::string> sessionMap;
59
60public:
61 chev();
62
63 ~chev();
64
65 const std::string & getLastError() const;
66
67 bool connect(const std::string & host, unsigned short port);
68
69 bool sms(const std::string & phone);
70
71 bool join(const std::string & id, const std::string & pw, const std::string & sms);
72
73 bool login(const std::string & id, const std::string & pw);
74
75 bool addFriend(const std::string & id);
76
77 std::vector<SFriend> getFriendList();
78
79 std::string getSessionID(std::vector<std::string> & idList);
80
81 bool tell(const SConversation & conversation);
82
83 bool listen(const SCallback & callback);
84};
Note: See TracBrowser for help on using the repository browser.