Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / examples / lock-app / k32w / main / include / BoltLockManager.h
1 /*
2  *
3  *    Copyright (c) 2020 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 #pragma once
20
21 #include <stdbool.h>
22 #include <stdint.h>
23
24 #include "AppEvent.h"
25
26 #include "FreeRTOS.h"
27 #include "timers.h" // provides FreeRTOS timer support
28
29 class BoltLockManager
30 {
31 public:
32     enum Action_t
33     {
34         LOCK_ACTION = 0,
35         UNLOCK_ACTION,
36
37         INVALID_ACTION
38     } Action;
39
40     enum State_t
41     {
42         kState_LockingInitiated = 0,
43         kState_LockingCompleted,
44         kState_UnlockingInitiated,
45         kState_UnlockingCompleted,
46     } State;
47
48     int Init();
49     bool IsUnlocked();
50     void EnableAutoRelock(bool aOn);
51     void SetAutoLockDuration(uint32_t aDurationInSecs);
52     bool IsActionInProgress();
53     bool InitiateAction(int32_t aActor, Action_t aAction);
54
55     typedef void (*Callback_fn_initiated)(Action_t, int32_t aActor);
56     typedef void (*Callback_fn_completed)(Action_t);
57     void SetCallbacks(Callback_fn_initiated aActionInitiated_CB, Callback_fn_completed aActionCompleted_CB);
58
59 private:
60     friend BoltLockManager & BoltLockMgr(void);
61     State_t mState;
62
63     Callback_fn_initiated mActionInitiated_CB;
64     Callback_fn_completed mActionCompleted_CB;
65
66     bool mAutoRelock;
67     uint32_t mAutoLockDuration;
68     bool mAutoLockTimerArmed;
69
70     void CancelTimer(void);
71     void StartTimer(uint32_t aTimeoutMs);
72
73     static void TimerEventHandler(TimerHandle_t xTimer);
74     static void AutoReLockTimerEventHandler(AppEvent * aEvent);
75     static void ActuatorMovementTimerEventHandler(AppEvent * aEvent);
76
77     static BoltLockManager sLock;
78 };
79
80 inline BoltLockManager & BoltLockMgr(void)
81 {
82     return BoltLockManager::sLock;
83 }