Line data Source code
1 : /*
2 : *
3 : * Distributed under the OpenDDS License.
4 : * See: http://www.opendds.org/license.html
5 : */
6 :
7 : #include "DCPS/DdsDcps_pch.h" //Only the _pch include should start with DCPS/
8 :
9 : #include "EntityImpl.h"
10 :
11 : #include "DomainParticipantImpl.h"
12 : #include "StatusConditionImpl.h"
13 : #include "transport/framework/TransportConfig.h"
14 :
15 : OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
16 :
17 : namespace OpenDDS {
18 : namespace DCPS {
19 :
20 12 : EntityImpl::EntityImpl()
21 12 : : enabled_(false)
22 12 : , entity_deleted_(false)
23 12 : , status_changes_(0)
24 12 : , status_condition_(new StatusConditionImpl(this))
25 12 : , observer_()
26 12 : , events_(Observer::e_NONE)
27 36 : , instance_handle_(DDS::HANDLE_NIL)
28 : {
29 12 : }
30 :
31 12 : EntityImpl::~EntityImpl()
32 : {
33 12 : const RcHandle<DomainParticipantImpl> participant = participant_for_instance_handle_.lock();
34 12 : if (participant) {
35 0 : participant->return_handle(instance_handle_);
36 : }
37 12 : }
38 :
39 : DDS::ReturnCode_t
40 0 : EntityImpl::set_enabled()
41 : {
42 0 : enabled_ = true;
43 :
44 0 : return DDS::RETCODE_OK;
45 : }
46 :
47 : bool
48 0 : EntityImpl::is_enabled() const
49 : {
50 0 : return enabled_;
51 : }
52 :
53 : DDS::StatusCondition_ptr
54 0 : EntityImpl::get_statuscondition()
55 : {
56 0 : ACE_GUARD_RETURN(ACE_Thread_Mutex, g, lock_, 0);
57 0 : return DDS::StatusCondition::_duplicate(status_condition_);
58 0 : }
59 :
60 : DDS::StatusMask
61 0 : EntityImpl::get_status_changes()
62 : {
63 0 : ACE_GUARD_RETURN(ACE_Thread_Mutex, g, lock_, 0);
64 0 : return status_changes_;
65 0 : }
66 :
67 : void
68 0 : EntityImpl::set_status_changed_flag(
69 : DDS::StatusKind status,
70 : bool status_changed_flag)
71 : {
72 0 : ACE_GUARD(ACE_Thread_Mutex, g, lock_);
73 :
74 0 : if (status_changed_flag) {
75 0 : status_changes_ |= status;
76 :
77 : } else {
78 0 : status_changes_ &= ~status;
79 : }
80 0 : }
81 :
82 : void
83 0 : EntityImpl::set_deleted(bool state)
84 : {
85 0 : entity_deleted_ = state;
86 0 : }
87 :
88 : bool
89 0 : EntityImpl::get_deleted() const
90 : {
91 0 : return entity_deleted_;
92 : }
93 :
94 0 : Observer_rch EntityImpl::get_observer(Observer::Event e)
95 : {
96 0 : ACE_GUARD_RETURN(ACE_Thread_Mutex, g, lock_, Observer_rch());
97 0 : return (observer_ && (events_ & e)) ? observer_ :
98 0 : parent() ? parent()->get_observer(e) : Observer_rch();
99 0 : }
100 :
101 : void
102 0 : EntityImpl::notify_status_condition()
103 : {
104 0 : DDS::StatusCondition_var sc_var;
105 : {
106 0 : ACE_GUARD(ACE_Thread_Mutex, g, lock_);
107 :
108 0 : sc_var = DDS::StatusCondition::_duplicate(status_condition_);
109 0 : }
110 :
111 0 : StatusConditionImpl* sci = dynamic_cast<StatusConditionImpl*>(sc_var.in());
112 0 : if (sci) {
113 0 : sci->signal_all();
114 : } else {
115 0 : ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: ")
116 : ACE_TEXT("EntityImpl::notify_status_condition: ")
117 : ACE_TEXT("failed to obtain the StatusConditionImpl.\n")));
118 : }
119 0 : }
120 :
121 : void
122 0 : EntityImpl::transport_config(const TransportConfig_rch& cfg)
123 : {
124 0 : ACE_GUARD(ACE_Thread_Mutex, g, lock_);
125 0 : transport_config_ = cfg;
126 0 : }
127 :
128 : TransportConfig_rch
129 0 : EntityImpl::transport_config() const
130 : {
131 0 : ACE_GUARD_RETURN(ACE_Thread_Mutex, g, lock_, TransportConfig_rch());
132 0 : return transport_config_;
133 0 : }
134 :
135 0 : void EntityImpl::set_observer(Observer_rch observer, Observer::Event e)
136 : {
137 0 : ACE_GUARD(ACE_Thread_Mutex, g, lock_);
138 0 : observer_ = observer;
139 0 : events_ = e;
140 0 : }
141 :
142 0 : DDS::InstanceHandle_t EntityImpl::get_entity_instance_handle(const GUID_t& id,
143 : const RcHandle<DomainParticipantImpl>& participant)
144 : {
145 0 : ACE_GUARD_RETURN(ACE_Thread_Mutex, g, lock_, DDS::HANDLE_NIL);
146 :
147 0 : if (instance_handle_ != DDS::HANDLE_NIL) {
148 0 : return instance_handle_;
149 : }
150 :
151 0 : if (!participant) {
152 0 : return DDS::HANDLE_NIL;
153 : }
154 :
155 0 : participant_for_instance_handle_ = participant;
156 0 : return instance_handle_ = participant->assign_handle(id);
157 0 : }
158 :
159 : } // namespace DCPS
160 : } // namespace OpenDDS
161 :
162 : OPENDDS_END_VERSIONED_NAMESPACE_DECL
|