• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (C) 2024 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 use crate::dispatcher::PinWeaverDispatcher;
18 use crate::service::PinWeaverService;
19 use crate::storage::{StorageClient, StorageClientService};
20 use binder::BinderFeatures;
21 use pinweaver_api::aidl::IPinWeaver::BnPinWeaver;
22 use rpcbinder::RpcServer;
23 use std::rc::Rc;
24 use std::sync::Arc;
25 use tipc::{Manager, PortCfg};
26 
27 mod dispatcher;
28 mod service;
29 mod storage;
30 
31 const PORT_COUNT: usize = 2;
32 const CONNECTION_COUNT: usize = 4;
33 
init_and_start_loop() -> tipc::Result<()>34 pub fn init_and_start_loop() -> tipc::Result<()> {
35     trusty_log::init();
36     let storage = Arc::new(StorageClient::default());
37     let storage_service = StorageClientService::new(storage.clone());
38 
39     let service =
40         BnPinWeaver::new_binder(PinWeaverService::new(storage), BinderFeatures::default());
41     let rpc_server = RpcServer::new_per_session(move |_uuid| Some(service.as_binder()));
42 
43     let mut dispatcher =
44         PinWeaverDispatcher::<PORT_COUNT>::new().expect("Dispatcher should be created");
45 
46     let service_cfg = PortCfg::new(pinweaver_api::PORT)
47         .expect("Service port shouldn't contain nul")
48         .allow_ta_connect();
49     dispatcher
50         .add_service(Rc::new(rpc_server), service_cfg)
51         .expect("RPC service should add to dispatcher");
52 
53     let storage_cfg = PortCfg::new(pinweaver_storage::current::PORT)
54         .expect("Storage port shouldn't contain nul")
55         .allow_ns_connect();
56     dispatcher
57         .add_service(Rc::new(storage_service), storage_cfg)
58         .expect("Storage service should add to dispatcher");
59 
60     Manager::<_, _, PORT_COUNT, CONNECTION_COUNT>::new_with_dispatcher(dispatcher, [])
61         .expect("Service manager should be created")
62         .run_event_loop()
63 }
64