From f2698c0fb7af1fb270004c1c956b85256648c92b Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Wed, 9 May 2012 12:34:11 +0200 Subject: [PATCH] Fix method registration. --- components/discovery/discoverycomponent.cpp | 43 ++++++++++++--------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/components/discovery/discoverycomponent.cpp b/components/discovery/discoverycomponent.cpp index 918f30ed1..fc9343dfa 100644 --- a/components/discovery/discoverycomponent.cpp +++ b/components/discovery/discoverycomponent.cpp @@ -242,7 +242,7 @@ int DiscoveryComponent::NewIdentityHandler(const EventArgs& ea) // the broker knows about our message types SendDiscoveryMessage("discovery::RegisterComponent", GetEndpointManager()->GetIdentity(), endpoint); - map::iterator i; + map::iterator ic; if (IsBroker()) { // we assume the other component _always_ wants @@ -254,21 +254,30 @@ int DiscoveryComponent::NewIdentityHandler(const EventArgs& ea) // send discovery::NewComponent messages for all components // we know about - for (i = m_Components.begin(); i != m_Components.end(); i++) { - SendDiscoveryMessage("discovery::NewComponent", i->first, endpoint); + for (ic = m_Components.begin(); ic != m_Components.end(); ic++) { + SendDiscoveryMessage("discovery::NewComponent", ic->first, endpoint); } } // check if we already know the other component - i = m_Components.find(endpoint->GetIdentity()); + ic = m_Components.find(endpoint->GetIdentity()); - if (i == m_Components.end()) { + if (ic == m_Components.end()) { // we don't know the other component yet, so // wait until we get a discovery::NewComponent message // from a broker return 0; } + // register published/subscribed methods for this endpoint + ComponentDiscoveryInfo::Ptr info = ic->second; + set::iterator it; + for (it = info->PublishedMethods.begin(); it != info->PublishedMethods.end(); it++) + endpoint->RegisterMethodSource(*it); + + for (it = info->SubscribedMethods.begin(); it != info->SubscribedMethods.end(); it++) + endpoint->RegisterMethodSink(*it); + FinishDiscoverySetup(endpoint); return 0; @@ -323,17 +332,6 @@ void DiscoveryComponent::FinishDiscoverySetup(Endpoint::Ptr endpoint) endpoint->SetSentWelcome(true); - ComponentDiscoveryInfo::Ptr info; - - if (GetComponentDiscoveryInfo(endpoint->GetIdentity(), &info)) { - set::iterator i; - for (i = info->PublishedMethods.begin(); i != info->PublishedMethods.end(); i++) - endpoint->RegisterMethodSource(*i); - - for (i = info->SubscribedMethods.begin(); i != info->SubscribedMethods.end(); i++) - endpoint->RegisterMethodSink(*i); - } - if (endpoint->GetReceivedWelcome()) { EventArgs ea; ea.Source = endpoint; @@ -448,12 +446,17 @@ void DiscoveryComponent::ProcessDiscoveryMessage(string identity, DiscoveryMessa if (endpointConfig) endpointConfig->GetPropertyDictionary("roles", &roles); + Endpoint::Ptr endpoint = GetEndpointManager()->GetEndpointByIdentity(identity); + Message provides; if (message.GetProvides(&provides)) { DictionaryIterator i; for (i = provides.GetDictionary()->Begin(); i != provides.GetDictionary()->End(); i++) { - if (trusted || HasMessagePermission(roles, "publish", i->second)) + if (trusted || HasMessagePermission(roles, "publish", i->second)) { info->PublishedMethods.insert(i->second); + if (endpoint) + endpoint->RegisterMethodSource(i->second); + } } } @@ -461,8 +464,11 @@ void DiscoveryComponent::ProcessDiscoveryMessage(string identity, DiscoveryMessa if (message.GetSubscribes(&subscribes)) { DictionaryIterator i; for (i = subscribes.GetDictionary()->Begin(); i != subscribes.GetDictionary()->End(); i++) { - if (trusted || HasMessagePermission(roles, "subscribe", i->second)) + if (trusted || HasMessagePermission(roles, "subscribe", i->second)) { info->SubscribedMethods.insert(i->second); + if (endpoint) + endpoint->RegisterMethodSink(i->second); + } } } @@ -478,7 +484,6 @@ void DiscoveryComponent::ProcessDiscoveryMessage(string identity, DiscoveryMessa if (IsBroker()) SendDiscoveryMessage("discovery::NewComponent", identity, Endpoint::Ptr()); - Endpoint::Ptr endpoint = GetEndpointManager()->GetEndpointByIdentity(identity); if (endpoint) FinishDiscoverySetup(endpoint); }