Sarah Marsh / Mbed OS EddystoneBeacon
Committer:
sarahmarshy
Date:
Tue Nov 29 06:29:10 2016 +0000
Revision:
0:1c7da5f83647
Initial commit

Who changed what in which revision?

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