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 //! Helper functions to deal with function id.
17 
18 #![allow(dead_code)]
19 
20 use std::ffi::{ c_char, CString };
21 
22 use hilog_rust::{ info, hilog, HiLogLabel, LogType };
23 
24 use fusion_data_rust::Intention;
25 use fusion_utils_rust::{ define_enum, FusionResult, FusionErrorCode };
26 
27 define_enum! {
28     CommonAction {
29         Enable,
30         Disable,
31         Start,
32         Stop,
33         AddWatch,
34         RemoveWatch,
35         SetParam,
36         GetParam,
37         Control
38     }
39 }
40 
41 const LOG_LABEL: HiLogLabel = HiLogLabel {
42     log_type: LogType::LogCore,
43     domain: 0xD002220,
44     tag: "FusionIpcServiceIdentity"
45 };
46 
47 const PARAMBITS: u32 = 12;
48 const PARAMMASK: u32 = (1u32 << PARAMBITS) - 1u32;
49 const INTENTIONSHIFT: u32 = PARAMBITS;
50 const INTENTIONBITS: u32 = 8;
51 const INTENTIONMASK: u32 = (1u32 << INTENTIONBITS) - 1u32;
52 const ACTIONSHIFT: u32 = INTENTIONSHIFT + INTENTIONBITS;
53 const ACTIONBITS: u32 = 4;
54 const ACTIONMASK: u32 = (1u32 << ACTIONBITS) - 1u32;
55 
compose_param_id(action: CommonAction, intention: Intention, param: u32) -> u3256 pub fn compose_param_id(action: CommonAction, intention: Intention, param: u32) -> u32
57 {
58     info!(LOG_LABEL, "In FusionIpcServiceIdentity::compose_param_id(): enter");
59     ((action as u32 & ACTIONMASK) << ACTIONSHIFT) |
60     ((intention as u32 & INTENTIONMASK) << INTENTIONSHIFT) |
61     (param & PARAMMASK)
62 }
63 
split_action(code: u32) -> FusionResult<CommonAction>64 pub fn split_action(code: u32) -> FusionResult<CommonAction>
65 {
66     info!(LOG_LABEL, "In FusionIpcServiceIdentity::split_action(): enter");
67     CommonAction::try_from((code >> ACTIONSHIFT) & ACTIONMASK)
68 }
69 
split_intention(code: u32) -> FusionResult<Intention>70 pub fn split_intention(code: u32) -> FusionResult<Intention>
71 {
72     info!(LOG_LABEL, "In FusionIpcServiceIdentity::split_intention(): enter");
73     Intention::try_from((code >> INTENTIONSHIFT) & INTENTIONMASK)
74 }
75 
split_param(code: u32) -> u3276 pub fn split_param(code: u32) -> u32
77 {
78     info!(LOG_LABEL, "In FusionIpcServiceIdentity::split_param(): enter");
79     code & PARAMMASK
80 }
81