client: Avoid obsolete src/kdbus.c functions

Stop using the src/kdbus.c functions that duplicate ell functionality so
they can be removed.  Actually connect to dbus and for now just listen
for signals.
This commit is contained in:
Andrew Zaborowski 2016-04-02 01:05:42 +02:00 committed by Denis Kenzior
parent 0e5d83b3eb
commit f983196d44
1 changed files with 57 additions and 6 deletions

View File

@ -25,14 +25,56 @@
#endif
#include <stdlib.h>
#include <stdio.h>
#include <ell/ell.h>
#include "src/kdbus.h"
static void signal_handler(struct l_signal *signal, uint32_t signo,
void *user_data)
{
switch (signo) {
case SIGINT:
case SIGTERM:
l_info("Terminate");
l_main_quit();
break;
}
}
static void signal_message(struct l_dbus_message *message, void *user_data)
{
const char *path, *interface, *member, *destination, *sender;
path = l_dbus_message_get_path(message);
destination = l_dbus_message_get_destination(message);
l_info("path=%s destination=%s", path, destination);
interface = l_dbus_message_get_interface(message);
member = l_dbus_message_get_member(message);
l_info("interface=%s member=%s", interface, member);
sender = l_dbus_message_get_sender(message);
l_info("sender=%s", sender);
}
int main(int argc, char *argv[])
{
char *bus_name;
char bus_address[64];
int exit_status;
struct l_dbus *dbus;
struct l_signal *signal;
sigset_t mask;
sigemptyset(&mask);
sigaddset(&mask, SIGINT);
sigaddset(&mask, SIGTERM);
signal = l_signal_create(&mask, signal_handler, NULL, NULL);
l_log_set_stderr();
l_debug_enable("*");
@ -45,18 +87,27 @@ int main(int argc, char *argv[])
l_debug("Bus location: %s", bus_name);
if (!kdbus_open_bus(bus_name, NULL, "iwctl")) {
snprintf(bus_address, sizeof(bus_address), "kernel:path=%s", bus_name);
l_free(bus_name);
dbus = l_dbus_new(bus_address);
if (!dbus) {
exit_status = EXIT_FAILURE;
goto destroy;
goto done;
}
l_dbus_add_signal_watch(dbus, "net.connman.iwd", NULL, NULL, NULL,
L_DBUS_MATCH_NONE, signal_message, NULL);
l_main_run();
exit_status = EXIT_SUCCESS;
destroy:
l_free(bus_name);
kdbus_close_bus();
l_dbus_destroy(dbus);
done:
l_signal_remove(signal);
return exit_status;
}