deCONZ C++ API v2.6.1
Loading...
Searching...
No Matches
binding_table.h
1#ifndef BINDING_TABLE_H
2#define BINDING_TABLE_H
3
4/*
5 * Copyright (c) 2012-2023 dresden elektronik ingenieurtechnik gmbh.
6 * All rights reserved.
7 *
8 * The software in this package is published under the terms of the BSD
9 * style license a copy of which has been included with this distribution in
10 * the LICENSE.txt file.
11 *
12 */
13
14#include "deconz/types.h"
15#include "deconz/aps.h"
16#include "deconz/timeref.h"
17
18class QDataStream;
19
20namespace deCONZ {
21
22
23class DECONZ_DLLSPEC Binding
24{
25public:
26 Binding() = default;
27 Binding(const quint64 src, const quint64 dst, const quint16 clusterId, const quint8 srcEndpoint, const quint8 dstEndpoint);
28 Binding(const quint64 src, const quint16 dstGroup, const quint16 clusterId, const quint8 srcEndpoint);
29
30 quint64 srcAddress() const { return m_srcAddr; }
31 void setSrcAddress(quint64 src) { m_srcAddr = src; }
32 uint8_t srcEndpoint() const { return m_srcEndpoint; }
33 void setSrcEndpoint(const uint8_t srcEndpoint) { m_srcEndpoint = srcEndpoint; }
34 uint16_t clusterId() const { return m_cluster; }
35 void setClusterId(const uint16_t clusterId) { m_cluster = clusterId; }
36 deCONZ::ApsAddressMode dstAddressMode() const { return m_dstAddrMode; }
37 void setDstAddressMode(const deCONZ::ApsAddressMode mode) { m_dstAddrMode = mode; }
38 deCONZ::Address &dstAddress() { return m_dstAddr; }
39 const deCONZ::Address &dstAddress() const { return m_dstAddr; }
40 uint8_t dstEndpoint() const { return m_dstEndpoint; }
41 void setDstEndpoint(const uint8_t dstEndpoint) { m_dstEndpoint = dstEndpoint; }
43 bool readFromStream(QDataStream &stream);
44 bool isValid() const;
48 deCONZ::SteadyTimeRef confirmedTimeRef() const { return m_confirmedTimeRef; }
49 void setConfirmedTimeRef(deCONZ::SteadyTimeRef t) { m_confirmedTimeRef = t; }
50
51 bool operator==(const Binding &other) const
52 {
53 if (dstAddress() == other.dstAddress() &&
54 dstAddressMode() == other.dstAddressMode() &&
55 srcAddress() == other.srcAddress() &&
56 srcEndpoint() == other.srcEndpoint() &&
57 dstEndpoint() == other.dstEndpoint() &&
58 clusterId() == other.clusterId())
59 {
60 return true;
61 }
62
63 return false;
64 }
65
66 bool operator !=(const Binding &other)
67 {
68 return !(*this == other);
69 }
70
71private:
72 deCONZ::Address m_dstAddr;
73 deCONZ::SteadyTimeRef m_confirmedTimeRef{};
74 quint64 m_srcAddr = 0;
76 uint16_t m_cluster = 0xffff;
77 uint8_t m_srcEndpoint = 0xff;
78 uint8_t m_dstEndpoint = 0xff;
79};
80
81class DECONZ_DLLSPEC BindingTable
82{
83public:
84 BindingTable() = default;
85
86 using size_type = std::vector<Binding>::size_type;
87 using iterator = std::vector<Binding>::iterator;
88 using const_iterator = std::vector<Binding>::const_iterator;
89
90 bool add(const Binding &binding);
91 bool remove(const Binding &binding);
92 size_type size() const { return m_table.size(); }
93 bool contains(const Binding &binding) const;
94 const_iterator const_begin() const;
95 const_iterator const_end() const;
96 const_iterator cbegin() const;
97 const_iterator cend() const;
98 iterator begin();
99 iterator end();
100 void clearOldBindings();
101 void setResponseIndex0TimeRef(deCONZ::SteadyTimeRef t) { m_responseIndex0TimeRef = t; }
102
103private:
104 deCONZ::SteadyTimeRef m_responseIndex0TimeRef{};
105 std::vector<Binding> m_table;
106};
107
108} // namespace deCONZ
109
110Q_DECLARE_METATYPE(deCONZ::BindingTable)
111
112
113#endif // BINDING_TABLE_H
114
Convenience class to work with network, extended and group addresses.
Definition aps.h:111
Definition binding_table.h:82
Definition binding_table.h:24
deCONZ::SteadyTimeRef confirmedTimeRef() const
Timestamp when the binding was last confirmed.
Definition binding_table.h:48
The deCONZ namespace.
Definition aps.cpp:19
ApsAddressMode
Address modes used to specify source and destination addresses.
Definition aps.h:83
@ ApsNoAddress
No addressing specified.
Definition aps.h:84
Definition timeref.h:22
Declaration of the most common deCONZ library types.