Subversion Repositories HomeAutomation

Rev

Rev 1604 | Go to most recent revision | Details | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
1601 runge 1
/*
2
 *
3
 *  Copyright (C) 2010  Mattias Runge
4
 *
5
 *  This program is free software; you can redistribute it and/or modify
6
 *  it under the terms of the GNU General Public License as published by
7
 *  the Free Software Foundation; either version 2 of the License, or
8
 *  (at your option) any later version.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU General Public License along
16
 *  with this program; if not, write to the Free Software Foundation, Inc.,
17
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
 *
19
 */
20
 
21
#include "Timer.h"
22
 
23
#include <v8.h>
24
#include <stdio.h>
25
 
26
#include <boost/concept_check.hpp>
27
#include <boost/lexical_cast.hpp>
28
 
29
#include "vm/Manager.h"
30
#include "timer/Manager.h"
31
 
32
namespace atom {
33
namespace vm {
34
namespace plugin {
35
 
36
logging::Logger Timer::LOG("vm::plugin::Timer");
37
 
38
Timer::Timer()
39
{
40
    this->name_ = "timer";
41
 
42
    this->ImportFunction("Timer_OnTimeout");
43
 
44
    this->ExportFunction("StartTimer",      Timer::Export_StartTimer);
45
    this->ExportFunction("ClearTimer",      Timer::Export_ClearTimer);
46
}
47
 
48
Timer::~Timer()
49
{
50
 
51
}
52
 
53
void Timer::SlotOnTimeoutHandler(timer::TimerId timer_id, bool repeat)
54
{
55
    ArgumentListPointer arguments = ArgumentListPointer(new ArgumentList);
56
    arguments->push_back(v8::Integer::New(timer_id));
57
    arguments->push_back(v8::Boolean::New(repeat));
58
 
59
    this->Call("Timer_OnTimeout", arguments);
60
}
61
 
62
Value Timer::Export_StartTimer(const v8::Arguments& args)
63
{
64
    return v8::Integer::New(timer::Manager::Instance()->Set(args[0]->Uint32Value(), args[1]->BooleanValue()));
65
}
66
 
67
Value Timer::Export_ClearTimer(const v8::Arguments& args)
68
{
69
    timer::Manager::Instance()->Cancel(args[0]->IsUint32());
70
    return v8::Undefined();
71
}
72
 
73
}; // namespace plugin
74
}; // namespace vm
75
}; // namespace atom