diff --git a/components/demo/democomponent.cpp b/components/demo/democomponent.cpp index b72b02f1e..19145330c 100644 --- a/components/demo/democomponent.cpp +++ b/components/demo/democomponent.cpp @@ -69,7 +69,7 @@ void DemoComponent::HelloWorldRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request) { Logger::Write(LogInformation, "demo", "Got 'hello world' from identity=" + - sender->GetName()); + (sender ? sender->GetName() : "(anonymous)")); } EXPORT_COMPONENT(demo, DemoComponent); diff --git a/components/replication/replicationcomponent.cpp b/components/replication/replicationcomponent.cpp index ec717566a..ef2c71767 100644 --- a/components/replication/replicationcomponent.cpp +++ b/components/replication/replicationcomponent.cpp @@ -35,13 +35,13 @@ void ReplicationComponent::Start(void) Endpoint::OnConnected.connect(boost::bind(&ReplicationComponent::EndpointConnectedHandler, this, _1)); m_Endpoint->RegisterTopicHandler("config::ObjectUpdate", - boost::bind(&ReplicationComponent::RemoteObjectUpdateHandler, this, _2, _3)); + boost::bind(&ReplicationComponent::RemoteObjectUpdateHandler, this, _3)); m_Endpoint->RegisterTopicHandler("config::ObjectRemoved", boost::bind(&ReplicationComponent::RemoteObjectRemovedHandler, this, _3)); /* service status */ m_Endpoint->RegisterTopicHandler("checker::ServiceStateChange", - boost::bind(&ReplicationComponent::ServiceStateChangeRequestHandler, _2, _3)); + boost::bind(&ReplicationComponent::ServiceStateChangeRequestHandler, _3)); } /** @@ -52,7 +52,7 @@ void ReplicationComponent::Stop(void) m_Endpoint->Unregister(); } -void ReplicationComponent::ServiceStateChangeRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request) +void ReplicationComponent::ServiceStateChangeRequestHandler(const RequestMessage& request) { ServiceStateChangeMessage params; if (!request.GetParams(¶ms)) @@ -163,7 +163,7 @@ void ReplicationComponent::TransactionClosingHandler(const set& modifiedObjects); - void RemoteObjectUpdateHandler(const Endpoint::Ptr& sender, const RequestMessage& request); + void RemoteObjectUpdateHandler(const RequestMessage& request); void RemoteObjectRemovedHandler(const RequestMessage& request); static RequestMessage MakeObjectMessage(const DynamicObject::Ptr& object, diff --git a/lib/remoting/endpointmanager.cpp b/lib/remoting/endpointmanager.cpp index 799f3c2f8..077b10643 100644 --- a/lib/remoting/endpointmanager.cpp +++ b/lib/remoting/endpointmanager.cpp @@ -184,18 +184,31 @@ void EndpointManager::ClientClosedHandler(const Stream::Ptr& client) m_PendingClients.erase(tlsStream); } +/** + * Sends an anonymous unicast message to the specified recipient. + * + * @param recipient The recipient of the message. + * @param message The message. + */ +void EndpointManager::SendUnicastMessage(const Endpoint::Ptr& recipient, + const MessagePart& message) +{ + SendUnicastMessage(Endpoint::Ptr(), recipient, message); +} + /** * Sends a unicast message to the specified recipient. * * @param sender The sender of the message. * @param recipient The recipient of the message. - * @param message The request. + * @param message The message. */ void EndpointManager::SendUnicastMessage(const Endpoint::Ptr& sender, const Endpoint::Ptr& recipient, const MessagePart& message) { - /* don't forward messages between non-local endpoints */ - if (!sender->IsLocal() && !recipient->IsLocal()) + /* don't forward messages between non-local endpoints, assume that + * anonymous senders (sender == null) are local */ + if ((sender && !sender->IsLocal()) && !recipient->IsLocal()) return; if (ResponseMessage::IsResponseMessage(message)) @@ -237,6 +250,17 @@ void EndpointManager::SendAnycastMessage(const Endpoint::Ptr& sender, SendUnicastMessage(sender, recipient, message); } +/** + * Sends an anonymous message to all recipients who have a subscription for the + * message#s topic. + * + * @param message The message. + */ +void EndpointManager::SendMulticastMessage(const RequestMessage& message) +{ + SendMulticastMessage(Endpoint::Ptr(), message); +} + /** * Sends a message to all recipients who have a subscription for the * message's topic. diff --git a/lib/remoting/endpointmanager.h b/lib/remoting/endpointmanager.h index b491846a1..120f9f57b 100644 --- a/lib/remoting/endpointmanager.h +++ b/lib/remoting/endpointmanager.h @@ -47,8 +47,10 @@ public: void AddListener(const String& service); void AddConnection(const String& node, const String& service); + void SendUnicastMessage(const Endpoint::Ptr& recipient, const MessagePart& message); void SendUnicastMessage(const Endpoint::Ptr& sender, const Endpoint::Ptr& recipient, const MessagePart& message); void SendAnycastMessage(const Endpoint::Ptr& sender, const RequestMessage& message); + void SendMulticastMessage(const RequestMessage& message); void SendMulticastMessage(const Endpoint::Ptr& sender, const RequestMessage& message); typedef function APICallback;