Sample program showing how to connect GR-PEACH into Watson IoT through mbed Connector and Watson's Connector Bridge
Dependencies: AsciiFont DisplayApp GR-PEACH_video LCD_shield_config LWIPBP3595Interface_STA_for_mbed-os USBDevice
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 // constructor 00029 TickerResourceObserver::TickerResourceObserver(DynamicResource *resource,int sleep_time) : 00030 ResourceObserver(resource,(int)(sleep_time/1000)) { 00031 this->setObserving(false); 00032 00033 // DEBUG 00034 if (sleep_time > 0) { 00035 this->logger()->log("TickerResourceObserver being used for %s (sleep_time: %d ms)",resource->getFullName().c_str(),sleep_time); 00036 } 00037 else { 00038 this->logger()->log("TickerResourceObserver being used for %s",resource->getFullName().c_str()); 00039 } 00040 } 00041 00042 // destructor 00043 TickerResourceObserver::~TickerResourceObserver() { 00044 this->stopObservation(); 00045 } 00046 00047 // notifier 00048 void TickerResourceObserver::observationNotifier() { 00049 if (this->isObserving() == true && this->getResource() != NULL && this->getResource()->isRegistered() == true) { 00050 this->getResource()->observe(); 00051 } 00052 } 00053 00054 // begin observing... 00055 void TickerResourceObserver::beginObservation() { 00056 if (this->isObserving() == false) { 00057 this->m_ticker.attach(this,&TickerResourceObserver::observationNotifier,(float)this->getSleepTime()); 00058 this->setObserving(true); 00059 } 00060 } 00061 00062 // begin observing... 00063 void TickerResourceObserver::stopObservation() { 00064 this->setObserving(false); 00065 } 00066 00067 // halt the underlying observer mechanism 00068 void TickerResourceObserver::halt() { 00069 this->m_ticker.detach(); 00070 } 00071 00072 #endif // CONNECTOR_USING_TICKER
Generated on Thu Jul 14 2022 21:25:54 by 1.7.2