Style
This commit is contained in:
parent
2f1f22ab26
commit
c10caca34c
@ -2,18 +2,19 @@
|
|||||||
#include <node_timer.h>
|
#include <node_timer.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
|
namespace node {
|
||||||
|
|
||||||
using namespace v8;
|
using namespace v8;
|
||||||
using namespace node;
|
|
||||||
|
|
||||||
Persistent<FunctionTemplate> Timer::constructor_template;
|
Persistent<FunctionTemplate> Timer::constructor_template;
|
||||||
|
|
||||||
|
|
||||||
static Persistent<String> timeout_symbol;
|
static Persistent<String> timeout_symbol;
|
||||||
static Persistent<String> repeat_symbol;
|
static Persistent<String> repeat_symbol;
|
||||||
static Persistent<String> callback_symbol;
|
static Persistent<String> callback_symbol;
|
||||||
|
|
||||||
void
|
|
||||||
Timer::Initialize (Handle<Object> target)
|
void Timer::Initialize(Handle<Object> target) {
|
||||||
{
|
|
||||||
HandleScope scope;
|
HandleScope scope;
|
||||||
|
|
||||||
Local<FunctionTemplate> t = FunctionTemplate::New(Timer::New);
|
Local<FunctionTemplate> t = FunctionTemplate::New(Timer::New);
|
||||||
@ -35,9 +36,9 @@ Timer::Initialize (Handle<Object> target)
|
|||||||
target->Set(String::NewSymbol("Timer"), constructor_template->GetFunction());
|
target->Set(String::NewSymbol("Timer"), constructor_template->GetFunction());
|
||||||
}
|
}
|
||||||
|
|
||||||
Handle<Value>
|
|
||||||
Timer::RepeatGetter (Local<String> property, const AccessorInfo& info)
|
Handle<Value> Timer::RepeatGetter(Local<String> property,
|
||||||
{
|
const AccessorInfo& info) {
|
||||||
HandleScope scope;
|
HandleScope scope;
|
||||||
Timer *timer = ObjectWrap::Unwrap<Timer>(info.This());
|
Timer *timer = ObjectWrap::Unwrap<Timer>(info.This());
|
||||||
|
|
||||||
@ -49,9 +50,9 @@ Timer::RepeatGetter (Local<String> property, const AccessorInfo& info)
|
|||||||
return scope.Close(v);
|
return scope.Close(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void Timer::RepeatSetter(Local<String> property,
|
||||||
Timer::RepeatSetter (Local<String> property, Local<Value> value, const AccessorInfo& info)
|
Local<Value> value,
|
||||||
{
|
const AccessorInfo& info) {
|
||||||
HandleScope scope;
|
HandleScope scope;
|
||||||
Timer *timer = ObjectWrap::Unwrap<Timer>(info.This());
|
Timer *timer = ObjectWrap::Unwrap<Timer>(info.This());
|
||||||
|
|
||||||
@ -61,9 +62,7 @@ Timer::RepeatSetter (Local<String> property, Local<Value> value, const AccessorI
|
|||||||
timer->watcher_.repeat = NODE_V8_UNIXTIME(value);
|
timer->watcher_.repeat = NODE_V8_UNIXTIME(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void Timer::OnTimeout(EV_P_ ev_timer *watcher, int revents) {
|
||||||
Timer::OnTimeout (EV_P_ ev_timer *watcher, int revents)
|
|
||||||
{
|
|
||||||
Timer *timer = static_cast<Timer*>(watcher->data);
|
Timer *timer = static_cast<Timer*>(watcher->data);
|
||||||
|
|
||||||
assert(revents == EV_TIMEOUT);
|
assert(revents == EV_TIMEOUT);
|
||||||
@ -89,14 +88,13 @@ Timer::OnTimeout (EV_P_ ev_timer *watcher, int revents)
|
|||||||
if (timer->watcher_.repeat == 0) timer->Unref();
|
if (timer->watcher_.repeat == 0) timer->Unref();
|
||||||
}
|
}
|
||||||
|
|
||||||
Timer::~Timer ()
|
|
||||||
{
|
Timer::~Timer() {
|
||||||
ev_timer_stop(EV_DEFAULT_UC_ &watcher_);
|
ev_timer_stop(EV_DEFAULT_UC_ &watcher_);
|
||||||
}
|
}
|
||||||
|
|
||||||
Handle<Value>
|
|
||||||
Timer::New (const Arguments& args)
|
Handle<Value> Timer::New(const Arguments& args) {
|
||||||
{
|
|
||||||
if (!args.IsConstructCall()) {
|
if (!args.IsConstructCall()) {
|
||||||
return FromConstructorTemplate(constructor_template, args);
|
return FromConstructorTemplate(constructor_template, args);
|
||||||
}
|
}
|
||||||
@ -109,9 +107,7 @@ Timer::New (const Arguments& args)
|
|||||||
return args.This();
|
return args.This();
|
||||||
}
|
}
|
||||||
|
|
||||||
Handle<Value>
|
Handle<Value> Timer::Start(const Arguments& args) {
|
||||||
Timer::Start (const Arguments& args)
|
|
||||||
{
|
|
||||||
HandleScope scope;
|
HandleScope scope;
|
||||||
Timer *timer = ObjectWrap::Unwrap<Timer>(args.Holder());
|
Timer *timer = ObjectWrap::Unwrap<Timer>(args.Holder());
|
||||||
|
|
||||||
@ -178,3 +174,6 @@ Handle<Value> Timer::Again(const Arguments& args) {
|
|||||||
|
|
||||||
return Undefined();
|
return Undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace node
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef node_timer_h
|
#ifndef SRC_NODE_TIMER_H_
|
||||||
#define node_timer_h
|
#define SRC_NODE_TIMER_H_
|
||||||
|
|
||||||
#include <node.h>
|
#include <node.h>
|
||||||
#include <node_object_wrap.h>
|
#include <node_object_wrap.h>
|
||||||
@ -20,14 +20,18 @@ class Timer : ObjectWrap {
|
|||||||
ev_timer_init(&watcher_, OnTimeout, 0., 1.);
|
ev_timer_init(&watcher_, OnTimeout, 0., 1.);
|
||||||
watcher_.data = this;
|
watcher_.data = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
~Timer();
|
~Timer();
|
||||||
|
|
||||||
static v8::Handle<v8::Value> New(const v8::Arguments& args);
|
static v8::Handle<v8::Value> New(const v8::Arguments& args);
|
||||||
static v8::Handle<v8::Value> Start(const v8::Arguments& args);
|
static v8::Handle<v8::Value> Start(const v8::Arguments& args);
|
||||||
static v8::Handle<v8::Value> Stop(const v8::Arguments& args);
|
static v8::Handle<v8::Value> Stop(const v8::Arguments& args);
|
||||||
static v8::Handle<v8::Value> Again(const v8::Arguments& args);
|
static v8::Handle<v8::Value> Again(const v8::Arguments& args);
|
||||||
static v8::Handle<v8::Value> RepeatGetter (v8::Local<v8::String> property, const v8::AccessorInfo& info);
|
static v8::Handle<v8::Value> RepeatGetter(v8::Local<v8::String> property,
|
||||||
static void RepeatSetter (v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::AccessorInfo& info);
|
const v8::AccessorInfo& info);
|
||||||
|
static void RepeatSetter(v8::Local<v8::String> property,
|
||||||
|
v8::Local<v8::Value> value,
|
||||||
|
const v8::AccessorInfo& info);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void OnTimeout(EV_P_ ev_timer *watcher, int revents);
|
static void OnTimeout(EV_P_ ev_timer *watcher, int revents);
|
||||||
@ -36,4 +40,4 @@ class Timer : ObjectWrap {
|
|||||||
};
|
};
|
||||||
|
|
||||||
} // namespace node
|
} // namespace node
|
||||||
#endif // node_timer_h
|
#endif // SRC_NODE_TIMER_H_
|
||||||
|
Loading…
x
Reference in New Issue
Block a user