-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiscoveryController.cpp
133 lines (101 loc) · 5.63 KB
/
DiscoveryController.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include "DCPS/Discovery/DiscoveryController.h"
#include "DCPS/Factory/DCPSConfig.h"
#include "DCPS/Pub/Publisher.h"
#include "DCPS/Pub/AnyDataWriterHolder.h"
#include "DCPS/Sub/Subscriber.h"
#include "DCPS/Sub/AnyDataReaderHolder.h"
#include "DCPS/Topic/TopicHolder.h"
#include "DCPS/Domain/DomainParticipant.h"
namespace DCPS { namespace Discovery
{
// ------------------------------------------------------------------------------
// Discovery controller state
// ------------------------------------------------------------------------------
DiscoveryControllerState::DiscoveryControllerState()
: participantDiscovery_(new ParticipantDiscoveryController())
, endpointDiscovery_(new EndpointDiscoveryController())
{ }
DiscoveryControllerState::~DiscoveryControllerState()
{
delete participantDiscovery_;
delete endpointDiscovery_;
participantDiscovery_ = NULL;
endpointDiscovery_ = NULL;
}
ParticipantDiscoveryController *DiscoveryControllerState::ParticipantDiscovery() const
{
return participantDiscovery_;
}
EndpointDiscoveryController *DiscoveryControllerState::EndpointDiscovery() const
{
return endpointDiscovery_;
}
// ------------------------------------------------------------------------------
// DiscoveryController implementation
// ------------------------------------------------------------------------------
Singleton<DiscoveryController> DiscoveryController::discoveryController_;
DiscoveryController::DiscoveryController()
: Templates::ContextData<DiscoveryControllerState>()
{ }
DiscoveryController::~DiscoveryController()
{
}
DiscoveryController& DiscoveryController::Instance()
{
return DiscoveryController::discoveryController_.GetRef();
}
void DiscoveryController::run()
{
}
void DiscoveryController::ObserveDomainCaches(DDS::Elements::DomainId domainId)
{
RxData::Cache::Ptr cache = RxData::CacheFactory::Instance().getOrCreateCache(DDS::Factory::DDSConfig::DDSCacheDescription(domainId));
ASSERT(cache);
cache->getOrCreateHome<DCPS::Domain::DomainParticipantPtr, DDS::Elements::DomainId>( DCPSConfig::DomainParticipantCacheTypeName())->Connect(this);
}
// ------------------------------------------------------------------------
// Callbacks
// ------------------------------------------------------------------------
bool DiscoveryController::OnObjectCreated(Domain::DomainParticipantPtr data)
{
//TODO: Connect here leads to deadlock when signaller is synchronous!
this->addDomainCacheObservers(data->GetDomainId());
return true;
}
bool DiscoveryController::OnObjectDeleted(Domain::DomainParticipantPtr data)
{
//TODO: RemoveObserver here leads to deadlock when signaller is synchronous!
this->removeDomainCacheObservers(data->GetDomainId());
return true;
}
bool DiscoveryController::OnObjectModified(Domain::DomainParticipantPtr data)
{
IDEBUG() << " domain participant modified?";
return true;
}
// ------------------------------------------------------------------------
// Add remove observers depending on call back event
// ------------------------------------------------------------------------
void DiscoveryController::addDomainCacheObservers(const DDS::Elements::DomainId &domainId)
{
RxData::Cache::Ptr cache = RxData::CacheFactory::Instance().findCacheByDescription(DDS::Factory::DDSConfig::DDSCacheDescription(domainId));
ASSERT(cache);
cache->getOrCreateHome<DCPS::Domain::DomainParticipantPtr, DDS::Elements::DomainId>( DCPSConfig::DomainParticipantCacheTypeName())->Connect(this->context().ParticipantDiscovery());
cache->getOrCreateHome<DCPS::Publication::AnyDataWriterHolderBasePtr, DDS::Elements::TopicName>(DCPSConfig::DataWriterCacheTypeName())->Connect(this->context().EndpointDiscovery());
cache->getOrCreateHome<DCPS::Subscription::AnyDataReaderHolderBasePtr, DDS::Elements::TopicName>(DCPSConfig::DataReaderCacheTypeName())->Connect(this->context().EndpointDiscovery());
cache->getOrCreateHome<DCPS::Subscription::SubscriberPtr, InstanceHandle>(DCPSConfig::SubscriberCacheTypeName())->Connect(this->context().EndpointDiscovery());
cache->getOrCreateHome<DCPS::Publication::PublisherPtr, InstanceHandle>(DCPSConfig::PublisherCacheTypeName())->Connect(this->context().EndpointDiscovery());
cache->getOrCreateHome<DCPS::Topic::TopicHolderPtr, InstanceHandle>(DCPSConfig::TopicCacheTypeName())->Connect(this->context().EndpointDiscovery());
}
void DiscoveryController::removeDomainCacheObservers(const DDS::Elements::DomainId &domainId)
{
RxData::Cache::Ptr cache = RxData::CacheFactory::Instance().findCacheByDescription(DDS::Factory::DDSConfig::DDSCacheDescription(domainId));
ASSERT(cache);
cache->getOrCreateHome<DCPS::Domain::DomainParticipantPtr, DDS::Elements::DomainId>( DCPSConfig::DomainParticipantCacheTypeName())->Disconnect(this->context().ParticipantDiscovery());
cache->getOrCreateHome<DCPS::Publication::AnyDataWriterHolderBasePtr, DDS::Elements::TopicName>(DCPSConfig::DataWriterCacheTypeName())->Disconnect(this->context().EndpointDiscovery());
cache->getOrCreateHome<DCPS::Subscription::AnyDataReaderHolderBasePtr, DDS::Elements::TopicName>(DCPSConfig::DataReaderCacheTypeName())->Disconnect(this->context().EndpointDiscovery());
cache->getOrCreateHome<DCPS::Subscription::SubscriberPtr, InstanceHandle>(DCPSConfig::SubscriberCacheTypeName())->Disconnect(this->context().EndpointDiscovery());
cache->getOrCreateHome<DCPS::Publication::PublisherPtr, InstanceHandle>(DCPSConfig::PublisherCacheTypeName())->Disconnect(this->context().EndpointDiscovery());
cache->getOrCreateHome<DCPS::Topic::TopicHolderPtr, InstanceHandle>(DCPSConfig::TopicCacheTypeName())->Disconnect(this->context().EndpointDiscovery());
}
}}