Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbedConnectorInterfaceV3 by
EventQueueResourceObserver.cpp
00001 /** 00002 * @file EventQueueResourceObserver.cpp 00003 * @brief mbed CoAP DynamicResource Thread-based observer (implementation) 00004 * @author Doug Anson/Chris Paola 00005 * @version 1.0 00006 * @see 00007 * 00008 * Copyright (c) 2017 00009 * 00010 * Licensed under the Apache License, Version 2.0 (the "License"); 00011 * you may not use this file except in compliance with the License. 00012 * You may obtain a copy of the License at 00013 * 00014 * http://www.apache.org/licenses/LICENSE-2.0 00015 * 00016 * Unless required by applicable law or agreed to in writing, software 00017 * distributed under the License is distributed on an "AS IS" BASIS, 00018 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00019 * See the License for the specific language governing permissions and 00020 * limitations under the License. 00021 */ 00022 00023 // Class support 00024 #include "mbed-connector-interface/EventQueueResourceObserver.h" 00025 00026 #ifdef CONNECTOR_USING_EVENT_QUEUES 00027 00028 // our instance 00029 static void *_instance = NULL; 00030 00031 // constructor 00032 EventQueueResourceObserver::EventQueueResourceObserver(DynamicResource *resource,int sleep_time) : ResourceObserver(resource,sleep_time), m_event_queue() { 00033 // default is not observing... 00034 this->setObserving(false); 00035 00036 // DEBUG 00037 this->logger()->log("EventQueueResourceObserver being used for %s (sleep_time: %d ms)",resource->getFullName().c_str(),sleep_time); 00038 00039 // our instance 00040 _instance = (void *)this; 00041 00042 // start the thread by invoking the thread task... 00043 this->m_id = this->m_event_queue.call_every(sleep_time,EventQueueResourceObserver::observation_task); 00044 } 00045 00046 // destructor 00047 EventQueueResourceObserver::~EventQueueResourceObserver() { 00048 this->stopObservation(); 00049 this->m_event_queue.cancel(this->m_id); 00050 } 00051 00052 // observation task method 00053 void EventQueueResourceObserver::observation_task() { 00054 EventQueueResourceObserver *me = (EventQueueResourceObserver *)_instance; 00055 if (me != NULL && me->isObserving() == true && me->getResource() != NULL) { 00056 DynamicResource *res = me->getResource(); 00057 if (res != NULL && res->isRegistered() == true) { 00058 res->observe(); 00059 } 00060 } 00061 } 00062 00063 // begin observing... 00064 void EventQueueResourceObserver::beginObservation() { 00065 this->setObserving(true); 00066 } 00067 00068 // stop observing... 00069 void EventQueueResourceObserver::stopObservation() { 00070 this->setObserving(false); 00071 } 00072 00073 // halt the underlying observer mechanism 00074 void EventQueueResourceObserver::halt() { 00075 this->m_event_queue.cancel(this->m_id); 00076 } 00077 00078 #endif // CONNECTOR_USING_EVENT_QUEUES
Generated on Tue Jul 12 2022 18:16:51 by
1.7.2
