SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tracitestclient_main.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
12 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
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 // used namespaces
41 // ===========================================================================
42 using namespace testclient;
43 
44 
45 // ===========================================================================
46 // method definitions
47 // ===========================================================================
48 int main(int argc, char* argv[]) {
49  std::string defFile = "";
50  std::string outFileName = "testclient_out.txt";
51  int port = -1;
52  std::string host = "localhost";
53  TraCITestClient* client;
54 
55  if ((argc == 1) || (argc % 2 == 0)) {
56  std::cout << "Usage: TraciTestClient -def <definition_file> -p <remote port>"
57  << "[-h <remote host>] [-o <outputfile name>]" << std::endl;
58  return 0;
59  }
60 
61  for (int i = 1; i < argc; i++) {
62  std::string arg = argv[i];
63  if (arg.compare("-def") == 0) {
64  defFile = argv[i + 1];
65  i++;
66  } else if (arg.compare("-o") == 0) {
67  outFileName = argv[i + 1];
68  i++;
69  } else if (arg.compare("-p") == 0) {
70  port = atoi(argv[i + 1]);
71  i++;
72  } else if (arg.compare("-h") == 0) {
73  host = argv[i + 1];
74  i++;
75  } else {
76  std::cout << "unknown parameter: " << argv[i] << std::endl;
77  return 1;
78  }
79  }
80 
81  if (port == -1) {
82  std::cout << "Missing port" << std::endl;
83  return 1;
84  }
85  if (defFile.compare("") == 0) {
86  std::cout << "Missing definition file" << std::endl;
87  return 1;
88  }
89 
90  client = new TraCITestClient(outFileName);
91  bool success = client->run(defFile, port, host);
92  delete client;
93 
94  return !success;
95 }