1 /* 2 * Copyright (C) 2022 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 //! Safe Rust interface to OHOS IPC/RPC 17 18 mod ipc_binding; 19 mod errors; 20 mod ipc; 21 mod ipc_async; 22 mod parcel; 23 mod process; 24 mod ashmem; 25 26 // Export types of this crate 27 pub use crate::errors::{IpcResult, status_result, IpcStatusCode, parse_status_code}; 28 pub use crate::ipc::{ 29 IRemoteBroker, IRemoteObj, IRemoteStub, FromRemoteObj, 30 RemoteObjRef, remote_obj::RemoteObj, remote_obj::death_recipient::DeathRecipient, remote_stub::RemoteStub, 31 }; 32 pub use crate::ipc_async::{ 33 IpcAsyncPool, IpcAsyncRuntime, ToAsyncIpc, ToSyncIpc, 34 BoxFuture, Ylong, Runtime, 35 }; 36 37 pub use crate::parcel::{ 38 MsgParcel, BorrowedMsgParcel, IMsgParcel, RawData, 39 parcelable::{Serialize, Deserialize, SerOption, DeOption}, 40 }; 41 pub use crate::parcel::parcelable::{SerArray, DeArray}; 42 pub use crate::parcel::types::{ 43 interface_token::InterfaceToken, file_desc::FileDesc, string16::String16 44 }; 45 pub use crate::ashmem::{ 46 Ashmem, PROT_NONE, PROT_READ, PROT_WRITE, 47 PROT_EXEC, 48 }; 49 pub use crate::process::{ 50 get_context_object, add_service, get_service, join_work_thread, 51 stop_work_thread, get_calling_uid, get_calling_token_id, get_first_token_id, 52 get_self_token_id, get_calling_pid, set_max_work_thread, is_local_calling, 53 set_calling_identity, get_local_device_id, get_calling_device_id, reset_calling_identity, 54 is_handling_transaction, 55 }; 56 57 pub use crate::ipc_binding::{CRemoteObject, CIRemoteObject}; 58 59 /// First request code available for user IPC request(inclusive) 60 pub const FIRST_CALL_TRANSACTION: isize = 0x00000001; 61 /// Last request code available for user IPC request(inclusive) 62 pub const LAST_CALL_TRANSACTION: isize = 0x00ffffff; 63 64 /// Trait for transparent Rust wrappers around native raw pointer types. 65 /// 66 /// # Safety 67 /// 68 /// The pointer return by this trait's methods should be immediately passed to 69 /// native and not stored by Rust. The pointer is valid only as long as the 70 /// underlying native object is alive, so users must be careful to take this into 71 /// account, as Rust cannot enforce this. 72 /// 73 /// For this trait to be a correct implementation, `T` must be a valid native 74 /// type. Since we cannot constrain this via the type system, this trait is 75 /// marked as unsafe. 76 pub unsafe trait AsRawPtr<T> { 77 /// Return a pointer to the native version of `self` as_raw(&self) -> *const T78 fn as_raw(&self) -> *const T; 79 80 /// Return a mutable pointer to the native version of `self` as_mut_raw(&mut self) -> *mut T81 fn as_mut_raw(&mut self) -> *mut T; 82 }