OpenSplice ISO C++ 2 DCPS  v6.x
ISO C++ 2 OpenSplice Data Distribution Service Data-Centric Publish-Subscribe API
DataWriterImpl.hpp
Go to the documentation of this file.
1 #ifndef OMG_DDS_PUB_DATA_WRITER_IMPL_HPP_
2 #define OMG_DDS_PUB_DATA_WRITER_IMPL_HPP_
3 
4 /* Copyright 2010, Object Management Group, Inc.
5  * Copyright 2010, PrismTech, Corp.
6  * Copyright 2010, Real-Time Innovations, Inc.
7  * All rights reserved.
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21 
22 
23 
24 
25 /***************************************************************************
26  *
27  * dds/pub/DataWriter<> WRAPPER implementation.
28  * Declaration can be found in dds/pub/DataWriter.hpp
29  *
30  ***************************************************************************/
31 
32 #include <dds/topic/Topic.hpp>
33 
34 namespace dds
35 {
36 namespace pub
37 {
38 
39 template <typename T>
41  const dds::pub::Publisher& pub,
42  const dds::topic::Topic<T>& topic) :
43  dds::core::Reference(
44  new DELEGATE<T>(pub,
45  topic,
46  pub.is_nil() ? dds::pub::qos::DataWriterQos() : pub.default_datawriter_qos(),
47  NULL,
48  dds::core::status::StatusMask::none()))
49 {
50  ISOCPP_REPORT_STACK_DDS_BEGIN(pub);
51  this->delegate()->init(this->impl_);
52 }
53 
54 template <typename T>
56  const ::dds::topic::Topic<T>& topic,
59  const dds::core::status::StatusMask& mask) :
60  dds::core::Reference(
61  new DELEGATE<T>(pub, topic, qos, listener, mask))
62 {
63  ISOCPP_REPORT_STACK_DDS_BEGIN(pub);
64  this->delegate()->init(this->impl_);
65 }
66 
67 template <typename T>
69 {
70 }
71 
72 template <typename T>
73 void
74 DataWriter<T>::write(const T& sample)
75 {
76  ISOCPP_REPORT_STACK_DDS_BEGIN(*this);
77  this->delegate()->write(sample);
78 }
79 
80 template <typename T>
81 void
82 DataWriter<T>::write(const T& sample, const dds::core::Time& timestamp)
83 {
84  ISOCPP_REPORT_STACK_DDS_BEGIN(*this);
85  this->delegate()->write(sample, timestamp);
86 }
87 
88 template <typename T>
89 void
90 DataWriter<T>::write(const T& sample, const ::dds::core::InstanceHandle& instance)
91 {
92  ISOCPP_REPORT_STACK_DDS_BEGIN(*this);
93  this->delegate()->write(sample, instance);
94 }
95 
96 template <typename T>
97 void
98 DataWriter<T>::write(const T& sample,
99  const ::dds::core::InstanceHandle& instance,
100  const dds::core::Time& timestamp)
101 {
102  ISOCPP_REPORT_STACK_DDS_BEGIN(*this);
103  this->delegate()->write(sample, instance, timestamp);
104 }
105 
106 template <typename T>
107 void
109 {
110  ISOCPP_REPORT_STACK_DDS_BEGIN(*this);
111  this->delegate()->write(i);
112 }
113 
114 template <typename T>
115 void
117  const dds::core::Time& timestamp)
118 {
119  ISOCPP_REPORT_STACK_DDS_BEGIN(*this);
120  this->delegate()->write(i, timestamp);
121 }
122 
123 template <typename T>
124 template <typename FWIterator>
125 void
126 DataWriter<T>::write(const FWIterator& begin, const FWIterator& end)
127 {
128  ISOCPP_REPORT_STACK_DDS_BEGIN(*this);
129 
130  FWIterator b = begin;
131  while(b != end)
132  {
133  this->delegate()->write(*b);
134  ++b;
135  }
136 }
137 
138 template <typename T>
139 template <typename FWIterator>
140 void
141 DataWriter<T>::write(const FWIterator& begin, const FWIterator& end,
142  const dds::core::Time& timestamp)
143 {
144  ISOCPP_REPORT_STACK_DDS_BEGIN(*this);
145 
146  FWIterator b = begin;
147  while(b != end)
148  {
149  this->delegate()->write(*b, timestamp);
150  ++b;
151  }
152 }
153 
154 template <typename T>
155 template <typename SamplesFWIterator, typename HandlesFWIterator>
156 void
157 DataWriter<T>::write(const SamplesFWIterator& data_begin,
158  const SamplesFWIterator& data_end,
159  const HandlesFWIterator& handle_begin,
160  const HandlesFWIterator& handle_end)
161 {
162  ISOCPP_REPORT_STACK_DDS_BEGIN(*this);
163 
164  SamplesFWIterator data = data_begin;
165  HandlesFWIterator handle = handle_begin;
166 
167  while(data != data_end && handle != handle_end)
168  {
169  this->delegate()->write(*data, *handle);
170  ++data;
171  ++handle;
172  }
173 }
174 
175 template <typename T>
176 template <typename SamplesFWIterator, typename HandlesFWIterator>
177 void
178 DataWriter<T>::write(const SamplesFWIterator& data_begin,
179  const SamplesFWIterator& data_end,
180  const HandlesFWIterator& handle_begin,
181  const HandlesFWIterator& handle_end,
182  const dds::core::Time& timestamp)
183 {
184  ISOCPP_REPORT_STACK_DDS_BEGIN(*this);
185 
186  SamplesFWIterator data = data_begin;
187  HandlesFWIterator handle = handle_begin;
188 
189  while(data != data_end && handle != handle_end)
190  {
191  this->delegate()->write(*data, *handle, timestamp);
192  ++data;
193  ++handle;
194  }
195 }
196 
197 template <typename T>
199 DataWriter<T>::operator <<(const ::dds::pub::qos::DataWriterQos& qos)
200 {
201  this->delegate()->qos(qos);
202  return *this;
203 }
204 
205 template <typename T>
208 {
209  ISOCPP_REPORT_STACK_DDS_BEGIN(*this);
210 
211  this->write(data);
212  return *this;
213 }
214 
215 template <typename T>
217 DataWriter<T>::operator << (const std::pair<T, dds::core::Time>& data)
218 {
219  ISOCPP_REPORT_STACK_DDS_BEGIN(*this);
220 
221  this->write(data.first, data.second);
222  return *this;
223 }
224 
225 template <typename T>
227 DataWriter<T>::operator << (const std::pair<T, ::dds::core::InstanceHandle>& data)
228 {
229  ISOCPP_REPORT_STACK_DDS_BEGIN(*this);
230 
231  this->write(data.first, data.second);
232  return *this;
233 }
234 
235 template <typename T>
238 {
239  ISOCPP_REPORT_STACK_DDS_BEGIN(*this);
240 
241  return manipulator(*this);
242 }
243 
244 template <typename T>
247 {
248  ISOCPP_REPORT_STACK_DDS_BEGIN(*this);
249  /* Invalid time will be used as current time. */
250  return this->delegate()->register_instance(key, dds::core::Time::invalid());
251 }
252 
253 template <typename T>
256  const dds::core::Time& timestamp)
257 {
258  ISOCPP_REPORT_STACK_DDS_BEGIN(*this);
259 
260  return this->delegate()->register_instance(key, timestamp);
261 }
262 
263 template <typename T>
265 DataWriter<T>::unregister_instance(const ::dds::core::InstanceHandle& i)
266 {
267  ISOCPP_REPORT_STACK_DDS_BEGIN(*this);
268  /* Invalid time will be used as current time. */
269  this->delegate()->unregister_instance(i, dds::core::Time::invalid());
270  return *this;
271 }
272 
273 template <typename T>
275 DataWriter<T>::unregister_instance(const ::dds::core::InstanceHandle& i,
276  const dds::core::Time& timestamp)
277 {
278  ISOCPP_REPORT_STACK_DDS_BEGIN(*this);
279  this->delegate()->unregister_instance(i, timestamp);
280  return *this;
281 }
282 
283 template <typename T>
286 {
287  ISOCPP_REPORT_STACK_DDS_BEGIN(*this);
288  /* Invalid time will be used as current time. */
289  this->delegate()->unregister_instance(key, dds::core::Time::invalid());
290  return *this;
291 }
292 
293 template <typename T>
296  const dds::core::Time& timestamp)
297 {
298  ISOCPP_REPORT_STACK_DDS_BEGIN(*this);
299  this->delegate()->unregister_instance(key, timestamp);
300  return *this;
301 }
302 
303 template <typename T>
305 DataWriter<T>::dispose_instance(const ::dds::core::InstanceHandle& i)
306 {
307  ISOCPP_REPORT_STACK_DDS_BEGIN(*this);
308  /* Invalid time will be used as current time. */
309  this->delegate()->dispose_instance(i, dds::core::Time::invalid());
310  return *this;
311 }
312 
313 template <typename T>
315 DataWriter<T>::dispose_instance(const ::dds::core::InstanceHandle& i,
316  const dds::core::Time& timestamp)
317 {
318  ISOCPP_REPORT_STACK_DDS_BEGIN(*this);
319  this->delegate()->dispose_instance(i, timestamp);
320  return *this;
321 }
322 
323 template <typename T>
326 {
327  ISOCPP_REPORT_STACK_DDS_BEGIN(*this);
328  /* Invalid time will be used as current time. */
329  this->delegate()->dispose_instance(key, dds::core::Time::invalid());
330  return *this;
331 }
332 
333 template <typename T>
336  const dds::core::Time& timestamp)
337 {
338  ISOCPP_REPORT_STACK_DDS_BEGIN(*this);
339  this->delegate()->dispose_instance(key, timestamp);
340  return *this;
341 }
342 
343 template <typename T>
346  const ::dds::core::InstanceHandle& h)
347 {
348  ISOCPP_REPORT_STACK_DDS_BEGIN(*this);
349 
350  return this->delegate()->key_value(i, h);
351 }
352 
353 template <typename T>
354 T&
355 DataWriter<T>::key_value(T& sample, const ::dds::core::InstanceHandle& h)
356 {
357  ISOCPP_REPORT_STACK_DDS_BEGIN(*this);
358 
359  return this->delegate()->key_value(sample, h);
360 }
361 
362 template <typename T>
365 {
366  ISOCPP_REPORT_STACK_DDS_BEGIN(*this);
367 
368  return this->delegate()->lookup_instance(key);
369 }
370 
371 template <typename T>
374 {
375  ISOCPP_REPORT_STACK_DDS_BEGIN(*this);
376 
377  return this->delegate()->topic();
378 }
379 
380 template <typename T>
381 void
383  const ::dds::core::status::StatusMask& mask)
384 {
385  ISOCPP_REPORT_STACK_DDS_BEGIN(*this);
386 
387  this->delegate()->listener(listener, mask);
388 }
389 
390 template <typename T>
393 {
394  ISOCPP_REPORT_STACK_DDS_BEGIN(*this);
395 
396  return this->delegate()->listener();
397 }
398 
399 }
400 }
401 
402 
403 
404 
405 /***************************************************************************
406  *
407  * dds/pub/detail/DataWriter<> DELEGATE implementation.
408  * Declaration can be found in dds/pub/detail/DataWriter.hpp
409  *
410  * Implementation and declaration have been separated because some circular
411  * dependencies, like with DataWriterListener and AnyDataWriter.
412  *
413  ***************************************************************************/
414 
420 #include <dds/pub/AnyDataWriter.hpp>
422 #include <org/opensplice/pub/AnyDataWriterDelegate.hpp>
423 
424 template <typename T>
425 dds::pub::detail::DataWriter<T>::DataWriter(
426  const dds::pub::Publisher& pub,
427  const ::dds::topic::Topic<T>& topic,
430  const dds::core::status::StatusMask& mask)
431  : ::org::opensplice::pub::AnyDataWriterDelegate(qos, topic), pub_(pub), topic_(topic)
432 {
433  ISOCPP_REPORT_STACK_DDS_BEGIN(pub);
434 
436  ISOCPP_THROW_EXCEPTION(ISOCPP_PRECONDITION_NOT_MET_ERROR, "DataWriter cannot be created, topic information not found");
437  }
438 
439  /* Create a implicit publisher with the topic participant when needed. */
440  if (pub_.is_nil()) {
441  pub_ = dds::pub::Publisher(topic->domain_participant());
442  }
443 
444  /* Merge the topic QoS implicitly when needed. */
445  if (topic.qos()->force_merge()) {
446  qos_ = topic.qos();
447  }
448 
449  org::opensplice::pub::qos::DataWriterQosDelegate dwQos = qos_.delegate();
450 
451  // get and validate the kernel qos
452  dwQos.check();
453  u_writerQos uQos = dwQos.u_qos();
454 
455  u_publisher uPublisher = (u_publisher)(pub_.delegate()->get_user_handle());
456  u_topic uTopic = (u_topic)(topic.delegate()->get_user_handle());
457 
458  std::string name = "writer <" + topic.name() + ">";
459 
460  u_writer uWriter = u_writerNew(uPublisher, name.c_str(), uTopic, uQos);
461  u_writerQosFree(uQos);
462 
463  if (!uWriter) {
464  ISOCPP_THROW_EXCEPTION(ISOCPP_ERROR, "Failed to create DataWriter");
465  } else {
466  topic_.delegate()->incrNrDependents();
467  }
468 
469  this->setCopyIn(org::opensplice::topic::TopicTraits<T>::getCopyIn());
470  this->setCopyOut(org::opensplice::topic::TopicTraits<T>::getCopyOut());
471 
472  this->userHandle = (u_object)uWriter;
473  this->listener_set((void*)listener, mask);
474  this->set_domain_id(this->pub_.delegate()->get_domain_id());
475 }
476 
477 template <typename T>
478 dds::pub::detail::DataWriter<T>::~DataWriter()
479 {
480  if (!this->closed) {
481  try {
482  this->close();
483  } catch (...) {
484  /* Empty: the exception throw should have already traced an error. */
485  }
486  }
487 }
488 
489 template <typename T>
490 void
491 dds::pub::detail::DataWriter<T>::init(ObjectDelegate::weak_ref_type weak_ref)
492 {
493  /* Set weak_ref before passing ourselves to other isocpp objects. */
494  this->set_weak_ref(weak_ref);
495  /* Register writer at publisher. */
496  this->pub_.delegate()->add_datawriter(*this);
497  /* Use listener dispatcher from the publisher. */
498  this->listener_dispatcher_set(this->pub_.delegate()->listener_dispatcher_get());
499  /* This only starts listening when the status mask shows interest. */
500  this->listener_enable();
501  /* Enable when needed. */
502  if (this->pub_.delegate()->is_enabled() && this->pub_.delegate()->is_auto_enable()) {
503  this->enable();
504  }
505 }
506 
507 template <typename T>
508 void
509 dds::pub::detail::DataWriter<T>::write(const T& sample)
510 {
511  this->check();
512  AnyDataWriterDelegate::write((u_writer)(this->userHandle),
513  &sample,
514  dds::core::InstanceHandle(dds::core::null),
516 }
517 
518 template <typename T>
519 void
520 dds::pub::detail::DataWriter<T>::write(const T& sample, const dds::core::Time& timestamp)
521 {
522  this->check();
523  AnyDataWriterDelegate::write((u_writer)(this->userHandle),
524  &sample,
525  dds::core::InstanceHandle(dds::core::null),
526  timestamp);
527 }
528 
529 template <typename T>
530 void
531 dds::pub::detail::DataWriter<T>::write(const T& sample, const ::dds::core::InstanceHandle& instance)
532 {
533  this->check();
534  AnyDataWriterDelegate::write((u_writer)(this->userHandle),
535  &sample,
536  instance,
538 }
539 
540 template <typename T>
541 void
542 dds::pub::detail::DataWriter<T>::write(const T& sample,
543  const ::dds::core::InstanceHandle& instance,
544  const dds::core::Time& timestamp)
545 {
546  this->check();
547  AnyDataWriterDelegate::write((u_writer)(this->userHandle),
548  &sample,
549  instance,
550  timestamp);
551 }
552 
553 template <typename T>
554 void
555 dds::pub::detail::DataWriter<T>::write(const dds::topic::TopicInstance<T>& i)
556 {
557  this->check();
558  AnyDataWriterDelegate::write((u_writer)(this->userHandle),
559  &i.sample(),
560  i.handle(),
562 }
563 
564 template <typename T>
565 void
566 dds::pub::detail::DataWriter<T>::write(const dds::topic::TopicInstance<T>& i,
567  const dds::core::Time& timestamp)
568 {
569  this->check();
570  AnyDataWriterDelegate::write((u_writer)(this->userHandle),
571  &i.sample(),
572  i.handle(),
573  timestamp);
574 }
575 
576 template <typename T>
577 void
578 dds::pub::detail::DataWriter<T>::writedispose(const T& sample)
579 {
580  ISOCPP_REPORT_STACK_DELEGATE_BEGIN(this);
581  this->check();
582  AnyDataWriterDelegate::writedispose(
583  (u_writer)(this->userHandle),
584  &sample,
585  dds::core::InstanceHandle(dds::core::null),
587 }
588 
589 template <typename T>
590 void
591 dds::pub::detail::DataWriter<T>::writedispose(const T& sample, const dds::core::Time& timestamp)
592 {
593  ISOCPP_REPORT_STACK_DELEGATE_BEGIN(this);
594  this->check();
595  AnyDataWriterDelegate::writedispose(
596  (u_writer)(this->userHandle),
597  &sample,
598  dds::core::InstanceHandle(dds::core::null),
599  timestamp);
600 }
601 
602 template <typename T>
603 void
604 dds::pub::detail::DataWriter<T>::writedispose(const T& sample, const ::dds::core::InstanceHandle& instance)
605 {
606  ISOCPP_REPORT_STACK_DELEGATE_BEGIN(this);
607  this->check();
608  AnyDataWriterDelegate::writedispose(
609  (u_writer)(this->userHandle),
610  &sample,
611  instance,
613 }
614 
615 template <typename T>
616 void
617 dds::pub::detail::DataWriter<T>::writedispose(
618  const T& sample,
619  const ::dds::core::InstanceHandle& instance,
620  const dds::core::Time& timestamp)
621 {
622  ISOCPP_REPORT_STACK_DELEGATE_BEGIN(this);
623  this->check();
624  AnyDataWriterDelegate::writedispose(
625  (u_writer)(this->userHandle),
626  &sample,
627  instance,
628  timestamp);
629 }
630 
631 template <typename T>
632 void
633 dds::pub::detail::DataWriter<T>::writedispose(const dds::topic::TopicInstance<T>& i)
634 {
635  ISOCPP_REPORT_STACK_DELEGATE_BEGIN(this);
636  this->check();
637  AnyDataWriterDelegate::writedispose(
638  (u_writer)(this->userHandle),
639  &i.sample(),
640  i.handle(),
642 }
643 
644 template <typename T>
645 void
646 dds::pub::detail::DataWriter<T>::writedispose(
648  const dds::core::Time& timestamp)
649 {
650  ISOCPP_REPORT_STACK_DELEGATE_BEGIN(this);
651  this->check();
652  AnyDataWriterDelegate::writedispose(
653  (u_writer)(this->userHandle),
654  &i.sample(),
655  i.handle(),
656  timestamp);
657 }
658 
659 template <typename T>
660 template <typename FWIterator>
661 void
662 dds::pub::detail::DataWriter<T>::writedispose(const FWIterator& begin, const FWIterator& end)
663 {
664  ISOCPP_REPORT_STACK_DELEGATE_BEGIN(this);
665 
666  FWIterator b = begin;
667  while(b != end)
668  {
669  this->writedispose(*b);
670  ++b;
671  }
672 }
673 
674 template <typename T>
675 template <typename FWIterator>
676 void
677 dds::pub::detail::DataWriter<T>::writedispose(const FWIterator& begin, const FWIterator& end,
678  const dds::core::Time& timestamp)
679 {
680  ISOCPP_REPORT_STACK_DELEGATE_BEGIN(this);
681 
682  FWIterator b = begin;
683  while(b != end)
684  {
685  this->writedispose(*b, timestamp);
686  ++b;
687  }
688 }
689 
690 template <typename T>
691 template <typename SamplesFWIterator, typename HandlesFWIterator>
692 void
693 dds::pub::detail::DataWriter<T>::writedispose(
694  const SamplesFWIterator& data_begin,
695  const SamplesFWIterator& data_end,
696  const HandlesFWIterator& handle_begin,
697  const HandlesFWIterator& handle_end)
698 {
699  ISOCPP_REPORT_STACK_DELEGATE_BEGIN(this);
700 
701  SamplesFWIterator data = data_begin;
702  HandlesFWIterator handle = handle_begin;
703 
704  while(data != data_end && handle != handle_end)
705  {
706  this->writedispose(*data, *handle);
707  ++data;
708  ++handle;
709  }
710 }
711 
712 template <typename T>
713 template <typename SamplesFWIterator, typename HandlesFWIterator>
714 void
715 dds::pub::detail::DataWriter<T>::writedispose(
716  const SamplesFWIterator& data_begin,
717  const SamplesFWIterator& data_end,
718  const HandlesFWIterator& handle_begin,
719  const HandlesFWIterator& handle_end,
720  const dds::core::Time& timestamp)
721 {
722  ISOCPP_REPORT_STACK_DELEGATE_BEGIN(this);
723 
724  SamplesFWIterator data = data_begin;
725  HandlesFWIterator handle = handle_begin;
726 
727  while(data != data_end && handle != handle_end)
728  {
729  this->writedispose(*data, *handle, timestamp);
730  ++data;
731  ++handle;
732  }
733 }
734 
735 template <typename T>
736 const ::dds::core::InstanceHandle
737 dds::pub::detail::DataWriter<T>::register_instance(const T& key,
738  const dds::core::Time& timestamp)
739 {
740  this->check();
741  dds::core::InstanceHandle handle(AnyDataWriterDelegate::register_instance((u_writer)(this->userHandle), &key, timestamp));
742  return handle;
743 }
744 
745 template <typename T>
746 void
747 dds::pub::detail::DataWriter<T>::unregister_instance(const ::dds::core::InstanceHandle& handle,
748  const dds::core::Time& timestamp)
749 {
750  this->check();
751  AnyDataWriterDelegate::unregister_instance((u_writer)(this->userHandle), handle, timestamp);
752 }
753 
754 template <typename T>
755 void
756 dds::pub::detail::DataWriter<T>::unregister_instance(const T& sample,
757  const dds::core::Time& timestamp)
758 {
759  this->check();
760  AnyDataWriterDelegate::unregister_instance((u_writer)(this->userHandle), &sample, timestamp);
761 }
762 
763 template <typename T>
764 void
765 dds::pub::detail::DataWriter<T>::dispose_instance(const ::dds::core::InstanceHandle& handle,
766  const dds::core::Time& timestamp)
767 {
768  this->check();
769  AnyDataWriterDelegate::dispose_instance((u_writer)(this->userHandle), handle, timestamp);
770 }
771 
772 template <typename T>
773 void
774 dds::pub::detail::DataWriter<T>::dispose_instance(const T& sample,
775  const dds::core::Time& timestamp)
776 {
777  this->check();
778  AnyDataWriterDelegate::dispose_instance((u_writer)(this->userHandle), &sample, timestamp);
779 }
780 
781 
782 template <typename T>
784 dds::pub::detail::DataWriter<T>::key_value(dds::topic::TopicInstance<T>& i,
785  const ::dds::core::InstanceHandle& h)
786 {
787  this->check();
788 
789  T sample;
790  AnyDataWriterDelegate::get_key_value((u_writer)(this->userHandle), &sample, h);
791  i.handle(h);
792  i.sample(sample);
793 
794  return i;
795 }
796 
797 template <typename T>
798 T&
799 dds::pub::detail::DataWriter<T>::key_value(T& sample, const ::dds::core::InstanceHandle& h)
800 {
801  this->check();
802 
803  AnyDataWriterDelegate::get_key_value((u_writer)(this->userHandle), &sample, h);
804 
805  return sample;
806 }
807 
808 template <typename T>
810 dds::pub::detail::DataWriter<T>::lookup_instance(const T& key)
811 {
812  this->check();
813 
814  dds::core::InstanceHandle handle(AnyDataWriterDelegate::lookup_instance((u_writer)(this->userHandle), &key));
815 
816  return handle;
817 }
818 
819 template <typename T>
821 dds::pub::detail::DataWriter<T>::topic() const
822 {
823  return this->topic_;
824 }
825 
826 template <typename T>
827 const dds::pub::Publisher&
828 dds::pub::detail::DataWriter<T>::publisher() const
829 {
830  return this->pub_;
831 }
832 
833 template <typename T>
834 void
835 dds::pub::detail::DataWriter<T>::listener(DataWriterListener<T>* listener,
836  const ::dds::core::status::StatusMask& mask)
837 {
838  /* EntityDelegate takes care of thread safety. */
839  this->listener_set((void*)listener, mask);
840  this->listener_enable();
841 }
842 
843 template <typename T>
845 dds::pub::detail::DataWriter<T>::listener() const
846 {
847  return reinterpret_cast<dds::pub::DataWriterListener<T>*>(this->listener_get());
848 }
849 
850 template <typename T>
851 void
852 dds::pub::detail::DataWriter<T>::close()
853 {
855  this->listener_dispatcher_reset();
856 
857  org::opensplice::core::ScopedObjectLock scopedLock(*this);
858 
859  topic_.delegate()->decrNrDependents();
860 
861  this->pub_.delegate()->remove_datawriter(*this);
862 
863  org::opensplice::pub::AnyDataWriterDelegate::close();
864 
865  scopedLock.unlock();
866 }
867 
868 template <typename T>
870 dds::pub::detail::DataWriter<T>::wrapper()
871 {
872  typename DataWriter::ref_type ref =
873  OSPL_CXX11_STD_MODULE::dynamic_pointer_cast<DataWriter<T> >(this->get_strong_ref());
875 
876  return writer;
877 }
878 
879 template <typename T>
880 void
881 dds::pub::detail::DataWriter<T>::listener_notify(
882  ObjectDelegate::ref_type source,
883  uint32_t triggerMask,
884  void *eventData,
885  void *l)
886 {
887  /* The EntityDelegate takes care of the thread safety and always
888  * provides a listener and source. */
890  reinterpret_cast<dds::pub::DataWriterListener<T>*>(l);
891  assert(listener);
892 
893  /* Get DataWriter wrapper from given source EntityDelegate. */
894  typename DataWriter::ref_type ref =
895  OSPL_CXX11_STD_MODULE::dynamic_pointer_cast<DataWriter<T> >(source);
897 
898 
899  if (triggerMask & V_EVENT_LIVELINESS_LOST) {
901  status.delegate().v_status(((v_writerStatus)eventData)->livelinessLost);
902  listener->on_liveliness_lost(writer, status);
903  }
904 
905  if (triggerMask & V_EVENT_OFFERED_DEADLINE_MISSED) {
907  status.delegate().v_status(((v_writerStatus)eventData)->deadlineMissed);
908  listener->on_offered_deadline_missed(writer, status);
909  }
910 
911  if (triggerMask & V_EVENT_OFFERED_INCOMPATIBLE_QOS) {
913  status.delegate().v_status(((v_writerStatus)eventData)->incompatibleQos);
914  listener->on_offered_incompatible_qos(writer, status);
915  }
916 
917  if (triggerMask & V_EVENT_PUBLICATION_MATCHED) {
919  status.delegate().v_status(((v_writerStatus)eventData)->publicationMatch);
920  listener->on_publication_matched(writer, status);
921  }
922 }
923 
926 #endif /* OMG_DDS_PUB_DATA_WRITER_IMPL_HPP_ */
DataWriter allows the application to set the value of the sample to be published under a given Topic...
Definition: DataWriter.hpp:88
virtual void on_liveliness_lost(dds::pub::DataWriter< T > &writer, const dds::core::status::LivelinessLostStatus &status)=0
static StatusMask none()
Definition: State.hpp:205
DataWriter & operator<<(const T &data)
const ::dds::core::InstanceHandle register_instance(const T &key)
const ::dds::core::InstanceHandle handle() const
DataWriter & unregister_instance(const ::dds::core::InstanceHandle &i)
A TopicInstance encapsulates a dds::sub::Sample and its associated dds::core::InstanceHandle.
Topic is the most basic description of the data to be published and subscribed.
Definition: Topic.hpp:36
virtual void on_publication_matched(dds::pub::DataWriter< T > &writer, const dds::core::status::PublicationMatchedStatus &status)=0
void write(const T &sample)
dds::topic::TopicInstance< T > & key_value(dds::topic::TopicInstance< T > &i, const ::dds::core::InstanceHandle &h)
Support functionality to check if a given object type is a Topic.
Definition: TopicTraits.hpp:30
Class to hold the handle associated with in sample instance.
static const Time invalid()
virtual void on_offered_deadline_missed(dds::pub::DataWriter< T > &writer, const dds::core::status::OfferedDeadlineMissedStatus &status)=0
void writedispose(const T &sample)
Definition: array.hpp:23
const dds::pub::qos::PublisherQos & qos() const
virtual void on_offered_incompatible_qos(dds::pub::DataWriter< T > &writer, const dds::core::status::OfferedIncompatibleQosStatus &status)=0
StatusMask is a bitmap or bitset field.
Definition: State.hpp:144
DataWriter events Listener.
DataWriter(const dds::pub::Publisher &pub, const ::dds::topic::Topic< T > &topic)
DataWriterListener< T > * listener() const
dds::core::InstanceHandle lookup_instance(const T &key)
This object provides the basic mechanism for an application to specify Quality of Service attributes ...
const dds::topic::Topic< T > & topic() const
The Publisher acts on the behalf of one or several DataWriter objects that belong to it...
Definition: Publisher.hpp:55
dds::pub::qos::DataWriterQos qos() const
dds::sub::functors::InstanceManipulatorFunctor instance(const dds::core::InstanceHandle &h)
DataWriter & dispose_instance(const ::dds::core::InstanceHandle &i)