本文整理汇总了C++中tcpip::Storage::readUnsignedByte方法的典型用法代码示例。如果您正苦于以下问题:C++ Storage::readUnsignedByte方法的具体用法?C++ Storage::readUnsignedByte怎么用?C++ Storage::readUnsignedByte使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tcpip::Storage
的用法示例。
在下文中一共展示了Storage::readUnsignedByte方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: catch
bool
TraCIServerAPI_VehicleType::processSet(TraCIServer& server, tcpip::Storage& inputStorage,
tcpip::Storage& outputStorage) {
std::string warning = ""; // additional description for response
// variable
int variable = inputStorage.readUnsignedByte();
if (variable != VAR_LENGTH && variable != VAR_MAXSPEED && variable != VAR_VEHICLECLASS
&& variable != VAR_SPEED_FACTOR && variable != VAR_SPEED_DEVIATION && variable != VAR_EMISSIONCLASS
&& variable != VAR_WIDTH && variable != VAR_MINGAP && variable != VAR_SHAPECLASS
&& variable != VAR_ACCEL && variable != VAR_DECEL && variable != VAR_IMPERFECTION
&& variable != VAR_TAU && variable != VAR_COLOR
) {
server.writeStatusCmd(CMD_SET_VEHICLETYPE_VARIABLE, RTYPE_ERR, "Change Vehicle Type State: unsupported variable specified", outputStorage);
return false;
}
// id
std::string id = inputStorage.readString();
MSVehicleType* v = MSNet::getInstance()->getVehicleControl().getVType(id);
if (v == 0) {
server.writeStatusCmd(CMD_SET_VEHICLETYPE_VARIABLE, RTYPE_ERR, "Vehicle type '" + id + "' is not known", outputStorage);
return false;
}
// process
try {
if (setVariable(CMD_SET_VEHICLETYPE_VARIABLE, variable, inputStorage.readUnsignedByte(),
*v, server, inputStorage, outputStorage)) {
server.writeStatusCmd(CMD_SET_VEHICLETYPE_VARIABLE, RTYPE_OK, warning, outputStorage);
return true;
}
} catch (ProcessError& e) {
server.writeStatusCmd(CMD_SET_VEHICLETYPE_VARIABLE, RTYPE_ERR, e.what(), outputStorage);
}
return false;
}
示例2:
bool
TraCIServer::readTypeCheckingUnsignedByte(tcpip::Storage& inputStorage, int& into) {
if (inputStorage.readUnsignedByte() != TYPE_UBYTE) {
return false;
}
into = inputStorage.readUnsignedByte();
return true;
}
示例3: ReadGetResponse
void Query::ReadGetResponse(tcpip::Storage & content) {
int position = 0;
int length2 = 0;
int extLength = 0;
int length = 0;
int commandId = 0;
int varId = 0;
string objectId = "";
int variableType = 0;
try {
position = content.position();
length2 = content.size();
extLength = content.readUnsignedByte();
if (extLength == 0) {
length = content.readInt();
}
commandId = content.readUnsignedByte();
varId = content.readUnsignedByte();
objectId = content.readString();
variableType = content.readUnsignedByte();
int listLen = 0;
int count = 0;
switch (variableType) {
case TYPE_STRING:
stringValue = content.readString();
break;
case TYPE_INTEGER:
intValue = content.readInt();
break;
case TYPE_DOUBLE:
doubleValue = content.readDouble();
break;
case TYPE_STRINGLIST:
listLen = content.readInt();
stringListValue.clear();
for (int i=0; i<listLen; i++) {
stringListValue.push_back(content.readString());
}
break;
case POSITION_2D:
positionValue.x = content.readDouble();
positionValue.y = content.readDouble();
break;
case TYPE_BOUNDINGBOX:
count = content.size()/sizeof(double);
for (int i = 0; i < count-1; i++) {
vectorValue.push_back(content.readDouble());
}
break;
default:
break;
}
}
catch (exception & ex) {
cout << "can't read response for object " << objectId << ex.what() << endl;
cout<<position<<" "<<length2 << " "<<extLength<<" "<<length<<" "<<commandId<<" "<<varId<<" "<<objectId<<" "<<variableType<< "\n";
}
}
示例4: getMainWindow
// ===========================================================================
// method definitions
// ===========================================================================
bool
TraCIServerAPI_GUI::processGet(TraCIServer& server, tcpip::Storage& inputStorage,
tcpip::Storage& outputStorage) {
// variable & id
int variable = inputStorage.readUnsignedByte();
std::string id = inputStorage.readString();
// check variable
if (variable != ID_LIST && variable != VAR_VIEW_ZOOM && variable != VAR_VIEW_OFFSET
&& variable != VAR_VIEW_SCHEMA && variable != VAR_VIEW_BOUNDARY) {
return server.writeErrorStatusCmd(CMD_GET_GUI_VARIABLE, "Get GUI Variable: unsupported variable specified", outputStorage);
}
// begin response building
tcpip::Storage tempMsg;
// response-code, variableID, objectID
tempMsg.writeUnsignedByte(RESPONSE_GET_GUI_VARIABLE);
tempMsg.writeUnsignedByte(variable);
tempMsg.writeString(id);
// process request
if (variable == ID_LIST) {
std::vector<std::string> ids = getMainWindow()->getViewIDs();
tempMsg.writeUnsignedByte(TYPE_STRINGLIST);
tempMsg.writeStringList(ids);
} else {
GUISUMOAbstractView* v = getNamedView(id);
if (v == 0) {
return server.writeErrorStatusCmd(CMD_GET_GUI_VARIABLE, "View '" + id + "' is not known", outputStorage);
}
switch (variable) {
case VAR_VIEW_ZOOM:
tempMsg.writeUnsignedByte(TYPE_DOUBLE);
tempMsg.writeDouble(v->getChanger().getZoom());
break;
case VAR_VIEW_OFFSET:
tempMsg.writeUnsignedByte(POSITION_2D);
tempMsg.writeDouble(v->getChanger().getXPos());
tempMsg.writeDouble(v->getChanger().getYPos());
break;
case VAR_VIEW_SCHEMA: {
FXComboBox& c = v->getColoringSchemesCombo();
tempMsg.writeUnsignedByte(TYPE_STRING);
tempMsg.writeString((std::string)c.getItem(c.getCurrentItem()).text());
break;
}
case VAR_VIEW_BOUNDARY: {
tempMsg.writeUnsignedByte(TYPE_BOUNDINGBOX);
Boundary b = v->getVisibleBoundary();
tempMsg.writeDouble(b.xmin());
tempMsg.writeDouble(b.ymin());
tempMsg.writeDouble(b.xmax());
tempMsg.writeDouble(b.ymax());
break;
}
default:
break;
}
}
server.writeStatusCmd(CMD_GET_GUI_VARIABLE, RTYPE_OK, "", outputStorage);
server.writeResponseWithLength(outputStorage, tempMsg);
return true;
}
示例5: switch
// ===========================================================================
// method definitions
// ===========================================================================
bool
TraCIServerAPI_POI::processGet(TraCIServer& server, tcpip::Storage& inputStorage,
tcpip::Storage& outputStorage) {
const int variable = inputStorage.readUnsignedByte();
const std::string id = inputStorage.readString();
server.initWrapper(libsumo::RESPONSE_GET_POI_VARIABLE, variable, id);
try {
if (!libsumo::POI::handleVariable(id, variable, &server)) {
switch (variable) {
case libsumo::VAR_PARAMETER: {
std::string paramName = "";
if (!server.readTypeCheckingString(inputStorage, paramName)) {
return server.writeErrorStatusCmd(libsumo::CMD_GET_POI_VARIABLE, "Retrieval of a parameter requires its name.", outputStorage);
}
server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_STRING);
server.getWrapperStorage().writeString(libsumo::POI::getParameter(id, paramName));
break;
}
default:
return server.writeErrorStatusCmd(libsumo::CMD_GET_POI_VARIABLE, "Get PoI Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
}
}
} catch (libsumo::TraCIException& e) {
return server.writeErrorStatusCmd(libsumo::CMD_GET_POI_VARIABLE, e.what(), outputStorage);
}
server.writeStatusCmd(libsumo::CMD_GET_POI_VARIABLE, libsumo::RTYPE_OK, "", outputStorage);
server.writeResponseWithLength(outputStorage, server.getWrapperStorage());
return true;
}
示例6: getPoI
// ===========================================================================
// method definitions
// ===========================================================================
bool
TraCIServerAPI_POI::processGet(TraCIServer& server, tcpip::Storage& inputStorage,
tcpip::Storage& outputStorage) {
// variable & id
int variable = inputStorage.readUnsignedByte();
std::string id = inputStorage.readString();
// check variable
if (variable != ID_LIST && variable != VAR_TYPE && variable != VAR_COLOR && variable != VAR_POSITION && variable != ID_COUNT) {
return server.writeErrorStatusCmd(CMD_GET_POI_VARIABLE, "Get PoI Variable: unsupported variable specified", outputStorage);
}
// begin response building
tcpip::Storage tempMsg;
// response-code, variableID, objectID
tempMsg.writeUnsignedByte(RESPONSE_GET_POI_VARIABLE);
tempMsg.writeUnsignedByte(variable);
tempMsg.writeString(id);
// process request
if (variable == ID_LIST || variable == ID_COUNT) {
std::vector<std::string> ids;
ShapeContainer& shapeCont = MSNet::getInstance()->getShapeContainer();
shapeCont.getPOIs().insertIDs(ids);
if (variable == ID_LIST) {
tempMsg.writeUnsignedByte(TYPE_STRINGLIST);
tempMsg.writeStringList(ids);
} else {
tempMsg.writeUnsignedByte(TYPE_INTEGER);
tempMsg.writeInt((int) ids.size());
}
} else {
PointOfInterest* p = getPoI(id);
if (p == 0) {
return server.writeErrorStatusCmd(CMD_GET_POI_VARIABLE, "POI '" + id + "' is not known", outputStorage);
}
switch (variable) {
case VAR_TYPE:
tempMsg.writeUnsignedByte(TYPE_STRING);
tempMsg.writeString(p->getType());
break;
case VAR_COLOR:
tempMsg.writeUnsignedByte(TYPE_COLOR);
tempMsg.writeUnsignedByte(p->getColor().red());
tempMsg.writeUnsignedByte(p->getColor().green());
tempMsg.writeUnsignedByte(p->getColor().blue());
tempMsg.writeUnsignedByte(p->getColor().alpha());
break;
case VAR_POSITION:
tempMsg.writeUnsignedByte(POSITION_2D);
tempMsg.writeDouble(p->x());
tempMsg.writeDouble(p->y());
break;
default:
break;
}
}
server.writeStatusCmd(CMD_GET_POI_VARIABLE, RTYPE_OK, "", outputStorage);
server.writeResponseWithLength(outputStorage, tempMsg);
return true;
}
示例7: switch
bool
TraCIServerAPI_Route::processSet(TraCIServer& server, tcpip::Storage& inputStorage,
tcpip::Storage& outputStorage) {
std::string warning = ""; // additional description for response
// variable
int variable = inputStorage.readUnsignedByte();
if (variable != ADD) {
server.writeStatusCmd(CMD_SET_ROUTE_VARIABLE, RTYPE_ERR, "Change Route State: unsupported variable specified", outputStorage);
return false;
}
// id
std::string id = inputStorage.readString();
// process
int valueDataType = inputStorage.readUnsignedByte();
switch (variable) {
case ADD: {
if (valueDataType != TYPE_STRINGLIST) {
server.writeStatusCmd(CMD_SET_ROUTE_VARIABLE, RTYPE_ERR, "A string list is needed for adding a new route.", outputStorage);
return false;
}
//read itemNo
int numEdges = inputStorage.readInt();
MSEdgeVector edges;
while (numEdges--) {
std::string edgeID = inputStorage.readString();
MSEdge* edge = MSEdge::dictionary(edgeID);
if (edge == 0) {
server.writeStatusCmd(CMD_SET_ROUTE_VARIABLE, RTYPE_ERR, "Unknown edge '" + edgeID + "' in route.", outputStorage);
return false;
}
edges.push_back(edge);
}
const std::vector<SUMOVehicleParameter::Stop> stops;
if (!MSRoute::dictionary(id, new MSRoute(id, edges, 1, 0, stops))) {
server.writeStatusCmd(CMD_SET_ROUTE_VARIABLE, RTYPE_ERR, "Could not add route.", outputStorage);
return false;
}
}
break;
default:
break;
}
server.writeStatusCmd(CMD_SET_ROUTE_VARIABLE, RTYPE_OK, warning, outputStorage);
return true;
}
示例8: toHex
// ===========================================================================
// method definitions
// ===========================================================================
bool
TraCIServerAPI_Route::processGet(TraCIServer& server, tcpip::Storage& inputStorage,
tcpip::Storage& outputStorage) {
// variable & id
int variable = inputStorage.readUnsignedByte();
std::string id = inputStorage.readString();
// check variable
if (variable != ID_LIST && variable != VAR_EDGES && variable != ID_COUNT && variable != VAR_PARAMETER) {
return server.writeErrorStatusCmd(CMD_GET_ROUTE_VARIABLE, "Get Route Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
}
// begin response building
tcpip::Storage tempMsg;
// response-code, variableID, objectID
tempMsg.writeUnsignedByte(RESPONSE_GET_ROUTE_VARIABLE);
tempMsg.writeUnsignedByte(variable);
tempMsg.writeString(id);
// process request
if (variable == ID_LIST) {
std::vector<std::string> ids;
MSRoute::insertIDs(ids);
tempMsg.writeUnsignedByte(TYPE_STRINGLIST);
tempMsg.writeStringList(ids);
} else if (variable == ID_COUNT) {
std::vector<std::string> ids;
MSRoute::insertIDs(ids);
tempMsg.writeUnsignedByte(TYPE_INTEGER);
tempMsg.writeInt((int) ids.size());
} else {
const MSRoute* r = MSRoute::dictionary(id);
if (r == 0) {
return server.writeErrorStatusCmd(CMD_GET_ROUTE_VARIABLE, "Route '" + id + "' is not known", outputStorage);
}
switch (variable) {
case VAR_EDGES:
tempMsg.writeUnsignedByte(TYPE_STRINGLIST);
tempMsg.writeInt(r->size());
for (MSRouteIterator i = r->begin(); i != r->end(); ++i) {
tempMsg.writeString((*i)->getID());
}
break;
case VAR_PARAMETER: {
std::string paramName = "";
if (!server.readTypeCheckingString(inputStorage, paramName)) {
return server.writeErrorStatusCmd(CMD_GET_ROUTE_VARIABLE, "Retrieval of a parameter requires its name.", outputStorage);
}
tempMsg.writeUnsignedByte(TYPE_STRING);
tempMsg.writeString(r->getParameter(paramName, ""));
}
break;
default:
break;
}
}
server.writeStatusCmd(CMD_GET_ROUTE_VARIABLE, RTYPE_OK, "", outputStorage);
server.writeResponseWithLength(outputStorage, tempMsg);
return true;
}
示例9: switch
bool
TraCIServerAPI_Lane::processSet(TraCIServer& server, tcpip::Storage& inputStorage,
tcpip::Storage& outputStorage) {
std::string warning = ""; // additional description for response
// variable
int variable = inputStorage.readUnsignedByte();
if (variable != VAR_MAXSPEED && variable != VAR_LENGTH && variable != LANE_ALLOWED && variable != LANE_DISALLOWED) {
return server.writeErrorStatusCmd(CMD_SET_LANE_VARIABLE, "Change Lane State: unsupported variable specified", outputStorage);
}
// id
std::string id = inputStorage.readString();
MSLane* l = MSLane::dictionary(id);
if (l == 0) {
return server.writeErrorStatusCmd(CMD_SET_LANE_VARIABLE, "Lane '" + id + "' is not known", outputStorage);
}
// process
switch (variable) {
case VAR_MAXSPEED: {
double value = 0;
if (!server.readTypeCheckingDouble(inputStorage, value)) {
return server.writeErrorStatusCmd(CMD_SET_LANE_VARIABLE, "The speed must be given as a double.", outputStorage);
}
l->setMaxSpeed(value);
}
break;
case VAR_LENGTH: {
double value = 0;
if (!server.readTypeCheckingDouble(inputStorage, value)) {
return server.writeErrorStatusCmd(CMD_SET_LANE_VARIABLE, "The length must be given as a double.", outputStorage);
}
l->setLength(value);
}
break;
case LANE_ALLOWED: {
std::vector<std::string> classes;
if (!server.readTypeCheckingStringList(inputStorage, classes)) {
return server.writeErrorStatusCmd(CMD_SET_LANE_VARIABLE, "Allowed classes must be given as a list of strings.", outputStorage);
}
l->setPermissions(parseVehicleClasses(classes));
l->getEdge().rebuildAllowedLanes();
}
break;
case LANE_DISALLOWED: {
std::vector<std::string> classes;
if (!server.readTypeCheckingStringList(inputStorage, classes)) {
return server.writeErrorStatusCmd(CMD_SET_LANE_VARIABLE, "Not allowed classes must be given as a list of strings.", outputStorage);
}
l->setPermissions(~parseVehicleClasses(classes)); // negation yields allowed
l->getEdge().rebuildAllowedLanes();
}
break;
default:
break;
}
server.writeStatusCmd(CMD_SET_LANE_VARIABLE, RTYPE_OK, warning, outputStorage);
return true;
}
示例10: if
// ===========================================================================
// method definitions
// ===========================================================================
bool
TraCIServerAPI_Junction::processGet(TraCIServer& server, tcpip::Storage& inputStorage,
tcpip::Storage& outputStorage) {
// variable
int variable = inputStorage.readUnsignedByte();
std::string id = inputStorage.readString();
// check variable
if (variable != ID_LIST && variable != VAR_POSITION && variable != ID_COUNT && variable != VAR_SHAPE) {
return server.writeErrorStatusCmd(CMD_GET_JUNCTION_VARIABLE, "Get Junction Variable: unsupported variable specified", outputStorage);
}
// begin response building
tcpip::Storage tempMsg;
// response-code, variableID, objectID
tempMsg.writeUnsignedByte(RESPONSE_GET_JUNCTION_VARIABLE);
tempMsg.writeUnsignedByte(variable);
tempMsg.writeString(id);
if (variable == ID_LIST) {
std::vector<std::string> ids;
MSNet::getInstance()->getJunctionControl().insertIDs(ids);
tempMsg.writeUnsignedByte(TYPE_STRINGLIST);
tempMsg.writeStringList(ids);
} else if (variable == ID_COUNT) {
std::vector<std::string> ids;
MSNet::getInstance()->getJunctionControl().insertIDs(ids);
tempMsg.writeUnsignedByte(TYPE_INTEGER);
tempMsg.writeInt((int) ids.size());
} else {
MSJunction* j = MSNet::getInstance()->getJunctionControl().get(id);
if (j == 0) {
return server.writeErrorStatusCmd(CMD_GET_JUNCTION_VARIABLE, "Junction '" + id + "' is not known", outputStorage);
}
switch (variable) {
case ID_LIST:
break;
case VAR_POSITION:
tempMsg.writeUnsignedByte(POSITION_2D);
tempMsg.writeDouble(j->getPosition().x());
tempMsg.writeDouble(j->getPosition().y());
break;
case VAR_SHAPE:
tempMsg.writeUnsignedByte(TYPE_POLYGON);
tempMsg.writeUnsignedByte((int)MIN2(static_cast<size_t>(255), j->getShape().size()));
for (unsigned int iPoint = 0; iPoint < MIN2(static_cast<size_t>(255), j->getShape().size()); ++iPoint) {
tempMsg.writeDouble(j->getShape()[iPoint].x());
tempMsg.writeDouble(j->getShape()[iPoint].y());
}
break;
default:
break;
}
}
server.writeStatusCmd(CMD_GET_JUNCTION_VARIABLE, RTYPE_OK, "", outputStorage);
server.writeResponseWithLength(outputStorage, tempMsg);
return true;
}
示例11: toHex
// ===========================================================================
// method definitions
// ===========================================================================
bool
TraCIServerAPI_MultiEntryExit::processGet(TraCIServer& server, tcpip::Storage& inputStorage,
tcpip::Storage& outputStorage) {
const int variable = inputStorage.readUnsignedByte();
const std::string id = inputStorage.readString();
server.initWrapper(libsumo::RESPONSE_GET_MULTIENTRYEXIT_VARIABLE, variable, id);
try {
if (!libsumo::MultiEntryExit::handleVariable(id, variable, &server)) {
return server.writeErrorStatusCmd(libsumo::CMD_GET_MULTIENTRYEXIT_VARIABLE, "Get Multi Entry Exit Detector Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
}
} catch (libsumo::TraCIException& e) {
return server.writeErrorStatusCmd(libsumo::CMD_GET_MULTIENTRYEXIT_VARIABLE, e.what(), outputStorage);
}
server.writeStatusCmd(libsumo::CMD_GET_MULTIENTRYEXIT_VARIABLE, libsumo::RTYPE_OK, "", outputStorage);
server.writeResponseWithLength(outputStorage, server.getWrapperStorage());
return true;
}
示例12: if
// ===========================================================================
// method definitions
// ===========================================================================
bool
TraCIServerAPI_VehicleType::processGet(TraCIServer& server, tcpip::Storage& inputStorage,
tcpip::Storage& outputStorage) {
std::string warning = ""; // additional description for response
// variable & id
int variable = inputStorage.readUnsignedByte();
std::string id = inputStorage.readString();
// check variable
if (variable != ID_LIST && variable != VAR_LENGTH && variable != VAR_MAXSPEED && variable != VAR_ACCEL && variable != VAR_DECEL
&& variable != VAR_TAU && variable != VAR_VEHICLECLASS && variable != VAR_EMISSIONCLASS && variable != VAR_SHAPECLASS
&& variable != VAR_SPEED_FACTOR && variable != VAR_SPEED_DEVIATION && variable != VAR_IMPERFECTION
&& variable != VAR_MINGAP && variable != VAR_WIDTH && variable != VAR_COLOR && variable != ID_COUNT) {
server.writeStatusCmd(CMD_GET_VEHICLETYPE_VARIABLE, RTYPE_ERR, "Get Vehicle Type Variable: unsupported variable specified", outputStorage);
return false;
}
// begin response building
tcpip::Storage tempMsg;
// response-code, variableID, objectID
tempMsg.writeUnsignedByte(RESPONSE_GET_VEHICLETYPE_VARIABLE);
tempMsg.writeUnsignedByte(variable);
tempMsg.writeString(id);
// process request
if (variable == ID_LIST) {
std::vector<std::string> ids;
MSNet::getInstance()->getVehicleControl().insertVTypeIDs(ids);
tempMsg.writeUnsignedByte(TYPE_STRINGLIST);
tempMsg.writeStringList(ids);
} else if (variable == ID_COUNT) {
std::vector<std::string> ids;
MSNet::getInstance()->getVehicleControl().insertVTypeIDs(ids);
tempMsg.writeUnsignedByte(TYPE_INTEGER);
tempMsg.writeInt((int) ids.size());
} else {
MSVehicleType* v = MSNet::getInstance()->getVehicleControl().getVType(id);
if (v == 0) {
server.writeStatusCmd(CMD_GET_VEHICLETYPE_VARIABLE, RTYPE_ERR, "Vehicle type '" + id + "' is not known", outputStorage);
return false;
}
getVariable(variable, *v, tempMsg);
}
server.writeStatusCmd(CMD_GET_VEHICLETYPE_VARIABLE, RTYPE_OK, warning, outputStorage);
server.writeResponseWithLength(outputStorage, tempMsg);
return true;
}
示例13: toHex
bool
TraCIServerAPI_Simulation::processSet(TraCIServer& server, tcpip::Storage& inputStorage,
tcpip::Storage& outputStorage) {
std::string warning = ""; // additional description for response
// variable
int variable = inputStorage.readUnsignedByte();
if (variable != CMD_CLEAR_PENDING_VEHICLES
&& variable != CMD_SAVE_SIMSTATE) {
return server.writeErrorStatusCmd(CMD_SET_SIM_VARIABLE, "Set Simulation Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
}
// id
std::string id = inputStorage.readString();
// process
try {
switch (variable) {
case CMD_CLEAR_PENDING_VEHICLES: {
//clear any pending vehicle insertions
std::string route;
if (!server.readTypeCheckingString(inputStorage, route)) {
return server.writeErrorStatusCmd(CMD_SET_SIM_VARIABLE, "A string is needed for clearing pending vehicles.", outputStorage);
}
libsumo::Simulation::clearPending(route);
}
break;
case CMD_SAVE_SIMSTATE: {
//save current simulation state
std::string file;
if (!server.readTypeCheckingString(inputStorage, file)) {
return server.writeErrorStatusCmd(CMD_SET_SIM_VARIABLE, "A string is needed for saving simulation state.", outputStorage);
}
libsumo::Simulation::saveState(file);
}
break;
default:
break;
}
} catch (libsumo::TraCIException& e) {
return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, e.what(), outputStorage);
}
server.writeStatusCmd(CMD_SET_SIM_VARIABLE, RTYPE_OK, warning, outputStorage);
return true;
}
示例14: switch
bool
TraCIServerAPI_Route::processSet(TraCIServer& server, tcpip::Storage& inputStorage,
tcpip::Storage& outputStorage) {
std::string warning = ""; // additional description for response
// variable
int variable = inputStorage.readUnsignedByte();
if (variable != ADD) {
return server.writeErrorStatusCmd(CMD_SET_ROUTE_VARIABLE, "Change Route State: unsupported variable specified", outputStorage);
}
// id
std::string id = inputStorage.readString();
// process
switch (variable) {
case ADD: {
std::vector<std::string> edgeIDs;
if (!server.readTypeCheckingStringList(inputStorage, edgeIDs)) {
return server.writeErrorStatusCmd(CMD_SET_ROUTE_VARIABLE, "A string list is needed for adding a new route.", outputStorage);
}
//read itemNo
MSEdgeVector edges;
for (std::vector<std::string>::const_iterator i = edgeIDs.begin(); i != edgeIDs.end(); ++i) {
MSEdge* edge = MSEdge::dictionary(*i);
if (edge == 0) {
return server.writeErrorStatusCmd(CMD_SET_ROUTE_VARIABLE, "Unknown edge '" + *i + "' in route.", outputStorage);
}
edges.push_back(edge);
}
const std::vector<SUMOVehicleParameter::Stop> stops;
if (!MSRoute::dictionary(id, new MSRoute(id, edges, 1, 0, stops))) {
return server.writeErrorStatusCmd(CMD_SET_ROUTE_VARIABLE, "Could not add route.", outputStorage);
}
}
break;
default:
break;
}
server.writeStatusCmd(CMD_SET_ROUTE_VARIABLE, RTYPE_OK, warning, outputStorage);
return true;
}
示例15: if
// ===========================================================================
// method definitions
// ===========================================================================
bool
TraCIServerAPI_MeMeDetector::processGet(TraCIServer& server, tcpip::Storage& inputStorage,
tcpip::Storage& outputStorage) {
std::string warning = ""; // additional description for response
// variable & id
int variable = inputStorage.readUnsignedByte();
std::string id = inputStorage.readString();
// check variable
if (variable != ID_LIST && variable != LAST_STEP_VEHICLE_NUMBER && variable != LAST_STEP_MEAN_SPEED
&& variable != LAST_STEP_VEHICLE_ID_LIST && variable != LAST_STEP_VEHICLE_HALTING_NUMBER
&& variable != ID_COUNT) {
server.writeStatusCmd(CMD_GET_MULTI_ENTRY_EXIT_DETECTOR_VARIABLE, RTYPE_ERR, "Get MeMeDetector Variable: unsupported variable specified", outputStorage);
return false;
}
// begin response building
tcpip::Storage tempMsg;
// response-code, variableID, objectID
tempMsg.writeUnsignedByte(RESPONSE_GET_MULTI_ENTRY_EXIT_DETECTOR_VARIABLE);
tempMsg.writeUnsignedByte(variable);
tempMsg.writeString(id);
if (variable == ID_LIST) {
std::vector<std::string> ids;
MSNet::getInstance()->getDetectorControl().getTypedDetectors(SUMO_TAG_ENTRY_EXIT_DETECTOR).insertIDs(ids);
tempMsg.writeUnsignedByte(TYPE_STRINGLIST);
tempMsg.writeStringList(ids);
} else if (variable == ID_COUNT) {
std::vector<std::string> ids;
MSNet::getInstance()->getDetectorControl().getTypedDetectors(SUMO_TAG_ENTRY_EXIT_DETECTOR).insertIDs(ids);
tempMsg.writeUnsignedByte(TYPE_INTEGER);
tempMsg.writeInt((int) ids.size());
} else {
MSE3Collector* e3 = static_cast<MSE3Collector*>(MSNet::getInstance()->getDetectorControl().getTypedDetectors(SUMO_TAG_ENTRY_EXIT_DETECTOR).get(id));
if (e3 == 0) {
server.writeStatusCmd(CMD_GET_MULTI_ENTRY_EXIT_DETECTOR_VARIABLE, RTYPE_ERR, "Areal detector '" + id + "' is not known", outputStorage);
return false;
}
switch (variable) {
case ID_LIST:
break;
case LAST_STEP_VEHICLE_NUMBER:
tempMsg.writeUnsignedByte(TYPE_INTEGER);
tempMsg.writeInt((int) e3->getVehiclesWithin());
break;
case LAST_STEP_MEAN_SPEED:
tempMsg.writeUnsignedByte(TYPE_DOUBLE);
tempMsg.writeDouble(e3->getCurrentMeanSpeed());
break;
case LAST_STEP_VEHICLE_ID_LIST: {
tempMsg.writeUnsignedByte(TYPE_STRINGLIST);
std::vector<std::string> ids = e3->getCurrentVehicleIDs();
tempMsg.writeStringList(ids);
}
break;
case LAST_STEP_VEHICLE_HALTING_NUMBER:
tempMsg.writeUnsignedByte(TYPE_INTEGER);
tempMsg.writeInt((int) e3->getCurrentHaltingNumber());
break;
default:
break;
}
}
server.writeStatusCmd(CMD_GET_MULTI_ENTRY_EXIT_DETECTOR_VARIABLE, RTYPE_OK, warning, outputStorage);
server.writeResponseWithLength(outputStorage, tempMsg);
return true;
}