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 mbedConnectorInterface by
ThreadedResourceObserver.cpp
00001 /** 00002 * @file ThreadedResourceObserver.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) 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 "ThreadedResourceObserver.h" 00024 00025 #ifdef CONNECTOR_USING_THREADS 00026 // DEBUG 00027 //DigitalOut __threaded_led(LED2); 00028 #endif 00029 00030 // constructor 00031 ThreadedResourceObserver::ThreadedResourceObserver(DynamicResource *resource,int sleep_time) : 00032 ResourceObserver(resource,sleep_time) 00033 #ifdef CONNECTOR_USING_THREADS 00034 ,m_observation_thread(&ThreadedResourceObserver::_observation_notifier,this) 00035 #endif 00036 { 00037 this->setObserving(false); 00038 // DEBUG 00039 std::printf("ThreadedResourceObserver being used for %s (sleep_time=%d)\r\n",resource->getName().c_str(),sleep_time); 00040 } 00041 00042 // destructor 00043 ThreadedResourceObserver::~ThreadedResourceObserver() { 00044 this->stopObservation(); 00045 #ifdef CONNECTOR_USING_THREADS 00046 this->m_observation_thread.terminate(); 00047 #endif 00048 } 00049 00050 // notifier 00051 void ThreadedResourceObserver::_observation_notifier(void const *instance) { 00052 #ifdef CONNECTOR_USING_THREADS 00053 ThreadedResourceObserver *me = (ThreadedResourceObserver *)instance; 00054 while(true) { 00055 Thread::wait(me->getSleepTime()); 00056 if (me->isObserving() == true && me->getResource() != NULL && nsdl_endpoint_is_registered() == true) { 00057 me->getResource()->observe(); 00058 //__threaded_led = !__threaded_led; 00059 } 00060 } 00061 #endif 00062 } 00063 00064 // begin observing... 00065 void ThreadedResourceObserver::beginObservation() { 00066 this->setObserving(true); 00067 } 00068 00069 // stop observing... 00070 void ThreadedResourceObserver::stopObservation() { 00071 this->setObserving(false); 00072 }
Generated on Wed Jul 13 2022 02:58:57 by
1.7.2
