1 /*
2 * Copyright (c) 2023 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 INTENTION_IDENTITY_H
17 #define INTENTION_IDENTITY_H
18
19 #include <cinttypes>
20
21 #include "message_parcel.h"
22
23 namespace OHOS {
24 namespace Msdp {
25 namespace DeviceStatus {
26 enum CommonAction : uint32_t {
27 UNKNOWN_COMMON_ACTION,
28 ENABLE,
29 DISABLE,
30 START,
31 STOP,
32 ADD_WATCH,
33 REMOVE_WATCH,
34 SET_PARAM,
35 GET_PARAM,
36 CONTROL
37 };
38
39 enum class Intention : uint32_t {
40 UNKNOWN_INTENTION,
41 SOCKET,
42 STATIONARY,
43 DRAG,
44 COOPERATE,
45 };
46
47 inline constexpr uint32_t PARAMBITS { 12U };
48 inline constexpr uint32_t PARAMMASK { (uint32_t(1U) << PARAMBITS) - uint32_t(1U) };
49 inline constexpr uint32_t INTENTIONSHIFT { PARAMBITS };
50 inline constexpr uint32_t INTENTIONBITS { 8U };
51 inline constexpr uint32_t INTENTIONMASK { (uint32_t(1U) << INTENTIONBITS) - uint32_t(1U) };
52 inline constexpr uint32_t ACTIONSHIFT { INTENTIONSHIFT + INTENTIONBITS };
53 inline constexpr uint32_t ACTIONBITS { 4U };
54 inline constexpr uint32_t ACTIONMASK { (uint32_t(1U) << ACTIONBITS) - uint32_t(1U) };
55
PARAMID(uint32_t action,uint32_t intention,uint32_t param)56 constexpr uint32_t PARAMID(uint32_t action, uint32_t intention, uint32_t param)
57 {
58 return (
59 ((action & ACTIONMASK) << ACTIONSHIFT) |
60 ((intention & INTENTIONMASK) << INTENTIONSHIFT) |
61 (param & PARAMMASK)
62 );
63 }
64
GACTION(uint32_t id)65 constexpr uint32_t GACTION(uint32_t id)
66 {
67 return ((id >> ACTIONSHIFT) & ACTIONMASK);
68 }
69
GINTENTION(uint32_t id)70 constexpr uint32_t GINTENTION(uint32_t id)
71 {
72 return ((id >> INTENTIONSHIFT) & INTENTIONMASK);
73 }
74
GPARAM(uint32_t id)75 constexpr uint32_t GPARAM(uint32_t id)
76 {
77 return (id & PARAMMASK);
78 }
79
80 class ParamBase {
81 public:
82 virtual ~ParamBase() = default;
83
84 virtual bool Marshalling(MessageParcel &parcel) const = 0;
85 virtual bool Unmarshalling(MessageParcel &parcel) = 0;
86 };
87 } // namespace DeviceStatus
88 } // namespace Msdp
89 } // namespace OHOS
90 #endif // INTENTION_IDENTITY_H
91