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