1f857971dSopenharmony_ci/*
2f857971dSopenharmony_ci * Copyright (C) 2023 Huawei Device Co., Ltd.
3f857971dSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4f857971dSopenharmony_ci * you may not use this file except in compliance with the License.
5f857971dSopenharmony_ci * You may obtain a copy of the License at
6f857971dSopenharmony_ci *
7f857971dSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8f857971dSopenharmony_ci *
9f857971dSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10f857971dSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11f857971dSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12f857971dSopenharmony_ci * See the License for the specific language governing permissions and
13f857971dSopenharmony_ci * limitations under the License.
14f857971dSopenharmony_ci */
15f857971dSopenharmony_ci
16f857971dSopenharmony_ci//! Helper functions to deal with function id.
17f857971dSopenharmony_ci
18f857971dSopenharmony_ci#![allow(dead_code)]
19f857971dSopenharmony_ci
20f857971dSopenharmony_ciuse std::ffi::{ c_char, CString };
21f857971dSopenharmony_ci
22f857971dSopenharmony_ciuse hilog_rust::{ info, hilog, HiLogLabel, LogType };
23f857971dSopenharmony_ci
24f857971dSopenharmony_ciuse fusion_data_rust::Intention;
25f857971dSopenharmony_ciuse fusion_utils_rust::{ define_enum, FusionResult, FusionErrorCode };
26f857971dSopenharmony_ci
27f857971dSopenharmony_cidefine_enum! {
28f857971dSopenharmony_ci    CommonAction {
29f857971dSopenharmony_ci        Enable,
30f857971dSopenharmony_ci        Disable,
31f857971dSopenharmony_ci        Start,
32f857971dSopenharmony_ci        Stop,
33f857971dSopenharmony_ci        AddWatch,
34f857971dSopenharmony_ci        RemoveWatch,
35f857971dSopenharmony_ci        SetParam,
36f857971dSopenharmony_ci        GetParam,
37f857971dSopenharmony_ci        Control
38f857971dSopenharmony_ci    }
39f857971dSopenharmony_ci}
40f857971dSopenharmony_ci
41f857971dSopenharmony_ciconst LOG_LABEL: HiLogLabel = HiLogLabel {
42f857971dSopenharmony_ci    log_type: LogType::LogCore,
43f857971dSopenharmony_ci    domain: 0xD002220,
44f857971dSopenharmony_ci    tag: "FusionIpcServiceIdentity"
45f857971dSopenharmony_ci};
46f857971dSopenharmony_ci
47f857971dSopenharmony_ciconst PARAMBITS: u32 = 12;
48f857971dSopenharmony_ciconst PARAMMASK: u32 = (1u32 << PARAMBITS) - 1u32;
49f857971dSopenharmony_ciconst INTENTIONSHIFT: u32 = PARAMBITS;
50f857971dSopenharmony_ciconst INTENTIONBITS: u32 = 8;
51f857971dSopenharmony_ciconst INTENTIONMASK: u32 = (1u32 << INTENTIONBITS) - 1u32;
52f857971dSopenharmony_ciconst ACTIONSHIFT: u32 = INTENTIONSHIFT + INTENTIONBITS;
53f857971dSopenharmony_ciconst ACTIONBITS: u32 = 4;
54f857971dSopenharmony_ciconst ACTIONMASK: u32 = (1u32 << ACTIONBITS) - 1u32;
55f857971dSopenharmony_ci
56f857971dSopenharmony_cipub fn compose_param_id(action: CommonAction, intention: Intention, param: u32) -> u32
57f857971dSopenharmony_ci{
58f857971dSopenharmony_ci    info!(LOG_LABEL, "In FusionIpcServiceIdentity::compose_param_id(): enter");
59f857971dSopenharmony_ci    ((action as u32 & ACTIONMASK) << ACTIONSHIFT) |
60f857971dSopenharmony_ci    ((intention as u32 & INTENTIONMASK) << INTENTIONSHIFT) |
61f857971dSopenharmony_ci    (param & PARAMMASK)
62f857971dSopenharmony_ci}
63f857971dSopenharmony_ci
64f857971dSopenharmony_cipub fn split_action(code: u32) -> FusionResult<CommonAction>
65f857971dSopenharmony_ci{
66f857971dSopenharmony_ci    info!(LOG_LABEL, "In FusionIpcServiceIdentity::split_action(): enter");
67f857971dSopenharmony_ci    CommonAction::try_from((code >> ACTIONSHIFT) & ACTIONMASK)
68f857971dSopenharmony_ci}
69f857971dSopenharmony_ci
70f857971dSopenharmony_cipub fn split_intention(code: u32) -> FusionResult<Intention>
71f857971dSopenharmony_ci{
72f857971dSopenharmony_ci    info!(LOG_LABEL, "In FusionIpcServiceIdentity::split_intention(): enter");
73f857971dSopenharmony_ci    Intention::try_from((code >> INTENTIONSHIFT) & INTENTIONMASK)
74f857971dSopenharmony_ci}
75f857971dSopenharmony_ci
76f857971dSopenharmony_cipub fn split_param(code: u32) -> u32
77f857971dSopenharmony_ci{
78f857971dSopenharmony_ci    info!(LOG_LABEL, "In FusionIpcServiceIdentity::split_param(): enter");
79f857971dSopenharmony_ci    code & PARAMMASK
80f857971dSopenharmony_ci}
81