SUMO - Simulation of Urban MObility
tracitestclient_main.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
20 // Main method for TraCITestClient
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <iostream>
34 #include <string>
35 #include <cstdlib>
36 #include "TraCITestClient.h"
37 
38 
39 // ===========================================================================
40 // method definitions
41 // ===========================================================================
42 int main(int argc, char* argv[]) {
43  std::string defFile = "";
44  std::string outFileName = "testclient_out.txt";
45  int port = -1;
46  std::string host = "localhost";
47 
48  if ((argc == 1) || (argc % 2 == 0)) {
49  std::cout << "Usage: TraCITestClient -def <definition_file> -p <remote port>"
50  << "[-h <remote host>] [-o <outputfile name>]" << std::endl;
51  return 0;
52  }
53 
54  for (int i = 1; i < argc; i++) {
55  std::string arg = argv[i];
56  if (arg.compare("-def") == 0) {
57  defFile = argv[i + 1];
58  i++;
59  } else if (arg.compare("-o") == 0) {
60  outFileName = argv[i + 1];
61  i++;
62  } else if (arg.compare("-p") == 0) {
63  port = atoi(argv[i + 1]);
64  i++;
65  } else if (arg.compare("-h") == 0) {
66  host = argv[i + 1];
67  i++;
68  } else {
69  std::cerr << "unknown parameter: " << argv[i] << std::endl;
70  return 1;
71  }
72  }
73 
74  if (port == -1) {
75  std::cerr << "Missing port" << std::endl;
76  return 1;
77  }
78  if (defFile.compare("") == 0) {
79  std::cerr << "Missing definition file" << std::endl;
80  return 1;
81  }
82 
83  try {
84  TraCITestClient client(outFileName);
85  return client.run(defFile, port, host);
86  } catch (tcpip::SocketException& e) {
87  std::cerr << "Socket error running the test client: " << e.what();
88  return 1;
89  } catch (libsumo::TraCIException& e) {
90  std::cerr << "TraCI error running the test client: " << e.what();
91  return 1;
92  }
93 }
int run(std::string fileName, int port, std::string host="localhost")
Runs a test.
A test execution class.
virtual const char * what() const
Definition: socket.h:70
int main(int argc, char *argv[])