diff --git a/examples/gio_dbus_register_object/main.rs b/examples/gio_dbus_register_object/main.rs
index e5d5302aa767..cc169a5a4d6b 100644
--- a/examples/gio_dbus_register_object/main.rs
+++ b/examples/gio_dbus_register_object/main.rs
@@ -1,126 +1,186 @@
-use gio::{prelude::*, IOErrorEnum};
-use std::{
- sync::mpsc::{channel, Receiver, Sender},
- time::Duration,
-};
-
-const EXAMPLE_XML: &str = r#"
-
-
-
-
-
-
-
-
-
-
-
-
-
-"#;
+use gio::prelude::*;
-#[derive(Debug, glib::Variant)]
-struct Hello {
- name: String,
+glib::wrapper! {
+ pub struct SampleApplication(ObjectSubclass)
+ @extends gio::Application,
+ @implements gio::ActionGroup, gio::ActionMap;
}
-#[derive(Debug, glib::Variant)]
-struct SlowHello {
- name: String,
- delay: u32,
+impl Default for SampleApplication {
+ fn default() -> Self {
+ glib::Object::builder()
+ .property(
+ "application-id",
+ "com.github.gtk-rs.examples.RegisterDBusObject",
+ )
+ .build()
+ }
}
-#[derive(Debug)]
-enum HelloMethod {
- Hello(Hello),
- SlowHello(SlowHello),
-}
+mod imp {
+ use std::cell::RefCell;
+ use std::time::Duration;
+
+ use gio::prelude::*;
+ use gio::subclass::prelude::*;
+ use gio::{DBusConnection, DBusError};
+
+ const EXAMPLE_XML: &str = r#"
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+"#;
+
+ #[derive(Debug, glib::Variant)]
+ struct Hello {
+ name: String,
+ }
+
+ #[derive(Debug, glib::Variant)]
+ struct SlowHello {
+ name: String,
+ delay: u32,
+ }
-impl DBusMethodCall for HelloMethod {
- fn parse_call(
- _obj_path: &str,
- _interface: Option<&str>,
- method: &str,
- params: glib::Variant,
- ) -> Result {
- match method {
- "Hello" => Ok(params.get::().map(Self::Hello)),
- "SlowHello" => Ok(params.get::().map(Self::SlowHello)),
- _ => Err(glib::Error::new(IOErrorEnum::Failed, "No such method")),
+ #[derive(Debug)]
+ enum HelloMethod {
+ Hello(Hello),
+ SlowHello(SlowHello),
+ GoodBye,
+ }
+
+ impl DBusMethodCall for HelloMethod {
+ fn parse_call(
+ _obj_path: &str,
+ _interface: Option<&str>,
+ method: &str,
+ params: glib::Variant,
+ ) -> Result {
+ match method {
+ "Hello" => Ok(params.get::().map(Self::Hello)),
+ "SlowHello" => Ok(params.get::().map(Self::SlowHello)),
+ "GoodBye" => Ok(Some(Self::GoodBye)),
+ _ => Err(glib::Error::new(DBusError::UnknownMethod, "No such method")),
+ }
+ .and_then(|p| {
+ p.ok_or_else(|| glib::Error::new(DBusError::InvalidArgs, "Invalid parameters"))
+ })
}
- .and_then(|p| p.ok_or_else(|| glib::Error::new(IOErrorEnum::Failed, "Invalid parameters")))
}
-}
-fn on_startup(app: &gio::Application, tx: &Sender) {
- let connection = app.dbus_connection().expect("connection");
-
- let example = gio::DBusNodeInfo::for_xml(EXAMPLE_XML)
- .ok()
- .and_then(|e| e.lookup_interface("com.github.gtk_rs.examples.HelloWorld"))
- .expect("Example interface");
-
- if let Ok(id) = connection
- .register_object("/com/github/gtk_rs/examples/HelloWorld", &example)
- .typed_method_call::()
- .invoke_and_return_future_local(|_, sender, call| {
- println!("Method call from {sender:?}");
- async {
- match call {
- HelloMethod::Hello(Hello { name }) => {
- let greet = format!("Hello {name}!");
- println!("{greet}");
- Ok(Some(greet.to_variant()))
- }
- HelloMethod::SlowHello(SlowHello { name, delay }) => {
- glib::timeout_future(Duration::from_secs(delay as u64)).await;
- let greet = format!("Hello {name} after {delay} seconds!");
- println!("{greet}");
- Ok(Some(greet.to_variant()))
+ #[derive(Default)]
+ pub struct SampleApplication {
+ registration_id: RefCell