Eclipse SUMO - Simulation of Urban MObility
libsumo/Rerouter.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 // Copyright (C) 2017-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 /****************************************************************************/
18 // C++ TraCI client API implementation
19 /****************************************************************************/
20 #include <config.h>
21 
22 #include <microsim/MSNet.h>
23 #include <microsim/MSEdge.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 
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 
74 
75 
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());
100  paramData->readUnsignedByte();
101  return wrapper->wrapString(objID, variable, getParameter(objID, paramData->readString()));
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 /****************************************************************************/
#define LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(CLASS, DOM)
Definition: TraCIDefs.h:76
#define LIBSUMO_GET_PARAMETER_WITH_KEY_IMPLEMENTATION(CLASS)
Definition: TraCIDefs.h:123
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:182
Reroutes traffic objects passing an edge.
static const std::map< std::string, MSTriggeredRerouter * > & getInstances()
return all rerouter instances
C++ TraCI client API implementation.
Definition: Rerouter.h:29
virtual std::string readString()
Definition: storage.cpp:180
virtual int readUnsignedByte()
Definition: storage.cpp:155
TRACI_CONST int TRACI_ID_LIST
std::map< std::string, libsumo::SubscriptionResults > ContextSubscriptionResults
Definition: TraCIDefs.h:338
std::map< std::string, libsumo::TraCIResults > SubscriptionResults
{object->{variable->value}}
Definition: TraCIDefs.h:337
TRACI_CONST int ID_COUNT
TRACI_CONST int VAR_PARAMETER
TRACI_CONST int VAR_PARAMETER_WITH_KEY