Subversion Repositories HomeAutomation

Rev

Rev 1740 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1740 Rev 1741
Line 72... Line 72...
72
 
72
 
73
void Timer::SlotOnTimeoutHandler(timer::TimerId timer_id, bool repeat)
73
void Timer::SlotOnTimeoutHandler(timer::TimerId timer_id, bool repeat)
74
{
74
{
75
    v8::Locker lock;
75
    v8::Locker lock;
76
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
76
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
-
 
77
    v8::HandleScope handle_scope;
77
 
78
 
78
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
79
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
79
   
80
   
80
    if (!repeat)
81
    if (!repeat)
81
    {
82
    {
Line 96... Line 97...
96
 
97
 
97
Value Timer::Export_SetAlarm(const v8::Arguments& args)
98
Value Timer::Export_SetAlarm(const v8::Arguments& args)
98
{
99
{
99
    v8::Locker lock;
100
    v8::Locker lock;
100
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
101
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
-
 
102
    v8::HandleScope handle_scope;
101
   
103
   
102
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
104
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
103
   
105
   
104
    if (args.Length() < 1)
106
    if (args.Length() < 1)
105
    {
107
    {
106
        LOG.Error(std::string(__FUNCTION__) + ": To few arguments.");
108
        LOG.Error(std::string(__FUNCTION__) + ": To few arguments.");
107
        return v8::Boolean::New(false);
109
        return handle_scope.Close(v8::Boolean::New(false));
108
    }
110
    }
109
   
111
   
110
    v8::String::AsciiValue time(args[0]);
112
    v8::String::AsciiValue time(args[0]);
111
   
113
   
112
    timer::TimerId timer_id = timer::Manager::Instance()->SetAlarm(*time);
114
    timer::TimerId timer_id = timer::Manager::Instance()->SetAlarm(*time);
113
   
115
   
114
    Timer::timers_.insert(timer_id);
116
    Timer::timers_.insert(timer_id);
115
   
117
   
116
    return v8::Integer::New(timer_id);
118
    return handle_scope.Close(v8::Integer::New(timer_id));
117
}
119
}
118
 
120
 
119
Value Timer::Export_SetTimer(const v8::Arguments& args)
121
Value Timer::Export_SetTimer(const v8::Arguments& args)
120
{
122
{
121
    v8::Locker lock;
123
    v8::Locker lock;
122
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
124
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
-
 
125
    v8::HandleScope handle_scope;
123
   
126
   
124
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
127
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
125
   
128
   
126
    if (args.Length() < 2)
129
    if (args.Length() < 2)
127
    {
130
    {
128
        LOG.Error(std::string(__FUNCTION__) + ": To few arguments.");
131
        LOG.Error(std::string(__FUNCTION__) + ": To few arguments.");
129
        return v8::Boolean::New(false);
132
        return handle_scope.Close(v8::Boolean::New(false));
130
    }
133
    }
131
   
134
   
132
    timer::TimerId timer_id = timer::Manager::Instance()->SetTimer(args[0]->Uint32Value(), args[1]->BooleanValue());
135
    timer::TimerId timer_id = timer::Manager::Instance()->SetTimer(args[0]->Uint32Value(), args[1]->BooleanValue());
133
   
136
   
134
    Timer::timers_.insert(timer_id);
137
    Timer::timers_.insert(timer_id);
135
   
138
   
136
    return v8::Integer::New(timer_id);
139
    return handle_scope.Close(v8::Integer::New(timer_id));
137
}
140
}
138
 
141
 
139
Value Timer::Export_Cancel(const v8::Arguments& args)
142
Value Timer::Export_Cancel(const v8::Arguments& args)
140
{
143
{
141
    v8::Locker lock;
144
    v8::Locker lock;
142
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
145
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
-
 
146
    v8::HandleScope handle_scope;
143
   
147
   
144
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
148
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
145
   
149
   
146
    if (args.Length() < 1)
150
    if (args.Length() < 1)
147
    {
151
    {
148
        LOG.Error(std::string(__FUNCTION__) + ": To few arguments.");
152
        LOG.Error(std::string(__FUNCTION__) + ": To few arguments.");
149
        return v8::Boolean::New(false);
153
        return handle_scope.Close(v8::Boolean::New(false));
150
    }
154
    }
151
   
155
   
152
    Timers::iterator it = Timer::timers_.find(args[0]->Uint32Value());
156
    Timers::iterator it = Timer::timers_.find(args[0]->Uint32Value());
153
   
157
   
154
    if (it != Timer::timers_.end())
158
    if (it != Timer::timers_.end())
155
    {
159
    {
156
        Timer::timers_.erase(it);
160
        Timer::timers_.erase(it);
157
    }
161
    }
158
   
162
   
159
    timer::Manager::Instance()->Cancel(args[0]->Uint32Value());
163
    timer::Manager::Instance()->Cancel(args[0]->Uint32Value());
160
    return v8::Undefined();
164
    return handle_scope.Close(v8::Undefined());
161
}
165
}
162
 
166
 
163
Value Timer::Export_Sleep(const v8::Arguments& args)
167
Value Timer::Export_Sleep(const v8::Arguments& args)
164
{
168
{
165
    v8::Locker lock;
169
    v8::Locker lock;
166
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
170
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
-
 
171
    v8::HandleScope handle_scope;
167
   
172
   
168
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
173
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
169
   
174
   
170
    if (args.Length() < 1)
175
    if (args.Length() < 1)
171
    {
176
    {
172
        LOG.Error(std::string(__FUNCTION__) + ": To few arguments.");
177
        LOG.Error(std::string(__FUNCTION__) + ": To few arguments.");
173
        return v8::Boolean::New(false);
178
        return handle_scope.Close(v8::Boolean::New(false));
174
    }
179
    }
175
   
180
   
176
    boost::this_thread::sleep(boost::posix_time::milliseconds(args[0]->Uint32Value()));
181
    boost::this_thread::sleep(boost::posix_time::milliseconds(args[0]->Uint32Value()));
177
   
182
   
178
    return v8::Undefined();
183
    return handle_scope.Close(v8::Undefined());
179
}
184
}
180
 
185
 
181
}; // namespace plugin
186
}; // namespace plugin
182
}; // namespace vm
187
}; // namespace vm
183
}; // namespace atom
188
}; // namespace atom