source: ntrip/trunk/GnssCenter/thrift/rtnet_sdo_example/rtnet_sdo_example.cpp@ 10590

Last change on this file since 10590 was 4941, checked in by mervart, 12 years ago
File size: 2.4 KB
Line 
1#include <concurrency/TimerManager.h>
2#include <concurrency/PlatformThreadFactory.h>
3
4#include "Client.h"
5#include "RtnetDataHandler.h"
6
7#include <cstdio>
8#include <cstring>
9extern "C" {
10#include <strings.h>
11#include <sys/signal.h>
12#include <unistd.h>
13}
14
15using namespace apache::thrift::concurrency;
16using namespace com::gpssolutions::rtnet;
17
18volatile int STOP=0;
19void catch_ctrlc(int /*sig_num*/)
20{
21 static int once=0;
22 printf("Caught SIGINT signal, terminating rtnet_sdo_example\n");
23 if (once) exit(-1);
24 once=1;
25 STOP=1;
26}
27
28void usage()
29{
30 printf("rtnet_sdo_example -H (RTNet host default=localhost)\n");
31 printf(" -p (RTNet SDO port)\n");
32 printf(" [-h (show this usage information)]\n");
33}
34
35int main(int argc, char** argv)
36{
37 signal(SIGINT, catch_ctrlc);
38 int ii;
39 bool prevArgSet=false;
40 bool rtnetPortSet=false;
41 enum Argument
42 {
43 RtnetPort,
44 RtnetHost
45 };
46 Argument prevArg=RtnetPort;
47 std::string host;
48 long port=0;
49 long tmpval;
50 char *endptr;
51 for (ii=1; ii < argc; ++ii)
52 {
53 if (prevArgSet)
54 {
55 switch (prevArg)
56 {
57 case RtnetPort:
58 tmpval = strtol(argv[ii],&endptr,10);
59 if (endptr == argv[ii] || tmpval < 1) {
60 fprintf(stderr,"Invalid port '%s' given for rtnet port.\n",argv[ii]);
61 usage();
62 return 1;
63 }
64 port = tmpval;
65 rtnetPortSet=true;
66 break;
67 case RtnetHost:
68 host = argv[ii];
69 break;
70 }
71 prevArgSet=false;
72 } else {
73 if (!strcmp(argv[ii],"-p")) {
74 prevArgSet=true;
75 prevArg=RtnetPort;
76 } else if (!strcmp(argv[ii],"-H")) {
77 prevArgSet=true;
78 prevArg=RtnetHost;
79 } else if (!strcmp(argv[ii],"-h")) {
80 usage();
81 return 0;
82 } else {
83 fprintf(stderr,"Unknown argument %s\n",argv[ii]);
84 usage();
85 return 1;
86 }
87 }
88 }
89 if (!rtnetPortSet) {
90 fprintf(stderr,"RTNet port must be set.\n");
91 usage();
92 return 1;
93 }
94 boost::shared_ptr<TimerManager> timeMgr(new TimerManager);
95 boost::shared_ptr<ThreadFactory> thFactory(new PlatformThreadFactory);
96 timeMgr->threadFactory(thFactory);
97 timeMgr->start();
98 boost::shared_ptr<RtnetDataHandler> dataHandler(new RtnetDataHandler());
99 boost::shared_ptr<Client> clnt(new Client(host,port,timeMgr,dataHandler));
100
101 while (!STOP)
102 usleep(100);
103
104 // application cleanup
105 timeMgr->stop();
106 clnt->stop();
107 printf("Clean stop\n");
108 return 0;
109}
110
Note: See TracBrowser for help on using the repository browser.