• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 //! Common items useful for binder clients and/or servers.
18 
19 pub mod lazy_service;
20 pub mod rpc_client;
21 pub mod rpc_server;
22 
23 use binder::{ExceptionCode, Status};
24 use std::ffi::CString;
25 
26 /// Constructs a new Binder error `Status` with the given `ExceptionCode` and message.
new_binder_exception<T: AsRef<str>>(exception: ExceptionCode, message: T) -> Status27 pub fn new_binder_exception<T: AsRef<str>>(exception: ExceptionCode, message: T) -> Status {
28     match exception {
29         ExceptionCode::SERVICE_SPECIFIC => new_binder_service_specific_error(-1, message),
30         _ => Status::new_exception(exception, to_cstring(message).as_deref()),
31     }
32 }
33 
34 /// Constructs a Binder `Status` representing a service-specific exception with the given code and
35 /// message.
new_binder_service_specific_error<T: AsRef<str>>(code: i32, message: T) -> Status36 pub fn new_binder_service_specific_error<T: AsRef<str>>(code: i32, message: T) -> Status {
37     Status::new_service_specific_error(code, to_cstring(message).as_deref())
38 }
39 
to_cstring<T: AsRef<str>>(message: T) -> Option<CString>40 fn to_cstring<T: AsRef<str>>(message: T) -> Option<CString> {
41     CString::new(message.as_ref()).ok()
42 }
43