Subversion Repositories HomeAutomation

Rev

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

Rev 1599 Rev 1601
Line 23... Line 23...
23
namespace atom {
23
namespace atom {
24
namespace timer {
24
namespace timer {
25
 
25
 
26
Manager::Pointer Manager::instance_;
26
Manager::Pointer Manager::instance_;
27
 
27
 
28
Manager::Manager() : io_service_work_(io_service_)
28
Manager::Manager()
29
{
29
{
30
    boost::thread thread(boost::bind(&boost::asio::io_service::run, &this->io_service_));
-
 
31
    this->thread_ = thread.move();
-
 
32
}
30
}
33
 
31
 
34
Manager::~Manager()
32
Manager::~Manager()
35
{
33
{
36
    this->mutex_timers_.lock();
34
    this->io_service_.stop();
-
 
35
   
37
    this->timers_.clear();
36
    this->timers_.clear();
38
    this->mutex_timers_.unlock();
-
 
39
   
-
 
40
    this->io_service_.stop();
-
 
41
   
-
 
42
    this->thread_.interrupt();
-
 
43
    this->thread_.join();
-
 
44
}
37
}
45
 
38
 
46
Manager::Pointer Manager::Instance()
39
Manager::Pointer Manager::Instance()
47
{
40
{
48
    return Manager::instance_;
41
    return Manager::instance_;
49
}
42
}
50
 
43
 
51
void Manager::Create()
44
void Manager::Create()
52
{
45
{
53
    Manager::instance_ = Manager::Pointer(new Manager());
46
    Manager::instance_ = Manager::Pointer(new Manager());
54
}
47
}
55
 
48
 
56
void Manager::Delete()
49
void Manager::Delete()
57
{
50
{
58
    Manager::instance_.reset();
51
    Manager::instance_.reset();
59
}
52
}
60
 
53
 
61
void Manager::ConnectSlots(const SignalOnTimeout::slot_type& slot_on_timeout)
54
void Manager::ConnectSlots(const SignalOnTimeout::slot_type& slot_on_timeout)
62
{
55
{
63
    this->signal_on_timeout_.connect(slot_on_timeout);
56
    this->signal_on_timeout_.connect(slot_on_timeout);
64
}
57
}
65
 
58
 
66
void Manager::SlotOnTimeout(TimerId id)
59
void Manager::SlotOnTimeout(TimerId id)
67
{
60
{
-
 
61
    bool repeat = false;
-
 
62
   
68
    this->mutex_timers_.lock();
63
    this->mutex_timers_.lock();
69
   
64
   
70
    TimerList::iterator it = this->timers_.find(id);
65
    TimerList::iterator it = this->timers_.find(id);
71
   
66
   
72
    if (it != this->timers_.end())
67
    if (it != this->timers_.end())
73
    {
68
    {
74
        if (!it->second->GetRepeat())
69
        repeat = it->second->GetRepeat();
-
 
70
       
-
 
71
        if (!repeat)
75
        {
72
        {
76
            this->timers_.erase(id);
73
            this->timers_.erase(id);
77
        }
74
        }
78
    }
75
    }
79
   
76
   
80
    this->mutex_timers_.unlock();
77
    this->mutex_timers_.unlock();
81
   
78
   
82
    this->signal_on_timeout_(id);
79
    this->signal_on_timeout_(id, repeat);
83
}
80
}
84
 
81
 
85
TimerId Manager::Set(unsigned int timeout, bool repeat)
82
TimerId Manager::Set(unsigned int timeout, bool repeat)
86
{
83
{
87
    this->mutex_timers_.lock();
84
    this->mutex_timers_.lock();