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-sim.org/
13 // Copyright (C) 2001-2013 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 #include <utils/traci/TraCIAPI.h>
36 
37 
38 namespace testclient {
39 
40 // ===========================================================================
41 // class definitions
42 // ===========================================================================
49 class TraCITestClient : public TraCIAPI {
50 public:
54  TraCITestClient(std::string outputFileName = "testclient_result.out");
55 
56 
59 
60 
66  bool run(std::string fileName, int port, std::string host = "localhost");
67 
68 
69 protected:
72 
77 
78 
81  void commandClose();
82 
83 
90  void commandGetVariable(int domID, int varID, const std::string& objID, tcpip::Storage* addData = 0);
91 
92 
99  void commandSetValue(int domID, int varID, const std::string& objID, std::ifstream& defFile);
100 
101 
110  void commandSubscribeObjectVariable(int domID, const std::string& objID, int beginTime, int endTime, int varNo, std::ifstream& defFile);
111 
112 
123  void commandSubscribeContextVariable(int domID, const std::string& objID, int beginTime, int endTime, int domain, SUMOReal range, int varNo, std::ifstream& defFile);
125 
126 
127 
128 private:
131 
134  void writeResult();
135 
136 
140  void errorMsg(std::stringstream& msg);
142 
143 
144 
147 
153 
154 
161 
162 
163 
166 
174  int setValueTypeDependant(tcpip::Storage& into, std::ifstream& defFile, std::stringstream& msg);
175 
176 
181  void readAndReportTypeDependent(tcpip::Storage& inMsg, int valueDataType);
183 
184 
185 private:
187  std::string outputFileName;
188 
190  std::stringstream answerLog;
191 
192 };
193 
194 }
195 
196 #endif
C++ TraCI client API implementation.
Definition: TraCIAPI.h:52
void commandClose()
Sends and validates a Close command.
bool run(std::string fileName, int port, std::string host="localhost")
Runs a test.
int setValueTypeDependant(tcpip::Storage &into, std::ifstream &defFile, std::stringstream &msg)
Parses the next value type / value pair from the stream and inserts it into the storage.
bool validateSimulationStep2(tcpip::Storage &inMsg)
Validates whether the given message is a valid answer to CMD_SIMSTEP2.
A test execution class.
void writeResult()
Writes the results file.
TraCITestClient(std::string outputFileName="testclient_result.out")
Constructor.
bool validateSubscription(tcpip::Storage &inMsg)
Validates whether the given message is a valid subscription return message.
void commandSubscribeContextVariable(int domID, const std::string &objID, int beginTime, int endTime, int domain, SUMOReal range, int varNo, std::ifstream &defFile)
Sends and validates a SubscribeContext command.
void commandSimulationStep(SUMOTime time)
Sends and validates a simulation step command.
std::string outputFileName
The name of the file to write the results log into.
void commandGetVariable(int domID, int varID, const std::string &objID, tcpip::Storage *addData=0)
Sends and validates a GetVariable command.
#define SUMOReal
Definition: config.h:221
void readAndReportTypeDependent(tcpip::Storage &inMsg, int valueDataType)
Reads a value of the given type from the given storage and reports it.
void commandSubscribeObjectVariable(int domID, const std::string &objID, int beginTime, int endTime, int varNo, std::ifstream &defFile)
Sends and validates a SubscribeVariable command.
void errorMsg(std::stringstream &msg)
Writes an error message.
void commandSetValue(int domID, int varID, const std::string &objID, std::ifstream &defFile)
Sends and validates a SetVariable command.
std::stringstream answerLog
Stream containing the log.