#include "RtnetDataListener.h" #include using namespace apache::thrift; using namespace apache::thrift::protocol; using namespace com::gpssolutions::rtnet; RtnetDataListener::RtnetDataListener(boost::shared_ptr& protocol, boost::shared_ptr& connectionMonitor, boost::shared_ptr dataHandler) : ConnectionRequiredRunnable(connectionMonitor,"StreamDataRequestService"), dataHandler_(dataHandler), protocol_(protocol), processor_() { processor_ = boost::shared_ptr(new RtnetDataProcessor(dataHandler_)); } RtnetDataListener::~RtnetDataListener() { } void RtnetDataListener::run() { printf("Starting RtnetDataListener thread.\n"); while (!stop_) { printf("RtnetDataListener::waiting for connection\n"); connectWait(); printf("RtnetDataListener::Connected to rtnet\n"); if (stop_) { printf("Quitting RtnetDataListener thread (stop is true)\n"); return; } try { while (processor_->process(protocol_,protocol_,0)) {} } catch(TException& e) { fprintf(stderr,"Caught an exception generated by Thrift in RtnetDataListener: %s\n",e.what()); } catch(...) { fprintf(stderr,"Unknown exception generated by Thrift in RtnetDataListener\n"); } if (!stop_) disconnected(); } printf("Quitting RtnetDataListener thread\n"); } void RtnetDataListener::stop(){ printf("RtnetDataListener::stop()\n"); protocol_->getTransport()->close(); ConnectionRequiredRunnable::stop(); }