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_ENABLE_RECEIVING
37 static int udev_monitor_enable_receiving(struct udev_monitor *monitor)
43 #ifdef NEED_UDEV_MONITOR_RECEIVE_DEVICE
44 static struct udev_device *udev_monitor_receive_device(struct udev_monitor *monitor)
46 return udev_monitor_get_device(monitor);
50 #ifdef NEED_UDEV_DEVICE_GET_ACTION
51 static const char *udev_device_get_action(struct udev_device *device)
57 static gboolean udev_event(GIOChannel *channel,
58 GIOCondition condition, gpointer user_data)
60 struct udev_monitor *monitor = user_data;
61 struct udev_device *device;
64 device = udev_monitor_receive_device(monitor);
68 action = udev_device_get_action(device);
72 connman_debug("=== %s ===", action);
75 udev_device_unref(device);
80 static struct udev *udev_ctx;
81 static struct udev_monitor *udev_mon;
82 static guint udev_watch = 0;
84 int __connman_udev_init(void)
91 udev_ctx = udev_new();
92 if (udev_ctx == NULL) {
93 connman_error("Failed to create udev context");
97 udev_mon = udev_monitor_new_from_socket(udev_ctx,
98 "@/org/moblin/connman/udev");
99 if (udev_mon == NULL) {
100 connman_error("Failed to create udev monitor");
101 udev_unref(udev_ctx);
106 if (udev_monitor_enable_receiving(udev_mon) < 0) {
107 connman_error("Failed to enable udev monitor");
108 udev_unref(udev_ctx);
110 udev_monitor_unref(udev_mon);
114 fd = udev_monitor_get_fd(udev_mon);
116 channel = g_io_channel_unix_new(fd);
120 udev_watch = g_io_add_watch(channel, G_IO_IN, udev_event, udev_mon);
122 g_io_channel_unref(channel);
127 void __connman_udev_cleanup(void)
132 g_source_remove(udev_watch);
134 if (udev_ctx == NULL)
137 udev_monitor_unref(udev_mon);
138 udev_unref(udev_ctx);