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 BOOMERANG,
46 };
47
48 inline constexpr uint32_t PARAMBITS { 12U };
49 inline constexpr uint32_t PARAMMASK { (uint32_t(1U) << PARAMBITS) - uint32_t(1U) };
50 inline constexpr uint32_t INTENTIONSHIFT { PARAMBITS };
51 inline constexpr uint32_t INTENTIONBITS { 8U };
52 inline constexpr uint32_t INTENTIONMASK { (uint32_t(1U) << INTENTIONBITS) - uint32_t(1U) };
53 inline constexpr uint32_t ACTIONSHIFT { INTENTIONSHIFT + INTENTIONBITS };
54 inline constexpr uint32_t ACTIONBITS { 4U };
55 inline constexpr uint32_t ACTIONMASK { (uint32_t(1U) << ACTIONBITS) - uint32_t(1U) };
56
PARAMID(uint32_t action,uint32_t intention,uint32_t param)57 constexpr uint32_t PARAMID(uint32_t action, uint32_t intention, uint32_t param)
58 {
59 return (
60 ((action & ACTIONMASK) << ACTIONSHIFT) |
61 ((intention & INTENTIONMASK) << INTENTIONSHIFT) |
62 (param & PARAMMASK)
63 );
64 }
65
GACTION(uint32_t id)66 constexpr uint32_t GACTION(uint32_t id)
67 {
68 return ((id >> ACTIONSHIFT) & ACTIONMASK);
69 }
70
GINTENTION(uint32_t id)71 constexpr uint32_t GINTENTION(uint32_t id)
72 {
73 return ((id >> INTENTIONSHIFT) & INTENTIONMASK);
74 }
75
GPARAM(uint32_t id)76 constexpr uint32_t GPARAM(uint32_t id)
77 {
78 return (id & PARAMMASK);
79 }
80
81 class ParamBase {
82 public:
83 virtual ~ParamBase() = default;
84
85 virtual bool Marshalling(MessageParcel &parcel) const = 0;
86 virtual bool Unmarshalling(MessageParcel &parcel) = 0;
87 };
88 } // namespace DeviceStatus
89 } // namespace Msdp
90 } // namespace OHOS
91 #endif // INTENTION_IDENTITY_H
92