Line data Source code
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" 17 : #include "RestoreOutputStreamState.h" 18 : 19 : #include <dds/DdsDcpsGuidTypeSupportImpl.h> 20 : 21 : #include <iomanip> 22 : #include <iostream> 23 : #include <stdexcept> 24 : 25 : 26 : #if !defined (__ACE_INLINE__) 27 : #include "CoherentChangeControl.inl" 28 : #endif /* __ACE_INLINE__ */ 29 : 30 : OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL 31 : 32 : namespace OpenDDS { 33 : namespace DCPS { 34 : 35 : ACE_CDR::Boolean 36 0 : operator<<(Serializer& serializer, CoherentChangeControl& value) 37 : { 38 0 : if (!(serializer << value.coherent_samples_.num_samples_) || 39 0 : !(serializer << value.coherent_samples_.last_sample_) || 40 0 : !(serializer << ACE_OutputCDR::from_boolean(value.group_coherent_))) { 41 0 : return false; 42 : } 43 : 44 0 : if (value.group_coherent_) { 45 0 : if (!(serializer << value.publisher_id_) || 46 0 : !(serializer << static_cast<ACE_UINT32>(value.group_coherent_samples_.size()))) { 47 0 : return false; 48 : } 49 0 : GroupCoherentSamples::iterator itEnd = value.group_coherent_samples_.end(); 50 0 : for (GroupCoherentSamples::iterator it = 51 0 : value.group_coherent_samples_.begin(); it != itEnd; ++it) { 52 0 : if (!(serializer << it->first) || 53 0 : !(serializer << it->second.num_samples_) || 54 0 : !(serializer << it->second.last_sample_)) { 55 0 : return false; 56 : } 57 : } 58 : } 59 : 60 0 : return serializer.good_bit(); 61 : } 62 : 63 : ACE_CDR::Boolean 64 0 : operator>>(Serializer& serializer, CoherentChangeControl& value) 65 : { 66 0 : if (!(serializer >> value.coherent_samples_.num_samples_) || 67 0 : !(serializer >> value.coherent_samples_.last_sample_) || 68 0 : !(serializer >> ACE_InputCDR::to_boolean(value.group_coherent_))) { 69 0 : return false; 70 : } 71 : 72 0 : if (value.group_coherent_) { 73 0 : ACE_UINT32 sz = 0; 74 0 : if (!(serializer >> value.publisher_id_) || 75 0 : !(serializer >> sz)) { 76 0 : return false; 77 : } 78 : 79 0 : for (ACE_UINT32 i = 0; i < sz; ++i) { 80 0 : GUID_t writer(GUID_UNKNOWN); 81 0 : ACE_UINT32 num_sample = 0; 82 0 : ACE_INT16 last_sample = 0; 83 : 84 0 : if (!(serializer >> writer) || 85 0 : !(serializer >> num_sample) || 86 0 : !(serializer >> last_sample)) { 87 0 : return false; 88 : } 89 : 90 : std::pair<GroupCoherentSamples::iterator, bool> pair = 91 0 : value.group_coherent_samples_.insert(GroupCoherentSamples::value_type( 92 0 : writer, WriterCoherentSample(num_sample, last_sample))); 93 0 : if (!pair.second) { 94 0 : return false; 95 : } 96 : } 97 : } 98 : 99 0 : return serializer.good_bit(); 100 : } 101 : 102 : /// Message header insertion onto an ostream. 103 : extern OpenDDS_Dcps_Export 104 0 : std::ostream& operator<<(std::ostream& str, const CoherentChangeControl& value) 105 : { 106 0 : RestoreOutputStreamState stream_state(str); 107 : 108 0 : str << "num_samples: " << std::dec << value.coherent_samples_.num_samples_ 109 0 : << ", last_sample: " << value.coherent_samples_.last_sample_.getValue() 110 0 : << ", "; 111 0 : if (value.group_coherent_) { 112 0 : str << "publisher: " << std::dec << LogGuid(value.publisher_id_).c_str() << ", "; 113 0 : str << "group size: " << std::dec << value.group_coherent_samples_.size() 114 0 : << ", "; 115 : GroupCoherentSamples::const_iterator itEnd = 116 0 : value.group_coherent_samples_.end(); 117 0 : for (GroupCoherentSamples::const_iterator it = 118 0 : value.group_coherent_samples_.begin(); it != itEnd; ++it) { 119 0 : str << "writer: " << LogGuid(it->first).c_str() << ", " 120 0 : << "num_samples: " << it->second.num_samples_ << ", " 121 0 : << "last_sample: " << it->second.last_sample_.getValue() << std::endl; 122 : } 123 : } 124 0 : return str; 125 0 : } 126 : 127 : } // namespace DCPS 128 : } // namespace OpenDDS 129 : 130 : OPENDDS_END_VERSIONED_NAMESPACE_DECL 131 : 132 : #endif // OPENDDS_NO_OBJECT_MODEL_PROFILE