From 126e3ba2d381ae1b8a5539f4f369895f77711bdf Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Wed, 8 Jun 2011 04:01:07 +0200 Subject: [PATCH] Get rid of node_idle_watcher --- src/node.cc | 4 -- src/node_idle_watcher.cc | 145 --------------------------------------- src/node_idle_watcher.h | 62 ----------------- 3 files changed, 211 deletions(-) delete mode 100644 src/node_idle_watcher.cc delete mode 100644 src/node_idle_watcher.h diff --git a/src/node.cc b/src/node.cc index 0e9834176c8..e248309c491 100644 --- a/src/node.cc +++ b/src/node.cc @@ -57,10 +57,6 @@ #include #include #include -#if 0 -// not in use -# include -#endif #include #include #include diff --git a/src/node_idle_watcher.cc b/src/node_idle_watcher.cc deleted file mode 100644 index 293714a0038..00000000000 --- a/src/node_idle_watcher.cc +++ /dev/null @@ -1,145 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -#include - -#include -#include - -#include - -namespace node { - -using namespace v8; - -Persistent IdleWatcher::constructor_template; -static Persistent callback_symbol; - -void IdleWatcher::Initialize(Handle target) { - HandleScope scope; - - Local t = FunctionTemplate::New(IdleWatcher::New); - constructor_template = Persistent::New(t); - constructor_template->InstanceTemplate()->SetInternalFieldCount(1); - constructor_template->SetClassName(String::NewSymbol("IdleWatcher")); - - NODE_SET_PROTOTYPE_METHOD(constructor_template, "start", IdleWatcher::Start); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "stop", IdleWatcher::Stop); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "setPriority", - IdleWatcher::SetPriority); - - target->Set(String::NewSymbol("IdleWatcher"), constructor_template->GetFunction()); - - callback_symbol = NODE_PSYMBOL("callback"); -} - - -Handle IdleWatcher::SetPriority(const Arguments& args) { - IdleWatcher *idle = ObjectWrap::Unwrap(args.Holder()); - - HandleScope scope; - - int priority = args[0]->Int32Value(); - - ev_set_priority(&idle->watcher_, priority); - - return Undefined(); -} - - -void IdleWatcher::Callback(EV_P_ ev_idle *w, int revents) { - IdleWatcher *idle = static_cast(w->data); - - assert(w == &idle->watcher_); - assert(revents == EV_IDLE); - - HandleScope scope; - - Local callback_v = idle->handle_->Get(callback_symbol); - if (!callback_v->IsFunction()) { - idle->Stop(); - return; - } - - Local callback = Local::Cast(callback_v); - - TryCatch try_catch; - - callback->Call(idle->handle_, 0, NULL); - - if (try_catch.HasCaught()) { - FatalException(try_catch); - } -} - - -// -// var idle = new process.IdleWatcher(); -// idle.callback = function () { /* ... */ }; -// idle.start(); -// -Handle IdleWatcher::New(const Arguments& args) { - if (!args.IsConstructCall()) { - return FromConstructorTemplate(constructor_template, args); - } - - HandleScope scope; - - IdleWatcher *s = new IdleWatcher(); - s->Wrap(args.This()); - - return args.This(); -} - - -Handle IdleWatcher::Start(const Arguments& args) { - HandleScope scope; - IdleWatcher *idle = ObjectWrap::Unwrap(args.Holder()); - idle->Start(); - return Undefined(); -} - - -void IdleWatcher::Start () { - if (!watcher_.active) { - ev_idle_start(EV_DEFAULT_UC_ &watcher_); - Ref(); - } -} - - -Handle IdleWatcher::Stop(const Arguments& args) { - HandleScope scope; - IdleWatcher *idle = ObjectWrap::Unwrap(args.Holder()); - idle->Stop(); - return Undefined(); -} - - -void IdleWatcher::Stop () { - if (watcher_.active) { - ev_idle_stop(EV_DEFAULT_UC_ &watcher_); - Unref(); - } -} - - -} // namespace node diff --git a/src/node_idle_watcher.h b/src/node_idle_watcher.h deleted file mode 100644 index c1c7bd21abb..00000000000 --- a/src/node_idle_watcher.h +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -#ifndef NODE_IDLE_H_ -#define NODE_IDLE_H_ - -#include -#include - -namespace node { - -class IdleWatcher : ObjectWrap { - public: - static void Initialize(v8::Handle target); - - protected: - static v8::Persistent constructor_template; - - IdleWatcher() : ObjectWrap() { - ev_idle_init(&watcher_, IdleWatcher::Callback); - watcher_.data = this; - } - - ~IdleWatcher() { - ev_idle_stop(EV_DEFAULT_UC_ &watcher_); - } - - static v8::Handle New(const v8::Arguments& args); - static v8::Handle Start(const v8::Arguments& args); - static v8::Handle Stop(const v8::Arguments& args); - static v8::Handle SetPriority(const v8::Arguments& args); - - private: - static void Callback(EV_P_ ev_idle *watcher, int revents); - - void Start(); - void Stop(); - - ev_idle watcher_; -}; - -} // namespace node -#endif // NODE_IDLE_H_ -