1 // Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
12 use std::rt::rtio::{RtioSignal, Callback};
14 use homing::{HomingIO, HomeHandle};
15 use super::{UvError, UvHandle};
17 use uvio::UvIoFactory;
19 pub struct SignalWatcher {
20 handle: *uvll::uv_signal_t,
23 cb: Box<Callback + Send>,
27 pub fn new(io: &mut UvIoFactory, signum: int, cb: Box<Callback + Send>)
28 -> Result<Box<SignalWatcher>, UvError> {
29 let s = box SignalWatcher {
30 handle: UvHandle::alloc(None::<SignalWatcher>, uvll::UV_SIGNAL),
31 home: io.make_handle(),
35 uvll::uv_signal_init(io.uv_loop(), s.handle)
39 uvll::uv_signal_start(s.handle, signal_cb, signum as c_int)
48 extern fn signal_cb(handle: *uvll::uv_signal_t, _signum: c_int) {
49 let s: &mut SignalWatcher = unsafe { UvHandle::from_uv_handle(&handle) };
53 impl HomingIO for SignalWatcher {
54 fn home<'r>(&'r mut self) -> &'r mut HomeHandle { &mut self.home }
57 impl UvHandle<uvll::uv_signal_t> for SignalWatcher {
58 fn uv_handle(&self) -> *uvll::uv_signal_t { self.handle }
61 impl RtioSignal for SignalWatcher {}
63 impl Drop for SignalWatcher {
65 let _m = self.fire_homing_missile();