Subversion Repositories HomeAutomation

Rev

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

Rev 1593 Rev 1595
Line 31... Line 31...
31
    this->thread_ = thread.move();
31
    this->thread_ = thread.move();
32
}
32
}
33
 
33
 
34
Manager::~Manager()
34
Manager::~Manager()
35
{
35
{
-
 
36
    this->mutex_timers_.lock();
36
    this->timers_.clear();
37
    this->timers_.clear();
-
 
38
    this->mutex_timers_.unlock();
37
   
39
   
38
    this->thread_.interrupt();
40
    this->thread_.interrupt();
39
    this->thread_.join();
41
    this->thread_.join();
40
}
42
}
41
 
43
 
Line 54... Line 56...
54
    this->signal_on_timeout_.connect(slot_on_timeout);
56
    this->signal_on_timeout_.connect(slot_on_timeout);
55
}
57
}
56
 
58
 
57
void Manager::SlotOnTimeout(TimerId id)
59
void Manager::SlotOnTimeout(TimerId id)
58
{
60
{
-
 
61
    this->mutex_timers_.lock();
-
 
62
   
59
    TimerList::iterator it = this->timers_.find(id);
63
    TimerList::iterator it = this->timers_.find(id);
60
   
64
   
61
    if (it != this->timers_.end())
65
    if (it != this->timers_.end())
62
    {
66
    {
63
        if (!it->second->GetRepeat())
67
        if (!it->second->GetRepeat())
64
        {
68
        {
65
            this->timers_.erase(id);
69
            this->timers_.erase(id);
66
        }
70
        }
67
    }
71
    }
-
 
72
   
-
 
73
    this->mutex_timers_.unlock();
68
   
74
   
69
    this->signal_on_timeout_(id);
75
    this->signal_on_timeout_(id);
70
}
76
}
71
 
77
 
72
TimerId Manager::Set(unsigned int timeout, bool repeat)
78
TimerId Manager::Set(unsigned int timeout, bool repeat)
73
{
79
{
-
 
80
    this->mutex_timers_.lock();
-
 
81
   
74
    Timer::Pointer timer = Timer::Pointer(new Timer(this->io_service_, this->GetFreeId(), timeout, repeat));
82
    Timer::Pointer timer = Timer::Pointer(new Timer(this->io_service_, this->GetFreeId(), timeout, repeat));
75
 
83
 
76
    this->timers_[timer->GetId()] = timer;
84
    this->timers_[timer->GetId()] = timer;
-
 
85
   
-
 
86
    this->mutex_timers_.unlock();
77
   
87
   
78
    timer->ConnectSlots(Timer::SignalOnTimeout::slot_type(&Manager::SlotOnTimeout, this, _1).track(Manager::instance_));
88
    timer->ConnectSlots(Timer::SignalOnTimeout::slot_type(&Manager::SlotOnTimeout, this, _1).track(Manager::instance_));
79
   
89
   
80
    timer->Start();
90
    timer->Start();
81
   
91
   
Line 87... Line 97...
87
    this->io_service_.post(boost::bind(&Manager::CancelHandler, this, id));
97
    this->io_service_.post(boost::bind(&Manager::CancelHandler, this, id));
88
}
98
}
89
 
99
 
90
void Manager::CancelHandler(TimerId id)
100
void Manager::CancelHandler(TimerId id)
91
{
101
{
-
 
102
    this->mutex_timers_.lock();
-
 
103
   
92
    TimerList::iterator it = this->timers_.find(id);
104
    TimerList::iterator it = this->timers_.find(id);
93
   
105
   
94
    if (it != this->timers_.end())
106
    if (it != this->timers_.end())
95
    {
107
    {
96
        it->second->Cancel();
108
        it->second->Cancel();
97
    }
109
    }
-
 
110
   
-
 
111
    this->mutex_timers_.unlock();
98
}
112
}
99
 
113
 
100
TimerId Manager::GetFreeId()
114
TimerId Manager::GetFreeId()
101
{
115
{
102
    TimerId id = 1;
116
    TimerId id = 1;
103
       
117
       
Line 106... Line 120...
106
        id++;
120
        id++;
107
    }
121
    }
108
       
122
       
109
    return id;
123
    return id;
110
}
124
}
111
 
-
 
112
 
125
 
113
}; // namespace timer
126
}; // namespace timer
114
}; // namespace atom
127
}; // namespace atom