1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
10 /// @file    GUIMEVehicleControl.h
11 /// @author  Jakob Erdmann
12 /// @date    Okt 2012
13 /// @version $Id$
14 ///
15 // The class responsible for building and deletion of meso vehicles (gui-version)
16 /****************************************************************************/
17 #ifndef GUIMEVehicleControl_h
18 #define GUIMEVehicleControl_h
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <vector>
27 #include <fx.h>
28 #include <utils/gui/globjects/GUIGlObject.h>
29 #include <mesosim/MEVehicleControl.h>
30 
31 
32 // ===========================================================================
33 // class definitions
34 // ===========================================================================
35 /**
36  * @class GUIMEVehicleControl
37  * @brief The class responsible for building and deletion of vehicles (gui-version)
38  *
39  * @see MEVehicleControl
40  */
41 class GUIMEVehicleControl : public MEVehicleControl {
42 public:
43     /// @brief Constructor
44     GUIMEVehicleControl() ;
45 
46 
47     /// @brief Destructor
48     ~GUIMEVehicleControl() ;
49 
50     /// @name Vehicle creation
51     /// @{
52 
53     /** @brief Builds a vehicle, increases the number of built vehicles
54      *
55      * Instead of a MEVehicle, a GUIMEVehicle is built
56      *
57      * @param[in] defs The parameter defining the vehicle
58      * @param[in] route The route of this vehicle
59      * @param[in] type The type of this vehicle
60      * @param[in] ignoreStopErrors whether invalid stops trigger a warning only
61      * @param[in] fromRouteFile whether we are just reading the route file or creating via trigger, traci, ...
62      * @return The built vehicle (GUIVehicle instance)
63      * @see MSVehicleControl::buildVehicle
64      */
65     SUMOVehicle* buildVehicle(SUMOVehicleParameter* defs,
66                               const MSRoute* route, MSVehicleType* type,
67                               const bool ignoreStopErrors, const bool fromRouteFile = true);
68     /// @}
69 
70     /** @brief Tries to insert the vehicle into the internal vehicle container
71      *
72      * Identical to the MSVehicleControl implementation except for locking.
73      *
74      * @param[in] id The id of the vehicle
75      * @param[in] v The vehicle
76      * @return Whether the vehicle could be inserted (no other vehicle with the same id was inserted before)
77      */
78     bool addVehicle(const std::string& id, SUMOVehicle* v);
79 
80     /** @brief Deletes the vehicle
81      *
82      * Identical to the MSVehicleControl implementation except for locking.
83      *
84      * @param[in] v The vehicle to delete
85      * @param[discard] Whether the vehicle is discard during loading (scale < 1)
86      */
87     void deleteVehicle(SUMOVehicle* v, bool discard = false);
88 
89     /** @brief Returns the list of all known vehicles by gl-id
90      * @param[fill] into The list to fill with vehicle ids
91      * @todo Well, what about concurrent modifications?
92      */
93     void insertVehicleIDs(std::vector<GUIGlID>& into);
94 
95     /// @brief lock access to vehicle removal/additions for thread synchronization
96     void secureVehicles();
97 
98     /// @brief unlock access to vehicle removal/additions for thread synchronization
99     void releaseVehicles();
100 
101 
102 private:
103     /// The mutex used to avoid concurrent updates of the vehicle buffer
104     mutable FXMutex myLock;
105 
106 
107 private:
108     /// @brief invalidated copy constructor
109     GUIMEVehicleControl(const GUIMEVehicleControl& s);
110 
111     /// @brief invalidated assignment operator
112     GUIMEVehicleControl& operator=(const GUIMEVehicleControl& s);
113 
114 
115 };
116 
117 
118 #endif
119 
120 /****************************************************************************/
121 
122