TraCIServerAPI_Junction.cpp
Go to the documentation of this file.00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
00044
00045 using namespace std;
00046 using namespace traci;
00047 using namespace tcpip;
00048
00049
00050
00051
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 = "";
00059
00060 int variable = inputStorage.readUnsignedByte();
00061 std::string id = inputStorage.readString();
00062
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
00068 Storage tempMsg;
00069
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
00100 outputStorage.writeUnsignedByte(0);
00101 outputStorage.writeInt(1 + 4 + tempMsg.size());
00102 outputStorage.writeStorage(tempMsg);
00103 return true;
00104 }
00105
00106
00107
00108