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 //! IPC data definitions of Coordination module. 17 18 use std::ffi::{ c_char, CString }; 19 20 use hilog_rust::{ hilog, HiLogLabel, LogType }; 21 use ipc_rust::{ BorrowedMsgParcel, Serialize, Deserialize, IpcResult }; 22 23 use fusion_utils_rust::call_debug_enter; 24 25 const LOG_LABEL: HiLogLabel = HiLogLabel { 26 log_type: LogType::LogCore, 27 domain: 0xD002220, 28 tag: "FusionCoordinationData" 29 }; 30 31 /// General parameters of request of multi-device cooperation. 32 #[derive(Default)] 33 pub struct GeneralCoordinationParam { 34 /// ID of one request. 35 pub user_data: i32, 36 } 37 38 impl Serialize for GeneralCoordinationParam { serialize(&self, parcel: &mut BorrowedMsgParcel<'_>) -> IpcResult<()>39 fn serialize(&self, parcel: &mut BorrowedMsgParcel<'_>) -> IpcResult<()> 40 { 41 call_debug_enter!("GeneralCoordinationParam::serialize"); 42 self.user_data.serialize(parcel)?; 43 Ok(()) 44 } 45 } 46 47 impl Deserialize for GeneralCoordinationParam { deserialize(parcel: &BorrowedMsgParcel<'_>) -> IpcResult<Self>48 fn deserialize(parcel: &BorrowedMsgParcel<'_>) -> IpcResult<Self> 49 { 50 call_debug_enter!("GeneralCoordinationParam::deserialize"); 51 Ok(Self { 52 user_data: i32::deserialize(parcel)?, 53 }) 54 } 55 } 56 57 /// Parameters of request to start multi-device cooperation. 58 pub struct StartCoordinationParam { 59 /// ID of one request. 60 pub user_data: i32, 61 /// The input device that trigger multi-device cooperation. 62 pub start_device_id: i32, 63 /// The remote device we want to cooperate with. 64 pub remote_network_id: String, 65 } 66 67 impl Serialize for StartCoordinationParam { serialize(&self, parcel: &mut BorrowedMsgParcel<'_>) -> IpcResult<()>68 fn serialize(&self, parcel: &mut BorrowedMsgParcel<'_>) -> IpcResult<()> 69 { 70 call_debug_enter!("StartCoordinationParam::serialize"); 71 self.user_data.serialize(parcel)?; 72 self.start_device_id.serialize(parcel)?; 73 self.remote_network_id.serialize(parcel)?; 74 Ok(()) 75 } 76 } 77 78 impl Deserialize for StartCoordinationParam { deserialize(parcel: &BorrowedMsgParcel<'_>) -> IpcResult<Self>79 fn deserialize(parcel: &BorrowedMsgParcel<'_>) -> IpcResult<Self> 80 { 81 call_debug_enter!("StartCoordinationParam::deserialize"); 82 Ok(Self { 83 user_data: i32::deserialize(parcel)?, 84 start_device_id: i32::deserialize(parcel)?, 85 remote_network_id: String::deserialize(parcel)?, 86 }) 87 } 88 } 89 90 /// Parameters of request to stop multi-device cooperation. 91 pub struct StopCoordinationParam { 92 /// ID of one request. 93 pub user_data: i32, 94 /// Indicate whether to stop remote input. 95 pub is_unchained: i32, 96 } 97 98 impl Serialize for StopCoordinationParam { serialize(&self, parcel: &mut BorrowedMsgParcel<'_>) -> IpcResult<()>99 fn serialize(&self, parcel: &mut BorrowedMsgParcel<'_>) -> IpcResult<()> 100 { 101 call_debug_enter!("StopCoordinationParam::serialize"); 102 self.user_data.serialize(parcel)?; 103 self.is_unchained.serialize(parcel)?; 104 Ok(()) 105 } 106 } 107 108 impl Deserialize for StopCoordinationParam { deserialize(parcel: &BorrowedMsgParcel<'_>) -> IpcResult<Self>109 fn deserialize(parcel: &BorrowedMsgParcel<'_>) -> IpcResult<Self> 110 { 111 call_debug_enter!("StopCoordinationParam::deserialize"); 112 Ok(Self { 113 user_data: i32::deserialize(parcel)?, 114 is_unchained: i32::deserialize(parcel)?, 115 }) 116 } 117 } 118 119 /// Parameters of request to check switch status of multi-device cooperation 120 /// of the remote device. 121 pub struct GetCoordinationStateParam { 122 /// ID of one request. 123 pub user_data: i32, 124 /// The remote device. 125 pub device_id: String, 126 } 127 128 impl Serialize for GetCoordinationStateParam { serialize(&self, parcel: &mut BorrowedMsgParcel<'_>) -> IpcResult<()>129 fn serialize(&self, parcel: &mut BorrowedMsgParcel<'_>) -> IpcResult<()> 130 { 131 call_debug_enter!("GetCoordinationStateParam::serialize"); 132 self.user_data.serialize(parcel)?; 133 self.device_id.serialize(parcel)?; 134 Ok(()) 135 } 136 } 137 138 impl Deserialize for GetCoordinationStateParam { deserialize(parcel: &BorrowedMsgParcel<'_>) -> IpcResult<Self>139 fn deserialize(parcel: &BorrowedMsgParcel<'_>) -> IpcResult<Self> 140 { 141 call_debug_enter!("GetCoordinationStateParam::deserialize"); 142 Ok(Self { 143 user_data: i32::deserialize(parcel)?, 144 device_id: String::deserialize(parcel)?, 145 }) 146 } 147 } 148