class UEvent : Service
{
- protected int sock;
+ protected IOChannel sock;
+ protected uint sock_watch = 0;
+ public Omhacks.UEvent.Event event_data;
+ public signal void event();
+
+ public UEvent()
+ {
+ event_data = Omhacks.UEvent.Event();
+ }
+
+ protected bool on_input_data(IOChannel source, IOCondition condition)
+ {
+ if (condition != IOCondition.IN) return true;
+
+ Omhacks.UEvent.read(sock.unix_get_fd(), ref event_data);
+ event();
+
+ return true;
+ }
/// Activate the service
protected override void start()
{
if (started) return;
- sock = Omhacks.UEvent.open();
- if (sock < 0)
+ int sock_fd = Omhacks.UEvent.open();
+ if (sock_fd < 0)
{
zavai.log.error("UEvent: error getting socket");
return;
}
+ sock = new IOChannel.unix_new(sock_fd);
+ sock_watch = sock.add_watch(IOCondition.IN, on_input_data);
+
base.start();
}
protected override void stop()
{
if (!started) return;
- // Do here
+ Source.remove(sock_watch);
+ try {
+ sock.shutdown(false);
+ } catch (IOChannelError e) {
+ zavai.log.error("When closing UEvent socket: " + e.message);
+ }
+ sock = null;
base.stop();
}
}