LCOV - code coverage report
Current view: top level - src/libsumo - Subscription.h (source / functions) Hit Total Coverage
Test: lcov.info Lines: 19 22 86.4 %
Date: 2024-04-28 15:39:05 Functions: 1 4 25.0 %

          Line data    Source code
       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             : /****************************************************************************/
      14             : /// @file    Subscription.h
      15             : /// @author  Michael Behrisch
      16             : /// @date    2007/10/24
      17             : ///
      18             : // Subscription representation for libsumo and TraCI
      19             : /****************************************************************************/
      20             : #pragma once
      21             : #include <config.h>
      22             : #include <vector>
      23             : #include <set>
      24             : #include <foreign/tcpip/storage.h>
      25             : #include <libsumo/TraCIDefs.h>
      26             : #include <utils/common/SUMOVehicleClass.h>
      27             : #include <utils/common/SUMOTime.h>
      28             : 
      29             : 
      30             : // ===========================================================================
      31             : // class definitions
      32             : // ===========================================================================
      33             : namespace libsumo {
      34             : 
      35             : /** @brief Filter types for context subscriptions
      36             :  */
      37             : enum SubscriptionFilterType {
      38             :     // No filters
      39             :     SUBS_FILTER_NONE = 0,
      40             :     // Filter by list of lanes relative to ego vehicle
      41             :     SUBS_FILTER_LANES = 1,
      42             :     // Exclude vehicles on opposite (and other) lanes from context subscription result
      43             :     SUBS_FILTER_NOOPPOSITE = 1 << 1,
      44             :     // Specify maximal downstream distance for vehicles in context subscription result
      45             :     SUBS_FILTER_DOWNSTREAM_DIST = 1 << 2,
      46             :     // Specify maximal upstream distance for vehicles in context subscription result
      47             :     SUBS_FILTER_UPSTREAM_DIST = 1 << 3,
      48             :     // Only return leader and follower on specified lanes in context subscription result
      49             :     SUBS_FILTER_LEAD_FOLLOW = 1 << 4,
      50             :     // Only return foes on upcoming junctions in context subscription result
      51             :     SUBS_FILTER_TURN = 1 << 6,
      52             :     // Only return vehicles of the given vClass in context subscription result
      53             :     SUBS_FILTER_VCLASS = 1 << 7,
      54             :     // Only return vehicles of the given vType in context subscription result
      55             :     SUBS_FILTER_VTYPE = 1 << 8,
      56             :     // Only return vehicles within field of vision in context subscription result
      57             :     // NOTE: relies on rTree, therefore incompatible with SUBS_FILTER_NO_RTREE
      58             :     SUBS_FILTER_FIELD_OF_VISION = 1 << 9,
      59             :     // Only return vehicles within the given lateral distance in context subscription result
      60             :     SUBS_FILTER_LATERAL_DIST = 1 << 10,
      61             :     // Filter category for measuring distances along the road network instead of using the usual rtree query
      62             :     SUBS_FILTER_NO_RTREE = SUBS_FILTER_LANES | SUBS_FILTER_DOWNSTREAM_DIST | SUBS_FILTER_UPSTREAM_DIST | SUBS_FILTER_LEAD_FOLLOW | SUBS_FILTER_TURN | SUBS_FILTER_LATERAL_DIST,
      63             :     // Filter category for maneuver filters
      64             :     SUBS_FILTER_MANEUVER = SUBS_FILTER_LEAD_FOLLOW | SUBS_FILTER_TURN,
      65             : };
      66             : 
      67             : /** @class Subscription
      68             :  * @brief Representation of a subscription
      69             :  */
      70             : class Subscription {
      71             : public:
      72             :     /** @brief Constructor
      73             :     * @param[in] commandIdArg The command id of the subscription
      74             :     * @param[in] idArg The id of the object that is subscribed
      75             :     * @param[in] variablesArg The subscribed variables
      76             :     * @param[in] paramsArg The parameters for the subscribed variables
      77             :     * @param[in] beginTimeArg The begin time of the subscription
      78             :     * @param[in] endTimeArg The end time of the subscription
      79             :     * @param[in] contextDomainArg The domain ID of the context
      80             :     * @param[in] rangeArg The range of the context
      81             :     */
      82       10681 :     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       10681 :         : commandId(commandIdArg),
      88       10681 :           id(idArg),
      89       10681 :           variables(variablesArg),
      90       10681 :           parameters(paramsArg),
      91       10681 :           beginTime(beginTimeArg),
      92       10681 :           endTime(endTimeArg),
      93       10681 :           contextDomain(contextDomainArg),
      94       10681 :           range(rangeArg),
      95       10681 :           activeFilters(SUBS_FILTER_NONE),
      96             :           filterLanes(),
      97       10681 :           filterDownstreamDist(-1),
      98       10681 :           filterUpstreamDist(-1),
      99       10681 :           filterFoeDistToJunction(-1),
     100             :           filterVTypes(),
     101       10681 :           filterVClasses(0),
     102       10681 :           filterFieldOfVisionOpeningAngle(-1),
     103       10681 :           filterLateralDist(-1) {}
     104             : 
     105             :     bool isVehicleToVehicleContextSubscription() const {
     106       13140 :         return commandId == CMD_SUBSCRIBE_VEHICLE_CONTEXT && contextDomain == CMD_GET_VEHICLE_VARIABLE;
     107             :     }
     108             : 
     109             :     bool isVehicleToPersonContextSubscription() const {
     110        9192 :         return commandId == CMD_SUBSCRIBE_VEHICLE_CONTEXT && contextDomain == CMD_GET_PERSON_VARIABLE;
     111             :     }
     112             : 
     113             :     /// @brief commandIdArg The command id of the subscription
     114             :     int commandId;
     115             :     /// @brief The id of the object that is subscribed
     116             :     std::string id;
     117             :     /// @brief The subscribed variables
     118             :     std::vector<int> variables;
     119             :     /// @brief The parameters for the subscribed variables
     120             :     std::vector<std::shared_ptr<tcpip::Storage> > parameters;
     121             :     /// @brief The begin time of the subscription
     122             :     SUMOTime beginTime;
     123             :     /// @brief The end time of the subscription
     124             :     SUMOTime endTime;
     125             :     /// @brief The domain ID of the context
     126             :     int contextDomain;
     127             :     /// @brief The range of the context
     128             :     double range;
     129             : 
     130             :     /// @brief Active filters for the subscription (bitset, @see SubscriptionFilterType)
     131             :     int activeFilters;
     132             :     /// @brief lanes specified by the lanes filter
     133             :     std::vector<int> filterLanes;
     134             :     /// @brief Downstream distance specified by the downstream distance filter
     135             :     double filterDownstreamDist;
     136             :     /// @brief Upstream distance specified by the upstream distance filter
     137             :     double filterUpstreamDist;
     138             :     /// @brief Foe distance to junction specified by the turn filter
     139             :     double filterFoeDistToJunction;
     140             :     /// @brief vTypes specified by the vTypes filter
     141             :     std::set<std::string> filterVTypes;
     142             :     /// @brief vClasses specified by the vClasses filter, @see SVCPermissions
     143             :     SVCPermissions filterVClasses;
     144             :     /// @brief Opening angle (in deg) specified by the field of vision filter
     145             :     double filterFieldOfVisionOpeningAngle;
     146             :     /// @brief Lateral distance specified by the lateral distance filter
     147             :     double filterLateralDist;
     148             : };
     149             : 
     150             : class VariableWrapper {
     151             : public:
     152             :     /// @brief Definition of a method to be called for serving an associated commandID
     153             :     typedef bool(*SubscriptionHandler)(const std::string& objID, const int variable, VariableWrapper* wrapper, tcpip::Storage* paramData);
     154        9449 :     VariableWrapper(SubscriptionHandler handler = nullptr) : handle(handler) {}
     155             :     virtual ~VariableWrapper() {}
     156             :     SubscriptionHandler handle;
     157           0 :     virtual void setContext(const std::string* const /* refID */) {}
     158           0 :     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           0 :     virtual void empty(const std::string& /* objID */) {}
     170             : };
     171             : 
     172             : 
     173             : }

Generated by: LCOV version 1.14