Subversion Repositories HomeAutomation

Rev

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

Rev 1644 Rev 1646
Line 39... Line 39...
39
 
39
 
40
Timer::Timer(boost::asio::io_service& io_service) : Plugin(io_service)
40
Timer::Timer(boost::asio::io_service& io_service) : Plugin(io_service)
41
{
41
{
42
    this->name_ = "timer";
42
    this->name_ = "timer";
43
   
43
   
44
    this->ExportFunction("TimerExport_StartTimer",      Timer::Export_StartTimer);
44
    this->ExportFunction("TimerExport_SetTimer",      Timer::Export_SetTimer);
-
 
45
    this->ExportFunction("TimerExport_SetAlarm",      Timer::Export_SetAlarm);
45
    this->ExportFunction("TimerExport_ClearTimer",      Timer::Export_ClearTimer);
46
    this->ExportFunction("TimerExport_Cancel",        Timer::Export_Cancel);
46
    this->ExportFunction("TimerExport_Sleep",           Timer::Export_Sleep);
47
    this->ExportFunction("TimerExport_Sleep",         Timer::Export_Sleep);
47
}
48
}
48
 
49
 
49
Timer::~Timer()
50
Timer::~Timer()
50
{
51
{
Line 86... Line 87...
86
    arguments->push_back(v8::Boolean::New(repeat));
87
    arguments->push_back(v8::Boolean::New(repeat));
87
   
88
   
88
    this->Call( timer_id, "Timer_OnTimeout",arguments);
89
    this->Call( timer_id, "Timer_OnTimeout",arguments);
89
}
90
}
90
 
91
 
-
 
92
Value Timer::Export_SetAlarm(const v8::Arguments& args)
-
 
93
{
-
 
94
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
-
 
95
   
-
 
96
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
-
 
97
   
-
 
98
    if (args.Length() < 1)
-
 
99
    {
-
 
100
        LOG.Error(std::string(__FUNCTION__) + ": To few arguments.");
-
 
101
    }
-
 
102
   
-
 
103
    v8::String::AsciiValue time(args[0]);
-
 
104
   
-
 
105
    timer::TimerId timer_id = timer::Manager::Instance()->SetAlarm(*time);
-
 
106
   
-
 
107
    Timer::timers_.insert(timer_id);
-
 
108
   
-
 
109
    return v8::Integer::New(timer_id);
-
 
110
}
-
 
111
 
91
Value Timer::Export_StartTimer(const v8::Arguments& args)
112
Value Timer::Export_SetTimer(const v8::Arguments& args)
92
{
113
{
93
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
114
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
94
   
115
   
95
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
116
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
96
   
117
   
97
    if (args.Length() < 2)
118
    if (args.Length() < 2)
98
    {
119
    {
99
        LOG.Error(std::string(__FUNCTION__) + ": To few arguments.");
120
        LOG.Error(std::string(__FUNCTION__) + ": To few arguments.");
100
    }
121
    }
101
   
122
   
102
    timer::TimerId timer_id = timer::Manager::Instance()->Set(args[0]->Uint32Value(), args[1]->BooleanValue());
123
    timer::TimerId timer_id = timer::Manager::Instance()->SetTimer(args[0]->Uint32Value(), args[1]->BooleanValue());
103
   
124
   
104
    Timer::timers_.insert(timer_id);
125
    Timer::timers_.insert(timer_id);
105
   
126
   
106
    return v8::Integer::New(timer_id);
127
    return v8::Integer::New(timer_id);
107
}
128
}
108
 
129
 
109
Value Timer::Export_ClearTimer(const v8::Arguments& args)
130
Value Timer::Export_Cancel(const v8::Arguments& args)
110
{
131
{
111
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
132
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
112
   
133
   
113
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
134
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
114
   
135