Rev 1601 | Rev 1608 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1601 | Rev 1604 | ||
|---|---|---|---|
| Line 18... | Line 18... | ||
| 18 | * |
18 | * |
| 19 | */ |
19 | */ |
| 20 | 20 | ||
| 21 | #include "Timer.h" |
21 | #include "Timer.h" |
| 22 | 22 | ||
| 23 | #include <v8.h> |
23 | #include <v8-debug.h> |
| 24 | #include <stdio.h> |
24 | #include <stdio.h> |
| 25 | 25 | ||
| 26 | #include <boost/concept_check.hpp> |
26 | #include <boost/concept_check.hpp> |
| 27 | #include <boost/lexical_cast.hpp> |
27 | #include <boost/lexical_cast.hpp> |
| 28 | 28 | ||
| Line 32... | Line 32... | ||
| 32 | namespace atom { |
32 | namespace atom { |
| 33 | namespace vm { |
33 | namespace vm { |
| 34 | namespace plugin { |
34 | namespace plugin { |
| 35 | 35 | ||
| 36 | logging::Logger Timer::LOG("vm::plugin::Timer"); |
36 | logging::Logger Timer::LOG("vm::plugin::Timer"); |
| - | 37 | ||
| - | 38 | Timer::Timers Timer::timers_; |
|
| 37 | 39 | ||
| 38 | Timer::Timer() |
40 | Timer::Timer() |
| 39 | { |
41 | { |
| 40 | this->name_ = "timer"; |
42 | this->name_ = "timer"; |
| 41 | 43 | ||
| 42 | this->ImportFunction("Timer_OnTimeout"); |
44 | this->ImportFunction("Timer_OnTimeout"); |
| 43 | 45 | ||
| 44 | this->ExportFunction("StartTimer", Timer::Export_StartTimer); |
46 | this->ExportFunction("StartTimer", Timer::Export_StartTimer); |
| 45 | this->ExportFunction("ClearTimer", Timer::Export_ClearTimer); |
47 | this->ExportFunction("ClearTimer", Timer::Export_ClearTimer); |
| 46 | } |
48 | } |
| 47 | 49 | ||
| 48 | Timer::~Timer() |
50 | Timer::~Timer() |
| 49 | { |
51 | { |
| 50 | 52 | ||
| - | 53 | } |
|
| - | 54 | ||
| - | 55 | void Timer::InitializeDone() |
|
| - | 56 | { |
|
| - | 57 | atom::vm::Plugin::InitializeDone(); |
|
| - | 58 | ||
| - | 59 | timer::Manager::Instance()->ConnectSlots(timer::Manager::SignalOnTimeout::slot_type(&Timer::SlotOnTimeout, this, _1, _2).track(this->tracker_)); |
|
| 51 | } |
60 | } |
| 52 | 61 | ||
| 53 | void Timer:: |
62 | void Timer::SlotOnTimeout(timer::TimerId timer_id, bool repeat) |
| 54 | { |
63 | { |
| - | 64 | if (!repeat) |
|
| - | 65 | { |
|
| - | 66 | Timers::iterator it = Timer::timers_.find(timer_id); |
|
| - | 67 | ||
| - | 68 | if (it != Timer::timers_.end()) |
|
| - | 69 | { |
|
| - | 70 | Timer::timers_.erase(it); |
|
| - | 71 | } |
|
| - | 72 | } |
|
| - | 73 | ||
| 55 | ArgumentListPointer arguments = ArgumentListPointer(new ArgumentList); |
74 | ArgumentListPointer arguments = ArgumentListPointer(new ArgumentList); |
| 56 | arguments->push_back(v8::Integer::New(timer_id)); |
75 | arguments->push_back(v8::Integer::New(timer_id)); |
| 57 | arguments->push_back(v8::Boolean::New(repeat)); |
76 | arguments->push_back(v8::Boolean::New(repeat)); |
| 58 | 77 | ||
| 59 | this->Call("Timer_OnTimeout", arguments); |
78 | this->Call("Timer_OnTimeout", arguments); |
| 60 | } |
79 | } |
| 61 | 80 | ||
| 62 | Value Timer::Export_StartTimer(const v8::Arguments& args) |
81 | Value Timer::Export_StartTimer(const v8::Arguments& args) |
| 63 | { |
82 | { |
| - | 83 | LOG.Debug(std::string(__FUNCTION__) + " called!"); |
|
| - | 84 | ||
| - | 85 | if (args.Length() < 2) |
|
| - | 86 | { |
|
| - | 87 | LOG.Error("To few arguments."); |
|
| - | 88 | } |
|
| - | 89 | ||
| 64 |
|
90 | timer::TimerId timer_id = timer::Manager::Instance()->Set(args[0]->Uint32Value(), args[1]->BooleanValue()); |
| - | 91 | ||
| - | 92 | Timer::timers_.insert(timer_id); |
|
| - | 93 | ||
| - | 94 | return v8::Integer::New(timer_id); |
|
| - | 95 | } |
|
| - | 96 | ||
| - | 97 | Value Timer::Export_ClearTimer(const v8::Arguments& args) |
|
| - | 98 | { |
|
| - | 99 | LOG.Debug(std::string(__FUNCTION__) + " called!"); |
|
| - | 100 | ||
| - | 101 | if (args.Length() < 1) |
|
| - | 102 | { |
|
| - | 103 | LOG.Error("To few arguments."); |
|
| - | 104 | } |
|
| - | 105 | ||
| - | 106 | Timers::iterator it = Timer::timers_.find(args[0]->IsUint32()); |
|
| - | 107 | ||
| - | 108 | if (it != Timer::timers_.end()) |
|
| - | 109 | { |
|
| - | 110 | Timer::timers_.erase(it); |
|
| 65 | } |
111 | } |
| 66 | 112 | ||
| 67 | Value Timer::Export_ClearTimer(const v8::Arguments& args) |
- | |
| 68 | { |
- | |
| 69 | timer::Manager::Instance()->Cancel(args[0]->IsUint32()); |
113 | timer::Manager::Instance()->Cancel(args[0]->IsUint32()); |
| 70 | return v8::Undefined(); |
114 | return v8::Undefined(); |
| 71 | } |
115 | } |
| 72 | 116 | ||
| 73 | }; // namespace plugin |
117 | }; // namespace plugin |