@@ -6,95 +6,76 @@ namespace node {
66
77using namespace v8 ;
88
9- Persistent<FunctionTemplate> SignalWatcher::constructor_template;
10- static Persistent<String> callback_symbol;
119
1210void SignalWatcher::Initialize (Handle<Object> target) {
1311 HandleScope scope;
1412
15- Local<FunctionTemplate> t = FunctionTemplate::New (SignalWatcher::New);
16- constructor_template = Persistent<FunctionTemplate>::New (t);
17- constructor_template->InstanceTemplate ()->SetInternalFieldCount (1 );
18- constructor_template->SetClassName (String::NewSymbol (" SignalWatcher" ));
13+ Local<FunctionTemplate> t = BuildTemplate<SignalWatcher>(" SignalWatcher" );
1914
20- NODE_SET_PROTOTYPE_METHOD (constructor_template, " start" , SignalWatcher::Start);
21- NODE_SET_PROTOTYPE_METHOD (constructor_template, " stop" , SignalWatcher::Stop);
15+ NODE_SET_PROTOTYPE_METHOD (t, " start" , Start);
16+ NODE_SET_PROTOTYPE_METHOD (t, " stop" , Stop);
17+ NODE_SET_PROTOTYPE_METHOD (t, " set" , Set);
2218
23- target->Set (String::NewSymbol (" SignalWatcher" ),
24- constructor_template->GetFunction ());
25-
26- callback_symbol = NODE_PSYMBOL (" callback" );
19+ target->Set (String::NewSymbol (" SignalWatcher" ), t->GetFunction ());
2720}
2821
22+
2923void SignalWatcher::Callback (EV_P_ ev_signal *watcher, int revents) {
3024 SignalWatcher *w = static_cast <SignalWatcher*>(watcher->data );
31-
3225 assert (watcher == &w->watcher_ );
33-
34- HandleScope scope;
35-
36- Local<Value> callback_v = w->handle_ ->Get (callback_symbol);
37- if (!callback_v->IsFunction ()) {
38- w->Stop ();
39- return ;
40- }
41-
42- Local<Function> callback = Local<Function>::Cast (callback_v);
43-
44- TryCatch try_catch;
45-
46- callback->Call (w->handle_ , 0 , NULL );
47-
48- if (try_catch.HasCaught ()) {
49- FatalException (try_catch);
50- }
26+ w->MakeCallback (0 , NULL );
5127}
5228
53- Handle<Value> SignalWatcher::New (const Arguments& args) {
29+
30+ Handle<Value> SignalWatcher::Set (const Arguments& args) {
5431 HandleScope scope;
32+ SignalWatcher *w = ObjectWrap::Unwrap<SignalWatcher>(args.Holder ());
5533
5634 if (args.Length () != 1 || !args[0 ]->IsInt32 ()) {
5735 return ThrowException (String::New (" Bad arguments" ));
5836 }
5937
6038 int sig = args[0 ]->Int32Value ();
6139
62- SignalWatcher *w = new SignalWatcher (sig);
63- w->Wrap (args.Holder ());
64-
65- return args.This ();
40+ ev_signal_set (&w->watcher_ , sig);
41+ return Undefined ();
6642}
6743
44+
6845Handle<Value> SignalWatcher::Start (const Arguments& args) {
6946 HandleScope scope;
7047 SignalWatcher *w = ObjectWrap::Unwrap<SignalWatcher>(args.Holder ());
7148 w->Start ();
7249 return Undefined ();
7350}
7451
52+
7553void SignalWatcher::Start () {
76- if (!watcher_. active ) {
54+ if (!ev_is_active (& watcher_) ) {
7755 ev_signal_start (EV_DEFAULT_UC_ &watcher_);
7856 ev_unref (EV_DEFAULT_UC);
79- Ref ();
57+ Active ();
8058 }
8159}
8260
61+
8362Handle<Value> SignalWatcher::Stop (const Arguments& args) {
8463 HandleScope scope;
8564 SignalWatcher *w = ObjectWrap::Unwrap<SignalWatcher>(args.Holder ());
8665 w->Stop ();
8766 return Undefined ();
8867}
8968
69+
9070void SignalWatcher::Stop () {
91- if (watcher_. active ) {
71+ if (ev_is_active (& watcher_) ) {
9272 ev_ref (EV_DEFAULT_UC);
9373 ev_signal_stop (EV_DEFAULT_UC_ &watcher_);
94- Unref ();
74+ Inactive ();
9575 }
9676}
9777
78+
9879} // namespace node
9980
10081NODE_MODULE (node_signal_watcher, node::SignalWatcher::Initialize);
0 commit comments