HAN-FUN API  1.5.3
This project provides the common implementation of ULE Alliance's HAN-FUN application protocol.
attributes.h
Go to the documentation of this file.
1 // =============================================================================
15 // =============================================================================
16 #ifndef HF_ATTRIBUTES_H
17 #define HF_ATTRIBUTES_H
18 
19 #include "hanfun/common.h"
20 #include "hanfun/protocol.h"
21 
22 namespace HF
23 {
24  struct Interface;
25 
30  namespace Attributes
31  {
44  struct IAttribute: public Common::Serializable, public Common::Cloneable<IAttribute>
45  {
51  virtual uint8_t uid() const = 0;
52 
59  virtual bool isWritable() const = 0;
60 
66  virtual uint16_t interface() const = 0;
67 
76  virtual HF::Interface const *owner() const = 0;
77 
79 
87  virtual uint16_t size(bool with_uid) const = 0;
88 
90 
102  virtual uint16_t pack(Common::ByteArray &array, uint16_t offset, bool with_uid) const = 0;
103 
105 
116  virtual uint16_t unpack(const Common::ByteArray &array, uint16_t offset,
117  bool with_uid) = 0;
118 
119  virtual bool operator==(const IAttribute &other) const = 0;
120 
121  virtual bool operator<(const IAttribute &other) const = 0;
122 
123  virtual bool operator>(const IAttribute &other) const = 0;
124 
133  virtual float changed(const IAttribute &other) const = 0;
134 
147  virtual int compare(const IAttribute &other) const = 0;
148  };
149 
151  typedef IAttribute * (*Factory)(uint8_t);
152 
158 
172 
176  struct UIDS: public std::vector<uint8_t>
177  {
178  UIDS(): std::vector<uint8_t>()
179  {}
180 
186  UIDS(std::initializer_list<uint8_t> uids): vector<uint8_t>(uids)
187  {}
188 
198  vector<uint8_t>::size_type length() const
199  {
200  return vector<uint8_t>::size();
201  }
202 
204  static constexpr uint8_t min_size = sizeof(uint8_t);
205 
206  uint16_t size() const
207  {
208  return min_size + sizeof(uint8_t) * vector<uint8_t>::size();
209  }
210 
211  uint16_t pack(Common::ByteArray &array, uint16_t offset = 0) const
212  {
213  HF_SERIALIZABLE_CHECK(array, offset, size());
214 
215  uint16_t start = offset;
216 
217  uint8_t count = length();
218  offset += array.write(offset, count);
219 
220  /* *INDENT-OFF* */
221  std::for_each (vector<uint8_t>::begin(), vector<uint8_t>::end(),
222  [&offset,&array](uint8_t uid)
223  {
224  offset += array.write (offset, uid);
225  });
226  /* *INDENT-ON* */
227 
228  return offset - start;
229  }
230 
231  uint16_t unpack(const Common::ByteArray &array, uint16_t offset = 0)
232  {
233  uint8_t count = 0;
234 
235  return unpack(array, offset, count);
236  }
237 
244  uint16_t unpack(const Common::ByteArray &array, uint16_t offset, uint8_t &count)
245  {
246  HF_SERIALIZABLE_CHECK(array, offset, min_size);
247 
248  uint16_t start = offset;
249 
250  offset += array.read(offset, count);
251 
252  HF_SERIALIZABLE_CHECK(array, offset, count);
253 
254  vector<uint8_t>::reserve(count);
255 
256  for (uint8_t i = 0; i < count; i++)
257  {
258  uint8_t uid;
259  offset += array.read(offset, uid);
260  vector<uint8_t>::push_back(uid);
261  }
262 
263  return offset - start;
264  }
265  };
266 
271  {
272  protected:
273 
274  const uint16_t _itf_uid;
275  const uint8_t _uid;
276  const bool _writable;
277 
278  AbstractAttribute(const uint16_t itf_uid, const uint8_t uid, const bool writable = false):
279  _itf_uid(itf_uid), _uid(uid), _writable(writable)
280  {}
281 
282  public:
283 
284  uint8_t uid() const
285  {
286  return _uid;
287  }
288 
289  bool isWritable() const
290  {
291  return _writable;
292  }
293 
294  uint16_t interface() const
295  {
296  return _itf_uid;
297  }
298 
299  bool operator==(const IAttribute &other) const
300  {
301  return this->compare(other) == 0;
302  }
303 
304  bool operator==(IAttribute &other) const
305  {
306  return this->compare(other) == 0;
307  }
308 
309  bool operator<(const IAttribute &other) const
310  {
311  return this->compare(other) < 0;
312  }
313 
314  bool operator<(IAttribute &other) const
315  {
316  return this->compare(other) < 0;
317  }
318 
319  bool operator>(const IAttribute &other) const
320  {
321  return this->compare(other) > 0;
322  }
323 
324  bool operator>(IAttribute &other) const
325  {
326  return this->compare(other) > 0;
327  }
328 
329  int compare(const IAttribute &other) const
330  {
331  int res = this->interface() - other.interface();
332 
333  if (res != 0)
334  {
335  return res;
336  }
337 
338  return this->uid() - other.uid();
339  }
340  };
341 
348  template<typename T, typename _Owner = void, typename = void>
350  {
360  Attribute(const uint16_t interface, const uint8_t uid, const HF::Interface *__owner,
361  T data, bool writable = false):
362  AbstractAttribute(interface, uid, writable), helper(data), _owner(__owner)
363  {}
364 
372  Attribute(const uint16_t interface, const uint8_t uid, bool writable = false):
373  AbstractAttribute(interface, uid, writable), _owner(nullptr)
374  {}
375 
384  Attribute(const uint16_t interface, const uint8_t uid, T data, bool writable = false):
385  AbstractAttribute(interface, uid, writable), helper(data), _owner(nullptr)
386  {}
387 
388  typedef typename std::remove_reference<T>::type value_type;
389 
390  // =============================================================================
391  // API
392  // =============================================================================
393 
394  void set(value_type __value)
395  {
396  value(__value);
397  }
398 
399  value_type get() const
400  {
401  return value();
402  }
403 
404  value_type value() const
405  {
406  return helper.data;
407  }
408 
409  void value(value_type __value)
410  {
411  helper.data = __value;
412  }
413 
414  HF::Interface const *owner() const
415  {
416  return _owner;
417  }
418 
419  uint16_t size(bool with_uid) const
420  {
421  return size() + (with_uid ? sizeof(uint8_t) : 0);
422  }
423 
424  uint16_t size() const
425  {
426  return helper.size();
427  }
428 
429  uint16_t pack(Common::ByteArray &array, uint16_t offset, bool with_uid) const
430  {
431  HF_SERIALIZABLE_CHECK(array, offset, size(with_uid));
432 
433  uint16_t start = offset;
434 
435  if (with_uid)
436  {
437  offset += array.write(offset, uid());
438  }
439 
440  offset += helper.pack(array, offset);
441 
442  return offset - start;
443  }
444 
445  uint16_t pack(Common::ByteArray &array, uint16_t offset = 0) const
446  {
447  return helper.pack(array, offset);
448  }
449 
450  uint16_t unpack(const Common::ByteArray &array, uint16_t offset, bool with_uid)
451  {
452  HF_SERIALIZABLE_CHECK(array, offset, size(with_uid));
453 
454  uint16_t start = offset;
455 
456  if (with_uid)
457  {
458  uint8_t temp;
459  offset += array.read(offset, temp);
460 
461  if (temp != uid())
462  {
463  return 0;
464  }
465  }
466 
467  offset += helper.unpack(array, offset);
468 
469  return offset - start;
470  }
471 
472  uint16_t unpack(const Common::ByteArray &array, uint16_t offset = 0)
473  {
474  return helper.unpack(array, offset);
475  }
476 
477  IAttribute *clone() const
478  {
479  return new HF::Attributes::Attribute<T>(this->_itf_uid, this->_uid, this->_owner,
480  this->helper.data, this->_writable);
481  }
482 
483  int compare(const IAttribute &other) const
484  {
485  int res = AbstractAttribute::compare(other);
486 
487  if (res == 0)
488  {
489  Attribute<T> *temp = (Attribute<T> *) & other;
490  res = helper.compare(temp->helper);
491  }
492 
493  return res;
494  }
495 
496  float changed(const IAttribute &other) const
497  {
498  int res = AbstractAttribute::compare(other);
499 
500  if (res == 0)
501  {
502  Attribute<T> *temp = (Attribute<T> *) & other;
503  return helper.changed(temp->helper);
504  }
505 
506  return 0.0;
507  }
508 
509  protected:
510 
512 
513  const HF::Interface *_owner;
514 
515  private:
516 
517  // Don't allow copy.
518  Attribute(const Attribute &other) = delete;
519  };
520 
527  template<typename T, typename _Owner>
528  struct Attribute<T, _Owner, EnableIf(IsParent(HF::Interface, _Owner))>:
529  public AbstractAttribute
530  {
531  typedef typename std::remove_reference<T>::type value_type;
532 
533  typedef typename std::function<value_type(_Owner &)> getter_t;
534  typedef typename std::function<void (_Owner &, T)> setter_t;
535 
545  Attribute(_Owner &__owner, const uint8_t uid, getter_t _getter, setter_t _setter,
546  bool writable = false):
547  AbstractAttribute(__owner.uid(), uid, writable), _owner(&__owner), getter(_getter),
548  setter(_setter)
549  {}
550 
559  Attribute(_Owner &__owner, const uint8_t uid, getter_t _getter, bool writable = false):
560  AbstractAttribute(__owner.uid(), uid, writable), _owner(&__owner), getter(_getter)
561  {}
562 
572  __attribute__((__nonnull__(2)))
573  Attribute(_Owner *__owner, const uint8_t uid, getter_t _getter, setter_t _setter,
574  bool writable = false):
575  AbstractAttribute(__owner->uid(), uid, writable), _owner(__owner), getter(_getter),
576  setter(_setter)
577  {}
578 
587  __attribute__((__nonnull__(2)))
588  Attribute(_Owner *__owner, const uint8_t uid, getter_t _getter, bool writable = false):
589  AbstractAttribute(__owner->uid(), uid, writable), _owner(__owner), getter(_getter)
590  {}
591 
592  // =============================================================================
593  // API
594  // =============================================================================
595 
596  void set(value_type __value)
597  {
598  value(__value);
599  }
600 
601  value_type get() const
602  {
603  return value();
604  }
605 
606  value_type value() const
607  {
608  return getter(*_owner);
609  }
610 
611  void value(value_type __value)
612  {
613  if (setter)
614  {
615  setter(*_owner, __value);
616  }
617  }
618 
619  HF::Interface const *owner() const
620  {
621  return _owner;
622  }
623 
624  uint16_t size(bool with_uid) const
625  {
626  return size() + (with_uid ? sizeof(uint8_t) : 0);
627  }
628 
629  uint16_t size() const
630  {
632  return helper.size();
633  }
634 
635  uint16_t pack(Common::ByteArray &array, uint16_t offset, bool with_uid) const
636  {
637  HF_SERIALIZABLE_CHECK(array, offset, size(with_uid));
638 
639  uint16_t start = offset;
640 
641  if (with_uid)
642  {
643  offset += array.write(offset, uid());
644  }
645 
647 
648  offset += helper.pack(array, offset);
649 
650  return offset - start;
651  }
652 
653  uint16_t pack(Common::ByteArray &array, uint16_t offset = 0) const
654  {
656 
657  return helper.pack(array, offset);
658  }
659 
660  uint16_t unpack(const Common::ByteArray &array, uint16_t offset, bool with_uid)
661  {
662  HF_SERIALIZABLE_CHECK(array, offset, size(with_uid));
663 
665  uint16_t start = offset;
666 
667  if (with_uid)
668  {
669  uint8_t temp;
670  offset += array.read(offset, temp);
671 
672  if (temp != uid())
673  {
674  goto _end;
675  }
676  }
677 
678  offset += helper.unpack(array, offset);
679 
680  setter(*_owner, helper.data);
681 
682  _end:
683  return offset - start;
684  }
685 
686  uint16_t unpack(const Common::ByteArray &array, uint16_t offset = 0)
687  {
689  uint16_t result = helper.unpack(array, offset);
690 
691  setter(*_owner, helper.data);
692  return result;
693  }
694 
695  IAttribute *clone() const
696  {
697  return new HF::Attributes::Attribute<T, _Owner>(this->_owner, this->uid(),
698  this->getter, this->setter,
699  this->isWritable());
700  }
701 
702  int compare(const IAttribute &other) const
703  {
704  int res = AbstractAttribute::compare(other);
705 
706  if (res == 0)
707  {
709  Common::SerializableHelper<value_type> rhs(((Attribute<T> *) & other)->value());
710 
711  res = lhs.compare(rhs);
712  }
713 
714  return res;
715  }
716 
717  float changed(const IAttribute &other) const
718  {
719  int res = AbstractAttribute::compare(other);
720 
721  if (res == 0)
722  {
724  Common::SerializableHelper<value_type> rhs(((Attribute<T> *) & other)->value());
725 
726  return lhs.changed(rhs);
727  }
728 
729  return 0.0;
730  }
731 
732  protected:
733 
734  _Owner *_owner;
735  getter_t getter;
736  setter_t setter;
737 
738  private:
739 
740  // Don't allow copy.
741  Attribute(const Attribute &other) = delete;
742  };
743 
752  struct List: public std::list<IAttribute *>
753  {
754  IAttribute *operator[](uint8_t uid) const
755  {
756  for (const_iterator it = begin(); it != end(); ++it)
757  {
758  if ((*it)->uid() == uid)
759  {
760  return *it;
761  }
762  }
763 
764  return nullptr;
765  }
766  };
767 
773  {
774  IAttribute *attribute;
775 
782  Response(IAttribute *_attribute = nullptr):
783  attribute(_attribute)
784  {}
785 
786  virtual ~Response()
787  {
788  delete attribute;
789  }
790 
791  uint16_t size() const
792  {
793  return Protocol::Response::size() + (attribute != nullptr ? attribute->size() : 0);
794  }
795 
796  uint16_t pack(Common::ByteArray &array, uint16_t offset = 0) const
797  {
798  HF_SERIALIZABLE_CHECK(array, offset, size());
799 
800  uint16_t start = offset;
801 
802  offset += Protocol::Response::pack(array, offset);
803 
804  offset += (attribute != nullptr ? attribute->pack(array, offset) : 0);
805 
806  return offset - start;
807  }
808 
809  uint16_t unpack(const Common::ByteArray &array, uint16_t offset = 0)
810  {
811  HF_SERIALIZABLE_CHECK(array, offset, min_size);
812 
813  uint16_t start = offset;
814 
815  offset += Protocol::Response::unpack(array, offset);
816  offset += (attribute != nullptr ? attribute->unpack(array, offset) : 0);
817 
818  return offset - start;
819  }
820  };
821 
840  typedef enum _Pack
841  {
842  MANDATORY = 0x00,
843  ALL = 0xFE,
844  DYNAMIC = 0xFF,
845  } Pack;
846 
858  List get(const HF::Interface &itf, uint8_t pack_id, const UIDS &uids);
859 
860  template<typename T>
861  Attribute<T> *adapt(IAttribute *attr)
862  {
863  return static_cast<Attribute<T> *>(attr);
864  }
865 
866  template<typename T>
867  const Attribute<T> *adapt(const IAttribute *attr)
868  {
869  return static_cast<const Attribute<T> *>(attr);
870  }
871 
873  } // namespace Attributes
874 
875  namespace Protocol
876  {
886  namespace GetAttributePack
887  {
892  struct Request
893  {
895 
902  uint8_t count;
903 
904  Request(): count(0) {}
905 
908  {}
909 
911  uint16_t size() const
912  {
913  return attributes.size();
914  }
915 
917  uint16_t pack(Common::ByteArray &array, uint16_t offset = 0) const
918  {
919  return attributes.pack(array, offset);
920  }
921 
923  uint16_t unpack(const Common::ByteArray &array, uint16_t offset = 0)
924  {
925  return attributes.unpack(array, offset, count);
926  }
927  };
928 
935  {
938 
940  HF::Attributes::List attributes;
941 
948  uint8_t count;
949 
954  {}
955 
962  attribute_factory(nullptr), attributes(attributes)
963  {}
964 
972  attribute_factory(factory)
973  {}
974 
975  virtual ~Response()
976  {
977  /* *INDENT-OFF* */
978  std::for_each (attributes.begin (), attributes.end (),
980  {
981  delete attr;
982  });
983  /* *INDENT-ON* */
984  }
985 
987  static constexpr uint16_t min_size = Protocol::Response::min_size // General response.
988  + sizeof(uint8_t); // Number of attributes.
989 
991  uint16_t size() const;
992 
994  uint16_t pack(Common::ByteArray &array, uint16_t offset = 0) const;
995 
1001  uint16_t unpack(const Common::ByteArray &array, uint16_t offset = 0);
1002  };
1003 
1004  } // namespace GetAttributePack
1005 
1010  namespace SetAttributePack
1011  {
1016  struct Request
1017  {
1019 
1026  uint8_t count;
1027 
1028  virtual ~Request();
1029 
1031  static constexpr uint16_t min_size = sizeof(uint8_t); // Number of attributes.
1032 
1034  uint16_t size() const;
1035 
1037  uint16_t pack(Common::ByteArray &array, uint16_t offset = 0) const;
1038 
1046  uint16_t unpack(const Common::ByteArray &array, uint16_t offset = 0);
1047  };
1048 
1052  struct Response
1053  {
1057  struct Result
1058  {
1059  uint8_t uid;
1061 
1062  Result() {}
1063 
1071  uid(uid), code(code)
1072  {}
1073 
1075  static constexpr uint16_t min_size = sizeof(uint8_t) + sizeof(uint8_t);
1076 
1078  uint16_t size() const
1079  {
1080  return min_size;
1081  }
1082 
1084  uint16_t pack(Common::ByteArray &array, uint16_t offset = 0) const
1085  {
1086  HF_SERIALIZABLE_CHECK(array, offset, min_size);
1087 
1088  offset += array.write(offset, (uint8_t) uid);
1089 
1090  array.write(offset, (uint8_t) code);
1091 
1092  return min_size;
1093  }
1094 
1096  uint16_t unpack(const Common::ByteArray &array, uint16_t offset = 0)
1097  {
1098  HF_SERIALIZABLE_CHECK(array, offset, min_size);
1099 
1100  offset += array.read(offset, uid);
1101 
1102  uint8_t temp;
1103  array.read(offset, temp);
1104  code = static_cast<Common::Result>(temp);
1105 
1106  return min_size;
1107  }
1108  };
1109 
1110  typedef std::vector<Result> results_t;
1111 
1112  results_t results;
1113 
1120  uint8_t count;
1121 
1123  static constexpr uint16_t min_size = sizeof(uint8_t); // Number of attribute results.
1124 
1126  uint16_t size() const
1127  {
1128  uint16_t result = min_size;
1129 
1130  result += results.size() * Result::min_size;
1131 
1132  return result;
1133  }
1134 
1136  uint16_t pack(Common::ByteArray &array, uint16_t offset = 0) const;
1137 
1139  uint16_t unpack(const Common::ByteArray &array, uint16_t offset = 0);
1140  };
1141 
1142  } // namespace SetAttributePack
1145  } // namespace Protocol
1146 
1147 } // namespace HF
1148 
1149 #endif /* HF_ATTRIBUTES_H */
uint8_t count
Unpack attribute count.
Definition: attributes.h:1026
virtual float changed(const IAttribute &other) const =0
This method is used to get the percentage of change that the attribute has in relation to the value p...
This class represents the payload of a HF::Message::GET_ATTR_PACK_RES message.
Definition: attributes.h:934
uint8_t count
Unpack the results count.
Definition: attributes.h:1120
uint16_t unpack(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
uint16_t size() const
Number bytes needed to serialize the message.
virtual bool isWritable() const =0
Indicate if the attribute is writable.
results_t results
Response results.
Definition: attributes.h:1112
const bool _writable
Attribute access mode.
Definition: attributes.h:276
IAttribute * clone() const
Create a clone object of the object where this method is being called.
Definition: attributes.h:477
This class represents the payload of a HF::Message::SET_ATTR_PACK_RES message.
Definition: attributes.h:1052
uint16_t size() const
Number bytes needed to serialize the message.
virtual uint16_t unpack(const ByteArray &array, uint16_t offset=0)=0
Read a message from a ByteArray.
uint16_t write(uint16_t offset, uint8_t data)
Write a byte into the array at the given offset.
This class represents the interface that cloneable objects need to implement.
This class represents the payload of a HF::Message::GET_ATTR_PACK_REQ request, when the payload is Ty...
Definition: attributes.h:892
uint16_t pack(Common::ByteArray &array, uint16_t offset=0) const
Write the object on to a ByteArray so it can be sent over the network.
Definition: attributes.h:1084
uint16_t unpack(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
Definition: attributes.h:923
Return all mandatory and optional attributes for the interface.
Definition: attributes.h:843
static constexpr uint8_t min_size
Minimum pack/unpack required data size.
Definition: attributes.h:204
T data
Data type instance wrapped.
float changed(const IAttribute &other) const
This method is used to get the percentage of change that the attribute has in relation to the value p...
Definition: attributes.h:717
List of attributes UIDs.
Definition: attributes.h:176
uint16_t unpack(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
Definition: attributes.h:1096
Return all mandatory attributes for the interface.
Definition: attributes.h:842
This file contains the common defines for the HAN-FUN library.
bool isWritable() const
Indicate if the attribute is writable.
Definition: attributes.h:289
const uint8_t _uid
Attribute unique identifier.
Definition: attributes.h:275
This represents the common interface for message serialization.
uint8_t count
Unpack attribute count.
Definition: attributes.h:948
uint16_t unpack(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
Definition: attributes.h:472
Factory get_factory(Common::Interface itf)
Return the attribute factory associated with the given interface identifier.
Result(uint8_t uid, Common::Result code)
Constructor.
Definition: attributes.h:1070
uint16_t unpack(const ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
uint16_t pack(Common::ByteArray &array, uint16_t offset=0) const
Write the object on to a ByteArray so it can be sent over the network.
Definition: attributes.h:445
virtual uint16_t size() const =0
Number bytes needed to serialize the message.
This class has the same behavior has a list, however the list element access methods where overwritte...
Definition: attributes.h:752
uint16_t size() const
Number bytes needed to serialize the message.
This file contains the definitions for the HAN-FUN protocol messages.
uint16_t unpack(const Common::ByteArray &array, uint16_t offset, uint8_t &count)
Read a message from a ByteArray.
Definition: attributes.h:244
Attribute(const uint16_t interface, const uint8_t uid, T data, bool writable=false)
Attribute template constructor.
Definition: attributes.h:384
Attribute(_Owner &__owner, const uint8_t uid, getter_t _getter, setter_t _setter, bool writable=false)
Attribute template constructor.
Definition: attributes.h:545
uint8_t count
Unpack attribute count.
Definition: attributes.h:902
Response(HF::Attributes::Factory factory)
Constructor.
Definition: attributes.h:971
Response(HF::Attributes::List &attributes)
Constructor.
Definition: attributes.h:961
Return the attributes with the given attributes.
Definition: attributes.h:844
uint16_t pack(Common::ByteArray &array, uint16_t offset=0) const
Write the object on to a ByteArray so it can be sent over the network.
Definition: attributes.h:917
virtual HF::Interface const * owner() const =0
Pointer to the interface that owns this attribute.
#define HF_SERIALIZABLE_CHECK(__array, __offset, __size)
Helper macro to check if the given __array has enough size so __size bytes can be written/read from t...
virtual uint16_t size(bool with_uid) const =0
Number bytes needed to serialize the message.
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
Definition: attributes.h:1031
float changed(const IAttribute &other) const
This method is used to get the percentage of change that the attribute has in relation to the value p...
Definition: attributes.h:496
uint16_t unpack(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
Definition: attributes.h:686
vector< uint8_t >::size_type length() const
Number of elements in the list.
Definition: attributes.h:198
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
Definition: attributes.h:987
Attribute(const uint16_t interface, const uint8_t uid, bool writable=false)
Attribute template constructor.
Definition: attributes.h:372
HF::Interface const * owner() const
Pointer to the interface that owns this attribute.
Definition: attributes.h:414
HF::Interface const * owner() const
Pointer to the interface that owns this attribute.
Definition: attributes.h:619
This class represents the response sent when a Protocol::Message::GET_ATTR_REQ request.
Definition: attributes.h:772
uint16_t pack(Common::ByteArray &array, uint16_t offset=0) const
Write the object on to a ByteArray so it can be sent over the network.
Definition: attributes.h:653
UIDS(std::initializer_list< uint8_t > uids)
Constructor.
Definition: attributes.h:186
uint16_t pack(Common::ByteArray &array, uint16_t offset=0) const
Write the object on to a ByteArray so it can be sent over the network.
Attribute(_Owner &__owner, const uint8_t uid, getter_t _getter, bool writable=false)
Attribute template constructor.
Definition: attributes.h:559
uint16_t unpack(const Common::ByteArray &array, uint16_t offset, bool with_uid)
Read a message from a ByteArray.
Definition: attributes.h:660
uint16_t pack(Common::ByteArray &array, uint16_t offset=0) const
Write the object on to a ByteArray so it can be sent over the network.
This class represents a byte array.
Pack
Attribute Pack Special IDs.
Definition: attributes.h:840
HF::Attributes::Factory attribute_factory
Pointer to the function to request the attribute instances to unpack the response.
Definition: attributes.h:937
Set attribute operation result.
Definition: attributes.h:1057
uint16_t size() const
Number bytes needed to serialize the message.
Definition: attributes.h:1078
uint16_t unpack(const Common::ByteArray &array, uint16_t offset, bool with_uid)
Read a message from a ByteArray.
Definition: attributes.h:450
int compare(const IAttribute &other) const
Compare this attribute with the given attribute in other.
Definition: attributes.h:483
Parent class for Attribute API implementation.
Definition: attributes.h:270
uint16_t size(bool with_uid) const
Number bytes needed to serialize the message.
Definition: attributes.h:624
Response(IAttribute *_attribute=nullptr)
Constructor.
Definition: attributes.h:782
IAttribute *(* Factory)(uint8_t)
Attribute factory function type.
Definition: attributes.h:151
uint16_t pack(ByteArray &array, uint16_t offset=0) const
Write the object on to a ByteArray so it can be sent over the network.
uint16_t interface() const
Return the UID of the interface the attribute belongs to.
Definition: attributes.h:294
uint16_t size(bool with_uid) const
Number bytes needed to serialize the message.
Definition: attributes.h:419
uint16_t unpack(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
uint16_t pack(Common::ByteArray &array, uint16_t offset, bool with_uid) const
Write the object on to a ByteArray so it can be sent over the network.
Definition: attributes.h:635
uint16_t pack(Common::ByteArray &array, uint16_t offset=0) const
Write the object on to a ByteArray so it can be sent over the network.
uint16_t size() const
Number bytes needed to serialize the message.
Definition: attributes.h:911
virtual uint16_t pack(Common::ByteArray &array, uint16_t offset, bool with_uid) const =0
Write the object on to a ByteArray so it can be sent over the network.
Interface/Service Attribute API.
Definition: attributes.h:44
HF::Attributes::UIDS attributes
Vector containing the attributes UID&#39;s to get.
Definition: attributes.h:894
uint16_t read(uint16_t offset, uint8_t &data) const
Read the byte at offset into data.
uint16_t size() const
Number bytes needed to serialize the message.
const uint16_t _itf_uid
Interface this attribute belongs to.
Definition: attributes.h:274
Attributes::Factory(* FactoryGetter)(Common::Interface)
Function pointer to a function that returns the attribute factory associated with a given interface...
Definition: attributes.h:157
uint8_t uid() const
Attribute&#39;s UID.
Definition: attributes.h:284
Parent class for the response messages.
Definition: protocol.h:368
virtual uint16_t pack(ByteArray &array, uint16_t offset=0) const =0
Write the object on to a ByteArray so it can be sent over the network.
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
Definition: attributes.h:1075
uint16_t size() const
Number bytes needed to serialize the message.
Definition: attributes.h:1126
Helper template class to declare an attribute with the given T type.
Definition: attributes.h:349
HF::Attributes::List attributes
List containing the attributes to send.
Definition: attributes.h:1018
Attribute(const uint16_t interface, const uint8_t uid, const HF::Interface *__owner, T data, bool writable=false)
Attribute template constructor.
Definition: attributes.h:360
static constexpr uint16_t min_size
Minimum number of bytes required by this message.
Definition: protocol.h:375
IAttribute * clone() const
Create a clone object of the object where this method is being called.
Definition: attributes.h:695
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
Definition: attributes.h:1123
Common interface for all Interfaces.
Definition: interface.h:43
virtual int compare(const IAttribute &other) const =0
Compare this attribute with the given attribute in other.
uint16_t pack(Common::ByteArray &array, uint16_t offset=0) const
Write the object on to a ByteArray so it can be sent over the network.
int compare(const IAttribute &other) const
Compare this attribute with the given attribute in other.
Definition: attributes.h:329
uint16_t unpack(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
uint16_t unpack(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
virtual uint8_t uid() const =0
Attribute&#39;s UID.
uint16_t size() const
Number bytes needed to serialize the message.
Definition: attributes.h:424
Result
Commands result codes.
uint16_t pack(Common::ByteArray &array, uint16_t offset, bool with_uid) const
Write the object on to a ByteArray so it can be sent over the network.
Definition: attributes.h:429
int compare(const IAttribute &other) const
Compare this attribute with the given attribute in other.
Definition: attributes.h:702
virtual uint16_t unpack(const Common::ByteArray &array, uint16_t offset, bool with_uid)=0
Read a message from a ByteArray.
virtual uint16_t interface() const =0
Return the UID of the interface the attribute belongs to.
This class represents the message payload of a HF::Message::SET_ATTR_PACK_REQ or HF::Message::SET_ATT...
Definition: attributes.h:1016
uint16_t size() const
Number bytes needed to serialize the message.
Definition: attributes.h:629
Top-level namespace for the HAN-FUN library.
Definition: attributes.h:22