#include <config.h>
#include <microsim/MSNet.h>
#include <microsim/MSLane.h>
#include <microsim/trigger/MSLaneSpeedTrigger.h>
#include <libsumo/TraCIConstants.h>
#include "Helper.h"
#include "VariableSpeedSign.h"
namespace libsumo {
SubscriptionResults VariableSpeedSign::mySubscriptionResults;
ContextSubscriptionResults VariableSpeedSign::myContextSubscriptionResults;
std::vector<std::string>
VariableSpeedSign::getIDList() {
MSNet::getInstance();
std::vector<std::string> ids;
for (auto& item : MSLaneSpeedTrigger::getInstances()) {
ids.push_back(item.first);
}
return ids;
}
int
VariableSpeedSign::getIDCount() {
return (int)getIDList().size();
}
std::vector<std::string>
VariableSpeedSign::getLanes(const std::string& vssID) {
std::vector<std::string> result;
MSLaneSpeedTrigger* vss = getVariableSpeedSign(vssID);
for (MSLane* lane : vss->getLanes()) {
result.push_back(lane->getID());
}
return result;
}
std::string
VariableSpeedSign::getParameter(const std::string& , const std::string& ) {
return "";
}
LIBSUMO_GET_PARAMETER_WITH_KEY_IMPLEMENTATION(VariableSpeedSign)
void
VariableSpeedSign::setParameter(const std::string& , const std::string& , const std::string& ) {
}
LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(VariableSpeedSign, VARIABLESPEEDSIGN)
MSLaneSpeedTrigger*
VariableSpeedSign::getVariableSpeedSign(const std::string& id) {
const auto& dict = MSLaneSpeedTrigger::getInstances();
auto it = dict.find(id);
if (it == dict.end()) {
throw TraCIException("VariableSpeedSign '" + id + "' is not known");
}
return it->second;
}
std::shared_ptr<VariableWrapper>
VariableSpeedSign::makeWrapper() {
return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
}
bool
VariableSpeedSign::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper, tcpip::Storage* paramData) {
switch (variable) {
case TRACI_ID_LIST:
return wrapper->wrapStringList(objID, variable, getIDList());
case ID_COUNT:
return wrapper->wrapInt(objID, variable, getIDCount());
case VAR_LANES:
return wrapper->wrapStringList(objID, variable, getLanes(objID));
case libsumo::VAR_PARAMETER:
paramData->readUnsignedByte();
return wrapper->wrapString(objID, variable, getParameter(objID, paramData->readString()));
case libsumo::VAR_PARAMETER_WITH_KEY:
paramData->readUnsignedByte();
return wrapper->wrapStringPair(objID, variable, getParameterWithKey(objID, paramData->readString()));
default:
return false;
}
}
}