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-2024 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>
28
29
30// ===========================================================================
31// class definitions
32// ===========================================================================
33namespace libsumo {
34
38 // No filters
40 // Filter by list of lanes relative to ego vehicle
42 // Exclude vehicles on opposite (and other) lanes from context subscription result
44 // Specify maximal downstream distance for vehicles in context subscription result
46 // Specify maximal upstream distance for vehicles in context subscription result
48 // Only return leader and follower on specified lanes in context subscription result
50 // Only return foes on upcoming junctions in context subscription result
52 // Only return vehicles of the given vClass in context subscription result
54 // Only return vehicles of the given vType in context subscription result
56 // Only return vehicles within field of vision in context subscription result
57 // NOTE: relies on rTree, therefore incompatible with SUBS_FILTER_NO_RTREE
59 // Only return vehicles within the given lateral distance in context subscription result
61 // Filter category for measuring distances along the road network instead of using the usual rtree query
63 // Filter category for maneuver filters
65};
66
71public:
82 Subscription(int commandIdArg, const std::string& idArg,
83 const std::vector<int>& variablesArg,
84 const std::vector<std::shared_ptr<tcpip::Storage> >& paramsArg,
85 SUMOTime beginTimeArg, SUMOTime endTimeArg,
86 int contextDomainArg, double rangeArg)
87 : commandId(commandIdArg),
88 id(idArg),
89 variables(variablesArg),
90 parameters(paramsArg),
91 beginTime(beginTimeArg),
92 endTime(endTimeArg),
93 contextDomain(contextDomainArg),
94 range(rangeArg),
100 filterVTypes(),
103 filterLateralDist(-1) {}
104
108
112
116 std::string id;
118 std::vector<int> variables;
120 std::vector<std::shared_ptr<tcpip::Storage> > parameters;
128 double range;
129
133 std::vector<int> filterLanes;
141 std::set<std::string> filterVTypes;
148};
149
151public:
153 typedef bool(*SubscriptionHandler)(const std::string& objID, const int variable, VariableWrapper* wrapper, tcpip::Storage* paramData);
154 VariableWrapper(SubscriptionHandler handler = nullptr) : handle(handler) {}
155 virtual ~VariableWrapper() {}
157 virtual void setContext(const std::string* const /* refID */) {}
158 virtual void clear() {}
159 virtual bool wrapDouble(const std::string& objID, const int variable, const double value) = 0;
160 virtual bool wrapInt(const std::string& objID, const int variable, const int value) = 0;
161 virtual bool wrapString(const std::string& objID, const int variable, const std::string& value) = 0;
162 virtual bool wrapStringList(const std::string& objID, const int variable, const std::vector<std::string>& value) = 0;
163 virtual bool wrapDoubleList(const std::string& objID, const int variable, const std::vector<double>& value) = 0;
164 virtual bool wrapPosition(const std::string& objID, const int variable, const TraCIPosition& value) = 0;
165 virtual bool wrapPositionVector(const std::string& objID, const int variable, const TraCIPositionVector& value) = 0;
166 virtual bool wrapColor(const std::string& objID, const int variable, const TraCIColor& value) = 0;
167 virtual bool wrapStringDoublePair(const std::string& objID, const int variable, const std::pair<std::string, double>& value) = 0;
168 virtual bool wrapStringPair(const std::string& objID, const int variable, const std::pair<std::string, std::string>& value) = 0;
169 virtual void empty(const std::string& /* objID */) {}
170};
171
172
173}
long long int SUMOTime
Definition GUI.h:36
long long int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
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.
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.
SVCPermissions filterVClasses
vClasses specified by the vClasses filter,
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