| 1 | // (C) Copyright Mac Murrett 2001. |
|---|
| 2 | // Use, modification and distribution are subject to the |
|---|
| 3 | // Boost Software License, Version 1.0. (See accompanying file |
|---|
| 4 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
|---|
| 5 | |
|---|
| 6 | // See http://www.boost.org for most recent version. |
|---|
| 7 | |
|---|
| 8 | #include "dt_scheduler.hpp" |
|---|
| 9 | |
|---|
| 10 | #include "ot_context.hpp" |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | #include <boost/thread/detail/singleton.hpp> |
|---|
| 14 | |
|---|
| 15 | #include <OpenTransportProtocol.h> |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | namespace boost { |
|---|
| 19 | |
|---|
| 20 | namespace threads { |
|---|
| 21 | |
|---|
| 22 | namespace mac { |
|---|
| 23 | |
|---|
| 24 | namespace detail { |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | const OTTimeout k_ulTimerTaskDelay = 1UL; |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | dt_scheduler::dt_scheduler(): |
|---|
| 31 | m_bReschedule(false), |
|---|
| 32 | m_uppTask(NULL), |
|---|
| 33 | m_lTask(0UL) |
|---|
| 34 | { |
|---|
| 35 | using ::boost::detail::thread::singleton; |
|---|
| 36 | |
|---|
| 37 | ot_context &rContext(singleton<ot_context>::instance()); |
|---|
| 38 | |
|---|
| 39 | m_uppTask = NewOTProcessUPP(task_entry); |
|---|
| 40 | m_lTask = OTCreateTimerTaskInContext(m_uppTask, this, rContext.get_context()); |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | dt_scheduler::~dt_scheduler() |
|---|
| 44 | { |
|---|
| 45 | OTDestroyTimerTask(m_lTask); |
|---|
| 46 | m_lTask = 0UL; |
|---|
| 47 | DisposeOTProcessUPP(m_uppTask); |
|---|
| 48 | m_uppTask = NULL; |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | void dt_scheduler::start_polling() |
|---|
| 53 | { |
|---|
| 54 | m_bReschedule = true; |
|---|
| 55 | schedule_task(); |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | void dt_scheduler::stop_polling() |
|---|
| 59 | { |
|---|
| 60 | m_bReschedule = false; |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | void dt_scheduler::schedule_task() |
|---|
| 65 | { |
|---|
| 66 | if(m_bReschedule) |
|---|
| 67 | { |
|---|
| 68 | OTScheduleTimerTask(m_lTask, k_ulTimerTaskDelay); |
|---|
| 69 | } |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | /*static*/ pascal void dt_scheduler::task_entry(void *pRefCon) |
|---|
| 74 | { |
|---|
| 75 | dt_scheduler *pThis = reinterpret_cast<dt_scheduler *>(pRefCon); |
|---|
| 76 | assert(pThis != NULL); |
|---|
| 77 | pThis->task(); |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | void dt_scheduler::task() |
|---|
| 81 | { |
|---|
| 82 | periodic_function(); |
|---|
| 83 | schedule_task(); |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | } // namespace detail |
|---|
| 88 | |
|---|
| 89 | } // namespace mac |
|---|
| 90 | |
|---|
| 91 | } // namespace threads |
|---|
| 92 | |
|---|
| 93 | } // namespace boost |
|---|