SUMO - Simulation of Urban MObility

TraCIServerAPI_Junction.cpp

Go to the documentation of this file.
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 #include "TraCIConstants.h"
00034 #include <microsim/MSJunction.h>
00035 #include <microsim/MSJunctionControl.h>
00036 #include <microsim/MSNet.h>
00037 #include "TraCIServerAPI_Junction.h"
00038 
00039 #ifdef CHECK_MEMORY_LEAKS
00040 #include <foreign/nvwa/debug_new.h>
00041 #endif // CHECK_MEMORY_LEAKS
00042 
00043 
00044 // ===========================================================================
00045 // used namespaces
00046 // ===========================================================================
00047 using namespace traci;
00048 
00049 
00050 // ===========================================================================
00051 // method definitions
00052 // ===========================================================================
00053 bool
00054 TraCIServerAPI_Junction::processGet(TraCIServer& server, tcpip::Storage& inputStorage,
00055                                     tcpip::Storage& outputStorage) {
00056     std::string warning = "";   // additional description for response
00057     // variable
00058     int variable = inputStorage.readUnsignedByte();
00059     std::string id = inputStorage.readString();
00060     // check variable
00061     if (variable != ID_LIST && variable != VAR_POSITION && variable != ID_COUNT) {
00062         server.writeStatusCmd(CMD_GET_JUNCTION_VARIABLE, RTYPE_ERR, "Get Junction Variable: unsupported variable specified", outputStorage);
00063         return false;
00064     }
00065     // begin response building
00066     tcpip::Storage tempMsg;
00067     //  response-code, variableID, objectID
00068     tempMsg.writeUnsignedByte(RESPONSE_GET_JUNCTION_VARIABLE);
00069     tempMsg.writeUnsignedByte(variable);
00070     tempMsg.writeString(id);
00071     if (variable == ID_LIST) {
00072         std::vector<std::string> ids;
00073         MSNet::getInstance()->getJunctionControl().insertIDs(ids);
00074         tempMsg.writeUnsignedByte(TYPE_STRINGLIST);
00075         tempMsg.writeStringList(ids);
00076     } else if (variable == ID_COUNT) {
00077         std::vector<std::string> ids;
00078         MSNet::getInstance()->getJunctionControl().insertIDs(ids);
00079         tempMsg.writeUnsignedByte(TYPE_INTEGER);
00080         tempMsg.writeInt((int) ids.size());
00081     } else {
00082         MSJunction* j = MSNet::getInstance()->getJunctionControl().get(id);
00083         if (j == 0) {
00084             server.writeStatusCmd(CMD_GET_JUNCTION_VARIABLE, RTYPE_ERR, "Junction '" + id + "' is not known", outputStorage);
00085             return false;
00086         }
00087         switch (variable) {
00088             case ID_LIST:
00089                 break;
00090             case VAR_POSITION:
00091                 tempMsg.writeUnsignedByte(POSITION_2D);
00092                 tempMsg.writeDouble(j->getPosition().x());
00093                 tempMsg.writeDouble(j->getPosition().y());
00094                 break;
00095             default:
00096                 break;
00097         }
00098     }
00099     server.writeStatusCmd(CMD_GET_JUNCTION_VARIABLE, RTYPE_OK, warning, outputStorage);
00100     server.writeResponseWithLength(outputStorage, tempMsg);
00101     return true;
00102 }
00103 
00104 
00105 /****************************************************************************/
00106 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines