91 static void openSocket(
const std::map<int, CmdExecutor>& execs);
115 static std::string execute(std::string cmd);
119 static void runEmbedded(std::string pyFile);
141 void writeStatusCmd(
int commandId,
int status,
const std::string& description);
290 : targetTime(t), socket(socket) {}
407 const std::vector<int>& variablesArg,
const std::vector<std::vector<unsigned char> >& paramsArg,
408 SUMOTime beginTimeArg,
SUMOTime endTimeArg,
bool contextVarsArg,
int contextDomainArg,
double rangeArg)
409 : commandId(commandIdArg), id(idArg), variables(variablesArg), parameters(paramsArg), beginTime(beginTimeArg), endTime(endTimeArg),
410 contextVars(contextVarsArg), contextDomain(contextDomainArg), range(rangeArg) {}
450 std::string& errors);
bool processSingleSubscription(const TraCIServer::Subscription &s, tcpip::Storage &writeInto, std::string &errors)
tcpip::Storage mySubscriptionCache
The last timestep's subscription results.
bool readTypeCheckingColor(tcpip::Storage &inputStorage, libsumo::TraCIColor &into)
Reads the value type and a color, verifying the type.
bool findObjectShape(int domain, const std::string &id, PositionVector &shape)
bool contextVars
Whether the subscription is a context subscription (variable subscription otherwise) ...
Interface for objects listening to vehicle state changes.
TraCIServer & operator=(const TraCIServer &s)
Invalidated assignment operator.
double range
The range of the context.
virtual ~TraCIServer()
Destructor.
bool commandGetVersion()
Returns the TraCI-version.
std::vector< std::vector< unsigned char > > parameters
The parameters for the subscribed variables.
SUMOTime beginTime
The begin time of the subscription.
bool(* CmdExecutor)(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Definition of a method to be called for serving an associated commandID.
tcpip::Storage myOutputStorage
The storage to writeto.
void postProcessSimulationStep()
Handles subscriptions to send after a simstep2 command.
bool readTypeCheckingInt(tcpip::Storage &inputStorage, int &into)
Reads the value type and an int, verifying the type.
std::vector< std::string > myLoadArgs
bool readTypeCheckingString(tcpip::Storage &inputStorage, std::string &into)
Reads the value type and a string, verifying the type.
bool readTypeCheckingDouble(tcpip::Storage &inputStorage, double &into)
Reads the value type and a double, verifying the type.
tcpip::Storage myInputStorage
The storage to read from.
Representation of a subscription.
void cleanup()
clean up subscriptions
bool readTypeCheckingPolygon(tcpip::Storage &inputStorage, PositionVector &into)
Reads the value type and a polygon, verifying the type.
std::vector< std::string > & getLoadArgs()
bool writeErrorStatusCmd(int commandId, const std::string &description, tcpip::Storage &outputStorage)
Writes a status command to the given storage with status = RTYPE_ERR.
A class that stores a 2D geometrical boundary.
static bool myDoCloseConnection
Whether the connection was set to be to close.
std::map< int, SocketInfo * >::iterator removeCurrentSocket()
removes myCurrentSocket from mySockets and returns an iterator pointing to the next member according ...
SUMOTime targetTime
Target time: next point of action for the client.
std::map< int, CmdExecutor > myExecutors
Map of commandIds -> their executors; applicable if the executor applies to the method footprint...
void vehicleStateChanged(const SUMOVehicle *const vehicle, MSNet::VehicleState to)
Called if a vehicle changes its state.
bool readTypeCheckingBoundary(tcpip::Storage &inputStorage, Boundary &into)
Reads the value type and a 2D bounding box, verifying the type.
void removeSubscription(int commandId, const std::string &identity, int domain)
static void close()
request termination of connection
bool addObjectVariableSubscription(const int commandId, const bool hasContext)
tcpip::Socket * socket
Socket object for this client.
int commandId
commandIdArg The command id of the subscription
std::vector< Subscription > mySubscriptions
The list of known, still valid subscriptions.
Representation of a vehicle.
Subscription(int commandIdArg, const std::string &idArg, const std::vector< int > &variablesArg, const std::vector< std::vector< unsigned char > > ¶msArg, SUMOTime beginTimeArg, SUMOTime endTimeArg, bool contextVarsArg, int contextDomainArg, double rangeArg)
Constructor.
std::string id
The id of the object that is subscribed.
std::vector< int > variables
The subscribed variables.
SUMOTime getTargetTime() const
bool readTypeCheckingStringList(tcpip::Storage &inputStorage, std::vector< std::string > &into)
Reads the value type and a string list, verifying the type.
SocketInfo(tcpip::Socket *socket, SUMOTime t)
constructor
int readCommandID(int &commandStart, int &commandLength)
Reads the next command ID from the input storage.
static TraCIServer * myInstance
Singleton instance of the server.
bool readTypeCheckingUnsignedByte(tcpip::Storage &inputStorage, int &into)
Reads the value type and an unsigned byte, verifying the type.
TraCI server used to control sumo by a remote TraCI client.
void sendOutputToAll() const
send out subscription results (actually just the content of myOutputStorage) to clients which will ac...
TraCIServer(const SUMOTime begin, const int port, const int numClients)
Constructor.
void sendSingleSimStepResponse()
sends an empty response to a simstep command to the current client. (This applies to a situation wher...
void writeResponseWithLength(tcpip::Storage &outputStorage, tcpip::Storage &tempMsg)
VehicleState
Definition of a vehicle state.
const bool myAmEmbedded
Whether the server runs in embedded mode.
void processCommandsUntilSimStep(SUMOTime step)
process all commands until the next SUMO simulation step. It is guaranteed that t->getTargetTime() >=...
void processReorderingRequests()
checks for and processes reordering requests (relevant for multiple clients)
static void openSocket(const std::map< int, CmdExecutor > &execs)
Initialises the server.
void collectObjectsInRange(int domain, const PositionVector &shape, double range, std::set< std::string > &into)
std::map< MSNet::VehicleState, std::vector< std::string > > vehicleStateChanges
container for vehicle state changes since last step taken by this client
std::map< int, SocketInfo * >::iterator myCurrentSocket
The currently active client socket.
SUMOTime nextTargetTime() const
get the minimal next target time among all clients
void setTargetTime(SUMOTime targetTime)
Sets myTargetTime on server and sockets to the given value.
const std::map< MSNet::VehicleState, std::vector< std::string > > & getVehicleStateChanges() const
static TraCIServer * getInstance()
SUMOTime myTargetTime
The time step to reach until processing the next commands.
bool readTypeCheckingPosition2D(tcpip::Storage &inputStorage, libsumo::TraCIPosition &into)
Reads the value type and a 2D position, verifying the type.
int dispatchCommand()
Handles command, writes response to myOutputStorage.
std::map< int, SocketInfo * > mySockets
The socket connections to the clients the first component (index) determines the client's order (lowe...
void writeStatusCmd(int commandId, int status, const std::string &description, tcpip::Storage &outputStorage)
Writes a status command to the given storage.
std::map< int, SocketInfo * > mySocketReorderRequests
This stores the setOrder(int) requests of the clients.
int contextDomain
The domain ID of the context.
void initialiseSubscription(const Subscription &s)
static bool wasClosed()
check whether close was requested
std::map< MSNet::VehicleState, std::vector< std::string > > myVehicleStateChanges
Changes in the states of simulated vehicles.
bool readTypeCheckingByte(tcpip::Storage &inputStorage, int &into)
Reads the value type and a byte, verifying the type.
tcpip::Socket * myServerSocket
The server socket.
SUMOTime endTime
The end time of the subscription.
std::map< int, int > myParameterSizes
Map of variable ids to the size of the parameter in bytes.
void checkClientOrdering()
Called once after connection of all clients for executing SET_ORDER (and possibly prior GET_VERSION) ...