tmisu

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

commit 5966e3302168f768687337f2aaac007289156e34
parent 66887b914234cdb50ff626ee80b8e19a1d1b5cf4
Author: Sweets <Sweets@users.noreply.github.com>
Date:   Sat, 25 Apr 2020 12:28:29 -0700

More work

Diffstat:
MMakefile | 15+++++++++++++--
Acallbacks.c | 42++++++++++++++++++++++++++++++++++++++++++
Acallbacks.h | 8++++++++
Mnote.c | 24+++++++++++++++++++-----
Mnote.h | 5+++--
5 files changed, 85 insertions(+), 9 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,3 +1,14 @@ -all: - $(CC) `pkg-config --libs --cflags glib-2.0 gio-2.0` note.c +TARGET = note +SRC := note.c callbacks.c + +CFLAGS = -Wall +LDFLAGS = $(shell pkg-config --libs --cflags glib-2.0 gio-2.0) + +all: $(TARGET) + +$(TARGET): $(OBJ) + $(CC) $(CFLAGS) $(LDFLAGS) $(SRC) -o $(TARGET) + +clean: + $(RM) ./note diff --git a/callbacks.c b/callbacks.c @@ -0,0 +1,42 @@ +#include "note.h" +#include "callbacks.h" + +void notification_received(GDBusConnection *connection, const gchar *sender, + GVariant *parameters, GDBusMethodInvocation *invocation) { + // +/* GVariantIter iterator; + GVariant *value; + gchar *key; + GVariant *dictionary; + + g_variant_iter_init(&iterator, dictionary); + while (g_variant_iter_loop(&iterator, "s", &key, &value)) { + g_print("Item '%s' has type '%s'\n", key, + g_variant_get_type_string(value)); + }*/ +} + +void bus_acquired(GDBusConnection *connection, const gchar *name, + gpointer user_data) { + printf("%s\n", "Bus has been acquired."); +} + +void name_acquired(GDBusConnection *connection, const gchar *name, + gpointer user_data) { + dbus_connection = connection; + printf("%s\n", "Name has been acquired."); +} + +void name_lost(GDBusConnection *connection, const gchar *name, + gpointer user_data) { + // we lost the Notifications daemon name or couldn't acquire it, shutdown + + if (!connection) { + printf("%s; %s\n", + "Unable to connect to acquire org.freedesktop.Notifications", + "could not connect to dbus."); + } else + printf("%s", "Successfully acquired org.freedesktop.Notifications"); + + exit(1); +} diff --git a/callbacks.h b/callbacks.h @@ -0,0 +1,8 @@ +#pragma once + +#include <gio/gio.h> +#include <glib.h> + +void bus_acquired(GDBusConnection*, const gchar*, gpointer); +void name_acquired(GDBusConnection*, const gchar*, gpointer); +void name_lost(GDBusConnection*, const gchar*, gpointer); diff --git a/note.c b/note.c @@ -5,9 +5,13 @@ #include <glib.h> #include "note.h" +#include "callbacks.h" #include "config.h" GDBusConnection *dbus_connection = NULL; + +/* Build introspection XML based on configuration */ + const char *introspection = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" "<node name=\"/org/freedesktop/Notifications\">\n" " <interface name=\"org.freedesktop.Notifications\">\n" @@ -34,21 +38,31 @@ const char *introspection = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" "</node>"; int main(int argc, char **argv) { - /* Build introspection */ + GMainLoop *main_loop; + guint owned_name; GDBusNodeInfo *introspection_data; + /* Connect to DBUS */ + introspection_data = g_dbus_node_info_new_for_xml(introspection, NULL); owned_name = g_bus_own_name(G_BUS_TYPE_SESSION, "org.freedesktop.Notifications", G_BUS_NAME_OWNER_FLAGS_NONE, - NULL, NULL, NULL, NULL, NULL); + (GBusAcquiredCallback)bus_acquired, /* bus_acquired_handler */ + (GBusNameAcquiredCallback)name_acquired, /* name_acquired_handler */ + (GBusNameLostCallback)name_lost, /* name_lost_handler */ + NULL, /* user_data */ + NULL); /* user_data_free_func */ + + /* Setup and start the loop */ + + main_loop = g_main_loop_new(NULL, FALSE); - printf("%s\n", introspection); - sleep(10); + 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_bus_unown_name(owned_name); - /* What now? */ } diff --git a/note.h b/note.h @@ -1,8 +1,9 @@ #pragma once +#include <stdio.h> +#include <string.h> + #include <gio/gio.h> #include <glib.h> extern GDBusConnection *dbus_connection; - -char *build_introspection_xml(void);