SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00009 // APIs for getting/setting junction values via TraCI 00010 /****************************************************************************/ 00011 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00012 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00013 /****************************************************************************/ 00014 // 00015 // This file is part of SUMO. 00016 // SUMO is free software: you can redistribute it and/or modify 00017 // it under the terms of the GNU General Public License as published by 00018 // the Free Software Foundation, either version 3 of the License, or 00019 // (at your option) any later version. 00020 // 00021 /****************************************************************************/ 00022 00023 00024 // =========================================================================== 00025 // included modules 00026 // =========================================================================== 00027 #ifdef _MSC_VER 00028 #include <windows_config.h> 00029 #else 00030 #include <config.h> 00031 #endif 00032 00033 #ifndef NO_TRACI 00034 00035 #include "TraCIConstants.h" 00036 #include <microsim/MSJunction.h> 00037 #include <microsim/MSJunctionControl.h> 00038 #include <microsim/MSNet.h> 00039 #include "TraCIServerAPI_Junction.h" 00040 00041 #ifdef CHECK_MEMORY_LEAKS 00042 #include <foreign/nvwa/debug_new.h> 00043 #endif // CHECK_MEMORY_LEAKS 00044 00045 00046 // =========================================================================== 00047 // used namespaces 00048 // =========================================================================== 00049 using namespace traci; 00050 00051 00052 // =========================================================================== 00053 // method definitions 00054 // =========================================================================== 00055 bool 00056 TraCIServerAPI_Junction::processGet(TraCIServer& server, tcpip::Storage& inputStorage, 00057 tcpip::Storage& outputStorage) { 00058 std::string warning = ""; // additional description for response 00059 // variable 00060 int variable = inputStorage.readUnsignedByte(); 00061 std::string id = inputStorage.readString(); 00062 // check variable 00063 if (variable != ID_LIST && variable != VAR_POSITION && variable != ID_COUNT) { 00064 server.writeStatusCmd(CMD_GET_JUNCTION_VARIABLE, RTYPE_ERR, "Get Junction Variable: unsupported variable specified", outputStorage); 00065 return false; 00066 } 00067 // begin response building 00068 tcpip::Storage tempMsg; 00069 // response-code, variableID, objectID 00070 tempMsg.writeUnsignedByte(RESPONSE_GET_JUNCTION_VARIABLE); 00071 tempMsg.writeUnsignedByte(variable); 00072 tempMsg.writeString(id); 00073 if (variable == ID_LIST) { 00074 std::vector<std::string> ids; 00075 MSNet::getInstance()->getJunctionControl().insertIDs(ids); 00076 tempMsg.writeUnsignedByte(TYPE_STRINGLIST); 00077 tempMsg.writeStringList(ids); 00078 } else if (variable == ID_COUNT) { 00079 std::vector<std::string> ids; 00080 MSNet::getInstance()->getJunctionControl().insertIDs(ids); 00081 tempMsg.writeUnsignedByte(TYPE_INTEGER); 00082 tempMsg.writeInt((int) ids.size()); 00083 } else { 00084 MSJunction* j = MSNet::getInstance()->getJunctionControl().get(id); 00085 if (j == 0) { 00086 server.writeStatusCmd(CMD_GET_JUNCTION_VARIABLE, RTYPE_ERR, "Junction '" + id + "' is not known", outputStorage); 00087 return false; 00088 } 00089 switch (variable) { 00090 case ID_LIST: 00091 break; 00092 case VAR_POSITION: 00093 tempMsg.writeUnsignedByte(POSITION_2D); 00094 tempMsg.writeDouble(j->getPosition().x()); 00095 tempMsg.writeDouble(j->getPosition().y()); 00096 break; 00097 default: 00098 break; 00099 } 00100 } 00101 server.writeStatusCmd(CMD_GET_JUNCTION_VARIABLE, RTYPE_OK, warning, outputStorage); 00102 server.writeResponseWithLength(outputStorage, tempMsg); 00103 return true; 00104 } 00105 00106 #endif 00107 00108 00109 /****************************************************************************/ 00110