Roy Want / Mbed OS beaconCompileReadyFork
Committer:
roywant
Date:
Mon Sep 19 00:59:11 2016 +0000
Revision:
0:ed0152b5c495
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
roywant 0:ed0152b5c495 1 /*
roywant 0:ed0152b5c495 2 * Copyright (c) 2016, ARM Limited, All Rights Reserved
roywant 0:ed0152b5c495 3 * SPDX-License-Identifier: Apache-2.0
roywant 0:ed0152b5c495 4 *
roywant 0:ed0152b5c495 5 * Licensed under the Apache License, Version 2.0 (the "License"); you may
roywant 0:ed0152b5c495 6 * not use this file except in compliance with the License.
roywant 0:ed0152b5c495 7 * You may obtain a copy of the License at
roywant 0:ed0152b5c495 8 *
roywant 0:ed0152b5c495 9 * http://www.apache.org/licenses/LICENSE-2.0
roywant 0:ed0152b5c495 10 *
roywant 0:ed0152b5c495 11 * Unless required by applicable law or agreed to in writing, software
roywant 0:ed0152b5c495 12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
roywant 0:ed0152b5c495 13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
roywant 0:ed0152b5c495 14 * See the License for the specific language governing permissions and
roywant 0:ed0152b5c495 15 * limitations under the License.
roywant 0:ed0152b5c495 16 */
roywant 0:ed0152b5c495 17 #ifndef EVENTQUEUE_EVENTQUEUEMINAR_H_
roywant 0:ed0152b5c495 18 #define EVENTQUEUE_EVENTQUEUEMINAR_H_
roywant 0:ed0152b5c495 19
roywant 0:ed0152b5c495 20 #include <minar/minar.h>
roywant 0:ed0152b5c495 21 #include "EventQueue.h"
roywant 0:ed0152b5c495 22
roywant 0:ed0152b5c495 23 namespace eq {
roywant 0:ed0152b5c495 24
roywant 0:ed0152b5c495 25 class EventQueueMinar: public EventQueue {
roywant 0:ed0152b5c495 26
roywant 0:ed0152b5c495 27 public:
roywant 0:ed0152b5c495 28 /// Construct an empty event queue
roywant 0:ed0152b5c495 29 EventQueueMinar() { }
roywant 0:ed0152b5c495 30
roywant 0:ed0152b5c495 31 virtual ~EventQueueMinar() { }
roywant 0:ed0152b5c495 32
roywant 0:ed0152b5c495 33 virtual bool cancel(event_handle_t event_handle) {
roywant 0:ed0152b5c495 34 return minar::Scheduler::cancelCallback(event_handle);
roywant 0:ed0152b5c495 35 }
roywant 0:ed0152b5c495 36
roywant 0:ed0152b5c495 37 private:
roywant 0:ed0152b5c495 38
roywant 0:ed0152b5c495 39 virtual event_handle_t do_post(const function_t& fn, ms_time_t ms_delay = 0, bool repeat = false) {
roywant 0:ed0152b5c495 40 // convert ms to minar time
roywant 0:ed0152b5c495 41 minar::tick_t tick = minar::milliseconds(ms_delay);
roywant 0:ed0152b5c495 42
roywant 0:ed0152b5c495 43 // convert thunk to minar FunctionPointerBind
roywant 0:ed0152b5c495 44 mbed::util::Event func(
roywant 0:ed0152b5c495 45 mbed::util::FunctionPointer1<void, function_t>(
roywant 0:ed0152b5c495 46 free_func_thunk_call
roywant 0:ed0152b5c495 47 ).bind(fn)
roywant 0:ed0152b5c495 48 );
roywant 0:ed0152b5c495 49
roywant 0:ed0152b5c495 50 if (ms_delay == 0) {
roywant 0:ed0152b5c495 51 return minar::Scheduler::postCallback(func).getHandle();
roywant 0:ed0152b5c495 52 }
roywant 0:ed0152b5c495 53
roywant 0:ed0152b5c495 54 if (repeat == false) {
roywant 0:ed0152b5c495 55 return minar::Scheduler::postCallback(func).delay(tick).tolerance(0).getHandle();
roywant 0:ed0152b5c495 56 } else {
roywant 0:ed0152b5c495 57 return minar::Scheduler::postCallback(func).period(tick).tolerance(0).getHandle();
roywant 0:ed0152b5c495 58 }
roywant 0:ed0152b5c495 59 }
roywant 0:ed0152b5c495 60
roywant 0:ed0152b5c495 61 // due to design limitations in function pointer classes, it is not possible
roywant 0:ed0152b5c495 62 // to use reference here ...
roywant 0:ed0152b5c495 63 static void free_func_thunk_call(function_t fn) {
roywant 0:ed0152b5c495 64 fn();
roywant 0:ed0152b5c495 65 }
roywant 0:ed0152b5c495 66 };
roywant 0:ed0152b5c495 67
roywant 0:ed0152b5c495 68 } // namespace eq
roywant 0:ed0152b5c495 69
roywant 0:ed0152b5c495 70 #endif /* EVENTQUEUE_EVENTQUEUEMINAR_H_ */