Initial commit master
authorJacob Casper <dev@jacobcasper.com>
Fri, 30 Oct 2020 21:41:54 +0000 (16:41 -0500)
committerJacob Casper <dev@jacobcasper.com>
Fri, 30 Oct 2020 21:41:54 +0000 (16:41 -0500)
.gitignore [new file with mode: 0644]
Cargo.lock [new file with mode: 0644]
Cargo.toml [new file with mode: 0644]
README.md [new file with mode: 0644]
src/main.rs [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..ea8c4bf
--- /dev/null
@@ -0,0 +1 @@
+/target
diff --git a/Cargo.lock b/Cargo.lock
new file mode 100644 (file)
index 0000000..c38cbb4
--- /dev/null
@@ -0,0 +1,49 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+[[package]]
+name = "dbus"
+version = "0.9.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "22c08adfeb70c940c14d8af988fa854dcb5529e6141f2397e4e0fa4c9375d094"
+dependencies = [
+ "libc",
+ "libdbus-sys",
+]
+
+[[package]]
+name = "dbus-crossroads"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0a816e8ae3382c7b1bccfa6f2778346ee5b13f80e0eccf80cf8f2912af73995a"
+dependencies = [
+ "dbus",
+]
+
+[[package]]
+name = "libc"
+version = "0.2.80"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4d58d1b70b004888f764dfbf6a26a3b0342a1632d33968e4a179d8011c760614"
+
+[[package]]
+name = "libdbus-sys"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dc12a3bc971424edbbf7edaf6e5740483444db63aa8e23d3751ff12a30f306f0"
+dependencies = [
+ "pkg-config",
+]
+
+[[package]]
+name = "mail-dbus"
+version = "0.1.0"
+dependencies = [
+ "dbus",
+ "dbus-crossroads",
+]
+
+[[package]]
+name = "pkg-config"
+version = "0.3.19"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c"
diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644 (file)
index 0000000..6358a73
--- /dev/null
@@ -0,0 +1,11 @@
+[package]
+name = "mail-dbus"
+version = "0.1.0"
+authors = ["Jacob Casper <git@jacobcasper.com>"]
+edition = "2018"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+dbus = "0.9.0"
+dbus-crossroads = "0.3.0"
diff --git a/README.md b/README.md
new file mode 100644 (file)
index 0000000..949501d
--- /dev/null
+++ b/README.md
@@ -0,0 +1,2 @@
+# mail-dbus
+A bouncer that registers a dbus interface name and sends a signal as a reaction to a method call.
diff --git a/src/main.rs b/src/main.rs
new file mode 100644 (file)
index 0000000..3f412dc
--- /dev/null
@@ -0,0 +1,28 @@
+use dbus::blocking::Connection;
+use dbus_crossroads::{Context, Crossroads};
+use std::error::Error;
+
+fn main() -> Result<(), Box<dyn Error>> {
+    let service_name: &'static str = "com.jacobcasper.Mail";
+    let conn = Connection::new_session()?;
+    conn.request_name(service_name, false, true, false)?;
+
+    let mut crossroads = Crossroads::new();
+
+    let interface_token = crossroads.register(service_name, |builder| {
+        builder.signal::<(u32,), _>("UnreadCount", ("count",));
+        builder.method(
+            "UnreadCount",
+            ("count",),
+            (),
+            |ctx: &mut Context, _, (count,): (u32,)| {
+                ctx.push_msg(ctx.make_signal("UnreadCount", (count,)));
+                Ok(())
+            },
+        );
+    });
+
+    crossroads.insert("/com/jacobcasper/Mail/Unread", &[interface_token], ());
+    crossroads.serve(&conn)?;
+    unreachable!()
+}