27 #include <boost/thread/mutex.hpp>
29 #include <rsc/logging/Logger.h>
30 #include <rsc/plugins/Provider.h>
32 #include <../ParticipantConfig.h>
33 #include <../Factory.h>
35 #include <../converter/Repository.h>
36 #include <../converter/VoidConverter.h>
37 #include <../converter/StringConverter.h>
38 #include <../converter/ProtocolBufferConverter.h>
40 #include <rsb/protocol/introspection/Hello.pb.h>
41 #include <rsb/protocol/introspection/Bye.pb.h>
49 template <
typename WireType>
52 bool forSerialization) {
53 if (forSerialization) {
63 bool forSerialization) {
66 boost::shared_ptr< rsb::converter::UnambiguousConverterMap<std::string> > converterSelection
72 addConverter(*converterSelection,
75 addConverter(*converterSelection,
79 std::set<rsb::ParticipantConfig::Transport> transports
81 for (std::set<rsb::ParticipantConfig::Transport>::const_iterator it
82 = transports.begin(); it != transports.end(); ++it) {
85 rsc::runtime::Properties options = transport.
getOptions();
93 class IntrospectionParticipantObserver :
public rsc::config::OptionHandler {
95 IntrospectionParticipantObserver()
96 : logger(rsc::logging::Logger::getLogger(
97 "rsb.introspection.IntrospectionParticipantObserver")) {
100 void handleOption(
const std::vector<std::string>& key,
101 const std::string& value) {
102 if (key.size() == 2 && key[0] ==
"introspection"
103 && key[1] ==
"displayname") {
104 processDisplayName.reset(
new std::string(value));
113 "Was notified of created participant " << participant->getId() <<
114 " at scope " << *participant->getScope());
116 if (participant->getScope()->isSubScopeOf(
"/__rsb/introspection")
117 || !participant->getConfig().isIntrospectionEnabled()) {
118 RSCDEBUG(logger,
"Ignoring created participant " << participant);
123 boost::mutex::scoped_lock lock(senderMutex);
126 RSCDEBUG(logger,
"Creating introspection sender");
127 configSerialization = createConfig(
rsb::getFactory().getDefaultParticipantConfig(),
true);
128 configDeserialization = createConfig(
rsb::getFactory().getDefaultParticipantConfig(),
false);
132 configDeserialization, configSerialization));
135 sender->addParticipant(participant, parent);
143 "Was notified of destroyed participant " << participant->
getId() <<
144 " at scope " << *participant->
getScope());
148 if (participant->
getScope()->isSubScopeOf(
"/__rsb/introspection")
150 RSCDEBUG(logger,
"Ignoring destroyed participant " << participant);
163 boost::mutex::scoped_lock lock(senderMutex);
166 RSCDEBUG(logger,
"Ignoring destroyed participant " << participant);
170 if (!sender->removeParticipant(*participant)) {
176 rsc::logging::LoggerPtr logger;
181 boost::shared_ptr<std::string> processDisplayName;
184 boost::mutex senderMutex;
187 typedef boost::shared_ptr<IntrospectionParticipantObserver> IntrospectionParticipantObserverPtr;
189 IntrospectionParticipantObserverPtr observer;
191 boost::signals2::connection participantCreatedConnection;
192 boost::signals2::connection participantDestroyedConnection;
198 RSC_PLUGIN_INIT_SIGNATURE() {
200 rsc::logging::LoggerPtr logger = rsc::logging::Logger::getLogger(
"rsb.introspection");
201 RSCDEBUG(logger,
"Registering converters for introspection types");
203 rsb::converter::converterRepository<std::string>()
206 rsb::converter::converterRepository<std::string>()
210 observer.reset(
new IntrospectionParticipantObserver());
217 RSCDEBUG(logger,
"Registering participant creation and destruction hooks");
219 participantCreatedConnection
221 ->connect(boost::bind(&IntrospectionParticipantObserver::handleParticipantCreated, observer, _1, _2));
222 participantDestroyedConnection
224 ->connect(boost::bind(&IntrospectionParticipantObserver::handleParticipantDestroyed, observer, _1));
227 RSC_PLUGIN_SHUTDOWN_SIGNATURE() {
228 rsc::logging::LoggerPtr logger = rsc::logging::Logger::getLogger(
"rsb.introspection");
230 RSCDEBUG(logger,
"Unregistering participant creation and destruction hooks");
232 participantCreatedConnection.disconnect();
233 participantDestroyedConnection.disconnect();
235 RSCDEBUG(logger,
"Destroying introspection sender");
rsc::runtime::Properties getOptions() const
Returns the specified options for the transport.
Objects of this class participate in the exchange of notifications on one channel of the bus...
Instances of this class publish information about the local host, the current process and its partici...
Converts any string into any string serializing content to a string.
boost::shared_ptr< IntrospectionSender > IntrospectionSenderPtr
SignalParticipantDestroyedPtr getSignalParticipantDestroyed()
A generic converter for data types based on Protocol Buffer messages.
virtual std::string getWireSchema() const
Returns the name of the wire schema this converter can (de)serialize from/to.
Objects this class store mappings of one of the followings forms.
ParticipantConfig getConfig() const
Returns a copy of the participant's configuration.
Factory & getFactory()
Returns a factory for client-level RSB objects.
bool isIntrospectionEnabled() const
Indicates whether introspection should be enabled for the participant.
boost::shared_ptr< Converter< WireType > > Ptr
boost::shared_ptr< Participant > ParticipantPtr
boost::shared_ptr< ConverterSelectionStrategy< WireType > > Ptr
Description of a desired transport.
virtual std::string getDataType() const
Returns the name of the data type this converter is applicable for.
void addConverter(const std::string &key, ConverterPtr converter)
Stores converter in the map under the name key.
Transport & mutableTransport(const std::string &name)
Returns a single configured transport which can be modified in place.
static void provideConfigOptions(rsc::config::OptionHandler &handler)
Provides the default configuration options for RSB to the specified handler.
A class describing the configuration of Participant instances.
SignalParticipantCreatedPtr getSignalParticipantCreated()
ScopePtr getScope() const
Returns the scope of this participant.
rsc::misc::UUID getId() const
Returns the unique id of the participant.
std::set< Transport > getTransports(bool includeDisabled=false) const
Returns the set of desired transports for a participant.
void setOptions(const rsc::runtime::Properties &options)
Sets the options for the transport.