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