Line data Source code
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 : /****************************************************************************/ 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 134 : Rerouter::getIDList() { 43 134 : MSNet::getInstance(); // just to check that we actually have a network 44 : std::vector<std::string> ids; 45 138 : for (const auto& item : MSTriggeredRerouter::getInstances()) { 46 6 : ids.push_back(item.first); 47 : } 48 132 : return ids; 49 0 : } 50 : 51 : int 52 6 : Rerouter::getIDCount() { 53 6 : return (int)MSTriggeredRerouter::getInstances().size(); 54 : } 55 : 56 : 57 : std::string 58 0 : Rerouter::getParameter(const std::string& /* rerouterID */, const std::string& /* param */) { 59 0 : return ""; 60 : } 61 : 62 : 63 0 : LIBSUMO_GET_PARAMETER_WITH_KEY_IMPLEMENTATION(Rerouter) 64 : 65 : 66 : void 67 0 : 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 0 : } 71 : 72 : 73 0 : LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(Rerouter, REROUTER) 74 : 75 : 76 : MSTriggeredRerouter* 77 0 : Rerouter::getRerouter(const std::string& id) { 78 : MSTriggeredRerouter* s = nullptr; 79 : if (s == nullptr) { 80 0 : throw TraCIException("Rerouter '" + id + "' is not known"); 81 : } 82 : return s; 83 : } 84 : 85 : 86 : std::shared_ptr<VariableWrapper> 87 267 : Rerouter::makeWrapper() { 88 267 : return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults); 89 : } 90 : 91 : 92 : bool 93 84 : Rerouter::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper, tcpip::Storage* paramData) { 94 84 : switch (variable) { 95 80 : case TRACI_ID_LIST: 96 80 : return wrapper->wrapStringList(objID, variable, getIDList()); 97 4 : case ID_COUNT: 98 4 : return wrapper->wrapInt(objID, variable, getIDCount()); 99 0 : case libsumo::VAR_PARAMETER: 100 0 : paramData->readUnsignedByte(); 101 0 : return wrapper->wrapString(objID, variable, getParameter(objID, paramData->readString())); 102 0 : case libsumo::VAR_PARAMETER_WITH_KEY: 103 0 : paramData->readUnsignedByte(); 104 0 : return wrapper->wrapStringPair(objID, variable, getParameterWithKey(objID, paramData->readString())); 105 : default: 106 : return false; 107 : } 108 : } 109 : 110 : } 111 : 112 : 113 : /****************************************************************************/