mirror of https://github.com/nodejs/node.git
Style
parent
2f1f22ab26
commit
c10caca34c
|
@ -2,18 +2,19 @@
|
|||
#include <node_timer.h>
|
||||
#include <assert.h>
|
||||
|
||||
namespace node {
|
||||
|
||||
using namespace v8;
|
||||
using namespace node;
|
||||
|
||||
Persistent<FunctionTemplate> Timer::constructor_template;
|
||||
|
||||
|
||||
static Persistent<String> timeout_symbol;
|
||||
static Persistent<String> repeat_symbol;
|
||||
static Persistent<String> callback_symbol;
|
||||
|
||||
void
|
||||
Timer::Initialize (Handle<Object> target)
|
||||
{
|
||||
|
||||
void Timer::Initialize(Handle<Object> target) {
|
||||
HandleScope scope;
|
||||
|
||||
Local<FunctionTemplate> t = FunctionTemplate::New(Timer::New);
|
||||
|
@ -35,23 +36,23 @@ Timer::Initialize (Handle<Object> target)
|
|||
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;
|
||||
Timer *timer = ObjectWrap::Unwrap<Timer>(info.This());
|
||||
|
||||
assert(timer);
|
||||
assert (property == repeat_symbol);
|
||||
assert(property == repeat_symbol);
|
||||
|
||||
Local<Integer> v = Integer::New(timer->watcher_.repeat);
|
||||
|
||||
return scope.Close(v);
|
||||
}
|
||||
|
||||
void
|
||||
Timer::RepeatSetter (Local<String> property, Local<Value> value, const AccessorInfo& info)
|
||||
{
|
||||
void Timer::RepeatSetter(Local<String> property,
|
||||
Local<Value> value,
|
||||
const AccessorInfo& info) {
|
||||
HandleScope scope;
|
||||
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);
|
||||
}
|
||||
|
||||
void
|
||||
Timer::OnTimeout (EV_P_ ev_timer *watcher, int revents)
|
||||
{
|
||||
void Timer::OnTimeout(EV_P_ ev_timer *watcher, int revents) {
|
||||
Timer *timer = static_cast<Timer*>(watcher->data);
|
||||
|
||||
assert(revents == EV_TIMEOUT);
|
||||
|
@ -89,14 +88,13 @@ Timer::OnTimeout (EV_P_ ev_timer *watcher, int revents)
|
|||
if (timer->watcher_.repeat == 0) timer->Unref();
|
||||
}
|
||||
|
||||
Timer::~Timer ()
|
||||
{
|
||||
|
||||
Timer::~Timer() {
|
||||
ev_timer_stop(EV_DEFAULT_UC_ &watcher_);
|
||||
}
|
||||
|
||||
Handle<Value>
|
||||
Timer::New (const Arguments& args)
|
||||
{
|
||||
|
||||
Handle<Value> Timer::New(const Arguments& args) {
|
||||
if (!args.IsConstructCall()) {
|
||||
return FromConstructorTemplate(constructor_template, args);
|
||||
}
|
||||
|
@ -109,9 +107,7 @@ Timer::New (const Arguments& args)
|
|||
return args.This();
|
||||
}
|
||||
|
||||
Handle<Value>
|
||||
Timer::Start (const Arguments& args)
|
||||
{
|
||||
Handle<Value> Timer::Start(const Arguments& args) {
|
||||
HandleScope scope;
|
||||
Timer *timer = ObjectWrap::Unwrap<Timer>(args.Holder());
|
||||
|
||||
|
@ -145,7 +141,7 @@ Handle<Value> Timer::Stop(const Arguments& args) {
|
|||
}
|
||||
|
||||
|
||||
void Timer::Stop () {
|
||||
void Timer::Stop() {
|
||||
if (watcher_.active) {
|
||||
ev_timer_stop(EV_DEFAULT_UC_ &watcher_);
|
||||
Unref();
|
||||
|
@ -178,3 +174,6 @@ Handle<Value> Timer::Again(const Arguments& args) {
|
|||
|
||||
return Undefined();
|
||||
}
|
||||
|
||||
|
||||
} // namespace node
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef node_timer_h
|
||||
#define node_timer_h
|
||||
#ifndef SRC_NODE_TIMER_H_
|
||||
#define SRC_NODE_TIMER_H_
|
||||
|
||||
#include <node.h>
|
||||
#include <node_object_wrap.h>
|
||||
|
@ -10,30 +10,34 @@ namespace node {
|
|||
|
||||
class Timer : ObjectWrap {
|
||||
public:
|
||||
static void Initialize (v8::Handle<v8::Object> target);
|
||||
static void Initialize(v8::Handle<v8::Object> target);
|
||||
|
||||
protected:
|
||||
static v8::Persistent<v8::FunctionTemplate> constructor_template;
|
||||
|
||||
Timer () : ObjectWrap () {
|
||||
Timer() : ObjectWrap() {
|
||||
// dummy timeout values
|
||||
ev_timer_init(&watcher_, OnTimeout, 0., 1.);
|
||||
watcher_.data = this;
|
||||
}
|
||||
|
||||
~Timer();
|
||||
|
||||
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> Stop (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 void RepeatSetter (v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::AccessorInfo& info);
|
||||
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> Stop(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 void RepeatSetter(v8::Local<v8::String> property,
|
||||
v8::Local<v8::Value> value,
|
||||
const v8::AccessorInfo& info);
|
||||
|
||||
private:
|
||||
static void OnTimeout (EV_P_ ev_timer *watcher, int revents);
|
||||
void Stop ();
|
||||
static void OnTimeout(EV_P_ ev_timer *watcher, int revents);
|
||||
void Stop();
|
||||
ev_timer watcher_;
|
||||
};
|
||||
|
||||
} // namespace node
|
||||
#endif // node_timer_h
|
||||
} // namespace node
|
||||
#endif // SRC_NODE_TIMER_H_
|
||||
|
|
Loading…
Reference in New Issue