5 * Copyright (C) 2007-2009 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 #include <sys/types.h>
29 #define LIBUDEV_I_KNOW_THE_API_IS_SUBJECT_TO_CHANGE
36 #ifdef NEED_UDEV_MONITOR_RECEIVE_DEVICE
37 static struct udev_device *udev_monitor_receive_device(struct udev_monitor *monitor);
39 return udev_monitor_get_device(monitor);
43 #ifdef NEED_UDEV_DEVICE_GET_ACTION
44 static const char *udev_device_get_action(struct udev_device *device)
50 static gboolean udev_event(GIOChannel *channel,
51 GIOCondition condition, gpointer user_data)
53 struct udev_monitor *monitor = user_data;
54 struct udev_device *device;
57 device = udev_monitor_receive_device(monitor);
61 action = udev_device_get_action(device);
65 connman_debug("=== %s ===", action);
68 udev_device_unref(device);
73 static struct udev *udev_ctx;
74 static struct udev_monitor *udev_mon;
75 static guint udev_watch = 0;
77 int __connman_udev_init(void)
84 udev_ctx = udev_new();
85 if (udev_ctx == NULL) {
86 connman_error("Failed to create udev context");
90 udev_mon = udev_monitor_new_from_socket(udev_ctx,
91 "@/org/moblin/connman/udev");
92 if (udev_mon == NULL) {
93 connman_error("Failed to create udev monitor");
99 if (udev_monitor_enable_receiving(udev_mon) < 0) {
100 connman_error("Failed to enable udev monitor");
101 udev_unref(udev_ctx);
103 udev_monitor_unref(udev_mon);
107 fd = udev_monitor_get_fd(udev_mon);
109 channel = g_io_channel_unix_new(fd);
113 udev_watch = g_io_add_watch(channel, G_IO_IN, udev_event, udev_mon);
115 g_io_channel_unref(channel);
120 void __connman_udev_cleanup(void)
125 g_source_remove(udev_watch);
127 if (udev_ctx == NULL)
130 udev_monitor_unref(udev_mon);
131 udev_unref(udev_ctx);