|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // APIs for getting/setting junction values via TraCI 00008 /****************************************************************************/ 00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00010 // Copyright (C) 2001-2011 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 "TraCIConstants.h" 00031 #include <microsim/MSJunction.h> 00032 #include <microsim/MSJunctionControl.h> 00033 #include <microsim/MSNet.h> 00034 #include "TraCIServerAPI_Junction.h" 00035 00036 #ifdef CHECK_MEMORY_LEAKS 00037 #include <foreign/nvwa/debug_new.h> 00038 #endif // CHECK_MEMORY_LEAKS 00039 00040 00041 // =========================================================================== 00042 // used namespaces 00043 // =========================================================================== 00044 using namespace traci; 00045 00046 00047 // =========================================================================== 00048 // method definitions 00049 // =========================================================================== 00050 bool 00051 TraCIServerAPI_Junction::processGet(TraCIServer& server, tcpip::Storage& inputStorage, 00052 tcpip::Storage& outputStorage) { 00053 std::string warning = ""; // additional description for response 00054 // variable 00055 int variable = inputStorage.readUnsignedByte(); 00056 std::string id = inputStorage.readString(); 00057 // check variable 00058 if (variable!=ID_LIST&&variable!=VAR_POSITION&&variable!=ID_COUNT) { 00059 server.writeStatusCmd(CMD_GET_JUNCTION_VARIABLE, RTYPE_ERR, "Get Junction Variable: unsupported variable specified", outputStorage); 00060 return false; 00061 } 00062 // begin response building 00063 tcpip::Storage tempMsg; 00064 // response-code, variableID, objectID 00065 tempMsg.writeUnsignedByte(RESPONSE_GET_JUNCTION_VARIABLE); 00066 tempMsg.writeUnsignedByte(variable); 00067 tempMsg.writeString(id); 00068 if (variable==ID_LIST) { 00069 std::vector<std::string> ids; 00070 MSNet::getInstance()->getJunctionControl().insertIDs(ids); 00071 tempMsg.writeUnsignedByte(TYPE_STRINGLIST); 00072 tempMsg.writeStringList(ids); 00073 } else if (variable==ID_COUNT) { 00074 std::vector<std::string> ids; 00075 MSNet::getInstance()->getJunctionControl().insertIDs(ids); 00076 tempMsg.writeUnsignedByte(TYPE_INTEGER); 00077 tempMsg.writeInt((int) ids.size()); 00078 } else { 00079 MSJunction* j = MSNet::getInstance()->getJunctionControl().get(id); 00080 if (j==0) { 00081 server.writeStatusCmd(CMD_GET_JUNCTION_VARIABLE, RTYPE_ERR, "Junction '" + id + "' is not known", outputStorage); 00082 return false; 00083 } 00084 switch (variable) { 00085 case ID_LIST: 00086 break; 00087 case VAR_POSITION: 00088 tempMsg.writeUnsignedByte(POSITION_2D); 00089 tempMsg.writeDouble(j->getPosition().x()); 00090 tempMsg.writeDouble(j->getPosition().y()); 00091 break; 00092 default: 00093 break; 00094 } 00095 } 00096 server.writeStatusCmd(CMD_GET_JUNCTION_VARIABLE, RTYPE_OK, warning, outputStorage); 00097 server.writeResponseWithLength(outputStorage, tempMsg); 00098 return true; 00099 } 00100 00101 00102 /****************************************************************************/ 00103