subscriptions.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/binary/stream.h>
00014 #include <opc/ua/protocol/monitored_items.h>
00015 
00016 namespace OpcUa
00017 {
00018 
00020    // SubscriptionData
00022 
00023    SubscriptionData::SubscriptionData()
00024      : RevisedPublishingInterval(100)
00025      , RevisedLifetimeCount(30) //Should be 3 times keepalive
00026      , RevisedMaxKeepAliveCount(10)
00027    {
00028    }
00029 
00031   // SubscriptionParameters
00033 
00034   CreateSubscriptionParameters::CreateSubscriptionParameters()
00035     : RequestedPublishingInterval(500)
00036     , RequestedLifetimeCount(3000)
00037     , RequestedMaxKeepAliveCount(10000)
00038     , MaxNotificationsPerPublish(0)
00039     , PublishingEnabled(true)
00040     , Priority(0)
00041   {
00042   }
00043 
00045   // PublishResult
00047 
00048   PublishResult::PublishResult()
00049     : MoreNotifications(false)
00050   {
00051   }
00052 
00054   // NotificationData
00056 
00057     NotificationData::NotificationData(DataChangeNotification notification) : DataChange(notification)
00058     {
00059       //Header.TypeId  = ObjectId::DataChangeNotification; 
00060       Header.TypeId  = ExpandedObjectId::DataChangeNotification;
00061       Header.Encoding  = static_cast<ExtensionObjectEncoding>(Header.Encoding | ExtensionObjectEncoding::HAS_BINARY_BODY);
00062     }
00063 
00064     NotificationData::NotificationData(EventNotificationList notification) : Events(notification)
00065     {
00066       Header.TypeId  = ExpandedObjectId::EventNotificationList; 
00067       Header.Encoding  = static_cast<ExtensionObjectEncoding>(Header.Encoding | ExtensionObjectEncoding::HAS_BINARY_BODY);
00068     }
00069 
00070     NotificationData::NotificationData(StatusChangeNotification notification) : StatusChange(notification)
00071     {
00072       Header.TypeId  = ExpandedObjectId::StatusChangeNotification; 
00073       Header.Encoding  = static_cast<ExtensionObjectEncoding>(Header.Encoding | ExtensionObjectEncoding::HAS_BINARY_BODY);
00074     }
00075 
00076 
00078   // NotificationMessage
00080 
00081   NotificationMessage::NotificationMessage()
00082     : SequenceNumber(0)
00083     , PublishTime(DateTime::Current())
00084   {
00085   }
00086 
00088 
00089   namespace Binary
00090   {
00092     // SubscriptionAcknowledgement -- to be removed
00094 
00095     template<>
00096     std::size_t RawSize(const std::vector<SubscriptionAcknowledgement>& ack)
00097     {
00098       return RawSizeContainer(ack);
00099     }
00100 
00101     template<>
00102     void DataDeserializer::Deserialize<std::vector<SubscriptionAcknowledgement>>(std::vector<SubscriptionAcknowledgement>& ack)
00103     {
00104       DeserializeContainer(*this, ack);
00105     }
00106 
00107     template<>
00108     void DataSerializer::Serialize<std::vector<SubscriptionAcknowledgement>>(const std::vector<SubscriptionAcknowledgement>& ack)
00109     {
00110       SerializeContainer(*this, ack);
00111     }
00112 
00113 
00115     // MonitoredItems
00117 
00118     template<>
00119     std::size_t RawSize(const MonitoredItems& request)
00120     {
00121       return RawSize(request.ClientHandle) + RawSize(request.Value);
00122     }
00123 
00124     template<>
00125     void DataDeserializer::Deserialize<MonitoredItems>(MonitoredItems& request)
00126     {
00127       *this >> request.ClientHandle;
00128       *this >> request.Value;
00129     }
00130 
00131     template<>
00132     void DataSerializer::Serialize<MonitoredItems>(const MonitoredItems& request)
00133     {
00134       *this << request.ClientHandle;
00135       *this << request.Value;
00136     }
00137 
00138     template<>
00139     void DataSerializer::Serialize<std::vector<MonitoredItems>>(const std::vector<MonitoredItems>& targets)
00140     {
00141       SerializeContainer(*this, targets);
00142     }
00143 
00144     template<>
00145     void DataDeserializer::Deserialize<std::vector<MonitoredItems>>(std::vector<MonitoredItems>& targets)
00146     {
00147       DeserializeContainer(*this, targets);
00148     }
00149 
00151     // StatusChangeNotification
00153 
00154     template<>
00155     std::size_t RawSize(const StatusChangeNotification& request)
00156     {
00157       return 4 + RawSize(request.Status) + RawSize(request.Diagnostic);
00158     }
00159 
00160     template<>
00161     void DataDeserializer::Deserialize<StatusChangeNotification>(StatusChangeNotification& request)
00162     {
00163       uint32_t tmp;
00164       *this >> tmp; //it seems we do not need the size
00165       *this >> request.Status;
00166       *this >> request.Diagnostic;
00167     }
00168 
00169     template<>
00170     void DataSerializer::Serialize<StatusChangeNotification>(const StatusChangeNotification& request)
00171     {
00172       *this << (uint32_t) RawSize(request);
00173       *this << request.Status;
00174       *this << request.Diagnostic;
00175     }
00176 
00177 
00179     // EventNotificationList
00181 
00182     template<>
00183     void DataSerializer::Serialize<std::vector<EventFieldList>>(const std::vector<EventFieldList>& targets)
00184     {
00185       SerializeContainer(*this, targets);
00186     }
00187 
00188     template<>
00189     void DataDeserializer::Deserialize<std::vector<EventFieldList>>(std::vector<EventFieldList>& targets)
00190     {
00191       DeserializeContainer(*this, targets);
00192     }
00193 
00194     template<>
00195     std::size_t RawSize(const EventFieldList& request)
00196     {
00197       return RawSize(request.ClientHandle) + RawSizeContainer(request.EventFields); 
00198     }
00199 
00200     template<>
00201     void DataDeserializer::Deserialize<EventFieldList>(EventFieldList& request)
00202     {
00203       *this >> request.ClientHandle; 
00204       *this >> request.EventFields;
00205     }
00206 
00207     template<>
00208     void DataSerializer::Serialize<EventFieldList>(const EventFieldList& request)
00209     {
00210       *this << request.ClientHandle;
00211       *this << request.EventFields;
00212     }
00213 
00214     template<>
00215     std::size_t RawSize(const EventNotificationList& request)
00216     {
00217       return 4 + RawSizeContainer(request.Events); 
00218     }
00219 
00220     template<>
00221     void DataDeserializer::Deserialize<EventNotificationList>(EventNotificationList& request)
00222     {
00223       uint32_t tmp;
00224       *this >> tmp; //it seems we do not need the size
00225       *this >> request.Events;
00226     }
00227 
00228     template<>
00229     void DataSerializer::Serialize<EventNotificationList>(const EventNotificationList& request)
00230     {
00231       *this << (uint32_t) RawSize(request);
00232       *this << request.Events;
00233     }
00234 
00235 
00236 
00238     // DataChangeNotification
00240 
00241     template<>
00242     std::size_t RawSize(const DataChangeNotification& request)
00243     {
00244       return 4 + RawSizeContainer(request.Notification) + RawSize(request.Diagnostic);
00245     }
00246 
00247     template<>
00248     void DataDeserializer::Deserialize<DataChangeNotification>(DataChangeNotification& request)
00249     {
00250       uint32_t tmp;
00251       *this >> tmp; //it seems we do not need the size
00252       *this >> request.Notification;
00253       *this >> request.Diagnostic;
00254     }
00255 
00256     template<>
00257     void DataSerializer::Serialize<DataChangeNotification>(const DataChangeNotification& request)
00258     {
00259       *this << (uint32_t) RawSize(request);
00260       *this << request.Notification;
00261       *this << request.Diagnostic;
00262     }
00263 
00264 
00266     // NotificationData
00268 
00269 
00270     template<>
00271     std::size_t RawSize(const NotificationData& data)
00272     {
00273       size_t total = 0;
00274       total += RawSize(data.Header);
00275       if ( data.Header.TypeId == ExpandedObjectId::DataChangeNotification) 
00276       {
00277         total += RawSize(data.DataChange);
00278       }
00279       else if ( data.Header.TypeId == ExpandedObjectId::EventNotificationList) 
00280       {
00281         total += RawSize(data.Events);
00282       }
00283       else if ( data.Header.TypeId == ExpandedObjectId::StatusChangeNotification) 
00284       {
00285         total += RawSize(data.StatusChange);
00286       }
00287       else
00288       {
00289         //Unknown type, we just ignore it
00290         //throw std::runtime_error("Uknown notificationData type" );
00291       }
00292       return total;
00293     }
00294 
00295     template<>
00296     void DataDeserializer::Deserialize<NotificationData>(NotificationData& data)
00297     {
00298       *this >> data.Header;
00299       if ( data.Header.TypeId == ExpandedObjectId::DataChangeNotification ) 
00300       {
00301           *this >> data.DataChange;
00302       }
00303       else if ( data.Header.TypeId == ExpandedObjectId::EventNotificationList ) 
00304       {
00305           *this >> data.Events;
00306       }
00307       else if ( data.Header.TypeId == ExpandedObjectId::StatusChangeNotification ) 
00308       {
00309           *this >> data.StatusChange;
00310       }
00311       else
00312       {
00313         //Unknown type, we just ignore it
00314         //throw std::runtime_error("Uknown notification data type found in NotificationData");
00315       }
00316     }
00317 
00318     template<>
00319     void DataSerializer::Serialize<NotificationData>(const NotificationData& data)
00320     {
00321       *this << data.Header;
00322       if ( data.Header.TypeId == ExpandedObjectId::DataChangeNotification ) 
00323       {
00324         *this << data.DataChange;
00325       }
00326       else if ( data.Header.TypeId == ExpandedObjectId::EventNotificationList ) 
00327       {
00328         *this << data.Events;
00329       }
00330       else if ( data.Header.TypeId == ExpandedObjectId::StatusChangeNotification ) 
00331       {
00332         *this << data.StatusChange;
00333       }
00334       else
00335       {
00336         //Unknown type, we just ignore it
00337         //throw std::runtime_error("Uknown notification data type found in NotificationData");// + itos(data.Header.TypeId.FourByteData.Identifier) );
00338       }
00339     }
00340 
00341   } // namespace Binary
00342 } // namespace OpcUa


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