1 | #include "Client.h"
|
---|
2 | #include "ConnectionStatusMonitor.h"
|
---|
3 | #include "RtnetDataHandler.h"
|
---|
4 | #include "RtnetDataListener.h"
|
---|
5 | #include "RtnetDataRequest.h"
|
---|
6 |
|
---|
7 | #include <transport/TSocket.h>
|
---|
8 | #include <protocol/TBinaryProtocol.h>
|
---|
9 |
|
---|
10 | #include <cstdio>
|
---|
11 |
|
---|
12 | using boost::shared_ptr;
|
---|
13 |
|
---|
14 | using namespace apache::thrift;
|
---|
15 | using namespace apache::thrift::protocol;
|
---|
16 | using namespace apache::thrift::transport;
|
---|
17 | using namespace apache::thrift::concurrency;
|
---|
18 |
|
---|
19 | Client::Client(const std::string& server,
|
---|
20 | int16_t port, boost::shared_ptr<TimerManager>& timeMgr,
|
---|
21 | boost::shared_ptr<RtnetDataHandler> dataHandler)
|
---|
22 | : connectionMonitor_(),
|
---|
23 | transport_(),
|
---|
24 | protocol_(),
|
---|
25 | sender_(),
|
---|
26 | senderThread_(),
|
---|
27 | receiver_(),
|
---|
28 | receiverThread_()
|
---|
29 | {
|
---|
30 | transport_ = boost::shared_ptr<TTransport>(new TSocket(server, port));
|
---|
31 | protocol_ = boost::shared_ptr<TProtocol>(new TBinaryProtocol(transport_));
|
---|
32 |
|
---|
33 | connectionMonitor_ = boost::shared_ptr<ConnectionStatusMonitor>(new ConnectionStatusMonitor(transport_,timeMgr));
|
---|
34 |
|
---|
35 | sender_ = boost::shared_ptr<ConnectionRequiredRunnable>(new RtnetDataRequest(protocol_, connectionMonitor_));
|
---|
36 | connectionMonitor_->addListener(sender_);
|
---|
37 | senderThread_ = timeMgr->threadFactory()->newThread(sender_);
|
---|
38 | senderThread_->start();
|
---|
39 | receiver_ = boost::shared_ptr<ConnectionRequiredRunnable>(new RtnetDataListener(protocol_, connectionMonitor_, dataHandler));
|
---|
40 | connectionMonitor_->addListener(receiver_);
|
---|
41 | receiverThread_ = timeMgr->threadFactory()->newThread(receiver_);
|
---|
42 | receiverThread_->start();
|
---|
43 |
|
---|
44 | connectionMonitor_->tryOpen();
|
---|
45 | }
|
---|
46 |
|
---|
47 | Client::~Client() {
|
---|
48 | }
|
---|
49 |
|
---|
50 | void
|
---|
51 | Client::stop() {
|
---|
52 | connectionMonitor_->stop();
|
---|
53 | }
|
---|
54 |
|
---|