source: ntrip/trunk/GnssCenter/monitor/thriftclient.cpp@ 5475

Last change on this file since 5475 was 5467, checked in by mervart, 11 years ago
File size: 3.7 KB
Line 
1
2#include <iostream>
3#include <iomanip>
4#include <sstream>
5#include <vector>
6
7#include "thriftclient.h"
8#include "monitor.h"
9
10using namespace apache::thrift;
11using namespace apache::thrift::protocol;
12using namespace apache::thrift::transport;
13
14using namespace com::gpssolutions::rtnet;
15using namespace std;
16using namespace boost;
17
18using namespace GnssCenter;
19
20// Constructor
21//////////////////////////////////////////////////////////////////////////////
22t_thriftClient::t_thriftClient(t_monitor* parent, const QString& host, int port) {
23 _stop = false;
24 _parent = parent;
25 _host = host.toAscii().data();
26 _port = port;
27}
28
29// Destructor
30//////////////////////////////////////////////////////////////////////////////
31t_thriftClient::~t_thriftClient() {
32}
33
34// Run (virtual)
35//////////////////////////////////////////////////////////////////////////////
36void t_thriftClient::run() {
37
38 shared_ptr<TSocket> socket(new TSocket(_host, _port));
39 shared_ptr<TTransport> transport(new TBufferedTransport(socket));
40 shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
41 shared_ptr<RtnetDataIf> dataHandler(new t_thriftHandler(_parent));
42 shared_ptr<TProcessor> processor(new RtnetDataProcessor(dataHandler));
43
44 try {
45 transport->open();
46 while (true) {
47 {
48 QMutexLocker locker(&_mutex);
49 if (_stop) {
50 break;
51 }
52 }
53 if (processor->process(protocol,protocol,0) == 0) {
54 break;
55 }
56 }
57 transport->close();
58 }
59 catch (TException& e) {
60 cerr << "Caught an exception generated by Thrift: " << e.what() << endl;
61 }
62 catch (...) {
63 cerr << "Unknown exception" << endl;
64 }
65}
66
67// Constructor
68//////////////////////////////////////////////////////////////////////////////
69t_thriftHandler::t_thriftHandler(t_monitor* parent) {
70 _parent = parent;
71}
72
73// Destructor
74//////////////////////////////////////////////////////////////////////////////
75t_thriftHandler::~t_thriftHandler() {
76}
77
78// Handle Satellite Positions
79//////////////////////////////////////////////////////////////////////////////
80void t_thriftHandler::
81handleSatelliteXYZ(const vector<SatelliteXYZ>& svXYZList) {
82 cout.setf(ios::fixed);
83 for (unsigned ii = 0; ii < svXYZList.size(); ii++) {
84// const SatelliteXYZ& sat = svXYZList[ii];
85// cout << unsigned(sat.ID) << ' '
86// << setprecision(3) << sat.xyz.x << ' '
87// << setprecision(3) << sat.xyz.y << ' '
88// << setprecision(3) << sat.xyz.z << endl;
89 }
90// cout << endl;
91}
92
93// Handle Station Info
94//////////////////////////////////////////////////////////////////////////////
95void t_thriftHandler::
96handleStationInfo(const vector<StationInfo>& stationList) {
97 for (unsigned ii = 0; ii < stationList.size(); ii++) {
98 const StationInfo& staInfo = stationList[ii];
99 _stationCrd[staInfo.ID]._x = staInfo.xyz.x;
100 _stationCrd[staInfo.ID]._y = staInfo.xyz.y;
101 _stationCrd[staInfo.ID]._z = staInfo.xyz.z;
102 }
103}
104
105// Handle Epoch Results
106//////////////////////////////////////////////////////////////////////////////
107void t_thriftHandler::
108handleEpochResults(const RtnetEpoch& epoch) {
109 vector<t_thriftResult*>* results = new vector<t_thriftResult*>;
110 for (unsigned ii = 0; ii < epoch.stationResultList.size(); ii++) {
111 const StationResults& staRes = epoch.stationResultList[ii];
112 t_thriftResult* res = new t_thriftResult;
113 res->_name = staRes.stationName;
114 res->_nGPS = staRes.nsv_gps_used;
115 res->_nGLO = staRes.nsv_glonass_used;
116 if (_stationCrd.find(staRes.stationName) != _stationCrd.end()) {
117 res->_x = _stationCrd[staRes.stationName]._x;
118 res->_y = _stationCrd[staRes.stationName]._y;
119 res->_z = _stationCrd[staRes.stationName]._z;
120 }
121 results->push_back(res);
122 }
123 _parent->putThriftResults(results);
124}
Note: See TracBrowser for help on using the repository browser.