tmisu

Notification to stdout daemon
git clone https://git.inz.fi/tmisu/
Log | Files | Refs | README | LICENSE

commit b57cbb8e0990f40735006286c18c7f7d46c4076a
parent 0dff99ab7b5001a058b7603589d45c39688aaf8e
Author: Sweets <Sweets@users.noreply.github.com>
Date:   Sat, 25 Apr 2020 16:19:23 -0700

is baby.

Diffstat:
Mcallbacks.c | 31++++++++++++++++++++++++++-----
Mcallbacks.h | 3+++
Mtiramisu.c | 8++++----
Mtiramisu.h | 5+++++
4 files changed, 38 insertions(+), 9 deletions(-)

diff --git a/callbacks.c b/callbacks.c @@ -16,15 +16,36 @@ void notification_received(GDBusConnection *connection, const gchar *sender, }*/ } +void method_handler(GDBusConnection *connection, const gchar *sender, + const gchar *object, const gchar *interface, const gchar *method, + GVariant *parameters, GDBusMethodInvocation *invocation, + gpointer user_data) { + + if (!strcmp(method, "Notify")) { + // ? + } + + print("%s %s\n", method, sender); + +} + void bus_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data) { - printf("%s\n", "Bus has been acquired."); + print("%s\n", "Bus has been acquired."); + + guint registered_object; + registered_object = g_dbus_connection_register_object(connection, + "/org/freedesktop/Notifications", introspection->interfaces[0], + &(const GDBusInterfaceVTable){ method_handler }, NULL, NULL, NULL); + + if (!registered_object) + print("%s\n", "Unable to register."); } void name_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data) { dbus_connection = connection; - printf("%s\n", "Name has been acquired."); + print("%s\n", "Name has been acquired."); } void name_lost(GDBusConnection *connection, const gchar *name, @@ -32,11 +53,11 @@ void name_lost(GDBusConnection *connection, const gchar *name, // we lost the Notifications daemon name or couldn't acquire it, shutdown if (!connection) { - printf("%s; %s\n", + print("%s; %s\n", "Unable to connect to acquire org.freedesktop.Notifications", "could not connect to dbus."); + exit(1); } else - printf("%s", "Successfully acquired org.freedesktop.Notifications"); + print("%s", "Successfully acquired org.freedesktop.Notifications"); - exit(1); } diff --git a/callbacks.h b/callbacks.h @@ -3,6 +3,9 @@ #include <gio/gio.h> #include <glib.h> +void method_handler(GDBusConnection*, const gchar*, const gchar*, const gchar*, + const gchar*, GVariant*, GDBusMethodInvocation*, gpointer); + void bus_acquired(GDBusConnection*, const gchar*, gpointer); void name_acquired(GDBusConnection*, const gchar*, gpointer); void name_lost(GDBusConnection*, const gchar*, gpointer); diff --git a/tiramisu.c b/tiramisu.c @@ -9,10 +9,11 @@ #include "config.h" GDBusConnection *dbus_connection = NULL; +GDBusNodeInfo *introspection = NULL; /* Build introspection XML based on configuration */ -const char *introspection = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +const char *xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" "<node name=\"/org/freedesktop/Notifications\">\n" " <interface name=\"org.freedesktop.Notifications\">\n" " <method name=\"Notify\">\n" @@ -41,11 +42,10 @@ int main(int argc, char **argv) { GMainLoop *main_loop; guint owned_name; - GDBusNodeInfo *introspection_data; /* Connect to DBUS */ - introspection_data = g_dbus_node_info_new_for_xml(introspection, NULL); + introspection = g_dbus_node_info_new_for_xml(xml, NULL); owned_name = g_bus_own_name(G_BUS_TYPE_SESSION, "org.freedesktop.Notifications", G_BUS_NAME_OWNER_FLAGS_NONE, @@ -62,7 +62,7 @@ int main(int argc, char **argv) { g_main_loop_run(main_loop); g_clear_pointer(&main_loop, g_main_loop_unref); - g_clear_pointer(&introspection_data, g_dbus_node_info_unref); + g_clear_pointer(&introspection, g_dbus_node_info_unref); g_bus_unown_name(owned_name); } diff --git a/tiramisu.h b/tiramisu.h @@ -6,4 +6,9 @@ #include <gio/gio.h> #include <glib.h> +#include "config.h" + extern GDBusConnection *dbus_connection; +extern GDBusNodeInfo *introspection; + +#define print(...) fprintf(stderr, __VA_ARGS__);