OpenDDS  Snapshot(2023/04/28-20:55)
CoherentChangeControl.cpp
Go to the documentation of this file.
1 /*
2  *
3  *
4  * Distributed under the OpenDDS License.
5  * See: http://www.opendds.org/license.html
6  */
7 
8 #include "DCPS/DdsDcps_pch.h" //Only the _pch include should start with DCPS/
9 
10 #ifndef OPENDDS_NO_OBJECT_MODEL_PROFILE
11 
12 #include "CoherentChangeControl.h"
13 
14 #include "Serializer.h"
15 #include "GuidConverter.h"
16 #include "PoolAllocator.h"
18 
19 #include <dds/DdsDcpsGuidTypeSupportImpl.h>
20 
21 #include <iomanip>
22 #include <iostream>
23 #include <stdexcept>
24 
25 
26 #if !defined (__ACE_INLINE__)
28 #endif /* __ACE_INLINE__ */
29 
31 
32 namespace OpenDDS {
33 namespace DCPS {
34 
37 {
38  if (!(serializer << value.coherent_samples_.num_samples_) ||
39  !(serializer << value.coherent_samples_.last_sample_) ||
40  !(serializer << ACE_OutputCDR::from_boolean(value.group_coherent_))) {
41  return false;
42  }
43 
44  if (value.group_coherent_) {
45  if (!(serializer << value.publisher_id_) ||
46  !(serializer << static_cast<ACE_UINT32>(value.group_coherent_samples_.size()))) {
47  return false;
48  }
49  GroupCoherentSamples::iterator itEnd = value.group_coherent_samples_.end();
50  for (GroupCoherentSamples::iterator it =
51  value.group_coherent_samples_.begin(); it != itEnd; ++it) {
52  if (!(serializer << it->first) ||
53  !(serializer << it->second.num_samples_) ||
54  !(serializer << it->second.last_sample_)) {
55  return false;
56  }
57  }
58  }
59 
60  return serializer.good_bit();
61 }
62 
65 {
66  if (!(serializer >> value.coherent_samples_.num_samples_) ||
67  !(serializer >> value.coherent_samples_.last_sample_) ||
68  !(serializer >> ACE_InputCDR::to_boolean(value.group_coherent_))) {
69  return false;
70  }
71 
72  if (value.group_coherent_) {
73  ACE_UINT32 sz = 0;
74  if (!(serializer >> value.publisher_id_) ||
75  !(serializer >> sz)) {
76  return false;
77  }
78 
79  for (ACE_UINT32 i = 0; i < sz; ++i) {
80  GUID_t writer(GUID_UNKNOWN);
81  ACE_UINT32 num_sample = 0;
82  ACE_INT16 last_sample = 0;
83 
84  if (!(serializer >> writer) ||
85  !(serializer >> num_sample) ||
86  !(serializer >> last_sample)) {
87  return false;
88  }
89 
90  std::pair<GroupCoherentSamples::iterator, bool> pair =
91  value.group_coherent_samples_.insert(GroupCoherentSamples::value_type(
92  writer, WriterCoherentSample(num_sample, last_sample)));
93  if (!pair.second) {
94  return false;
95  }
96  }
97  }
98 
99  return serializer.good_bit();
100 }
101 
102 /// Message header insertion onto an ostream.
103 extern OpenDDS_Dcps_Export
104 std::ostream& operator<<(std::ostream& str, const CoherentChangeControl& value)
105 {
106  RestoreOutputStreamState stream_state(str);
107 
108  str << "num_samples: " << std::dec << value.coherent_samples_.num_samples_
109  << ", last_sample: " << value.coherent_samples_.last_sample_.getValue()
110  << ", ";
111  if (value.group_coherent_) {
112  str << "publisher: " << std::dec << LogGuid(value.publisher_id_).c_str() << ", ";
113  str << "group size: " << std::dec << value.group_coherent_samples_.size()
114  << ", ";
115  GroupCoherentSamples::const_iterator itEnd =
116  value.group_coherent_samples_.end();
117  for (GroupCoherentSamples::const_iterator it =
118  value.group_coherent_samples_.begin(); it != itEnd; ++it) {
119  str << "writer: " << LogGuid(it->first).c_str() << ", "
120  << "num_samples: " << it->second.num_samples_ << ", "
121  << "last_sample: " << it->second.last_sample_.getValue() << std::endl;
122  }
123  }
124  return str;
125 }
126 
127 } // namespace DCPS
128 } // namespace OpenDDS
129 
131 
132 #endif // OPENDDS_NO_OBJECT_MODEL_PROFILE
const LogLevel::Value value
Definition: debug.cpp:61
const GUID_t GUID_UNKNOWN
Nil value for GUID.
Definition: GuidUtils.h:59
#define OpenDDS_Dcps_Export
Definition: dcps_export.h:24
const char * c_str() const
Class to serialize and deserialize data for DDS.
Definition: Serializer.h:369
ACE_CDR::Boolean operator<<(Serializer &serializer, CoherentChangeControl &value)
Marshal/Insertion into a buffer.
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
ACE_CDR::Boolean operator>>(Serializer &serializer, CoherentChangeControl &value)
bool Boolean
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28