SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TraCITestClient.h
Go to the documentation of this file.
1 /****************************************************************************/
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
13 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 #ifndef TRACITESTCLIENT_H
24 #define TRACITESTCLIENT_H
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #include <string>
30 #include <sstream>
31 #include <vector>
32 
33 #include <foreign/tcpip/socket.h>
34 #include <utils/common/SUMOTime.h>
35 
36 namespace testclient {
37 // ===========================================================================
38 // Definitions
39 // ===========================================================================
40 struct Position {
43 };
44 
45 struct Position3D {
49 };
50 
52  std::string roadId;
54  int laneId;
55 };
56 
57 struct BoundingBox {
60 };
61 
62 typedef std::vector<Position> Polygon;
63 
64 struct TLPhase {
65  std::string precRoadId;
66  std::string succRoadId;
67  int phase;
68 };
69 
70 typedef std::vector<TLPhase> TLPhaseList;
71 
72 // ===========================================================================
73 // class definitions
74 // ===========================================================================
79 
80 public:
81  TraCITestClient(std::string outputFileName = "testclient_result.out");
82 
84 
85  bool run(std::string fileName, int port, std::string host = "localhost");
86 
87  bool connect(int port, std::string host = "localhost");
88 
89  bool close();
90 
91  // simulation commands
93 
97 
107 
108  void commandGetVariable(int domID, int varID, const std::string& objID);
109  void commandGetVariablePlus(int domID, int varID, const std::string& objID, std::ifstream& defFile);
110  void commandSubscribeVariable(int domID, const std::string& objID, int beginTime, int endTime, int varNo, std::ifstream& defFile);
111  void commandSetValue(int domID, int varID, const std::string& objID, std::ifstream& defFile);
112 
113  void commandClose();
114 
115 private:
116  void writeResult();
117 
118  void errorMsg(std::stringstream& msg);
119 
121  testclient::Position3D* pos3D,
123  int posId);
124 
126  testclient::Position3D* pos1_3D,
127  testclient::PositionRoadMap* pos1_Road,
128  testclient::Position* pos2_2D,
129  testclient::Position3D* pos2_3D,
130  testclient::PositionRoadMap* pos2_Road,
131  int flag);
132 
133  // validation of received command responses
134  bool reportResultState(tcpip::Storage& inMsg, int command, bool ignoreCommandId = false);
135 
138 
140 
142 
143  bool readAndReportTypeDependent(tcpip::Storage& inMsg, int valueDataType);
144 
145 
153  int setValueTypeDependant(tcpip::Storage& into, std::ifstream& defFile, std::stringstream& msg);
154 
155 
156 
157 private:
159 
160  std::string outputFileName;
161 
162  std::stringstream answerLog;
163 };
164 
165 }
166 
167 #endif