Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / examples / bridge-app / linux / LightingManager.cpp
1 /*
2  *
3  *    Copyright (c) 2021 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 #include "LightingManager.h"
21
22 #include <cstdio>
23
24 LightingManager LightingManager::sLight;
25
26 int LightingManager::Init()
27 {
28     mState = kState_On;
29     return 0;
30 }
31
32 bool LightingManager::IsTurnedOn()
33 {
34     return mState == kState_On;
35 }
36
37 void LightingManager::SetCallbacks(LightingCallback_fn aActionInitiated_CB, LightingCallback_fn aActionCompleted_CB)
38 {
39     mActionInitiated_CB = aActionInitiated_CB;
40     mActionCompleted_CB = aActionCompleted_CB;
41 }
42
43 bool LightingManager::InitiateAction(Action_t aAction)
44 {
45     // TODO: this function is called InitiateAction because we want to implement some features such as ramping up here.
46     bool action_initiated = false;
47     State_t new_state;
48
49     switch (aAction)
50     {
51     case ON_ACTION:
52         printf("LightingManager::InitiateAction(ON_ACTION)");
53         break;
54     case OFF_ACTION:
55         printf("LightingManager::InitiateAction(OFF_ACTION)");
56         break;
57     default:
58         printf("LightingManager::InitiateAction(unknown)");
59         break;
60     }
61
62     // Initiate On/Off Action only when the previous one is complete.
63     if (mState == kState_Off && aAction == ON_ACTION)
64     {
65         action_initiated = true;
66         new_state        = kState_On;
67     }
68     else if (mState == kState_On && aAction == OFF_ACTION)
69     {
70         action_initiated = true;
71         new_state        = kState_Off;
72     }
73
74     if (action_initiated)
75     {
76         if (mActionInitiated_CB)
77         {
78             mActionInitiated_CB(aAction);
79         }
80
81         Set(new_state == kState_On);
82
83         if (mActionCompleted_CB)
84         {
85             mActionCompleted_CB(aAction);
86         }
87     }
88
89     return action_initiated;
90 }
91
92 void LightingManager::Set(bool aOn)
93 {
94     if (aOn)
95     {
96         mState = kState_On;
97     }
98     else
99     {
100         mState = kState_Off;
101     }
102 }