2 * uevent - zavai uevent handling
4 * Copyright (C) 2009 Enrico Zini <enrico@enricozini.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 class UEvent : Service
28 protected IOChannel sock;
29 protected uint sock_watch = 0;
30 public Omhacks.UEvent.Event event_data;
31 public signal void event();
35 //event_data = Omhacks.UEvent.Event();
38 protected bool on_input_data(IOChannel source, IOCondition condition)
40 if (condition != IOCondition.IN) return true;
42 Omhacks.UEvent.read(sock.unix_get_fd(), ref event_data);
48 /// Activate the service
49 protected override void start()
53 int sock_fd = Omhacks.UEvent.open();
56 zavai.log.error("UEvent: error getting socket");
60 sock = new IOChannel.unix_new(sock_fd);
61 sock_watch = sock.add_watch(IOCondition.IN, on_input_data);
66 /// Deactivate the service
67 protected override void stop()
70 Source.remove(sock_watch);
73 } catch (IOChannelError e) {
74 zavai.log.error("When closing UEvent socket: " + e.message);
85 if (Posix.getuid() == 0)
86 uevent = new UEvent();