EventSource.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 
18 #ifndef GAZEBO_PLUGINS_EVENTSOURCE_HH_
19 #define GAZEBO_PLUGINS_EVENTSOURCE_HH_
20 
21 #ifdef _WIN32
22  // Ensure that Winsock2.h is included before Windows.h, which can get
23  // pulled in by anybody (e.g., Boost).
24 #include <Winsock2.h>
25 #endif
26 
27 #include <memory>
28 #include <string>
29 
30 #include "gazebo/gazebo.hh"
31 #include "gazebo/physics/physics.hh"
32 #include "gazebo/common/common.hh"
34 
35 #include "SimEventsException.hh"
36 
37 namespace gazebo
38 {
41  {
47  const std::string &_type,
48  physics::WorldPtr _world);
49 
51  public: virtual ~EventSource();
52 
56  public: void Emit(const std::string& _data) const;
57 
60  public: virtual void Load(const sdf::ElementPtr _sdf);
61 
63  public: virtual void Init();
64 
68  public: virtual bool IsActive() const;
69 
71  protected: std::string name;
72 
74  protected: std::string type;
75 
78 
81  protected: bool active;
82 
85  };
86 
87  typedef std::shared_ptr<EventSource> EventSourcePtr;
88 
91  {
95  public: template<typename T>
97  ConnectSpawnModel(T _subscriber)
98  { return spawnModel.Connect(_subscriber); }
99 
103  public: static void DisconnectSpawnModel(
104  event::ConnectionPtr _subscriber)
105  GAZEBO_DEPRECATED(8.0)
106  { spawnModel.Disconnect(_subscriber->Id()); }
107 
110  };
111 }
112 
113 #endif
bool active
True if the event source is active.
Definition: EventSource.hh:81
boost::shared_ptr< World > WorldPtr
Definition: PhysicsTypes.hh:89
virtual void Load(const sdf::ElementPtr _sdf)
Load from an sdf element (with possible configuration data)
static event::ConnectionPtr ConnectSpawnModel(T _subscriber)
Connect a callback to the spawn model event.
Definition: EventSource.hh:97
std::shared_ptr< EventSource > EventSourcePtr
Definition: EventSource.hh:87
Forward declarations for transport.
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:49
virtual void Disconnect(ConnectionPtr _c) GAZEBO_DEPRECATED(8.0)
Disconnect a callback to this event.
Definition: Event.hh:595
std::string name
Name of the event.
Definition: EventSource.hh:71
transport::PublisherPtr pub
a way to send messages to the other topics (to the REST)
Definition: EventSource.hh:84
Gazebo events to detect model creation/deletion.
Definition: EventSource.hh:90
static event::EventT< void(std::string, bool)> spawnModel
A model has been completed and uploaded onto the server.
Definition: EventSource.hh:109
The base class for emitting SimEvents.
Definition: EventSource.hh:40
boost::shared_ptr< Connection > ConnectionPtr
Definition: CommonTypes.hh:134
#define GAZEBO_DEPRECATED(version)
Definition: system.hh:302
EventSource(transport::PublisherPtr _pub, const std::string &_type, physics::WorldPtr _world)
Constructor.
physics::WorldPtr world
Pointer to the world.
Definition: EventSource.hh:77
virtual ~EventSource()
Destructor.
std::string type
Type of event.
Definition: EventSource.hh:74
virtual bool IsActive() const
An event source can be used to enable other events.
ConnectionPtr Connect(const std::function< T > &_subscriber)
Connect a callback to this event.
Definition: Event.hh:580
static void DisconnectSpawnModel(event::ConnectionPtr _subscriber) GAZEBO_DEPRECATED(8.0)
Disconnect a callback to the spawn model event.
Definition: EventSource.hh:103
virtual void Init()
Initialize the event.
void Emit(const std::string &_data) const
emit an event with data to the internal publisher (and using the internal type)