TraCIServerAPI_Route.cpp
Go to the documentation of this file.00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifdef _MSC_VER
00025 #include <windows_config.h>
00026 #else
00027 #include <config.h>
00028 #endif
00029
00030 #include <microsim/MSNet.h>
00031 #include <microsim/MSRoute.h>
00032 #include <microsim/MSEdge.h>
00033 #include "TraCIConstants.h"
00034 #include "TraCIServerAPIHelper.h"
00035 #include "TraCIServerAPI_Route.h"
00036
00037 #ifdef CHECK_MEMORY_LEAKS
00038 #include <foreign/nvwa/debug_new.h>
00039 #endif // CHECK_MEMORY_LEAKS
00040
00041
00042
00043
00044
00045 using namespace std;
00046 using namespace traci;
00047 using namespace tcpip;
00048
00049
00050
00051
00052
00053 bool
00054 TraCIServerAPI_Route::processGet(tcpip::Storage &inputStorage,
00055 tcpip::Storage &outputStorage,
00056 bool withStatus) throw(TraCIException) {
00057 std::string warning = "";
00058
00059 int variable = inputStorage.readUnsignedByte();
00060 std::string id = inputStorage.readString();
00061
00062 if (variable!=ID_LIST&&variable!=VAR_EDGES) {
00063 TraCIServerAPIHelper::writeStatusCmd(CMD_GET_ROUTE_VARIABLE, RTYPE_ERR, "Get Route Variable: unsupported variable specified", outputStorage);
00064 return false;
00065 }
00066
00067 Storage tempMsg;
00068
00069 tempMsg.writeUnsignedByte(RESPONSE_GET_ROUTE_VARIABLE);
00070 tempMsg.writeUnsignedByte(variable);
00071 tempMsg.writeString(id);
00072
00073 if (variable==ID_LIST) {
00074 std::vector<std::string> ids;
00075 MSRoute::insertIDs(ids);
00076 tempMsg.writeUnsignedByte(TYPE_STRINGLIST);
00077 tempMsg.writeStringList(ids);
00078 } else {
00079 const MSRoute *r = MSRoute::dictionary(id);
00080 if (r==0) {
00081 TraCIServerAPIHelper::writeStatusCmd(CMD_GET_ROUTE_VARIABLE, RTYPE_ERR, "Route '" + id + "' is not known", outputStorage);
00082 return false;
00083 }
00084 switch (variable) {
00085 case VAR_EDGES:
00086 tempMsg.writeUnsignedByte(TYPE_STRINGLIST);
00087 tempMsg.writeInt(r->size());
00088 for (MSRouteIterator i=r->begin(); i!=r->end(); ++i) {
00089 tempMsg.writeString((*i)->getID());
00090 }
00091 break;
00092 default:
00093 break;
00094 }
00095 }
00096 if (withStatus) {
00097 TraCIServerAPIHelper::writeStatusCmd(CMD_GET_ROUTE_VARIABLE, RTYPE_OK, warning, outputStorage);
00098 }
00099
00100 outputStorage.writeUnsignedByte(0);
00101 outputStorage.writeInt(1 + 4 + tempMsg.size());
00102 outputStorage.writeStorage(tempMsg);
00103 return true;
00104 }
00105
00106
00107 bool
00108 TraCIServerAPI_Route::processSet(tcpip::Storage &inputStorage,
00109 tcpip::Storage &outputStorage) throw(TraCIException) {
00110 return true;
00111 }
00112
00113
00114
00115
00116