monitored_items.cpp
Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 #include "binary_serialization.h"
00012 
00013 #include <opc/ua/protocol/monitored_items.h>
00014 #include <opc/ua/protocol/protocol.h>
00015 #include <opc/ua/protocol/binary/stream.h>
00016 
00017 #include <iostream> //for debug
00018 #include <opc/ua/protocol/string_utils.h> //for debug
00019 
00020 namespace OpcUa
00021 {
00022 
00023   MonitoringFilter::MonitoringFilter(DataChangeFilter filter) : DataChange(filter)
00024   {
00025     Header.TypeId  = ExpandedObjectId::DataChangeFilter;
00026     Header.Encoding  = static_cast<ExtensionObjectEncoding>(Header.Encoding | ExtensionObjectEncoding::HAS_BINARY_BODY);
00027   }
00028 
00029   MonitoringFilter::MonitoringFilter(EventFilter filter) : Event(filter)
00030   {
00031     Header.TypeId  = ExpandedObjectId::EventFilter;
00032     Header.Encoding  = static_cast<ExtensionObjectEncoding>(Header.Encoding | ExtensionObjectEncoding::HAS_BINARY_BODY);
00033   }
00034 
00035   MonitoringFilter:: MonitoringFilter(AggregateFilter filter) : Aggregate(filter)
00036   {
00037     Header.TypeId  = ExpandedObjectId::DataChangeFilter;
00038     Header.Encoding  = static_cast<ExtensionObjectEncoding>(Header.Encoding | ExtensionObjectEncoding::HAS_BINARY_BODY);
00039   }
00040 
00041   namespace Binary
00042   {
00043 
00045     // AttributeOperand
00047 
00048     template<>
00049     std::size_t RawSize<AttributeOperand>(const OpcUa::AttributeOperand& params)
00050     {
00051       return RawSize(params.Node) +
00052           RawSize(params.Alias) +
00053           RawSize(params.Path) +
00054           RawSize(params.AttributeId) +
00055           RawSizeContainer(params.IndexRange); 
00056     }
00057 
00058     template<>
00059     void DataDeserializer::Deserialize<AttributeOperand>(AttributeOperand& params)
00060     {
00061       *this >> params.Node;
00062       *this >> params.Alias;
00063       *this >> params.Path;
00064       *this >> params.AttributeId;
00065       *this >> params.IndexRange;
00066     }
00067 
00068     template<>
00069     void DataSerializer::Serialize<AttributeOperand>(const AttributeOperand& params)
00070     {
00071       *this << params.Node;
00072       *this << params.Alias;
00073       *this << params.Path;
00074       *this << params.AttributeId;
00075       *this << params.IndexRange;
00076     }
00077 
00079     // SimpleAttributeOperand
00081 
00082     template<>
00083     std::size_t RawSize<SimpleAttributeOperand>(const OpcUa::SimpleAttributeOperand& params)
00084     {
00085       return RawSize(params.TypeId) +
00086           RawSizeContainer(params.BrowsePath) +
00087           RawSize(params.Attribute) +
00088           RawSizeContainer(params.IndexRange); 
00089     }
00090 
00091     template<>
00092     void DataDeserializer::Deserialize<SimpleAttributeOperand>(SimpleAttributeOperand& params)
00093     {
00094       *this >> params.TypeId;
00095       *this >> params.BrowsePath;
00096       *this >> params.Attribute;
00097       *this >> params.IndexRange;
00098     }
00099 
00100     template<>
00101     void DataSerializer::Serialize<SimpleAttributeOperand>(const SimpleAttributeOperand& params)
00102     {
00103       *this << params.TypeId;
00104       *this << params.BrowsePath;
00105       *this << params.Attribute;
00106       *this << params.IndexRange;
00107     }
00108 
00109     template<>
00110     void DataSerializer::Serialize<std::vector<SimpleAttributeOperand>>(const std::vector<SimpleAttributeOperand>& targets)
00111     {
00112       SerializeContainer(*this, targets);
00113     }
00114 
00115     template<>
00116     void DataDeserializer::Deserialize<std::vector<SimpleAttributeOperand>>(std::vector<SimpleAttributeOperand>& targets)
00117     {
00118       DeserializeContainer(*this, targets);
00119     }
00120 
00121 
00123     // LiteralOperand
00125 
00126     template<>
00127     std::size_t RawSize<LiteralOperand>(const OpcUa::LiteralOperand& params)
00128     {
00129       return RawSize(params.Value);
00130     }
00131 
00132     template<>
00133     void DataDeserializer::Deserialize<LiteralOperand>(LiteralOperand& params)
00134     {
00135       *this >> params.Value;
00136     }
00137 
00138     template<>
00139     void DataSerializer::Serialize<LiteralOperand>(const LiteralOperand& params)
00140     {
00141       *this << params.Value;
00142     }
00143 
00144 
00145 
00147     // ElementOperand
00149 
00150     template<>
00151     std::size_t RawSize<ElementOperand>(const OpcUa::ElementOperand& params)
00152     {
00153       return RawSize(params.Index);
00154     }
00155 
00156     template<>
00157     void DataDeserializer::Deserialize<ElementOperand>(ElementOperand& params)
00158     {
00159       *this >> params.Index;
00160     }
00161 
00162     template<>
00163     void DataSerializer::Serialize<ElementOperand>(const ElementOperand& params)
00164     {
00165       *this << params.Index;
00166     }
00167 
00168 
00170     // FilterOperand
00172 
00173     template<>
00174     std::size_t RawSize<FilterOperand>(const OpcUa::FilterOperand& params)
00175     {
00176       size_t total = RawSize(params.Header);
00177       if (params.Header.TypeId == ExpandedObjectId::ElementOperand )
00178       {
00179         total += 4;
00180         total += RawSize(params.Element);
00181       }
00182       else if (params.Header.TypeId == ExpandedObjectId::LiteralOperand )
00183       {
00184         total += 4;
00185         total += RawSize(params.Literal);
00186       }
00187       else if (params.Header.TypeId == ExpandedObjectId::AttributeOperand )
00188       {
00189         total += 4;
00190         total += RawSize(params.Attribute);
00191       }
00192       else if (params.Header.TypeId == ExpandedObjectId::SimpleAttributeOperand )
00193       {
00194         total += 4;
00195         total += RawSize(params.SimpleAttribute);
00196       }
00197 
00198       return total;
00199     }
00200 
00201     template<>
00202     void DataDeserializer::Deserialize<FilterOperand>(FilterOperand& params)
00203     {
00204       *this >> params.Header;
00205       uint32_t size;
00206       *this >> size;
00207       if ( params.Header.TypeId == ExpandedObjectId::ElementOperand )
00208       {
00209         *this >> params.Element;
00210       }
00211       else if ( params.Header.TypeId == ExpandedObjectId::LiteralOperand )
00212       {
00213         *this >> params.Literal;
00214       }
00215       else if ( params.Header.TypeId == ExpandedObjectId::AttributeOperand )
00216       {
00217         *this >> params.Attribute;
00218       }
00219       else if ( params.Header.TypeId == ExpandedObjectId::SimpleAttributeOperand )
00220       {
00221         *this >> params.SimpleAttribute;
00222       }
00223     }
00224 
00225     template<>
00226     void DataSerializer::Serialize<FilterOperand>(const FilterOperand& params)
00227     {
00228       *this << params.Header;
00229       if ( params.Header.TypeId == ExpandedObjectId::ElementOperand )
00230       {
00231         uint32_t size = RawSize(params.Element);
00232         *this << size;
00233         *this << params.Element;
00234       }
00235       else if ( params.Header.TypeId == ExpandedObjectId::LiteralOperand )
00236       {
00237         uint32_t size = RawSize(params.Literal);
00238         *this << size;
00239         *this << params.Literal;
00240       }
00241       else if ( params.Header.TypeId == ExpandedObjectId::AttributeOperand )
00242       {
00243         uint32_t size = RawSize(params.Attribute);
00244         *this << size;
00245         *this << params.Attribute;
00246       }
00247       else if ( params.Header.TypeId == ExpandedObjectId::SimpleAttributeOperand )
00248       {
00249         uint32_t size = RawSize(params.SimpleAttribute);
00250         *this << size;
00251         *this << params.SimpleAttribute;
00252       }
00253     }
00254     
00255     template<>
00256     void DataSerializer::Serialize<std::vector<FilterOperand>>(const std::vector<FilterOperand>& targets)
00257     {
00258       SerializeContainer(*this, targets);
00259     }
00260 
00261     template<>
00262     void DataDeserializer::Deserialize<std::vector<FilterOperand>>(std::vector<FilterOperand>& targets)
00263     {
00264       DeserializeContainer(*this, targets);
00265     }
00266 
00267 
00268 
00270     // ContentFilterElement
00272 
00273     template<>
00274     std::size_t RawSize<ContentFilterElement>(const OpcUa::ContentFilterElement& params)
00275     {
00276       return RawSize(params.Operator) +
00277           RawSizeContainer(params.FilterOperands); 
00278     }
00279 
00280     template<>
00281     void DataDeserializer::Deserialize<ContentFilterElement>(ContentFilterElement& params)
00282     {
00283       *this >> params.Operator;
00284       //*this >> params.FilterOperands;
00285       DeserializeContainer(*this, params.FilterOperands);
00286     }
00287 
00288     template<>
00289     void DataSerializer::Serialize<ContentFilterElement>(const ContentFilterElement& params)
00290     {
00291       *this << params.Operator;
00292       //*this << params.FilterOperands;
00293       SerializeContainer(*this, params.FilterOperands);
00294     }
00295 
00296 
00297 
00298 
00300     // AggregateFilter
00302 
00303     template<>
00304     std::size_t RawSize<AggregateFilter>(const OpcUa::AggregateFilter& params)
00305     {
00306       return RawSize(params.StartTime) +
00307           RawSize(params.AggregateType) +
00308           RawSize(params.ProcessingInterval) +
00309           RawSize(params.UseServerCapabilitiesDefaults) +
00310           RawSize(params.TreatUncertainAsBad) +
00311           RawSize(params.PercentDataBad) +
00312           RawSize(params.PercentDataGood) +
00313           RawSize(params.SteppedSlopedExtrapolation);
00314     }
00315 
00316     template<>
00317     void DataDeserializer::Deserialize<AggregateFilter>(AggregateFilter& params)
00318     {
00319       *this >> params.StartTime;
00320       *this >> params.AggregateType;
00321       *this >> params.ProcessingInterval;
00322       *this >> params.UseServerCapabilitiesDefaults;
00323       *this >> params.TreatUncertainAsBad;
00324       *this >> params.PercentDataBad;
00325       *this >> params.PercentDataGood;
00326       *this >> params.SteppedSlopedExtrapolation;
00327     }
00328 
00329     template<>
00330     void DataSerializer::Serialize<AggregateFilter>(const AggregateFilter& params)
00331     {
00332       *this << params.StartTime;
00333       *this << params.AggregateType;
00334       *this << params.ProcessingInterval;
00335       *this << params.UseServerCapabilitiesDefaults;
00336       *this << params.TreatUncertainAsBad;
00337       *this << params.PercentDataBad;
00338       *this << params.PercentDataGood;
00339       *this << params.SteppedSlopedExtrapolation;
00340     }
00341 
00342 
00343 
00345     // EventFilter
00347 
00348     template<>
00349     std::size_t RawSize<EventFilter>(const OpcUa::EventFilter& params)
00350     {
00351       return RawSizeContainer(params.SelectClauses) +
00352           RawSizeContainer(params.WhereClause);
00353     }
00354 
00355     template<>
00356     void DataDeserializer::Deserialize<EventFilter>(EventFilter& params)
00357     {
00358       *this >> params.SelectClauses;
00359       DeserializeContainer(*this, params.WhereClause);
00360     }
00361 
00362     template<>
00363     void DataSerializer::Serialize<EventFilter>(const EventFilter& params)
00364     {
00365       *this << params.SelectClauses;
00366       SerializeContainer(*this, params.WhereClause);
00367     }
00368 
00369 
00371     // DataChangeFilter
00373 
00374     template<>
00375     std::size_t RawSize<DataChangeFilter>(const OpcUa::DataChangeFilter& params)
00376     {
00377       return RawSize(params.Trigger) +
00378           RawSize(params.Deadband) +
00379           RawSize(params.DeadbandValue);
00380     }
00381 
00382     template<>
00383     void DataDeserializer::Deserialize<DataChangeFilter>(DataChangeFilter& params)
00384     {
00385       *this >> params.Trigger;
00386       *this >> params.Deadband;
00387       *this >> params.DeadbandValue;
00388     }
00389 
00390     template<>
00391     void DataSerializer::Serialize<DataChangeFilter>(const DataChangeFilter& params)
00392     {
00393       *this << params.Trigger;
00394       *this << params.Deadband;
00395       *this << params.DeadbandValue;
00396     }
00397 
00398 
00400     // MonitoringFilter
00402 
00403     template<>
00404     std::size_t RawSize<MonitoringFilter>(const MonitoringFilter& data)
00405     {
00406       size_t total = 0;
00407       total += RawSize(data.Header);
00408       if ( data.Header.TypeId == ExpandedObjectId::DataChangeFilter) 
00409       {
00410         total += 4;
00411         total += RawSize(data.DataChange);
00412       }
00413       else if ( data.Header.TypeId == ExpandedObjectId::EventFilter) 
00414       {
00415         total += 4;
00416         total += RawSize(data.Event);
00417       }
00418       else if ( data.Header.TypeId == ExpandedObjectId::AggregateFilter) 
00419       {
00420         total += 4;
00421         total += RawSize(data.Aggregate);
00422       }
00423       else if ( data.Header.TypeId == NodeId(0, 0) ) 
00424       {
00425         //No filter is used
00426       }
00427       else
00428       {
00429         throw std::runtime_error("MonitoringFilter type not implemented");
00430       }
00431 
00432       return total; 
00433     }
00434     
00435 
00436     template<>
00437     void DataDeserializer::Deserialize<MonitoringFilter>(MonitoringFilter& data)
00438     {
00439       *this >> data.Header;
00440       int32_t size;
00441       if ( data.Header.TypeId == ExpandedObjectId::DataChangeFilter ) 
00442       {
00443         *this >> size; //not used yet
00444         *this >> data.DataChange;
00445       }
00446       else if ( data.Header.TypeId == ExpandedObjectId::EventFilter ) 
00447       {
00448         *this >> size; //not used yet
00449         *this >> data.Event;
00450       }
00451       else if ( data.Header.TypeId == ExpandedObjectId::AggregateFilter ) 
00452       {
00453         *this >> size; //not used yet
00454         *this >> data.Aggregate;
00455       }
00456       else if ( data.Header.TypeId == NodeId(0, 0) ) 
00457       {
00458         //No filter is used
00459       }
00460       else
00461       {
00462         throw std::runtime_error("Filter data type not supported in deserialization");
00463       }
00464     }
00465 
00466     template<>
00467     void DataSerializer::Serialize<MonitoringFilter>(const MonitoringFilter& data)
00468     {
00469       *this << data.Header;
00470       if ( data.Header.TypeId == ExpandedObjectId::DataChangeFilter ) 
00471       {
00472         *this << (uint32_t) RawSize(data.DataChange);
00473         *this << data.DataChange;
00474       }
00475       else if ( data.Header.TypeId == ExpandedObjectId::EventFilter ) 
00476       {
00477         *this << (uint32_t) RawSize(data.Event);
00478         *this << data.Event;
00479       }
00480       else if ( data.Header.TypeId == ExpandedObjectId::AggregateFilter ) 
00481       {
00482         *this << (uint32_t) RawSize(data.Aggregate);
00483         *this << data.Aggregate;
00484       }
00485       else if ( data.Header.TypeId == NodeId(0, 0) ) 
00486       {
00487         //No filter is used
00488       }
00489       else
00490       {
00491         throw std::runtime_error("Filter data type not supported in serialization");
00492       }
00493     }
00494 
00496     // MonitoredItemCreateRequest
00498 
00499     template<>
00500     void DataSerializer::Serialize<std::vector<MonitoredItemCreateRequest>>(const std::vector<MonitoredItemCreateRequest>& targets)
00501     {
00502       SerializeContainer(*this, targets);
00503     }
00504 
00505     template<>
00506     void DataDeserializer::Deserialize<std::vector<MonitoredItemCreateRequest>>(std::vector<MonitoredItemCreateRequest>& targets)
00507     {
00508       DeserializeContainer(*this, targets);
00509     }
00510 
00512     // CreateMonitoredItemsRequest
00514 
00516 
00517     template<>
00518     void DataSerializer::Serialize<std::vector<MonitoredItemCreateResult>>(const std::vector<MonitoredItemCreateResult>& targets)
00519     {
00520       SerializeContainer(*this, targets);
00521     }
00522 
00523     template<>
00524     void DataDeserializer::Deserialize<std::vector<MonitoredItemCreateResult>>(std::vector<MonitoredItemCreateResult>& targets)
00525     {
00526       DeserializeContainer(*this, targets);
00527     }
00528 
00529 
00530 
00531 
00532 
00533   }
00534 }


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Sat Jun 8 2019 18:24:56