1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef SWITCH_EVENT_H
17 #define SWITCH_EVENT_H
18 
19 #include "nocopyable.h"
20 
21 #include "input_event.h"
22 
23 namespace OHOS {
24 namespace MMI {
25 class SwitchEvent : public InputEvent {
26 public:
27     static constexpr int32_t SWITCH_ON = 0;
28     static constexpr int32_t SWITCH_OFF = 1;
29 
30     /**
31      * @brief Enumerated values of switch type.
32     *
33     * @since 12
34     */
35     enum SwitchType {
36         /** Default, used to be compatible with calls to previously none switch type parameter */
37         SWITCH_DEFAULT = 0,
38         /** Lid switch type */
39         SWITCH_LID,
40         /** Tablet switch type */
41         SWITCH_TABLET,
42         /** Privacy switch type */
43         SWITCH_PRIVACY
44     };
45 
46 public:
GetSwitchType() const47     int32_t GetSwitchType() const
48     {
49         return switchType_;
50     }
51 
GetSwitchValue() const52     int32_t GetSwitchValue() const
53     {
54         return switchValue_;
55     }
56 
GetSwitchMask() const57     int32_t GetSwitchMask() const
58     {
59         return updateSwitchMask_;
60     }
61 
SetSwitchType(int32_t type)62     void SetSwitchType(int32_t type)
63     {
64         switchType_ = type;
65     }
66 
SetSwitchValue(int32_t value)67     void SetSwitchValue(int32_t value)
68     {
69         switchValue_ = value;
70     }
71 
SetSwitchMask(int32_t switchMask)72     void SetSwitchMask(int32_t switchMask)
73     {
74         updateSwitchMask_ = switchMask;
75     }
76 
77     virtual std::string ToString() override
78     {
79         std::string eventStr = InputEvent::ToString();
80         eventStr += ",switchValue:" + std::to_string(switchValue_);
81         eventStr += ",updateSwitchMask:" + std::to_string(updateSwitchMask_);
82         eventStr += ",switchType:" + std::to_string(switchType_);
83         return eventStr;
84     }
85 
SwitchEvent(int32_t value)86     explicit SwitchEvent(int32_t value)
87         : InputEvent(value),
88         switchValue_(value),
89         updateSwitchMask_(0),
90         switchType_(SwitchType::SWITCH_DEFAULT) {}
91 private:
92         int32_t switchValue_ { 0 };
93         int32_t updateSwitchMask_ { 0 };
94         int32_t switchType_ { SwitchType::SWITCH_DEFAULT };
95 };
96 } // namespace MMI
97 } // namespace OHOS
98 #endif // SWITCH_EVENT_H