subscriptions.cpp
Go to the documentation of this file.
1 
11 #include "binary_serialization.h"
12 
15 
16 namespace OpcUa
17 {
18 
20 // SubscriptionData
22 
24  : RevisedPublishingInterval(100)
25  , RevisedLifetimeCount(30) //Should be 3 times keepalive
26  , RevisedMaxKeepAliveCount(10)
27 {
28 }
29 
31 // SubscriptionParameters
33 
35  : RequestedPublishingInterval(500)
36  , RequestedLifetimeCount(3000)
37  , RequestedMaxKeepAliveCount(10000)
38  , MaxNotificationsPerPublish(0)
39  , PublishingEnabled(true)
40  , Priority(0)
41 {
42 }
43 
45 // PublishResult
47 
49  : MoreNotifications(false)
50 {
51 }
52 
54 // NotificationData
56 
57 NotificationData::NotificationData(DataChangeNotification notification) : DataChange(notification)
58 {
59  //Header.TypeId = ObjectId::DataChangeNotification;
62 }
63 
65 {
68 }
69 
71 {
74 }
75 
76 
78 // NotificationMessage
80 
82  : SequenceNumber(0)
83  , PublishTime(DateTime::Current())
84 {
85 }
86 
88 
89 namespace Binary
90 {
92 // SubscriptionAcknowledgement -- to be removed
94 
95 template<>
96 std::size_t RawSize(const std::vector<SubscriptionAcknowledgement> & ack)
97 {
98  return RawSizeContainer(ack);
99 }
100 
101 template<>
102 void DataDeserializer::Deserialize<std::vector<SubscriptionAcknowledgement>>(std::vector<SubscriptionAcknowledgement> & ack)
103 {
104  DeserializeContainer(*this, ack);
105 }
106 
107 template<>
108 void DataSerializer::Serialize<std::vector<SubscriptionAcknowledgement>>(const std::vector<SubscriptionAcknowledgement> & ack)
109 {
110  SerializeContainer(*this, ack);
111 }
112 
113 
115 // MonitoredItems
117 
118 template<>
119 std::size_t RawSize(const MonitoredItems & request)
120 {
121  return RawSize(request.ClientHandle) + RawSize(request.Value);
122 }
123 
124 template<>
125 void DataDeserializer::Deserialize<MonitoredItems>(MonitoredItems & request)
126 {
127  *this >> request.ClientHandle;
128  *this >> request.Value;
129 }
130 
131 template<>
132 void DataSerializer::Serialize<MonitoredItems>(const MonitoredItems & request)
133 {
134  *this << request.ClientHandle;
135  *this << request.Value;
136 }
137 
138 template<>
139 void DataSerializer::Serialize<std::vector<MonitoredItems>>(const std::vector<MonitoredItems> & targets)
140 {
141  SerializeContainer(*this, targets);
142 }
143 
144 template<>
145 void DataDeserializer::Deserialize<std::vector<MonitoredItems>>(std::vector<MonitoredItems> & targets)
146 {
147  DeserializeContainer(*this, targets);
148 }
149 
151 // StatusChangeNotification
153 
154 template<>
155 std::size_t RawSize(const StatusChangeNotification & request)
156 {
157  return 4 + RawSize(request.Status) + RawSize(request.Diagnostic);
158 }
159 
160 template<>
161 void DataDeserializer::Deserialize<StatusChangeNotification>(StatusChangeNotification & request)
162 {
163  uint32_t tmp;
164  *this >> tmp; //it seems we do not need the size
165  *this >> request.Status;
166  *this >> request.Diagnostic;
167 }
168 
169 template<>
170 void DataSerializer::Serialize<StatusChangeNotification>(const StatusChangeNotification & request)
171 {
172  *this << (uint32_t) RawSize(request);
173  *this << request.Status;
174  *this << request.Diagnostic;
175 }
176 
177 
179 // EventNotificationList
181 
182 template<>
183 void DataSerializer::Serialize<std::vector<EventFieldList>>(const std::vector<EventFieldList> & targets)
184 {
185  SerializeContainer(*this, targets);
186 }
187 
188 template<>
189 void DataDeserializer::Deserialize<std::vector<EventFieldList>>(std::vector<EventFieldList> & targets)
190 {
191  DeserializeContainer(*this, targets);
192 }
193 
194 template<>
195 std::size_t RawSize(const EventFieldList & request)
196 {
197  return RawSize(request.ClientHandle) + RawSizeContainer(request.EventFields);
198 }
199 
200 template<>
201 void DataDeserializer::Deserialize<EventFieldList>(EventFieldList & request)
202 {
203  *this >> request.ClientHandle;
204  *this >> request.EventFields;
205 }
206 
207 template<>
208 void DataSerializer::Serialize<EventFieldList>(const EventFieldList & request)
209 {
210  *this << request.ClientHandle;
211  *this << request.EventFields;
212 }
213 
214 template<>
215 std::size_t RawSize(const EventNotificationList & request)
216 {
217  return 4 + RawSizeContainer(request.Events);
218 }
219 
220 template<>
221 void DataDeserializer::Deserialize<EventNotificationList>(EventNotificationList & request)
222 {
223  uint32_t tmp;
224  *this >> tmp; //it seems we do not need the size
225  *this >> request.Events;
226 }
227 
228 template<>
229 void DataSerializer::Serialize<EventNotificationList>(const EventNotificationList & request)
230 {
231  *this << (uint32_t) RawSize(request);
232  *this << request.Events;
233 }
234 
235 
236 
238 // DataChangeNotification
240 
241 template<>
242 std::size_t RawSize(const DataChangeNotification & request)
243 {
244  return 4 + RawSizeContainer(request.Notification) + RawSize(request.Diagnostic);
245 }
246 
247 template<>
248 void DataDeserializer::Deserialize<DataChangeNotification>(DataChangeNotification & request)
249 {
250  uint32_t tmp;
251  *this >> tmp; //it seems we do not need the size
252  *this >> request.Notification;
253  *this >> request.Diagnostic;
254 }
255 
256 template<>
257 void DataSerializer::Serialize<DataChangeNotification>(const DataChangeNotification & request)
258 {
259  *this << (uint32_t) RawSize(request);
260  *this << request.Notification;
261  *this << request.Diagnostic;
262 }
263 
264 
266 // NotificationData
268 
269 
270 template<>
271 std::size_t RawSize(const NotificationData & data)
272 {
273  size_t total = 0;
274  total += RawSize(data.Header);
275 
277  {
278  total += RawSize(data.DataChange);
279  }
280 
282  {
283  total += RawSize(data.Events);
284  }
285 
287  {
288  total += RawSize(data.StatusChange);
289  }
290 
291  else
292  {
293  //Unknown type, we just ignore it
294  //throw std::runtime_error("Uknown notificationData type" );
295  }
296 
297  return total;
298 }
299 
300 template<>
301 void DataDeserializer::Deserialize<NotificationData>(NotificationData & data)
302 {
303  *this >> data.Header;
304 
305  if (data.Header.TypeId == ExpandedObjectId::DataChangeNotification)
306  {
307  *this >> data.DataChange;
308  }
309 
310  else if (data.Header.TypeId == ExpandedObjectId::EventNotificationList)
311  {
312  *this >> data.Events;
313  }
314 
315  else if (data.Header.TypeId == ExpandedObjectId::StatusChangeNotification)
316  {
317  *this >> data.StatusChange;
318  }
319 
320  else
321  {
322  //Unknown type, we just ignore it
323  //throw std::runtime_error("Uknown notification data type found in NotificationData");
324  }
325 }
326 
327 template<>
328 void DataSerializer::Serialize<NotificationData>(const NotificationData & data)
329 {
330  *this << data.Header;
331 
332  if (data.Header.TypeId == ExpandedObjectId::DataChangeNotification)
333  {
334  *this << data.DataChange;
335  }
336 
337  else if (data.Header.TypeId == ExpandedObjectId::EventNotificationList)
338  {
339  *this << data.Events;
340  }
341 
342  else if (data.Header.TypeId == ExpandedObjectId::StatusChangeNotification)
343  {
344  *this << data.StatusChange;
345  }
346 
347  else
348  {
349  //Unknown type, we just ignore it
350  //throw std::runtime_error("Uknown notification data type found in NotificationData");// + itos(data.Header.TypeId.FourByteData.Identifier) );
351  }
352 }
353 
354 } // namespace Binary
355 } // namespace OpcUa
std::size_t RawSize(const NotificationData &data)
DiagnosticInfoList Diagnostic
Definition: types_manual.h:65
ExtensionObjectEncoding
Definition: types.h:276
void SerializeContainer(Stream &out, const Container &c, uint32_t emptySizeValue=~uint32_t())
void DeserializeContainer(Stream &in, Container &c)
std::vector< Variant > EventFields
Definition: types_manual.h:48
ExpandedNodeId TypeId
Definition: types.h:286
EventNotificationList Events
Definition: types_manual.h:72
ExtensionObjectHeader Header
Definition: types_manual.h:70
OPC UA Address space part. GNU LGPL.
const char * Binary(const char *input, short n)
std::vector< EventFieldList > Events
Definition: types_manual.h:59
DataChangeNotification DataChange
Definition: types_manual.h:71
std::vector< MonitoredItems > Notification
Definition: types_manual.h:64
std::size_t RawSizeContainer(const T &container)
StatusChangeNotification StatusChange
Definition: types_manual.h:73


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Tue Jan 19 2021 03:12:08