forked from dresden-elektronik/deconz-rest-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aps_controller_wrapper.h
68 lines (58 loc) · 2 KB
/
aps_controller_wrapper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* Copyright (c) 2021 dresden elektronik ingenieurtechnik gmbh.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
* style license a copy of which has been included with this distribution in
* the LICENSE.txt file.
*
*/
#ifndef APS_CONTROLLER_WRAPPER_H
#define APS_CONTROLLER_WRAPPER_H
namespace deCONZ {
class ApsController;
class ApsDataIndication;
class ApsDataRequest;
class ZclFrame;
}
class ApsControllerWrapper;
/*! RAII helper to send a ZCL Default Response after APS indication if needed.
The class observes outgoing APS requests for specific responses for a request and
automatically sends a ZCL Default Response if no specifc response was send.
*/
class ZclDefaultResponder
{
public:
ZclDefaultResponder() = delete;
explicit ZclDefaultResponder(ApsControllerWrapper *apsCtrlWrapper, const deCONZ::ApsDataIndication &ind, const deCONZ::ZclFrame &zclFrame);
~ZclDefaultResponder();
void checkApsdeDataRequest(const deCONZ::ApsDataRequest &req);
private:
enum class State
{
Init,
NoResponseNeeded,
Watch,
HasResponse
};
ApsControllerWrapper *m_apsCtrlWrapper = nullptr;
const deCONZ::ApsDataIndication &m_ind;
const deCONZ::ZclFrame &m_zclFrame;
State m_state = State::Init;
};
/*! Wraps \c deCONZ::ApsController to intercept apsdeDataRequest().
The main purpose is to deterministic send ZCL Default Response if needed.
*/
class ApsControllerWrapper
{
public:
ApsControllerWrapper(deCONZ::ApsController *ctrl);
int apsdeDataRequest(const deCONZ::ApsDataRequest &req);
void registerZclDefaultResponder(ZclDefaultResponder *resp) { m_zclDefaultResponder = resp; }
void clearZclDefaultResponder() { m_zclDefaultResponder = nullptr; };
deCONZ::ApsController *apsController() { return m_apsCtrl; }
private:
deCONZ::ApsController *m_apsCtrl = nullptr;
ZclDefaultResponder *m_zclDefaultResponder = nullptr;
};
#endif // APS_CONTROLLER_WRAPPER_H