Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/libsumo/Rerouter.cpp
169665 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2017-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 Rerouter.cpp
15
/// @author Jakob Erdmann
16
/// @date 16.03.2020
17
///
18
// C++ TraCI client API implementation
19
/****************************************************************************/
20
#include <config.h>
21
22
#include <microsim/MSNet.h>
23
#include <microsim/MSEdge.h>
24
#include <microsim/trigger/MSTriggeredRerouter.h>
25
#include <libsumo/TraCIConstants.h>
26
#include "Helper.h"
27
#include "Rerouter.h"
28
29
30
namespace libsumo {
31
// ===========================================================================
32
// static member initializations
33
// ===========================================================================
34
SubscriptionResults Rerouter::mySubscriptionResults;
35
ContextSubscriptionResults Rerouter::myContextSubscriptionResults;
36
37
38
// ===========================================================================
39
// static member definitions
40
// ===========================================================================
41
std::vector<std::string>
42
Rerouter::getIDList() {
43
MSNet::getInstance(); // just to check that we actually have a network
44
std::vector<std::string> ids;
45
for (const auto& item : MSTriggeredRerouter::getInstances()) {
46
ids.push_back(item.first);
47
}
48
return ids;
49
}
50
51
int
52
Rerouter::getIDCount() {
53
return (int)MSTriggeredRerouter::getInstances().size();
54
}
55
56
57
std::string
58
Rerouter::getParameter(const std::string& /* rerouterID */, const std::string& /* param */) {
59
return "";
60
}
61
62
63
LIBSUMO_GET_PARAMETER_WITH_KEY_IMPLEMENTATION(Rerouter)
64
65
66
void
67
Rerouter::setParameter(const std::string& /* rerouterID */, const std::string& /* key */, const std::string& /* value */) {
68
//MSRerouter* r = const_cast<MSRerouter*>(getRerouter(rerouterID));
69
//r->setParameter(key, value);
70
}
71
72
73
LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(Rerouter, REROUTER)
74
75
76
MSTriggeredRerouter*
77
Rerouter::getRerouter(const std::string& id) {
78
MSTriggeredRerouter* s = nullptr;
79
if (s == nullptr) {
80
throw TraCIException("Rerouter '" + id + "' is not known");
81
}
82
return s;
83
}
84
85
86
std::shared_ptr<VariableWrapper>
87
Rerouter::makeWrapper() {
88
return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
89
}
90
91
92
bool
93
Rerouter::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper, tcpip::Storage* paramData) {
94
switch (variable) {
95
case TRACI_ID_LIST:
96
return wrapper->wrapStringList(objID, variable, getIDList());
97
case ID_COUNT:
98
return wrapper->wrapInt(objID, variable, getIDCount());
99
case libsumo::VAR_PARAMETER:
100
paramData->readUnsignedByte();
101
return wrapper->wrapString(objID, variable, getParameter(objID, paramData->readString()));
102
case libsumo::VAR_PARAMETER_WITH_KEY:
103
paramData->readUnsignedByte();
104
return wrapper->wrapStringPair(objID, variable, getParameterWithKey(objID, paramData->readString()));
105
default:
106
return false;
107
}
108
}
109
110
}
111
112
113
/****************************************************************************/
114
115