TraCIServerAPI_Route.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // APIs for getting/setting route values via TraCI
00008 /****************************************************************************/
00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00010 // Copyright 2001-2010 DLR (http://www.dlr.de/) and contributors
00011 /****************************************************************************/
00012 //
00013 //   This program is free software; you can redistribute it and/or modify
00014 //   it under the terms of the GNU General Public License as published by
00015 //   the Free Software Foundation; either version 2 of the License, or
00016 //   (at your option) any later version.
00017 //
00018 /****************************************************************************/
00019 
00020 
00021 // ===========================================================================
00022 // included modules
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 // used namespaces
00044 // ===========================================================================
00045 using namespace std;
00046 using namespace traci;
00047 using namespace tcpip;
00048 
00049 
00050 // ===========================================================================
00051 // method definitions
00052 // ===========================================================================
00053 bool
00054 TraCIServerAPI_Route::processGet(tcpip::Storage &inputStorage,
00055                                  tcpip::Storage &outputStorage,
00056                                  bool withStatus) throw(TraCIException) {
00057     std::string warning = ""; // additional description for response
00058     // variable & id
00059     int variable = inputStorage.readUnsignedByte();
00060     std::string id = inputStorage.readString();
00061     // check variable
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     // begin response building
00067     Storage tempMsg;
00068     //  response-code, variableID, objectID
00069     tempMsg.writeUnsignedByte(RESPONSE_GET_ROUTE_VARIABLE);
00070     tempMsg.writeUnsignedByte(variable);
00071     tempMsg.writeString(id);
00072     // process request
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     // send response
00100     outputStorage.writeUnsignedByte(0); // command length -> extended
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 

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