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:
Thu Jul 13 19:21:28 2017 +0000
Revision:
125:4bf229bf14a3
Parent:
54:dfee8691c83a
Child:
126:f37e34daa100
rebased R1.2B to include EventQueue additions

Who changed what in which revision?

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