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
TickerResourceObserver.cpp
00001 /** 00002 * @file TickerResourceObserver.cpp 00003 * @brief mbed CoAP DynamicResource Ticker-based observer (implementation) 00004 * @author Doug Anson/Chris Paola 00005 * @version 1.0 00006 * @see 00007 * 00008 * Copyright (c) 2014 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/TickerResourceObserver.h" 00025 00026 #ifdef CONNECTOR_USING_TICKER 00027 00028 // our instance 00029 static void *_instance = NULL; 00030 00031 // constructor 00032 TickerResourceObserver::TickerResourceObserver(DynamicResource *resource,int sleep_time) : ResourceObserver(resource,(int)(sleep_time/1000)) { 00033 this->setObserving(false); 00034 00035 // DEBUG 00036 this->logger()->log("TickerResourceObserver being used for %s (sleep_time: %d ms)",resource->getFullName().c_str(),sleep_time); 00037 00038 // our instance 00039 _instance = (void *)this; 00040 } 00041 00042 // destructor 00043 TickerResourceObserver::~TickerResourceObserver() { 00044 this->stopObservation(); 00045 } 00046 00047 // observation task method 00048 void TickerResourceObserver::observation_task() { 00049 TickerResourceObserver *me = (TickerResourceObserver *)_instance; 00050 if (me != NULL && me->isObserving() == true && me->getResource() != NULL) { 00051 DynamicResource *res = me->getResource(); 00052 if (res != NULL && res->isRegistered() == true) { 00053 res->observe(); 00054 } 00055 } 00056 } 00057 00058 // begin observing... 00059 void TickerResourceObserver::beginObservation() { 00060 if (this->isObserving() == false) { 00061 this->m_ticker.attach(this,&TickerResourceObserver::observation_task,(float)this->getSleepTime()); 00062 this->setObserving(true); 00063 } 00064 } 00065 00066 // begin observing... 00067 void TickerResourceObserver::stopObservation() { 00068 this->setObserving(false); 00069 } 00070 00071 // halt the underlying observer mechanism 00072 void TickerResourceObserver::halt() { 00073 this->m_ticker.detach(); 00074 } 00075 00076 #endif // CONNECTOR_USING_TICKER
Generated on Tue Jul 12 2022 18:16:52 by
1.7.2
