Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/traci-server/TraCIServerAPI_Route.cpp
169665 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 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
/****************************************************************************/
14
/// @file TraCIServerAPI_Route.cpp
15
/// @author Daniel Krajzewicz
16
/// @author Laura Bieker
17
/// @author Michael Behrisch
18
/// @date 07.05.2009
19
///
20
// APIs for getting/setting route values via TraCI
21
/****************************************************************************/
22
#include <config.h>
23
24
#include <microsim/MSNet.h>
25
#include <microsim/MSRoute.h>
26
#include <microsim/MSEdge.h>
27
#include <libsumo/Route.h>
28
#include <libsumo/TraCIConstants.h>
29
#include "TraCIServerAPI_Route.h"
30
31
32
// ===========================================================================
33
// method definitions
34
// ===========================================================================
35
bool
36
TraCIServerAPI_Route::processGet(TraCIServer& server, tcpip::Storage& inputStorage,
37
tcpip::Storage& outputStorage) {
38
const int variable = inputStorage.readUnsignedByte();
39
const std::string id = inputStorage.readString();
40
server.initWrapper(libsumo::RESPONSE_GET_ROUTE_VARIABLE, variable, id);
41
try {
42
if (!libsumo::Route::handleVariable(id, variable, &server, &inputStorage)) {
43
return server.writeErrorStatusCmd(libsumo::CMD_GET_ROUTE_VARIABLE, "Get Route Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
44
}
45
} catch (libsumo::TraCIException& e) {
46
return server.writeErrorStatusCmd(libsumo::CMD_GET_ROUTE_VARIABLE, e.what(), outputStorage);
47
}
48
server.writeStatusCmd(libsumo::CMD_GET_ROUTE_VARIABLE, libsumo::RTYPE_OK, "", outputStorage);
49
server.writeResponseWithLength(outputStorage, server.getWrapperStorage());
50
return true;
51
}
52
53
54
bool
55
TraCIServerAPI_Route::processSet(TraCIServer& server, tcpip::Storage& inputStorage,
56
tcpip::Storage& outputStorage) {
57
std::string warning = ""; // additional description for response
58
// variable
59
int variable = inputStorage.readUnsignedByte();
60
if (variable != libsumo::ADD && variable != libsumo::REMOVE && variable != libsumo::VAR_PARAMETER) {
61
return server.writeErrorStatusCmd(libsumo::CMD_SET_ROUTE_VARIABLE, "Change Route State: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
62
}
63
// id
64
std::string id = inputStorage.readString();
65
66
try {
67
// process
68
switch (variable) {
69
case libsumo::ADD: {
70
std::vector<std::string> edgeIDs;
71
if (!server.readTypeCheckingStringList(inputStorage, edgeIDs)) {
72
return server.writeErrorStatusCmd(libsumo::CMD_SET_ROUTE_VARIABLE, "A string list is needed for adding a new route.", outputStorage);
73
}
74
libsumo::Route::add(id, edgeIDs);
75
}
76
break;
77
case libsumo::REMOVE: {
78
libsumo::Route::remove(id);
79
}
80
break;
81
case libsumo::VAR_PARAMETER: {
82
if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
83
return server.writeErrorStatusCmd(libsumo::CMD_SET_ROUTE_VARIABLE, "A compound object is needed for setting a parameter.", outputStorage);
84
}
85
//read itemNo
86
inputStorage.readInt();
87
std::string name;
88
if (!server.readTypeCheckingString(inputStorage, name)) {
89
return server.writeErrorStatusCmd(libsumo::CMD_SET_ROUTE_VARIABLE, "The name of the parameter must be given as a string.", outputStorage);
90
}
91
std::string value;
92
if (!server.readTypeCheckingString(inputStorage, value)) {
93
return server.writeErrorStatusCmd(libsumo::CMD_SET_ROUTE_VARIABLE, "The value of the parameter must be given as a string.", outputStorage);
94
}
95
libsumo::Route::setParameter(id, name, value);
96
}
97
break;
98
default:
99
break;
100
}
101
} catch (libsumo::TraCIException& e) {
102
return server.writeErrorStatusCmd(libsumo::CMD_SET_ROUTE_VARIABLE, e.what(), outputStorage);
103
}
104
server.writeStatusCmd(libsumo::CMD_SET_ROUTE_VARIABLE, libsumo::RTYPE_OK, warning, outputStorage);
105
return true;
106
}
107
108
109
/****************************************************************************/
110
111