Swarm API

BrokerPlugin.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 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 
20 
21 #ifndef __SWARM_BROKER_PLUGIN_HH__
22 #define __SWARM_BROKER_PLUGIN_HH__
23 
24 #include <memory>
25 #include <mutex>
26 #include <queue>
27 #include <string>
28 #include <gazebo/common/Events.hh>
29 #include <gazebo/common/Plugin.hh>
30 #include <gazebo/common/UpdateInfo.hh>
31 #include <gazebo/physics/PhysicsTypes.hh>
32 #include <ignition/transport.hh>
33 #include <sdf/sdf.hh>
34 
35 #include "swarm/CommsModel.hh"
36 #include "swarm/SwarmTypes.hh"
37 #include "msgs/datagram.pb.h"
38 
39 namespace swarm
40 {
49  class IGNITION_VISIBLE BrokerPlugin : public gazebo::WorldPlugin
50  {
52  public: BrokerPlugin() = default;
53 
55  public: virtual ~BrokerPlugin();
56 
57  // Documentation Inherited.
58  public: virtual void Load(gazebo::physics::WorldPtr _world,
59  sdf::ElementPtr _sdf);
60 
67  private: void ReadSwarmFromSDF(sdf::ElementPtr _sdf);
68 
72  private: void Update(const gazebo::common::UpdateInfo &_info);
73 
76  private: void NotifyNeighbors();
77 
79  private: void DispatchMessages();
80 
85  private: void OnMsgReceived(const std::string &_topic,
86  const msgs::Datagram &_msg);
87 
89  private: gazebo::physics::WorldPtr world;
90 
92  private: sdf::ElementPtr sdf;
93 
95  private: gazebo::event::ConnectionPtr updateConnection;
96 
98  private: ignition::transport::Node node;
99 
101  private: std::queue<msgs::Datagram> incomingMsgs;
102 
104  private: SwarmMembershipPtr swarm;
105 
107  private: std::mutex mutex;
108 
110  private: std::unique_ptr<CommsModel> commsModel;
111  };
112 }
113 #endif
Definition: BooPlugin.hh:37
Manages how the communication behave between the members of the team.
This is a world plugin designed to centralize all the messages sent by the members of the swarm...
Definition: BrokerPlugin.hh:49