Path: blob/main/src/traci_testclient/tracitestclient_main.cpp
169665 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file tracitestclient_main.cpp14/// @author Friedemann Wesner15/// @author Axel Wegener16/// @author Michael Behrisch17/// @author Daniel Krajzewicz18/// @date 2008/04/0719///20// Main method for TraCITestClient21/****************************************************************************/22#include <config.h>2324#include <iostream>25#include <string>26#include <cstdlib>27#include "TraCITestClient.h"282930// ===========================================================================31// method definitions32// ===========================================================================33int main(int argc, char* argv[]) {34std::string defFile = "";35std::string outFileName = "testclient_out.txt";36int port = -1;37std::string host = "localhost";3839if ((argc == 1) || (argc % 2 == 0)) {40std::cout << "Usage: TraCITestClient -def <definition_file> -p <remote port>"41<< "[-h <remote host>] [-o <outputfile name>]" << std::endl;42return 0;43}4445for (int i = 1; i < argc; i++) {46std::string arg = argv[i];47if (arg.compare("-def") == 0) {48defFile = argv[i + 1];49i++;50} else if (arg.compare("-o") == 0) {51outFileName = argv[i + 1];52i++;53} else if (arg.compare("-p") == 0) {54port = atoi(argv[i + 1]);55i++;56} else if (arg.compare("-h") == 0) {57host = argv[i + 1];58i++;59} else {60std::cerr << "unknown parameter: " << argv[i] << std::endl;61return 1;62}63}6465if (port == -1) {66std::cerr << "Missing port" << std::endl;67return 1;68}69if (defFile.compare("") == 0) {70std::cerr << "Missing definition file" << std::endl;71return 1;72}7374try {75TraCITestClient client(outFileName);76return client.run(defFile, port, host);77} catch (tcpip::SocketException& e) {78std::cerr << "Socket error running the test client: " << e.what();79return 1;80} catch (libsumo::TraCIException& e) {81std::cerr << "TraCI error running the test client: " << e.what();82return 1;83}84}858687