1 | #include "RtnetDataListener.h"
|
---|
2 |
|
---|
3 | #include <cstdio>
|
---|
4 |
|
---|
5 | using namespace apache::thrift;
|
---|
6 | using namespace apache::thrift::protocol;
|
---|
7 | using namespace com::gpssolutions::rtnet;
|
---|
8 |
|
---|
9 | RtnetDataListener::RtnetDataListener(boost::shared_ptr<TProtocol>& protocol,
|
---|
10 | boost::shared_ptr<ConnectionStatusMonitor>& connectionMonitor,
|
---|
11 | boost::shared_ptr<com::gpssolutions::rtnet::RtnetDataIf> dataHandler)
|
---|
12 | : ConnectionRequiredRunnable(connectionMonitor,"StreamDataRequestService"),
|
---|
13 | dataHandler_(dataHandler),
|
---|
14 | protocol_(protocol),
|
---|
15 | processor_()
|
---|
16 | {
|
---|
17 | processor_ = boost::shared_ptr<RtnetDataProcessor>(new RtnetDataProcessor(dataHandler_));
|
---|
18 | }
|
---|
19 |
|
---|
20 | RtnetDataListener::~RtnetDataListener() {
|
---|
21 | }
|
---|
22 |
|
---|
23 | void
|
---|
24 | RtnetDataListener::run() {
|
---|
25 | printf("Starting RtnetDataListener thread.\n");
|
---|
26 | while (!stop_) {
|
---|
27 | printf("RtnetDataListener::waiting for connection\n");
|
---|
28 | connectWait();
|
---|
29 | printf("RtnetDataListener::Connected to rtnet\n");
|
---|
30 | if (stop_) {
|
---|
31 | printf("Quitting RtnetDataListener thread (stop is true)\n");
|
---|
32 | return;
|
---|
33 | }
|
---|
34 | try {
|
---|
35 | while (processor_->process(protocol_,protocol_,0)) {}
|
---|
36 | } catch(TException& e) {
|
---|
37 | fprintf(stderr,"Caught an exception generated by Thrift in RtnetDataListener: %s\n",e.what());
|
---|
38 | } catch(...) {
|
---|
39 | fprintf(stderr,"Unknown exception generated by Thrift in RtnetDataListener\n");
|
---|
40 | }
|
---|
41 | if (!stop_)
|
---|
42 | disconnected();
|
---|
43 | }
|
---|
44 | printf("Quitting RtnetDataListener thread\n");
|
---|
45 | }
|
---|
46 |
|
---|
47 | void
|
---|
48 | RtnetDataListener::stop(){
|
---|
49 | printf("RtnetDataListener::stop()\n");
|
---|
50 | protocol_->getTransport()->close();
|
---|
51 | ConnectionRequiredRunnable::stop();
|
---|
52 | }
|
---|
53 |
|
---|