TraCIServerAPI_Junction.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // APIs for getting/setting junction 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 "TraCIConstants.h"
00031 #include <microsim/MSJunction.h>
00032 #include <microsim/MSJunctionControl.h>
00033 #include <microsim/MSNet.h>
00034 #include "TraCIServerAPIHelper.h"
00035 #include "TraCIServerAPI_Junction.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_Junction::processGet(tcpip::Storage &inputStorage,
00055                                     tcpip::Storage &outputStorage,
00056                                     bool withStatus) throw(TraCIException) {
00057     Storage tmpResult;
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) {
00064         TraCIServerAPIHelper::writeStatusCmd(CMD_GET_JUNCTION_VARIABLE, RTYPE_ERR, "Get Junction Variable: unsupported variable specified", outputStorage);
00065         return false;
00066     }
00067     // begin response building
00068     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 {
00079         MSJunction *j = MSNet::getInstance()->getJunctionControl().get(id);
00080         if (j==0) {
00081             TraCIServerAPIHelper::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(TYPE_POSITION2D);
00089             tempMsg.writeFloat(j->getPosition().x());
00090             tempMsg.writeFloat(j->getPosition().y());
00091             break;
00092         default:
00093             break;
00094         }
00095     }
00096     if (withStatus) {
00097         TraCIServerAPIHelper::writeStatusCmd(CMD_GET_JUNCTION_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 /****************************************************************************/
00108 

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