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.dev/sumo
3
// Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4
// This program and the accompanying materials are made available under the
5
// terms of the Eclipse Public License 2.0 which is available at
6
// https://www.eclipse.org/legal/epl-2.0/
7
// This Source Code may also be made available under the following Secondary
8
// Licenses when the conditions for such availability set forth in the Eclipse
9
// Public License 2.0 are satisfied: GNU General Public License, version 2
10
// or later which is available at
11
// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
/****************************************************************************/
21
// Main method for TraCITestClient
22
/****************************************************************************/
23
#include <config.h>
24
25
#include <iostream>
26
#include <string>
27
#include <cstdlib>
28
#include "
TraCITestClient.h
"
29
30
31
// ===========================================================================
32
// method definitions
33
// ===========================================================================
34
int
main
(
int
argc,
char
* argv[]) {
35
std::string defFile =
""
;
36
std::string outFileName =
"testclient_out.txt"
;
37
int
port = -1;
38
std::string host =
"localhost"
;
39
40
if
((argc == 1) || (argc % 2 == 0)) {
41
std::cout <<
"Usage: TraCITestClient -def <definition_file> -p <remote port>"
42
<<
"[-h <remote host>] [-o <outputfile name>]"
<< std::endl;
43
return
0;
44
}
45
46
for
(
int
i = 1; i < argc; i++) {
47
std::string arg = argv[i];
48
if
(arg.compare(
"-def"
) == 0) {
49
defFile = argv[i + 1];
50
i++;
51
}
else
if
(arg.compare(
"-o"
) == 0) {
52
outFileName = argv[i + 1];
53
i++;
54
}
else
if
(arg.compare(
"-p"
) == 0) {
55
port = atoi(argv[i + 1]);
56
i++;
57
}
else
if
(arg.compare(
"-h"
) == 0) {
58
host = argv[i + 1];
59
i++;
60
}
else
{
61
std::cerr <<
"unknown parameter: "
<< argv[i] << std::endl;
62
return
1;
63
}
64
}
65
66
if
(port == -1) {
67
std::cerr <<
"Missing port"
<< std::endl;
68
return
1;
69
}
70
if
(defFile.compare(
""
) == 0) {
71
std::cerr <<
"Missing definition file"
<< std::endl;
72
return
1;
73
}
74
75
try
{
76
TraCITestClient
client(outFileName);
77
return
client.
run
(defFile, port, host);
78
}
catch
(
tcpip::SocketException
& e) {
79
std::cerr <<
"Socket error running the test client: "
<< e.what();
80
return
1;
81
}
catch
(
libsumo::TraCIException
& e) {
82
std::cerr <<
"TraCI error running the test client: "
<< e.what();
83
return
1;
84
}
85
}
TraCITestClient.h
TraCITestClient
A test execution class.
Definition:
TraCITestClient.h:42
TraCITestClient::run
int run(std::string fileName, int port, std::string host="localhost")
Runs a test.
Definition:
TraCITestClient.cpp:67
libsumo::TraCIException
An error which allows to continue.
Definition:
TraCIDefs.h:144
tcpip::SocketException
Definition:
socket.h:55
main
int main(int argc, char *argv[])
Definition:
tracitestclient_main.cpp:34
src
traci_testclient
tracitestclient_main.cpp
Generated on Sun Sep 22 2024 00:11:41 for Eclipse SUMO - Simulation of Urban MObility by
1.9.1