Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / examples / lock-app / cc13x2x7_26x2x7 / main / include / BoltLockManager.h
1 /*
2  *
3  *    Copyright (c) 2019 Google LLC.
4  *    All rights reserved.
5  *
6  *    Licensed under the Apache License, Version 2.0 (the "License");
7  *    you may not use this file except in compliance with the License.
8  *    You may obtain a copy of the License at
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *    Unless required by applicable law or agreed to in writing, software
13  *    distributed under the License is distributed on an "AS IS" BASIS,
14  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *    See the License for the specific language governing permissions and
16  *    limitations under the License.
17  */
18
19 #ifndef LOCK_MANAGER_H
20 #define LOCK_MANAGER_H
21
22 #include <stdbool.h>
23 #include <stdint.h>
24
25 #include "AppEvent.h"
26
27 #include <FreeRTOS.h>
28 #include <timers.h>
29
30 class BoltLockManager
31 {
32 public:
33     enum Action_t
34     {
35         LOCK_ACTION = 0,
36         UNLOCK_ACTION,
37
38         INVALID_ACTION
39     } Action;
40
41     enum State_t
42     {
43         kState_LockingInitiated = 0,
44         kState_LockingCompleted,
45         kState_UnlockingInitiated,
46         kState_UnlockingCompleted,
47     } State;
48
49     int Init();
50     bool IsUnlocked();
51     void EnableAutoRelock(bool aOn);
52     void SetAutoLockDuration(uint32_t aDurationInSecs);
53     bool IsActionInProgress();
54     bool InitiateAction(int32_t aActor, Action_t aAction);
55
56     typedef void (*Callback_fn_initiated)(Action_t, int32_t aActor);
57     typedef void (*Callback_fn_completed)(Action_t);
58     void SetCallbacks(Callback_fn_initiated aActionInitiated_CB, Callback_fn_completed aActionCompleted_CB);
59
60 private:
61     friend BoltLockManager & BoltLockMgr(void);
62     State_t mState;
63
64     Callback_fn_initiated mActionInitiated_CB;
65     Callback_fn_completed mActionCompleted_CB;
66
67     bool mAutoRelock;
68     uint32_t mAutoLockDuration;
69     bool mAutoLockTimerArmed;
70     TimerHandle_t mTimerHandle;
71
72     void CancelTimer(void);
73     void StartTimer(uint32_t aTimeoutMs);
74
75     static void TimerEventHandler(TimerHandle_t aTimer);
76     static void AutoReLockTimerEventHandler(AppEvent * aEvent);
77     static void ActuatorMovementTimerEventHandler(AppEvent * aEvent);
78
79     static BoltLockManager sLock;
80 };
81
82 inline BoltLockManager & BoltLockMgr(void)
83 {
84     return BoltLockManager::sLock;
85 }
86
87 #endif // LOCK_MANAGER_H