@@ -22,14 +22,34 @@ OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
22
22
namespace OpenDDS {
23
23
namespace DCPS {
24
24
25
+ /*
26
+ The InternalDataWriter supports the following QoS:
27
+
28
+ DurabilityQosPolicy durability; => VOLATILE, TRANSIENT_LOCAL
29
+ DurabilityServiceQosPolicy durability_service; => None
30
+ DeadlineQosPolicy deadline; => None
31
+ LatencyBudgetQosPolicy latency_budget => None
32
+ LivelinessQosPolicy liveliness => None
33
+ ReliabilityQosPolicy reliability => RELIABLE
34
+ DestinationOrderQosPolicy destination_order; => None
35
+ HistoryQosPolicy history; => KEEP_LAST_HISTORY, KEEP_ALL_HISTORY
36
+ ResourceLimitsQosPolicy resource_limits; => None
37
+ TransportPriorityQosPolicy transport_priority; => None
38
+ LifespanQosPolicy lifespan; => None
39
+ UserDataQosPolicy user_data; => None
40
+ OwnershipQosPolicy ownership; => None
41
+ OwnershipStrengthQosPolicy ownership_strength; => None
42
+ WriterDataLifecycleQosPolicy writer_data_lifecycle; => Yes
43
+ */
44
+
25
45
template <typename T>
26
46
class InternalDataWriter : public InternalEntity {
27
47
public:
28
48
typedef RcHandle<InternalDataReader<T> > InternalDataReader_rch;
29
49
typedef WeakRcHandle<InternalDataReader<T> > InternalDataReader_wrch;
30
50
31
- explicit InternalDataWriter (bool durable )
32
- : durable_(durable )
51
+ explicit InternalDataWriter (const DDS::DataWriterQos& qos )
52
+ : qos_(qos )
33
53
{}
34
54
35
55
// / @name InternalTopic Interface
@@ -39,14 +59,10 @@ class InternalDataWriter : public InternalEntity {
39
59
ACE_GUARD (ACE_Thread_Mutex, g, mutex_);
40
60
readers_.insert (reader);
41
61
42
- if (durable_ && reader->durable ()) {
43
- for (typename InstanceMap::const_iterator pos = instance_map_.begin (), limit = instance_map_.end ();
62
+ if (qos_. durability . kind == DDS::TRANSIENT_LOCAL_DURABILITY_QOS && reader->durable ()) {
63
+ for (typename InstanceMap::iterator pos = instance_map_.begin (), limit = instance_map_.end ();
44
64
pos != limit; ++pos) {
45
- if (pos->second .valid_data ) {
46
- reader->write (static_rchandle_cast<InternalEntity>(rchandle_from (this )), pos->second .sample );
47
- } else {
48
- reader->register_instance (static_rchandle_cast<InternalEntity>(rchandle_from (this )), pos->first );
49
- }
65
+ pos->second .add_reader (reader, static_rchandle_cast<InternalEntity>(rchandle_from (this )));
50
66
}
51
67
}
52
68
}
@@ -55,7 +71,7 @@ class InternalDataWriter : public InternalEntity {
55
71
{
56
72
ACE_GUARD (ACE_Thread_Mutex, g, mutex_);
57
73
if (readers_.erase (reader)) {
58
- reader->remove_publication (static_rchandle_cast<InternalEntity>(rchandle_from (this )));
74
+ reader->remove_publication (static_rchandle_cast<InternalEntity>(rchandle_from (this )), qos_. writer_data_lifecycle . autodispose_unregistered_instances );
59
75
}
60
76
}
61
77
@@ -73,30 +89,13 @@ class InternalDataWriter : public InternalEntity {
73
89
74
90
// / @name User Interface
75
91
// / @{
76
- void register_instance (const T& sample)
77
- {
78
- ACE_GUARD (ACE_Thread_Mutex, g, mutex_);
79
-
80
- if (durable_) {
81
- instance_map_.insert (std::make_pair (sample, SampleHolder ()));
82
- }
83
-
84
- for (typename ReaderSet::const_iterator pos = readers_.begin (), limit = readers_.end (); pos != limit; ++pos) {
85
- InternalDataReader_rch reader = pos->lock ();
86
- if (reader) {
87
- reader->register_instance (static_rchandle_cast<InternalEntity>(rchandle_from (this )), sample);
88
- }
89
- }
90
- }
91
-
92
92
void write (const T& sample)
93
93
{
94
94
ACE_GUARD (ACE_Thread_Mutex, g, mutex_);
95
95
96
- if (durable_ ) {
96
+ if (qos_. durability . kind == DDS::TRANSIENT_LOCAL_DURABILITY_QOS ) {
97
97
const std::pair<typename InstanceMap::iterator, bool > p = instance_map_.insert (std::make_pair (sample, SampleHolder ()));
98
- p.first ->second .sample = sample;
99
- p.first ->second .valid_data = true ;
98
+ p.first ->second .write (sample, qos_);
100
99
}
101
100
102
101
for (typename ReaderSet::const_iterator pos = readers_.begin (), limit = readers_.end (); pos != limit; ++pos) {
@@ -107,52 +106,81 @@ class InternalDataWriter : public InternalEntity {
107
106
}
108
107
}
109
108
110
- void unregister_instance (const T& sample)
109
+ void dispose (const T& sample)
111
110
{
112
111
ACE_GUARD (ACE_Thread_Mutex, g, mutex_);
113
112
114
- if (durable_) {
115
- instance_map_.erase (sample);
113
+ if (qos_.durability .kind == DDS::TRANSIENT_LOCAL_DURABILITY_QOS) {
114
+ typename InstanceMap::iterator pos = instance_map_.find (sample);
115
+ if (pos != instance_map_.end ()) {
116
+ pos->second .dispose ();
117
+ }
116
118
}
117
119
118
120
for (typename ReaderSet::const_iterator pos = readers_.begin (), limit = readers_.end (); pos != limit; ++pos) {
119
121
InternalDataReader_rch reader = pos->lock ();
120
122
if (reader) {
121
- reader->unregister_instance (static_rchandle_cast<InternalEntity>(rchandle_from (this )), sample);
123
+ reader->dispose (static_rchandle_cast<InternalEntity>(rchandle_from (this )), sample);
122
124
}
123
125
}
124
126
}
125
127
126
- void dispose (const T& sample)
128
+ void unregister_instance (const T& sample)
127
129
{
128
130
ACE_GUARD (ACE_Thread_Mutex, g, mutex_);
129
131
130
- if (durable_ ) {
132
+ if (qos_. durability . kind == DDS::TRANSIENT_LOCAL_DURABILITY_QOS ) {
131
133
instance_map_.erase (sample);
132
134
}
133
135
134
136
for (typename ReaderSet::const_iterator pos = readers_.begin (), limit = readers_.end (); pos != limit; ++pos) {
135
137
InternalDataReader_rch reader = pos->lock ();
136
138
if (reader) {
137
- reader->dispose (static_rchandle_cast<InternalEntity>(rchandle_from (this )), sample);
139
+ if (qos_.writer_data_lifecycle .autodispose_unregistered_instances ) {
140
+ reader->dispose (static_rchandle_cast<InternalEntity>(rchandle_from (this )), sample);
141
+ }
142
+ reader->unregister_instance (static_rchandle_cast<InternalEntity>(rchandle_from (this )), sample);
138
143
}
139
144
}
140
145
}
141
146
// / @}
142
147
143
148
private:
144
- const bool durable_ ;
149
+ const DDS::DataWriterQos qos_ ;
145
150
146
151
typedef OPENDDS_SET (InternalDataReader_wrch) ReaderSet;
147
152
ReaderSet readers_;
148
153
149
- struct SampleHolder {
150
- T sample;
151
- bool valid_data;
154
+ class SampleHolder {
155
+ public:
156
+ bool empty () const { return samples_.empty (); }
157
+
158
+ void add_reader (InternalDataReader_rch reader, RcHandle<InternalEntity> writer)
159
+ {
160
+ for (typename SampleList::const_iterator pos = samples_.begin (), limit = samples_.end (); pos != limit; ++pos) {
161
+ reader->write (writer, *pos);
162
+ }
163
+ }
164
+
165
+ void write (const T& sample,
166
+ const DDS::DataWriterQos& qos)
167
+ {
168
+ samples_.push_back (sample);
169
+ if (qos.history .kind == DDS::KEEP_LAST_HISTORY_QOS) {
170
+ while (samples_.size () > static_cast <std::size_t >(qos.history .depth )) {
171
+ samples_.pop_front ();
172
+ }
173
+ }
174
+ }
175
+
176
+ void dispose ()
177
+ {
178
+ samples_.clear ();
179
+ }
152
180
153
- SampleHolder ()
154
- : valid_data( false )
155
- {}
181
+ private:
182
+ typedef OPENDDS_LIST (T) SampleList;
183
+ SampleList samples_;
156
184
};
157
185
158
186
typedef OPENDDS_MAP_T (T, SampleHolder) InstanceMap;
0 commit comments