Browse Source

Use uniform watcher names

v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
8492c52e15
  1. 10
      src/node.cc
  2. 6
      src/node.js
  3. 46
      src/node_signal_watcher.cc
  4. 12
      src/node_signal_watcher.h
  5. 34
      src/node_stat_watcher.cc
  6. 15
      src/node_stat_watcher.h
  7. 4
      wscript

10
src/node.cc

@ -18,8 +18,8 @@
#include <node_file.h>
#include <node_idle_watcher.h>
#include <node_http.h>
#include <node_signal_handler.h>
#include <node_stat.h>
#include <node_signal_watcher.h>
#include <node_stat_watcher.h>
#include <node_timer.h>
#include <node_child_process.h>
#include <node_constants.h>
@ -1103,17 +1103,17 @@ static Handle<Value> Binding(const Arguments& args) {
stats_constructor_template = Persistent<FunctionTemplate>::New(stat_templ);
exports->Set(String::NewSymbol("Stats"),
stats_constructor_template->GetFunction());
Stat::Initialize(exports);
StatWatcher::Initialize(exports);
File::Initialize(exports);
binding_cache->Set(module, exports);
}
} else if (!strcmp(*module_v, "signal_handler")) {
} else if (!strcmp(*module_v, "signal_watcher")) {
if (binding_cache->Has(module)) {
exports = binding_cache->Get(module)->ToObject();
} else {
exports = Object::New();
SignalHandler::Initialize(exports);
SignalWatcher::Initialize(exports);
binding_cache->Set(module, exports);
}

6
src/node.js

@ -281,9 +281,9 @@ function isSignal (event) {
process.addListener("newListener", function (event) {
if (isSignal(event) && process.listeners(event).length === 0) {
var b = process.binding('signal_handler');
var handler = new b.SignalHandler(process[event]);
handler.addListener("signal", function () {
var b = process.binding('signal_watcher');
var w = new b.SignalWatcher(process[event]);
w.addListener("signal", function () {
process.emit(event);
});
}

46
src/node_signal_handler.cc → src/node_signal_watcher.cc

@ -1,48 +1,48 @@
// Copyright 2009 Ryan Dahl <ry@tinyclouds.org>
#include <node_signal_handler.h>
#include <node_signal_watcher.h>
#include <assert.h>
namespace node {
using namespace v8;
Persistent<FunctionTemplate> SignalHandler::constructor_template;
Persistent<FunctionTemplate> SignalWatcher::constructor_template;
static Persistent<String> signal_symbol;
void SignalHandler::Initialize(Handle<Object> target) {
void SignalWatcher::Initialize(Handle<Object> target) {
HandleScope scope;
Local<FunctionTemplate> t = FunctionTemplate::New(SignalHandler::New);
Local<FunctionTemplate> t = FunctionTemplate::New(SignalWatcher::New);
constructor_template = Persistent<FunctionTemplate>::New(t);
constructor_template->Inherit(EventEmitter::constructor_template);
constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
constructor_template->SetClassName(String::NewSymbol("SignalHandler"));
constructor_template->SetClassName(String::NewSymbol("SignalWatcher"));
NODE_SET_PROTOTYPE_METHOD(constructor_template, "stop", SignalHandler::Stop);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "stop", SignalWatcher::Stop);
signal_symbol = NODE_PSYMBOL("signal");
target->Set(String::NewSymbol("SignalHandler"),
target->Set(String::NewSymbol("SignalWatcher"),
constructor_template->GetFunction());
}
void SignalHandler::OnSignal(EV_P_ ev_signal *watcher, int revents) {
SignalHandler *handler = static_cast<SignalHandler*>(watcher->data);
void SignalWatcher::OnSignal(EV_P_ ev_signal *watcher, int revents) {
SignalWatcher *w = static_cast<SignalWatcher*>(watcher->data);
HandleScope scope;
assert(revents == EV_SIGNAL);
handler->Emit(signal_symbol, 0, NULL);
w->Emit(signal_symbol, 0, NULL);
}
SignalHandler::~SignalHandler() {
SignalWatcher::~SignalWatcher() {
if (watcher_.active) {
ev_ref(EV_DEFAULT_UC);
ev_signal_stop(EV_DEFAULT_UC_ &watcher_);
}
}
Handle<Value> SignalHandler::New(const Arguments& args) {
Handle<Value> SignalWatcher::New(const Arguments& args) {
HandleScope scope;
if (args.Length() != 1 || !args[0]->IsInt32()) {
@ -51,29 +51,29 @@ Handle<Value> SignalHandler::New(const Arguments& args) {
int sig = args[0]->Int32Value();
SignalHandler *handler = new SignalHandler();
handler->Wrap(args.Holder());
SignalWatcher *w = new SignalWatcher();
w->Wrap(args.Holder());
ev_signal_init(&handler->watcher_, SignalHandler::OnSignal, sig);
handler->watcher_.data = handler;
ev_signal_init(&w->watcher_, SignalWatcher::OnSignal, sig);
w->watcher_.data = w;
// Give signal handlers very high priority. The only thing that has higher
// priority is the garbage collector check.
ev_set_priority(&handler->watcher_, EV_MAXPRI-1);
ev_signal_start(EV_DEFAULT_UC_ &handler->watcher_);
ev_set_priority(&w->watcher_, EV_MAXPRI-1);
ev_signal_start(EV_DEFAULT_UC_ &w->watcher_);
ev_unref(EV_DEFAULT_UC);
handler->Ref();
w->Ref();
return args.This();
}
Handle<Value> SignalHandler::Stop(const Arguments& args) {
Handle<Value> SignalWatcher::Stop(const Arguments& args) {
HandleScope scope;
SignalHandler *handler = ObjectWrap::Unwrap<SignalHandler>(args.Holder());
SignalWatcher *w = ObjectWrap::Unwrap<SignalWatcher>(args.Holder());
ev_ref(EV_DEFAULT_UC);
ev_signal_stop(EV_DEFAULT_UC_ &handler->watcher_);
handler->Unref();
ev_signal_stop(EV_DEFAULT_UC_ &w->watcher_);
w->Unref();
return Undefined();
}

12
src/node_signal_handler.h → src/node_signal_watcher.h

@ -1,6 +1,6 @@
// Copyright 2009 Ryan Dahl <ry@tinyclouds.org>
#ifndef SRC_SIGNAL_HANDLER_H_
#define SRC_SIGNAL_HANDLER_H_
#ifndef NODE_SIGNAL_WATCHER_H_
#define NODE_SIGNAL_WATCHER_H_
#include <node.h>
#include <node_events.h>
@ -10,15 +10,15 @@
namespace node {
class SignalHandler : EventEmitter {
class SignalWatcher : EventEmitter {
public:
static void Initialize(v8::Handle<v8::Object> target);
protected:
static v8::Persistent<v8::FunctionTemplate> constructor_template;
SignalHandler() : EventEmitter() { }
~SignalHandler();
SignalWatcher() : EventEmitter() { }
~SignalWatcher();
static v8::Handle<v8::Value> New(const v8::Arguments& args);
static v8::Handle<v8::Value> Stop(const v8::Arguments& args);
@ -29,5 +29,5 @@ class SignalHandler : EventEmitter {
};
} // namespace node
#endif // SRC_SIGNAL_HANDLER_H_
#endif // NODE_SIGNAL_WATCHER_H_

34
src/node_stat.cc → src/node_stat_watcher.cc

@ -1,5 +1,5 @@
// Copyright 2009 Ryan Dahl <ry@tinyclouds.org>
#include <node_stat.h>
#include <node_stat_watcher.h>
#include <assert.h>
#include <string.h>
@ -9,33 +9,33 @@ namespace node {
using namespace v8;
Persistent<FunctionTemplate> Stat::constructor_template;
Persistent<FunctionTemplate> StatWatcher::constructor_template;
static Persistent<String> change_symbol;
static Persistent<String> stop_symbol;
void Stat::Initialize(Handle<Object> target) {
void StatWatcher::Initialize(Handle<Object> target) {
HandleScope scope;
Local<FunctionTemplate> t = FunctionTemplate::New(Stat::New);
Local<FunctionTemplate> t = FunctionTemplate::New(StatWatcher::New);
constructor_template = Persistent<FunctionTemplate>::New(t);
constructor_template->Inherit(EventEmitter::constructor_template);
constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
constructor_template->SetClassName(String::NewSymbol("StatWatcher"));
constructor_template->SetClassName(String::NewSymbol("StatWatcherWatcher"));
change_symbol = NODE_PSYMBOL("change");
stop_symbol = NODE_PSYMBOL("stop");
NODE_SET_PROTOTYPE_METHOD(constructor_template, "start", Stat::Start);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "stop", Stat::Stop);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "start", StatWatcher::Start);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "stop", StatWatcher::Stop);
target->Set(String::NewSymbol("StatWatcher"), constructor_template->GetFunction());
target->Set(String::NewSymbol("StatWatcherWatcher"), constructor_template->GetFunction());
}
void Stat::Callback(EV_P_ ev_stat *watcher, int revents) {
void StatWatcher::Callback(EV_P_ ev_stat *watcher, int revents) {
assert(revents == EV_STAT);
Stat *handler = static_cast<Stat*>(watcher->data);
StatWatcher *handler = static_cast<StatWatcher*>(watcher->data);
assert(watcher == &handler->watcher_);
HandleScope scope;
Handle<Value> argv[2];
@ -45,22 +45,22 @@ void Stat::Callback(EV_P_ ev_stat *watcher, int revents) {
}
Handle<Value> Stat::New(const Arguments& args) {
Handle<Value> StatWatcher::New(const Arguments& args) {
HandleScope scope;
Stat *s = new Stat();
StatWatcher *s = new StatWatcher();
s->Wrap(args.Holder());
return args.This();
}
Handle<Value> Stat::Start(const Arguments& args) {
Handle<Value> StatWatcher::Start(const Arguments& args) {
HandleScope scope;
if (args.Length() < 1 || !args[0]->IsString()) {
return ThrowException(Exception::TypeError(String::New("Bad arguments")));
}
Stat *handler = ObjectWrap::Unwrap<Stat>(args.Holder());
StatWatcher *handler = ObjectWrap::Unwrap<StatWatcher>(args.Holder());
String::Utf8Value path(args[0]->ToString());
assert(handler->path_ == NULL);
@ -86,16 +86,16 @@ Handle<Value> Stat::Start(const Arguments& args) {
}
Handle<Value> Stat::Stop(const Arguments& args) {
Handle<Value> StatWatcher::Stop(const Arguments& args) {
HandleScope scope;
Stat *handler = ObjectWrap::Unwrap<Stat>(args.Holder());
StatWatcher *handler = ObjectWrap::Unwrap<StatWatcher>(args.Holder());
handler->Emit(stop_symbol, 0, NULL);
handler->Stop();
return Undefined();
}
void Stat::Stop () {
void StatWatcher::Stop () {
if (watcher_.active) {
if (!persistent_) ev_ref(EV_DEFAULT_UC);
ev_stat_stop(EV_DEFAULT_UC_ &watcher_);

15
src/node_stat.h → src/node_stat_watcher.h

@ -1,6 +1,6 @@
// Copyright 2009 Ryan Dahl <ry@tinyclouds.org>
#ifndef NODE_STAT_H_
#define NODE_STAT_H_
#ifndef NODE_STAT_WATCHER_H_
#define NODE_STAT_WATCHER_H_
#include <node.h>
#include <node_events.h>
@ -8,21 +8,21 @@
namespace node {
class Stat : EventEmitter {
class StatWatcher : EventEmitter {
public:
static void Initialize(v8::Handle<v8::Object> target);
protected:
static v8::Persistent<v8::FunctionTemplate> constructor_template;
Stat() : EventEmitter() {
StatWatcher() : EventEmitter() {
persistent_ = false;
path_ = NULL;
ev_init(&watcher_, Stat::Callback);
ev_init(&watcher_, StatWatcher::Callback);
watcher_.data = this;
}
~Stat() {
~StatWatcher() {
Stop();
assert(path_ == NULL);
}
@ -42,5 +42,4 @@ class Stat : EventEmitter {
};
} // namespace node
#endif // NODE_STAT_H_
#endif // NODE_STAT_WATCHER_H_

4
wscript

@ -372,8 +372,8 @@ def build(bld):
src/node_file.cc
src/node_http.cc
src/node_net.cc
src/node_signal_handler.cc
src/node_stat.cc
src/node_signal_watcher.cc
src/node_stat_watcher.cc
src/node_stdio.cc
src/node_timer.cc
src/node_idle_watcher.cc

Loading…
Cancel
Save