mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-12-22 13:02:44 +01:00
dbus: Add basic D-Bus plumbing
This commit is contained in:
parent
59612f450b
commit
429ea08202
@ -44,7 +44,8 @@ src_iwd_SOURCES = src/main.c linux/nl80211.h linux/kdbus.h \
|
||||
src/netdev.h src/netdev.c \
|
||||
src/wiphy.h src/wiphy.c \
|
||||
src/sha1.h src/sha1.c \
|
||||
src/ie.h src/ie.c
|
||||
src/ie.h src/ie.c \
|
||||
src/dbus.h src/dbus.c
|
||||
src_iwd_LDADD = ell/libell-internal.la
|
||||
|
||||
client_iwctl_SOURCES = client/main.c linux/kdbus.h \
|
||||
|
102
src/dbus.c
Normal file
102
src/dbus.c
Normal file
@ -0,0 +1,102 @@
|
||||
/*
|
||||
*
|
||||
* Wireless daemon for Linux
|
||||
*
|
||||
* Copyright (C) 2013-2014 Intel Corporation. All rights reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <ell/ell.h>
|
||||
#include "src/dbus.h"
|
||||
|
||||
struct l_dbus *g_dbus = 0;
|
||||
|
||||
static void do_debug(const char *str, void *user_data)
|
||||
{
|
||||
const char *prefix = user_data;
|
||||
|
||||
l_info("%s%s", prefix, str);
|
||||
}
|
||||
|
||||
static void request_name_callback(struct l_dbus_message *message,
|
||||
void *user_data)
|
||||
{
|
||||
const char *error, *text;
|
||||
uint32_t result;
|
||||
|
||||
if (l_dbus_message_get_error(message, &error, &text)) {
|
||||
l_error("error=%s", error);
|
||||
l_error("message=%s", text);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!l_dbus_message_get_arguments(message, "u", &result))
|
||||
return;
|
||||
|
||||
l_info("request name result=%d", result);
|
||||
}
|
||||
|
||||
static void request_name_setup(struct l_dbus_message *message, void *user_data)
|
||||
{
|
||||
const char *name = "net.connman.iwd";
|
||||
|
||||
l_dbus_message_set_arguments(message, "su", name, 0);
|
||||
}
|
||||
|
||||
static void ready_callback(void *user_data)
|
||||
{
|
||||
l_info("ready");
|
||||
}
|
||||
|
||||
static void disconnect_callback(void *user_data)
|
||||
{
|
||||
l_info("D-Bus disconnected, quitting...");
|
||||
l_main_quit();
|
||||
}
|
||||
|
||||
struct l_dbus *dbus_get_bus(void)
|
||||
{
|
||||
return g_dbus;
|
||||
}
|
||||
|
||||
bool dbus_init(void)
|
||||
{
|
||||
g_dbus = l_dbus_new_default(L_DBUS_SYSTEM_BUS);
|
||||
l_dbus_set_debug(g_dbus, do_debug, "[DBUS] ", NULL);
|
||||
l_dbus_set_ready_handler(g_dbus, ready_callback, g_dbus, NULL);
|
||||
l_dbus_set_disconnect_handler(g_dbus, disconnect_callback, NULL, NULL);
|
||||
|
||||
l_dbus_method_call(g_dbus, "org.freedesktop.DBus",
|
||||
"/org/freedesktop/DBus",
|
||||
"org.freedesktop.DBus", "RequestName",
|
||||
request_name_setup,
|
||||
request_name_callback, NULL, NULL);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool dbus_exit(void)
|
||||
{
|
||||
l_dbus_destroy(g_dbus);
|
||||
g_dbus = NULL;
|
||||
|
||||
return true;
|
||||
}
|
30
src/dbus.h
Normal file
30
src/dbus.h
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
*
|
||||
* Wireless daemon for Linux
|
||||
*
|
||||
* Copyright (C) 2013-2014 Intel Corporation. All rights reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
struct l_dbus;
|
||||
|
||||
struct l_dbus *dbus_get_bus(void);
|
||||
|
||||
bool dbus_init(void);
|
||||
bool dbus_exit(void);
|
@ -32,6 +32,7 @@
|
||||
#include "src/netdev.h"
|
||||
#include "src/wiphy.h"
|
||||
#include "src/kdbus.h"
|
||||
#include "src/dbus.h"
|
||||
|
||||
static void signal_handler(struct l_signal *signal, uint32_t signo,
|
||||
void *user_data)
|
||||
@ -139,6 +140,11 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
if (!dbus_init()) {
|
||||
exit_status = EXIT_FAILURE;
|
||||
goto destroy;
|
||||
}
|
||||
|
||||
if (!netdev_init()) {
|
||||
exit_status = EXIT_FAILURE;
|
||||
goto destroy;
|
||||
@ -154,6 +160,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
wiphy_exit();
|
||||
netdev_exit();
|
||||
dbus_exit();
|
||||
|
||||
exit_status = EXIT_SUCCESS;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user