Kenji Arai / TYBLE16_mbedlized_os5_several_examples_1st

Dependencies:   nRF51_Vdd TextLCD BME280

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers EventQueue.cpp Source File

EventQueue.cpp

00001 /* events
00002  * Copyright (c) 2016 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #include "events/EventQueue.h"
00017 
00018 #include "events/mbed_events.h"
00019 #include "mbed.h"
00020 
00021 
00022 EventQueue::EventQueue(unsigned event_size, unsigned char *event_pointer)
00023 {
00024     if (!event_pointer) {
00025         equeue_create(&_equeue, event_size);
00026     } else {
00027         equeue_create_inplace(&_equeue, event_size, event_pointer);
00028     }
00029 }
00030 
00031 EventQueue::~EventQueue()
00032 {
00033     equeue_destroy(&_equeue);
00034 }
00035 
00036 void EventQueue::dispatch(int ms)
00037 {
00038     return equeue_dispatch(&_equeue, ms);
00039 }
00040 
00041 void EventQueue::break_dispatch()
00042 {
00043     return equeue_break(&_equeue);
00044 }
00045 
00046 unsigned EventQueue::tick()
00047 {
00048     return equeue_tick();
00049 }
00050 
00051 void EventQueue::cancel(int id)
00052 {
00053     return equeue_cancel(&_equeue, id);
00054 }
00055 
00056 int EventQueue::time_left(int id)
00057 {
00058     return equeue_timeleft(&_equeue, id);
00059 }
00060 
00061 void EventQueue::background(Callback<void(int)> update)
00062 {
00063     _update = update;
00064 
00065     if (_update) {
00066         equeue_background(&_equeue, &Callback<void(int)>::thunk, &_update);
00067     } else {
00068         equeue_background(&_equeue, 0, 0);
00069     }
00070 }
00071 
00072 void EventQueue::chain(EventQueue *target)
00073 {
00074     if (target) {
00075         equeue_chain(&_equeue, &target->_equeue);
00076     } else {
00077         equeue_chain(&_equeue, 0);
00078     }
00079 }