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