mbed Connector Interface simplification API on top of mbed-client

Fork of mbedConnectorInterfaceV3 by Doug Anson

NOTE:

This repo has been replaced with https://github.com/ARMmbed/mbedConnectorInterface. No further updates will occur with this repo. Please use the github repo instead. Thanks!

Committer:
ansond
Date:
Tue Jun 14 19:42:15 2016 +0000
Revision:
34:a10d65907549
Parent:
31:2507e64fcc42
Child:
54:dfee8691c83a
updated

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ansond 0:1f1f55e73248 1 /**
ansond 0:1f1f55e73248 2 * @file ThreadedResourceObserver.cpp
ansond 0:1f1f55e73248 3 * @brief mbed CoAP DynamicResource Thread-based observer (implementation)
ansond 0:1f1f55e73248 4 * @author Doug Anson/Chris Paola
ansond 0:1f1f55e73248 5 * @version 1.0
ansond 0:1f1f55e73248 6 * @see
ansond 0:1f1f55e73248 7 *
ansond 0:1f1f55e73248 8 * Copyright (c) 2014
ansond 0:1f1f55e73248 9 *
ansond 0:1f1f55e73248 10 * Licensed under the Apache License, Version 2.0 (the "License");
ansond 0:1f1f55e73248 11 * you may not use this file except in compliance with the License.
ansond 0:1f1f55e73248 12 * You may obtain a copy of the License at
ansond 0:1f1f55e73248 13 *
ansond 0:1f1f55e73248 14 * http://www.apache.org/licenses/LICENSE-2.0
ansond 0:1f1f55e73248 15 *
ansond 0:1f1f55e73248 16 * Unless required by applicable law or agreed to in writing, software
ansond 0:1f1f55e73248 17 * distributed under the License is distributed on an "AS IS" BASIS,
ansond 0:1f1f55e73248 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ansond 0:1f1f55e73248 19 * See the License for the specific language governing permissions and
ansond 0:1f1f55e73248 20 * limitations under the License.
ansond 0:1f1f55e73248 21 */
ansond 0:1f1f55e73248 22
ansond 31:2507e64fcc42 23 // Class support
ansond 31:2507e64fcc42 24 #include "mbed-connector-interface/ThreadedResourceObserver.h"
ansond 0:1f1f55e73248 25
ansond 34:a10d65907549 26 #ifdef CONNECTOR_USING_THREADS
ansond 34:a10d65907549 27
ansond 0:1f1f55e73248 28 // constructor
ansond 0:1f1f55e73248 29 ThreadedResourceObserver::ThreadedResourceObserver(DynamicResource *resource,int sleep_time) :
ansond 0:1f1f55e73248 30 ResourceObserver(resource,sleep_time)
ansond 0:1f1f55e73248 31 ,m_observation_thread(&ThreadedResourceObserver::_observation_notifier,this)
ansond 0:1f1f55e73248 32 {
ansond 0:1f1f55e73248 33 this->setObserving(false);
ansond 0:1f1f55e73248 34 // DEBUG
ansond 0:1f1f55e73248 35 std::printf("ThreadedResourceObserver being used for %s (sleep_time=%d)\r\n",resource->getFullName().c_str(),sleep_time);
ansond 0:1f1f55e73248 36 }
ansond 0:1f1f55e73248 37
ansond 0:1f1f55e73248 38 // destructor
ansond 0:1f1f55e73248 39 ThreadedResourceObserver::~ThreadedResourceObserver() {
ansond 0:1f1f55e73248 40 this->stopObservation();
ansond 0:1f1f55e73248 41 this->m_observation_thread.terminate();
ansond 0:1f1f55e73248 42 }
ansond 0:1f1f55e73248 43
ansond 0:1f1f55e73248 44 // notifier
ansond 0:1f1f55e73248 45 void ThreadedResourceObserver::_observation_notifier(void const *instance) {
ansond 0:1f1f55e73248 46 ThreadedResourceObserver *me = (ThreadedResourceObserver *)instance;
ansond 0:1f1f55e73248 47 while(true) {
ansond 0:1f1f55e73248 48 Thread::wait(me->getSleepTime());
ansond 16:dffa38c3340f 49 if (me->isObserving() == true && me->getResource() != NULL && me->getResource()->isRegistered() == true) {
ansond 0:1f1f55e73248 50 me->getResource()->observe();
ansond 0:1f1f55e73248 51 }
ansond 0:1f1f55e73248 52 }
ansond 0:1f1f55e73248 53 }
ansond 0:1f1f55e73248 54
ansond 0:1f1f55e73248 55 // begin observing...
ansond 0:1f1f55e73248 56 void ThreadedResourceObserver::beginObservation() {
ansond 0:1f1f55e73248 57 this->setObserving(true);
ansond 0:1f1f55e73248 58 }
ansond 0:1f1f55e73248 59
ansond 0:1f1f55e73248 60 // stop observing...
ansond 0:1f1f55e73248 61 void ThreadedResourceObserver::stopObservation() {
ansond 0:1f1f55e73248 62 this->setObserving(false);
ansond 34:a10d65907549 63 }
ansond 34:a10d65907549 64
ansond 34:a10d65907549 65 #endif // CONNECTOR_USING_THREADS