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 Sep 26 16:01:31 2017 +0000
Revision:
127:b4a661ff6fb9
Parent:
126:f37e34daa100
minor re-ordering of FCC init

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ansond 0:1f1f55e73248 1 /**
ansond 0:1f1f55e73248 2 * @file TickerResourceObserver.cpp
ansond 0:1f1f55e73248 3 * @brief mbed CoAP DynamicResource Ticker-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 33:1d0b855df5a5 23 // Class support
ansond 31:2507e64fcc42 24 #include "mbed-connector-interface/TickerResourceObserver.h"
ansond 34:a10d65907549 25
ansond 34:a10d65907549 26 #ifdef CONNECTOR_USING_TICKER
ansond 126:f37e34daa100 27
ansond 126:f37e34daa100 28 // our instance
ansond 126:f37e34daa100 29 static void *_instance = NULL;
ansond 0:1f1f55e73248 30
ansond 0:1f1f55e73248 31 // constructor
ansond 125:4bf229bf14a3 32 TickerResourceObserver::TickerResourceObserver(DynamicResource *resource,int sleep_time) : ResourceObserver(resource,(int)(sleep_time/1000)) {
ansond 0:1f1f55e73248 33 this->setObserving(false);
ansond 54:dfee8691c83a 34
ansond 0:1f1f55e73248 35 // DEBUG
ansond 125:4bf229bf14a3 36 this->logger()->log("TickerResourceObserver being used for %s (sleep_time: %d ms)",resource->getFullName().c_str(),sleep_time);
ansond 126:f37e34daa100 37
ansond 126:f37e34daa100 38 // our instance
ansond 126:f37e34daa100 39 _instance = (void *)this;
ansond 0:1f1f55e73248 40 }
ansond 0:1f1f55e73248 41
ansond 0:1f1f55e73248 42 // destructor
ansond 0:1f1f55e73248 43 TickerResourceObserver::~TickerResourceObserver() {
ansond 0:1f1f55e73248 44 this->stopObservation();
ansond 0:1f1f55e73248 45 }
ansond 0:1f1f55e73248 46
ansond 125:4bf229bf14a3 47 // observation task method
ansond 125:4bf229bf14a3 48 void TickerResourceObserver::observation_task() {
ansond 126:f37e34daa100 49 TickerResourceObserver *me = (TickerResourceObserver *)_instance;
ansond 126:f37e34daa100 50 if (me != NULL && me->isObserving() == true && me->getResource() != NULL) {
ansond 126:f37e34daa100 51 DynamicResource *res = me->getResource();
ansond 125:4bf229bf14a3 52 if (res != NULL && res->isRegistered() == true) {
ansond 125:4bf229bf14a3 53 res->observe();
ansond 125:4bf229bf14a3 54 }
ansond 0:1f1f55e73248 55 }
ansond 0:1f1f55e73248 56 }
ansond 0:1f1f55e73248 57
ansond 0:1f1f55e73248 58 // begin observing...
ansond 0:1f1f55e73248 59 void TickerResourceObserver::beginObservation() {
ansond 0:1f1f55e73248 60 if (this->isObserving() == false) {
ansond 126:f37e34daa100 61 this->m_ticker.attach(this,&TickerResourceObserver::observation_task,(float)this->getSleepTime());
ansond 0:1f1f55e73248 62 this->setObserving(true);
ansond 0:1f1f55e73248 63 }
ansond 0:1f1f55e73248 64 }
ansond 0:1f1f55e73248 65
ansond 0:1f1f55e73248 66 // begin observing...
ansond 0:1f1f55e73248 67 void TickerResourceObserver::stopObservation() {
ansond 0:1f1f55e73248 68 this->setObserving(false);
ansond 34:a10d65907549 69 }
ansond 54:dfee8691c83a 70
ansond 54:dfee8691c83a 71 // halt the underlying observer mechanism
ansond 54:dfee8691c83a 72 void TickerResourceObserver::halt() {
ansond 54:dfee8691c83a 73 this->m_ticker.detach();
ansond 54:dfee8691c83a 74 }
ansond 34:a10d65907549 75
ansond 35:782c99a7a290 76 #endif // CONNECTOR_USING_TICKER