-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmobile_client.h
66 lines (50 loc) · 1.7 KB
/
mobile_client.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "dispatcher.h"
#include "codec.h"
#include "remote_power.pb.h"
#include <muduo/base/Logging.h>
#include <muduo/base/Mutex.h>
#include <muduo/net/EventLoop.h>
#include <muduo/net/TcpClient.h>
#include <muduo/base/noncopyable.h>
#include <functional>
#include <stdio.h>
using namespace muduo;
using namespace muduo::net;
using std::placeholders::_1;
using std::placeholders::_2;
using std::placeholders::_3;
typedef std::shared_ptr<eh2tech::Empty> EmptyPtr;
typedef std::shared_ptr<eh2tech::Answer> AnswerPtr;
typedef std::shared_ptr<eh2tech::QueryAnswer> QueryAnswerPtr;
class MobileClient : muduo::noncopyable
{
public:
MobileClient(EventLoop* loop,
const InetAddress& serverAddr);
void connect();
private:
void onConnection(const TcpConnectionPtr& conn);
void onSetting(const TcpConnectionPtr&,
const MessagePtr& message,
Timestamp);
void onUnknownMessage(const TcpConnectionPtr&,
const MessagePtr& message,
Timestamp);
void onAnswer(const muduo::net::TcpConnectionPtr&,
const AnswerPtr& message,
muduo::Timestamp);
void onQueryAnswer(const muduo::net::TcpConnectionPtr&,
const QueryAnswerPtr& message,
muduo::Timestamp);
void onEmpty(const muduo::net::TcpConnectionPtr&,
const EmptyPtr& message,
muduo::Timestamp);
void submitMessage();
TcpConnectionPtr conn_;
eh2tech::Query data_;
eh2tech::Setting setting_;
EventLoop* loop_;
TcpClient client_;
ProtobufDispatcher dispatcher_;
ProtobufCodec codec_;
};