TraCIServerAPI_Simulation Class Reference

#include <TraCIServerAPI_Simulation.h>


Detailed Description

APIs for getting/setting simulation values via TraCI.

Definition at line 46 of file TraCIServerAPI_Simulation.h.


Static Public Member Functions

static bool processGet (tcpip::Storage &inputStorage, tcpip::Storage &outputStorage, const std::map< MSNet::VehicleState, std::vector< std::string > > &info, bool withStatus=true) throw (traci::TraCIException)
 Processes a get value command (Command 0xaa: Get Edge Variable).

Private Member Functions

TraCIServerAPI_Simulationoperator= (const TraCIServerAPI_Simulation &s)
 invalidated assignment operator
 TraCIServerAPI_Simulation (const TraCIServerAPI_Simulation &s)
 invalidated copy constructor

Constructor & Destructor Documentation

TraCIServerAPI_Simulation::TraCIServerAPI_Simulation ( const TraCIServerAPI_Simulation s  )  [private]

invalidated copy constructor


Member Function Documentation

TraCIServerAPI_Simulation& TraCIServerAPI_Simulation::operator= ( const TraCIServerAPI_Simulation s  )  [private]

invalidated assignment operator

bool TraCIServerAPI_Simulation::processGet ( tcpip::Storage inputStorage,
tcpip::Storage outputStorage,
const std::map< MSNet::VehicleState, std::vector< std::string > > &  info,
bool  withStatus = true 
) throw (traci::TraCIException) [static]

Processes a get value command (Command 0xaa: Get Edge Variable).

Parameters:
[in] inputStorage The storage to read the command from
[out] outputStorage The storage to write the result to
[in] withStatus Whether the status message shall be written (not in subscription)

Definition at line 54 of file TraCIServerAPI_Simulation.cpp.

References CMD_GET_SIM_VARIABLE, MSNet::getInstance(), RESPONSE_GET_SIM_VARIABLE, RTYPE_ERR, RTYPE_OK, tcpip::Storage::size(), TYPE_INTEGER, TYPE_STRINGLIST, VAR_ARRIVED_VEHICLES_IDS, VAR_ARRIVED_VEHICLES_NUMBER, VAR_DEPARTED_VEHICLES_IDS, VAR_DEPARTED_VEHICLES_NUMBER, VAR_LOADED_VEHICLES_IDS, VAR_LOADED_VEHICLES_NUMBER, VAR_TELEPORT_ENDING_VEHICLES_IDS, VAR_TELEPORT_ENDING_VEHICLES_NUMBER, VAR_TELEPORT_STARTING_VEHICLES_IDS, VAR_TELEPORT_STARTING_VEHICLES_NUMBER, VAR_TIME_STEP, MSNet::VEHICLE_STATE_ARRIVED, MSNet::VEHICLE_STATE_BUILT, MSNet::VEHICLE_STATE_DEPARTED, MSNet::VEHICLE_STATE_ENDING_TELEPORT, MSNet::VEHICLE_STATE_STARTING_TELEPORT, tcpip::Storage::writeInt(), TraCIServerAPIHelper::writeStatusCmd(), tcpip::Storage::writeString(), tcpip::Storage::writeStringList(), and tcpip::Storage::writeUnsignedByte().

Referenced by traci::TraCIServer::dispatchCommand(), and traci::TraCIServer::processSingleSubscription().

00057                                                                              {
00058     std::string warning = ""; // additional description for response
00059     // variable & id
00060     int variable = inputStorage.readUnsignedByte();
00061     std::string id = inputStorage.readString();
00062     // check variable
00063     if (variable!=VAR_TIME_STEP
00064             &&variable!=VAR_LOADED_VEHICLES_NUMBER&&variable!=VAR_LOADED_VEHICLES_IDS
00065             &&variable!=VAR_DEPARTED_VEHICLES_NUMBER&&variable!=VAR_DEPARTED_VEHICLES_IDS
00066             &&variable!=VAR_TELEPORT_STARTING_VEHICLES_NUMBER&&variable!=VAR_TELEPORT_STARTING_VEHICLES_IDS
00067             &&variable!=VAR_TELEPORT_ENDING_VEHICLES_NUMBER&&variable!=VAR_TELEPORT_ENDING_VEHICLES_IDS
00068             &&variable!=VAR_ARRIVED_VEHICLES_NUMBER&&variable!=VAR_ARRIVED_VEHICLES_IDS
00069        ) {
00070         TraCIServerAPIHelper::writeStatusCmd(CMD_GET_SIM_VARIABLE, RTYPE_ERR, "Get Simulation Variable: unsupported variable specified", outputStorage);
00071         return false;
00072     }
00073     // begin response building
00074     Storage tempMsg;
00075     //  response-code, variableID, objectID
00076     tempMsg.writeUnsignedByte(RESPONSE_GET_SIM_VARIABLE);
00077     tempMsg.writeUnsignedByte(variable);
00078     tempMsg.writeString(id);
00079     // process request
00080     switch (variable) {
00081     case VAR_TIME_STEP:
00082         tempMsg.writeUnsignedByte(TYPE_INTEGER);
00083         tempMsg.writeInt(MSNet::getInstance()->getCurrentTimeStep());
00084         break;
00085     case VAR_LOADED_VEHICLES_NUMBER: {
00086         const std::vector<std::string> &ids = infos.find(MSNet::VEHICLE_STATE_BUILT)->second;
00087         tempMsg.writeUnsignedByte(TYPE_INTEGER);
00088         tempMsg.writeInt((int) ids.size());
00089     }
00090     break;
00091     case VAR_LOADED_VEHICLES_IDS: {
00092         const std::vector<std::string> &ids = infos.find(MSNet::VEHICLE_STATE_BUILT)->second;
00093         tempMsg.writeUnsignedByte(TYPE_STRINGLIST);
00094         tempMsg.writeStringList(ids);
00095     }
00096     break;
00097     case VAR_DEPARTED_VEHICLES_NUMBER: {
00098         const std::vector<std::string> &ids = infos.find(MSNet::VEHICLE_STATE_DEPARTED)->second;
00099         tempMsg.writeUnsignedByte(TYPE_INTEGER);
00100         tempMsg.writeInt((int) ids.size());
00101     }
00102     break;
00103     case VAR_DEPARTED_VEHICLES_IDS: {
00104         const std::vector<std::string> &ids = infos.find(MSNet::VEHICLE_STATE_DEPARTED)->second;
00105         tempMsg.writeUnsignedByte(TYPE_STRINGLIST);
00106         tempMsg.writeStringList(ids);
00107     }
00108     break;
00109     case VAR_TELEPORT_STARTING_VEHICLES_NUMBER: {
00110         const std::vector<std::string> &ids = infos.find(MSNet::VEHICLE_STATE_STARTING_TELEPORT)->second;
00111         tempMsg.writeUnsignedByte(TYPE_INTEGER);
00112         tempMsg.writeInt((int) ids.size());
00113     }
00114     break;
00115     case VAR_TELEPORT_STARTING_VEHICLES_IDS: {
00116         const std::vector<std::string> &ids = infos.find(MSNet::VEHICLE_STATE_STARTING_TELEPORT)->second;
00117         tempMsg.writeUnsignedByte(TYPE_STRINGLIST);
00118         tempMsg.writeStringList(ids);
00119     }
00120     break;
00121     case VAR_TELEPORT_ENDING_VEHICLES_NUMBER: {
00122         const std::vector<std::string> &ids = infos.find(MSNet::VEHICLE_STATE_ENDING_TELEPORT)->second;
00123         tempMsg.writeUnsignedByte(TYPE_INTEGER);
00124         tempMsg.writeInt((int) ids.size());
00125     }
00126     break;
00127     case VAR_TELEPORT_ENDING_VEHICLES_IDS: {
00128         const std::vector<std::string> &ids = infos.find(MSNet::VEHICLE_STATE_ENDING_TELEPORT)->second;
00129         tempMsg.writeUnsignedByte(TYPE_STRINGLIST);
00130         tempMsg.writeStringList(ids);
00131     }
00132     break;
00133     case VAR_ARRIVED_VEHICLES_NUMBER: {
00134         const std::vector<std::string> &ids = infos.find(MSNet::VEHICLE_STATE_ARRIVED)->second;
00135         tempMsg.writeUnsignedByte(TYPE_INTEGER);
00136         tempMsg.writeInt((int) ids.size());
00137     }
00138     break;
00139     case VAR_ARRIVED_VEHICLES_IDS: {
00140         const std::vector<std::string> &ids = infos.find(MSNet::VEHICLE_STATE_ARRIVED)->second;
00141         tempMsg.writeUnsignedByte(TYPE_STRINGLIST);
00142         tempMsg.writeStringList(ids);
00143     }
00144     break;
00145     default:
00146         break;
00147     }
00148     if (withStatus) {
00149         TraCIServerAPIHelper::writeStatusCmd(CMD_GET_SIM_VARIABLE, RTYPE_OK, warning, outputStorage);
00150     }
00151     // send response
00152     outputStorage.writeUnsignedByte(0); // command length -> extended
00153     outputStorage.writeInt(1 + 4 + tempMsg.size());
00154     outputStorage.writeStorage(tempMsg);
00155     return true;
00156 }


The documentation for this class was generated from the following files:

Generated on Wed May 5 00:07:01 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6