##

ConnectionManager.hh
Go to the documentation of this file.
/*
* Copyright (C) 2012 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef _CONNECTION_MANAGER_HH_
#define _CONNECTION_MANAGER_HH_
#include <boost/shared_ptr.hpp>
#include <boost/interprocess/sync/interprocess_semaphore.hpp>
#include <string>
#include <list>
#include <vector>
#include "gazebo/msgs/msgs.hh"
#include "gazebo/common/SingletonT.hh"
#include "gazebo/transport/Publisher.hh"
#include "gazebo/transport/Connection.hh"
#include "gazebo/util/system.hh"
GZ_SINGLETON_DECLARE(GZ_TRANSPORT_VISIBLE, gazebo, transport, ConnectionManager)
namespace gazebo
{
namespace transport
{
class GZ_TRANSPORT_VISIBLE ConnectionManager :
public SingletonT<ConnectionManager>
{
private: ConnectionManager();
private: virtual ~ConnectionManager();
public: bool Init(const std::string &_masterHost,
unsigned int _masterPort,
uint32_t _timeoutIterations = 30);
public: bool IsInitialized() const;
public: void Run();
public: bool IsRunning() const;
public: void Fini();
public: void Stop();
public: void Subscribe(const std::string &_topic,
const std::string &_msgType,
bool _latching);
public: void Unsubscribe(const msgs::Subscribe &_sub);
public: void Unsubscribe(const std::string &_topic,
const std::string &_msgType);
public: void Advertise(const std::string &_topic,
const std::string &_msgType);
public: void Unadvertise(const std::string &_topic);
public: void GetAllPublishers(std::list<msgs::Publish> &_publishers);
public: void RemoveConnection(ConnectionPtr &_conn);
public: void RegisterTopicNamespace(const std::string &_name);
public: void GetTopicNamespaces(std::list<std::string> &_namespaces);
private: ConnectionPtr FindConnection(const std::string &_host,
unsigned int _port);
public: ConnectionPtr ConnectToRemoteHost(const std::string &_host,
unsigned int _port);
public: void TriggerUpdate();
private: void OnMasterRead(const std::string &_data);
private: void OnAccept(ConnectionPtr _newConnection);
private: void OnRead(ConnectionPtr _newConnection,
const std::string &_data);
private: void ProcessMessage(const std::string &_packet);
private: void RunUpdate();
private: boost::condition_variable updateCondition;
private: boost::mutex updateMutex;
private: ConnectionPtr masterConn;
private: Connection *serverConn;
private: std::list<ConnectionPtr> connections;
protected: std::vector<event::ConnectionPtr> eventConnections;
private: bool initialized;
private: bool stop, stopped;
private: unsigned int tmpIndex;
private: boost::recursive_mutex listMutex;
private: boost::mutex namespaceMutex;
private: boost::recursive_mutex masterMessagesMutex;
private: boost::recursive_mutex connectionMutex;
private: std::list<msgs::Publish> publishers;
private: std::list<std::string> namespaces;
private: std::list<std::string> masterMessages;
private: boost::condition_variable namespaceCondition;
// Singleton implementation
private: friend class SingletonT<ConnectionManager>;
};
}
}
#endif
gazebo
gazebo
Definition: ConnectionManager.hh:35
gazebo::transport::stop
void stop()
Stop the transport component from running.
gazebo
Forward declarations for the common classes.
Definition: Animation.hh:26
Connection.hh
SingletonT
Singleton template class.
Definition: SingletonT.hh:33
system.hh
msgs.hh
gazebo::transport::ConnectionPtr
boost::shared_ptr< Connection > ConnectionPtr
Definition: Connection.hh:50
gazebo::transport::ConnectionManager
Manager of connections.
Definition: ConnectionManager.hh:46
gazebo::msgs::Init
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
transport
transport
Definition: ConnectionManager.hh:35
gazebo::transport::Connection
Single TCP/IP connection manager.
Definition: Connection.hh:100
Publisher.hh
GZ_SINGLETON_DECLARE
#define GZ_SINGLETON_DECLARE(visibility, n1, n2, singletonType)
Helper to declare typed SingletonT.
Definition: SingletonT.hh:61
gazebo::transport::ConnectionManager::eventConnections
std::vector< event::ConnectionPtr > eventConnections
Definition: ConnectionManager.hh:177
SingletonT.hh
gazebo::gui::stop
void stop()