Changeset 5393 in ntrip


Ignore:
Timestamp:
Sep 9, 2013, 2:36:42 PM (11 years ago)
Author:
mervart
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GnssCenter/thrift/test_rtnet/rtnetThriftClient.cpp

    r5392 r5393  
    11
    22#include <iomanip>
     3#include <sstream>
    34#include <vector>
     5#include <map>
    46#include <string>
     7#include <getopt.h>
    58
    69#include <transport/TSocket.h>
     
    3740};
    3841
     42// Read Command-line Options
     43////////////////////////////////////////////////////////////////////////////////
     44void parseCmdLine(int argc, char* argv[], map<string, string>& OPT) {
     45
     46  static struct option longOptions[] = {
     47    {"host", required_argument, 0, 'h'},
     48    {"port", required_argument, 0, 'p'},
     49  };
     50
     51  while (true) {
     52    int index = 0;
     53    int iarg = getopt_long(argc, argv, "h:p:", longOptions, &index);
     54    if (iarg == -1) {
     55      break;
     56    }
     57    if (optarg) {
     58      OPT[longOptions[index].name] = string(optarg);
     59    }
     60    else {
     61      OPT[longOptions[index].name] = "y";
     62    }
     63  }
     64}
     65
    3966// Program
    4067//////////////////////////////////////////////////////////////////////////////
    4168int main(int argc, char **argv) {
    4269
    43   shared_ptr<TSocket>     socket(new TSocket("localhost", 6666));
     70  // Parse Input Options
     71  // -------------------
     72  map<string, string> OPT;
     73  parseCmdLine(argc, argv, OPT);
     74  if (OPT.find("port") == OPT.end()) {
     75    cerr << "usage: rtnetThriftClient [--host <host>] --port <port>" << endl;
     76    return 1;
     77  }
     78  string host = OPT.find("host") == OPT.end() ? "localhost" : OPT["host"];
     79  int    port; istringstream(OPT["port"]) >> port;
     80
     81  shared_ptr<TSocket>     socket(new TSocket(host, port));
    4482  shared_ptr<TTransport>  transport(new TBufferedTransport(socket));
    4583  shared_ptr<TProtocol>   protocol(new TBinaryProtocol(transport));
Note: See TracChangeset for help on using the changeset viewer.