SUMO - Simulation of Urban MObility

TraCITestClient.h

Go to the documentation of this file.
00001 /****************************************************************************/
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 #ifndef TRACITESTCLIENT_H
00020 #define TRACITESTCLIENT_H
00021 
00022 // ===========================================================================
00023 // included modules
00024 // ===========================================================================
00025 #include <string>
00026 #include <sstream>
00027 #include <vector>
00028 
00029 #include <foreign/tcpip/socket.h>
00030 #include <utils/common/SUMOTime.h>
00031 
00032 namespace testclient {
00033 // ===========================================================================
00034 // Definitions
00035 // ===========================================================================
00036 struct Position {
00037     SUMOReal x;
00038     SUMOReal y;
00039 };
00040 
00041 struct Position3D {
00042     SUMOReal x;
00043     SUMOReal y;
00044     SUMOReal z;
00045 };
00046 
00047 struct PositionRoadMap {
00048     std::string roadId;
00049     SUMOReal pos;
00050     int laneId;
00051 };
00052 
00053 struct BoundingBox {
00054     Position lowerLeft;
00055     Position upperRight;
00056 };
00057 
00058 typedef std::vector<Position> Polygon;
00059 
00060 struct TLPhase {
00061     std::string precRoadId;
00062     std::string succRoadId;
00063     int phase;
00064 };
00065 
00066 typedef std::vector<TLPhase> TLPhaseList;
00067 
00068 // ===========================================================================
00069 // class definitions
00070 // ===========================================================================
00074 class TraCITestClient {
00075 
00076 public:
00077     TraCITestClient(std::string outputFileName = "testclient_result.out");
00078 
00079     ~TraCITestClient();
00080 
00081     bool run(std::string fileName, int port, std::string host = "localhost");
00082 
00083     bool connect(int port, std::string host = "localhost");
00084 
00085     bool close();
00086 
00087     // simulation commands
00088     void commandSimulationStep2(SUMOTime time);
00089 
00090     void commandPositionConversion(testclient::Position pos, int posId);
00091     void commandPositionConversion(testclient::Position3D pos, int posId);
00092     void commandPositionConversion(testclient::PositionRoadMap pos, int posId);
00093 
00094     void commandDistanceRequest(testclient::Position pos1, testclient::Position pos2, int flag);
00095     void commandDistanceRequest(testclient::Position3D pos1, testclient::Position3D pos2, int flag);
00096     void commandDistanceRequest(testclient::Position pos1, testclient::Position3D pos2, int flag);
00097     void commandDistanceRequest(testclient::Position3D pos1, testclient::Position pos2, int flag);
00098     void commandDistanceRequest(testclient::PositionRoadMap pos1, testclient::PositionRoadMap pos2, int flag);
00099     void commandDistanceRequest(testclient::PositionRoadMap pos1, testclient::Position pos2, int flag);
00100     void commandDistanceRequest(testclient::PositionRoadMap pos1, testclient::Position3D pos2, int flag);
00101     void commandDistanceRequest(testclient::Position pos1, testclient::PositionRoadMap pos2, int flag);
00102     void commandDistanceRequest(testclient::Position3D pos1, testclient::PositionRoadMap pos2, int flag);
00103 
00104     void commandGetVariable(int domID, int varID, const std::string& objID);
00105     void commandGetVariablePlus(int domID, int varID, const std::string& objID, std::ifstream& defFile);
00106     void commandSubscribeVariable(int domID, const std::string& objID, int beginTime, int endTime, int varNo, std::ifstream& defFile);
00107     void commandSetValue(int domID, int varID, const std::string& objID, std::ifstream& defFile);
00108 
00109     void commandClose();
00110 
00111 private:
00112     void writeResult();
00113 
00114     void errorMsg(std::stringstream& msg);
00115 
00116     void commandPositionConversion(testclient::Position* pos2D,
00117                                    testclient::Position3D* pos3D,
00118                                    testclient::PositionRoadMap* posRoad,
00119                                    int posId);
00120 
00121     void commandDistanceRequest(testclient::Position* pos1_2D,
00122                                 testclient::Position3D* pos1_3D,
00123                                 testclient::PositionRoadMap* pos1_Road,
00124                                 testclient::Position* pos2_2D,
00125                                 testclient::Position3D* pos2_3D,
00126                                 testclient::PositionRoadMap* pos2_Road,
00127                                 int flag);
00128 
00129     // validation of received command responses
00130     bool reportResultState(tcpip::Storage& inMsg, int command, bool ignoreCommandId=false);
00131 
00132     bool validateSimulationStep2(tcpip::Storage& inMsg);
00133     bool validateSubscription(tcpip::Storage& inMsg);
00134 
00135     bool validatePositionConversion(tcpip::Storage& inMsg);
00136 
00137     bool validateDistanceRequest(tcpip::Storage& inMsg);
00138 
00139     bool readAndReportTypeDependent(tcpip::Storage& inMsg, int valueDataType);
00140 
00141 
00149     int setValueTypeDependant(tcpip::Storage& into, std::ifstream& defFile, std::stringstream& msg);
00150 
00151 
00152 
00153 private:
00154     tcpip::Socket* socket;
00155 
00156     std::string outputFileName;
00157 
00158     std::stringstream answerLog;
00159 };
00160 
00161 }
00162 
00163 #endif
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines