source: ntrip/trunk/GnssCenter/thrift/rtnet_sdo_example/Client.cpp@ 8136

Last change on this file since 8136 was 4941, checked in by mervart, 12 years ago
File size: 1.6 KB
Line 
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
12using boost::shared_ptr;
13
14using namespace apache::thrift;
15using namespace apache::thrift::protocol;
16using namespace apache::thrift::transport;
17using namespace apache::thrift::concurrency;
18
19Client::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
47Client::~Client() {
48}
49
50void
51Client::stop() {
52 connectionMonitor_->stop();
53}
54
Note: See TracBrowser for help on using the repository browser.