Skip to content

Commit 3019066

Browse files
author
Jeff Kim
committed
Updated examples to use the latest APIs.
1 parent 1ba5343 commit 3019066

File tree

6 files changed

+25
-20
lines changed

6 files changed

+25
-20
lines changed

example-hello/src/bin/hello_client.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use std::sync::Arc;
66
use env_logger::Env;
77
use rsbinder::*;
8-
use hub::{IServiceManager, IServiceCallback, BnServiceCallback};
8+
use hub::{IServiceCallback, BnServiceCallback};
99
use example_hello::*;
1010

1111
struct MyServiceCallback {
@@ -32,20 +32,17 @@ impl DeathRecipient for MyDeathRecipient {
3232
fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
3333
env_logger::Builder::from_env(Env::default().default_filter_or("warn")).init();
3434

35-
// Initialize ProcessState with binder path and max threads.
36-
// The meaning of zero max threads is to use the default value. It is dependent on the kernel.
37-
ProcessState::init(DEFAULT_BINDER_PATH, 0);
38-
// Get binder service manager.
39-
let hub = hub::default();
35+
// Initialize ProcessState with the default binder path and the default max threads.
36+
ProcessState::init_default();
4037

4138
println!("list services:");
4239
// This is an example of how to use service manager.
43-
for name in hub.listServices(hub::DUMP_FLAG_PRIORITY_DEFAULT)? {
40+
for name in hub::list_services(hub::DUMP_FLAG_PRIORITY_DEFAULT) {
4441
println!("{}", name);
4542
}
4643

4744
let service_callback = BnServiceCallback::new_binder(MyServiceCallback{});
48-
hub.registerForNotifications(SERVICE_NAME, &service_callback)?;
45+
hub::register_for_notifications(SERVICE_NAME, &service_callback)?;
4946

5047
// Create a Hello proxy from binder service manager.
5148
let hello: rsbinder::Strong<dyn IHello> = hub::get_interface(SERVICE_NAME)
@@ -58,8 +55,5 @@ fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
5855

5956
println!("Result: {echo}");
6057

61-
// sleep 1 second
62-
// std::thread::sleep(std::time::Duration::from_secs(1));
63-
6458
Ok(ProcessState::join_thread_pool()?)
6559
}

example-hello/src/bin/hello_service.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,24 @@
33

44
use env_logger::Env;
55
use rsbinder::*;
6-
use hub::IServiceManager;
76

87
use example_hello::*;
98

9+
// Define the name of the service to be registered in the HUB(service manager).
1010
struct IHelloService;
1111

12+
// Implement the IHello interface for the IHelloService.
1213
impl Interface for IHelloService {
14+
// Reimplement the dump method. This is optional.
1315
fn dump(&self, writer: &mut dyn std::io::Write, _args: &[String]) -> Result<()> {
1416
writeln!(writer, "Dump IHelloService")?;
1517
Ok(())
1618
}
1719
}
1820

21+
// Implement the IHello interface for the IHelloService.
1922
impl IHello for IHelloService {
23+
// Implement the echo method.
2024
fn echo(&self, echo: &str) -> rsbinder::status::Result<String> {
2125
Ok(echo.to_owned())
2226
}
@@ -25,16 +29,20 @@ impl IHello for IHelloService {
2529
fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
2630
env_logger::Builder::from_env(Env::default().default_filter_or("warn")).init();
2731

28-
// Initialize ProcessState with binder path and max threads.
29-
// The meaning of zero max threads is to use the default value. It is dependent on the kernel.
30-
ProcessState::init(DEFAULT_BINDER_PATH, 0);
32+
// Initialize ProcessState with the default binder path and the default max threads.
33+
ProcessState::init_default();
34+
35+
// Start the thread pool.
36+
// This is optional. If you don't call this, only one thread will be created to handle the binder transactions.
37+
ProcessState::start_thread_pool();
3138

3239
// Create a binder service.
3340
let service = BnHello::new_binder(IHelloService{});
3441

3542
// Add the service to binder service manager.
36-
let hub = hub::default();
37-
hub.addService(SERVICE_NAME, &service.as_binder(), false, hub::DUMP_FLAG_PRIORITY_DEFAULT)?;
43+
hub::add_service(SERVICE_NAME, service.as_binder())?;
3844

45+
// Join the thread pool.
46+
// This is a blocking call. It will return when the thread pool is terminated.
3947
Ok(ProcessState::join_thread_pool()?)
4048
}

example-hello/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
// Copyright 2022 Jeff Kim <hiking90@gmail.com>
22
// SPDX-License-Identifier: Apache-2.0
33

4+
// Include the code hello.rs generated from AIDL.
45
include!(concat!(env!("OUT_DIR"), "/hello.rs"));
56

7+
// Set up to use the APIs provided in the code generated for Client and Service.
68
pub use crate::hello::IHello::*;
79

10+
// Define the name of the service to be registered in the HUB(service manager).
811
pub const SERVICE_NAME: &str = "my.hello";

rsbinder-aidl/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.2.0"
44
edition = "2021"
55
license = "Apache-2.0"
66
description = "This is a AIDL compiler for rsbinder."
7-
homepage = "https://github.com/hiking90/rsbinder"
7+
homepage = "https://hiking90.github.io/rsbinder-book/"
88
repository = "https://github.com/hiking90/rsbinder/rsbinder-aidl"
99
readme = "README.md"
1010
rust-version = "1.71"

rsbinder-tools/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.2.0"
44
edition = "2021"
55
license = "Apache-2.0"
66
description = "This provides a few CLI binder tools for Linux."
7-
homepage = "https://github.com/hiking90/rsbinder"
7+
homepage = "https://hiking90.github.io/rsbinder-book/"
88
repository = "https://github.com/hiking90/rsbinder/rsbinder-tools"
99
readme = "README.md"
1010

rsbinder/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.2.0"
44
edition = "2021"
55
license = "Apache-2.0"
66
description = "This is a library for Linux Binder communication."
7-
homepage = "https://github.com/hiking90/rsbinder"
7+
homepage = "https://hiking90.github.io/rsbinder-book/"
88
repository = "https://github.com/hiking90/rsbinder"
99
readme = "README.md"
1010
rust-version = "1.71"

0 commit comments

Comments
 (0)