#include <glib.h>
+#include "lib/bluetooth.h"
+#include "lib/sdp.h"
+
#include "log.h"
#include "adapter.h"
-#include "manager.h"
#include "hcid.h"
enum rfkill_type {
memset(sysname, 0, sizeof(sysname));
- if (read(fd, sysname, sizeof(sysname)) < 4) {
+ if (read(fd, sysname, sizeof(sysname) - 1) < 4) {
close(fd);
return TRUE;
}
if (id < 0)
return TRUE;
- adapter = manager_find_adapter_by_id(id);
+ adapter = adapter_find_by_id(id);
if (!adapter)
return TRUE;
return TRUE;
}
-static GIOChannel *channel = NULL;
+static guint watch = 0;
void rfkill_init(void)
{
int fd;
-
- if (!main_opts.remember_powered)
- return;
+ GIOChannel *channel;
fd = open("/dev/rfkill", O_RDWR);
if (fd < 0) {
channel = g_io_channel_unix_new(fd);
g_io_channel_set_close_on_unref(channel, TRUE);
- g_io_add_watch(channel, G_IO_IN | G_IO_NVAL | G_IO_HUP | G_IO_ERR,
- rfkill_event, NULL);
+ watch = g_io_add_watch(channel,
+ G_IO_IN | G_IO_NVAL | G_IO_HUP | G_IO_ERR,
+ rfkill_event, NULL);
+
+ g_io_channel_unref(channel);
}
void rfkill_exit(void)
{
- if (!channel)
+ if (watch == 0)
return;
- g_io_channel_shutdown(channel, TRUE, NULL);
- g_io_channel_unref(channel);
-
- channel = NULL;
+ g_source_remove(watch);
+ watch = 0;
}