Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
Subscription.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2023 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
18// Subscription representation for libsumo and TraCI
19/****************************************************************************/
20#pragma once
21#include <config.h>
22#include <vector>
23#include <set>
25#include <libsumo/TraCIDefs.h>
27
28
29// ===========================================================================
30// class definitions
31// ===========================================================================
32namespace libsumo {
33
37 // No filters
39 // Filter by list of lanes relative to ego vehicle
41 // Exclude vehicles on opposite (and other) lanes from context subscription result
43 // Specify maximal downstream distance for vehicles in context subscription result
45 // Specify maximal upstream distance for vehicles in context subscription result
47 // Only return leader and follower on specified lanes in context subscription result
49 // Only return foes on upcoming junctions in context subscription result
51 // Only return vehicles of the given vClass in context subscription result
53 // Only return vehicles of the given vType in context subscription result
55 // Only return vehicles within field of vision in context subscription result
56 // NOTE: relies on rTree, therefore incompatible with SUBS_FILTER_NO_RTREE
58 // Only return vehicles within the given lateral distance in context subscription result
60 // Filter category for measuring distances along the road network instead of using the usual rtree query
62 // Filter category for maneuver filters
64};
65
70public:
81 Subscription(int commandIdArg, const std::string& idArg,
82 const std::vector<int>& variablesArg,
83 const std::vector<std::shared_ptr<tcpip::Storage> >& paramsArg,
84 SUMOTime beginTimeArg, SUMOTime endTimeArg,
85 int contextDomainArg, double rangeArg)
86 : commandId(commandIdArg),
87 id(idArg),
88 variables(variablesArg),
89 parameters(paramsArg),
90 beginTime(beginTimeArg),
91 endTime(endTimeArg),
92 contextDomain(contextDomainArg),
93 range(rangeArg),
102 filterLateralDist(-1) {}
103
107
111
115 std::string id;
117 std::vector<int> variables;
119 std::vector<std::shared_ptr<tcpip::Storage> > parameters;
127 double range;
128
132 std::vector<int> filterLanes;
140 std::set<std::string> filterVTypes;
147};
148
150public:
152 typedef bool(*SubscriptionHandler)(const std::string& objID, const int variable, VariableWrapper* wrapper, tcpip::Storage* paramData);
153 VariableWrapper(SubscriptionHandler handler = nullptr) : handle(handler) {}
154 virtual ~VariableWrapper() {}
156 virtual void setContext(const std::string* const /* refID */) {}
157 virtual void clear() {}
158 virtual bool wrapDouble(const std::string& objID, const int variable, const double value) = 0;
159 virtual bool wrapInt(const std::string& objID, const int variable, const int value) = 0;
160 virtual bool wrapString(const std::string& objID, const int variable, const std::string& value) = 0;
161 virtual bool wrapStringList(const std::string& objID, const int variable, const std::vector<std::string>& value) = 0;
162 virtual bool wrapDoubleList(const std::string& objID, const int variable, const std::vector<double>& value) = 0;
163 virtual bool wrapPosition(const std::string& objID, const int variable, const TraCIPosition& value) = 0;
164 virtual bool wrapPositionVector(const std::string& objID, const int variable, const TraCIPositionVector& value) = 0;
165 virtual bool wrapColor(const std::string& objID, const int variable, const TraCIColor& value) = 0;
166 virtual bool wrapStringDoublePair(const std::string& objID, const int variable, const std::pair<std::string, double>& value) = 0;
167 virtual bool wrapStringPair(const std::string& objID, const int variable, const std::pair<std::string, std::string>& value) = 0;
168 virtual void empty(const std::string& /* objID */) {}
169};
170
171
172}
173
174
long long int SUMOTime
Definition GUI.h:36
Representation of a subscription.
double filterUpstreamDist
Upstream distance specified by the upstream distance filter.
int commandId
commandIdArg The command id of the subscription
std::set< std::string > filterVTypes
vTypes specified by the vTypes filter
double filterFieldOfVisionOpeningAngle
Opening angle (in deg) specified by the field of vision filter.
std::vector< int > filterLanes
lanes specified by the lanes filter
std::string id
The id of the object that is subscribed.
int filterVClasses
vClasses specified by the vClasses filter,
SUMOTime endTime
The end time of the subscription.
int contextDomain
The domain ID of the context.
double filterFoeDistToJunction
Foe distance to junction specified by the turn filter.
bool isVehicleToVehicleContextSubscription() const
SUMOTime beginTime
The begin time of the subscription.
std::vector< int > variables
The subscribed variables.
bool isVehicleToPersonContextSubscription() const
double filterDownstreamDist
Downstream distance specified by the downstream distance filter.
double filterLateralDist
Lateral distance specified by the lateral distance filter.
Subscription(int commandIdArg, const std::string &idArg, const std::vector< int > &variablesArg, const std::vector< std::shared_ptr< tcpip::Storage > > &paramsArg, SUMOTime beginTimeArg, SUMOTime endTimeArg, int contextDomainArg, double rangeArg)
Constructor.
int activeFilters
Active filters for the subscription (bitset,.
double range
The range of the context.
std::vector< std::shared_ptr< tcpip::Storage > > parameters
The parameters for the subscribed variables.
virtual bool wrapStringList(const std::string &objID, const int variable, const std::vector< std::string > &value)=0
virtual bool wrapStringDoublePair(const std::string &objID, const int variable, const std::pair< std::string, double > &value)=0
virtual bool wrapString(const std::string &objID, const int variable, const std::string &value)=0
virtual bool wrapDoubleList(const std::string &objID, const int variable, const std::vector< double > &value)=0
virtual bool wrapStringPair(const std::string &objID, const int variable, const std::pair< std::string, std::string > &value)=0
SubscriptionHandler handle
virtual bool wrapInt(const std::string &objID, const int variable, const int value)=0
virtual bool wrapPosition(const std::string &objID, const int variable, const TraCIPosition &value)=0
virtual void empty(const std::string &)
virtual bool wrapPositionVector(const std::string &objID, const int variable, const TraCIPositionVector &value)=0
virtual bool wrapDouble(const std::string &objID, const int variable, const double value)=0
bool(* SubscriptionHandler)(const std::string &objID, const int variable, VariableWrapper *wrapper, tcpip::Storage *paramData)
Definition of a method to be called for serving an associated commandID.
VariableWrapper(SubscriptionHandler handler=nullptr)
virtual bool wrapColor(const std::string &objID, const int variable, const TraCIColor &value)=0
virtual void setContext(const std::string *const)
TRACI_CONST int CMD_SUBSCRIBE_VEHICLE_CONTEXT
TRACI_CONST int CMD_GET_VEHICLE_VARIABLE
TRACI_CONST int CMD_GET_PERSON_VARIABLE
SubscriptionFilterType
Filter types for context subscriptions.
@ SUBS_FILTER_LEAD_FOLLOW
@ SUBS_FILTER_UPSTREAM_DIST
@ SUBS_FILTER_VTYPE
@ SUBS_FILTER_NO_RTREE
@ SUBS_FILTER_LANES
@ SUBS_FILTER_NOOPPOSITE
@ SUBS_FILTER_DOWNSTREAM_DIST
@ SUBS_FILTER_LATERAL_DIST
@ SUBS_FILTER_TURN
@ SUBS_FILTER_VCLASS
@ SUBS_FILTER_NONE
@ SUBS_FILTER_MANEUVER
@ SUBS_FILTER_FIELD_OF_VISION
A 2D or 3D-position, for 2D positions z == INVALID_DOUBLE_VALUE.
Definition TraCIDefs.h:178
A list of positions.
Definition TraCIDefs.h:234