CoherentChangeControl.cpp

Go to the documentation of this file.
00001 /*
00002  *
00003  *
00004  * Distributed under the OpenDDS License.
00005  * See: http://www.opendds.org/license.html
00006  */
00007 
00008 #include "DCPS/DdsDcps_pch.h" //Only the _pch include should start with DCPS/
00009 
00010 #ifndef OPENDDS_NO_OBJECT_MODEL_PROFILE
00011 
00012 #include "CoherentChangeControl.h"
00013 #include "Serializer.h"
00014 #include "GuidConverter.h"
00015 #include "dds/DdsDcpsGuidTypeSupportImpl.h"
00016 #include "dds/DCPS/PoolAllocator.h"
00017 
00018 #include <iomanip>
00019 #include <iostream>
00020 #include <stdexcept>
00021 
00022 
00023 #if !defined (__ACE_INLINE__)
00024 #include "CoherentChangeControl.inl"
00025 #endif /* __ACE_INLINE__ */
00026 
00027 
00028 namespace OpenDDS {
00029 namespace DCPS {
00030 
00031 ACE_CDR::Boolean
00032 operator<<(Serializer& serializer, CoherentChangeControl& value)
00033 {
00034   serializer << value.coherent_samples_.num_samples_;
00035   serializer << value.coherent_samples_.last_sample_;
00036   serializer << ACE_OutputCDR::from_boolean(value.group_coherent_);
00037 
00038   if (value.group_coherent_) {
00039     serializer << value.publisher_id_;
00040     serializer << static_cast<ACE_UINT32>(value.group_coherent_samples_.size());
00041     GroupCoherentSamples::iterator itEnd = value.group_coherent_samples_.end();
00042     for (GroupCoherentSamples::iterator it =
00043            value.group_coherent_samples_.begin(); it != itEnd; ++it) {
00044       serializer << it->first;
00045       serializer << it->second.num_samples_;
00046       serializer << it->second.last_sample_;
00047     }
00048   }
00049 
00050   return serializer.good_bit();
00051 }
00052 
00053 ACE_CDR::Boolean
00054 operator>>(Serializer& serializer, CoherentChangeControl& value)
00055 {
00056   serializer >> value.coherent_samples_.num_samples_;
00057   if (!serializer.good_bit()) return false;
00058 
00059   serializer >> value.coherent_samples_.last_sample_;
00060   if (!serializer.good_bit()) return false;
00061 
00062   serializer >> ACE_InputCDR::to_boolean(value.group_coherent_);
00063   if (!serializer.good_bit()) return false;
00064 
00065   if (value.group_coherent_) {
00066     serializer >> value.publisher_id_;
00067     if (!serializer.good_bit()) return false;
00068 
00069     ACE_UINT32 sz = 0;
00070     serializer >> sz;
00071     if (!serializer.good_bit()) return false;
00072 
00073     for (ACE_UINT32 i = 0; i < sz; ++i) {
00074       PublicationId writer(GUID_UNKNOWN);
00075       ACE_UINT32 num_sample = 0;
00076       ACE_INT16 last_sample = 0;
00077 
00078       serializer >> writer;
00079       if (!serializer.good_bit()) return false;
00080       serializer >> num_sample;
00081       if (!serializer.good_bit()) return false;
00082       serializer >> last_sample;
00083       if (!serializer.good_bit()) return false;
00084 
00085       std::pair<GroupCoherentSamples::iterator, bool> pair =
00086         value.group_coherent_samples_.insert(GroupCoherentSamples::value_type(
00087           writer, WriterCoherentSample(num_sample, last_sample)));
00088       if (!pair.second) {
00089         return false;
00090       }
00091     }
00092   }
00093 
00094   return true;
00095 }
00096 
00097 /// Message header insertion onto an ostream.
00098 extern OpenDDS_Dcps_Export
00099 std::ostream& operator<<(std::ostream& str, const CoherentChangeControl& value)
00100 {
00101   str << "num_samples: " << std::dec << value.coherent_samples_.num_samples_
00102       << ", last_sample: " << value.coherent_samples_.last_sample_.getValue()
00103       << ", ";
00104   if (value.group_coherent_) {
00105     GuidConverter converter(value.publisher_id_);
00106     str << "publisher: " << std::dec << OPENDDS_STRING(converter).c_str() << ", ";
00107     str << "group size: " << std::dec << value.group_coherent_samples_.size()
00108         << ", ";
00109     GroupCoherentSamples::const_iterator itEnd =
00110       value.group_coherent_samples_.end();
00111     for (GroupCoherentSamples::const_iterator it =
00112            value.group_coherent_samples_.begin(); it != itEnd; ++it) {
00113       GuidConverter converter(it->first);
00114       str << "writer: " << OPENDDS_STRING(converter).c_str() << ", "
00115           << "num_samples: " << it->second.num_samples_ << ", "
00116           << "last_sample: " << it->second.last_sample_.getValue()  << std::endl;
00117     }
00118   }
00119   return str;
00120 }
00121 
00122 } // namespace DCPS
00123 } // namespace OpenDDS
00124 
00125 #endif // OPENDDS_NO_OBJECT_MODEL_PROFILE

Generated on Fri Feb 12 20:05:19 2016 for OpenDDS by  doxygen 1.4.7