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