mbedConnectorInterface back port from mbedOS v3 using mbed-client C++ call interface
Embed:
(wiki syntax)
Show/hide line numbers
TickerResourceObserver.cpp
Go to the documentation of this file.
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 #include "TickerResourceObserver.h" 00024 00025 // constructor 00026 TickerResourceObserver::TickerResourceObserver(DynamicResource *resource,int sleep_time) : 00027 ResourceObserver(resource,(int)(sleep_time/1000)) { 00028 this->setObserving(false); 00029 // DEBUG 00030 std::printf("TickerResourceObserver being used for %s (sleep_time=%d)\r\n",resource->getFullName().c_str(),sleep_time); 00031 } 00032 00033 // destructor 00034 TickerResourceObserver::~TickerResourceObserver() { 00035 this->stopObservation(); 00036 } 00037 00038 // notifier 00039 void TickerResourceObserver::observationNotifier() { 00040 if (this->isObserving() == true && this->getResource() != NULL && this->getResource()->isRegistered() == true) { 00041 this->getResource()->observe(); 00042 } 00043 } 00044 00045 // begin observing... 00046 void TickerResourceObserver::beginObservation() { 00047 if (this->isObserving() == false) { 00048 this->m_ticker.attach(this,&TickerResourceObserver::observationNotifier,(float)this->getSleepTime()); 00049 this->setObserving(true); 00050 } 00051 } 00052 00053 // begin observing... 00054 void TickerResourceObserver::stopObservation() { 00055 this->setObserving(false); 00056 }
Generated on Wed Jul 13 2022 21:59:32 by
1.7.2