use TCP to connect to mbed connector

Fork of mbedConnectorInterfaceWithDM by Doug Anson

Committer:
Maggie17
Date:
Mon Nov 28 15:52:56 2016 +0000
Revision:
90:b738617379a6
Parent:
54:dfee8691c83a
first release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ansond 33:1d0b855df5a5 1 /**
ansond 33:1d0b855df5a5 2 * @file ResourceObserver.cpp
ansond 33:1d0b855df5a5 3 * @brief mbed CoAP DynamicResource observer (implementation)
ansond 33:1d0b855df5a5 4 * @author Doug Anson/Chris Paola
ansond 33:1d0b855df5a5 5 * @version 1.0
ansond 33:1d0b855df5a5 6 * @see
ansond 33:1d0b855df5a5 7 *
ansond 33:1d0b855df5a5 8 * Copyright (c) 2014
ansond 33:1d0b855df5a5 9 *
ansond 33:1d0b855df5a5 10 * Licensed under the Apache License, Version 2.0 (the "License");
ansond 33:1d0b855df5a5 11 * you may not use this file except in compliance with the License.
ansond 33:1d0b855df5a5 12 * You may obtain a copy of the License at
ansond 33:1d0b855df5a5 13 *
ansond 33:1d0b855df5a5 14 * http://www.apache.org/licenses/LICENSE-2.0
ansond 33:1d0b855df5a5 15 *
ansond 33:1d0b855df5a5 16 * Unless required by applicable law or agreed to in writing, software
ansond 33:1d0b855df5a5 17 * distributed under the License is distributed on an "AS IS" BASIS,
ansond 33:1d0b855df5a5 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ansond 33:1d0b855df5a5 19 * See the License for the specific language governing permissions and
ansond 33:1d0b855df5a5 20 * limitations under the License.
ansond 33:1d0b855df5a5 21 */
ansond 33:1d0b855df5a5 22
ansond 33:1d0b855df5a5 23 // Class support
ansond 33:1d0b855df5a5 24 #include "mbed-connector-interface/ResourceObserver.h"
ansond 33:1d0b855df5a5 25
ansond 33:1d0b855df5a5 26 // constructor
ansond 33:1d0b855df5a5 27 ResourceObserver::ResourceObserver(DynamicResource *resource,int sleep_time) : m_is_observing(false), m_sleep_time(sleep_time) {
ansond 33:1d0b855df5a5 28 this->m_resource = resource;
ansond 33:1d0b855df5a5 29 if (resource != NULL) resource->setObserver(this);
ansond 0:1f1f55e73248 30 }
ansond 33:1d0b855df5a5 31
ansond 33:1d0b855df5a5 32 // copy constructor
ansond 33:1d0b855df5a5 33 ResourceObserver::ResourceObserver(const ResourceObserver &observer) {
ansond 33:1d0b855df5a5 34 this->m_resource = observer.m_resource;
ansond 33:1d0b855df5a5 35 }
ansond 33:1d0b855df5a5 36
ansond 33:1d0b855df5a5 37 // destructor
ansond 33:1d0b855df5a5 38 ResourceObserver::~ResourceObserver() {
ansond 33:1d0b855df5a5 39 }
ansond 33:1d0b855df5a5 40
ansond 33:1d0b855df5a5 41 // get our resource
ansond 33:1d0b855df5a5 42 DynamicResource *ResourceObserver::getResource() {
ansond 33:1d0b855df5a5 43 return this->m_resource;
ansond 33:1d0b855df5a5 44 }
ansond 33:1d0b855df5a5 45
ansond 33:1d0b855df5a5 46 // we are observing?
ansond 33:1d0b855df5a5 47 bool ResourceObserver::isObserving() {
ansond 33:1d0b855df5a5 48 return this->m_is_observing;
ansond 33:1d0b855df5a5 49 }
ansond 33:1d0b855df5a5 50
ansond 33:1d0b855df5a5 51 // set our observation state
ansond 33:1d0b855df5a5 52 void ResourceObserver::setObserving(bool observing) {
ansond 33:1d0b855df5a5 53 this->m_is_observing = observing;
ansond 33:1d0b855df5a5 54 }
ansond 33:1d0b855df5a5 55
ansond 33:1d0b855df5a5 56 // get our sleep time
ansond 33:1d0b855df5a5 57 int ResourceObserver::getSleepTime() {
ansond 33:1d0b855df5a5 58 return this->m_sleep_time;
ansond 33:1d0b855df5a5 59 }
ansond 54:dfee8691c83a 60
ansond 54:dfee8691c83a 61 // halt the underlying observer mechanism
ansond 54:dfee8691c83a 62 void ResourceObserver::halt() {
ansond 54:dfee8691c83a 63 }
ansond 54:dfee8691c83a 64
ansond 54:dfee8691c83a 65 // get our logger instance
ansond 54:dfee8691c83a 66 Logger *ResourceObserver::logger() {
ansond 54:dfee8691c83a 67 if (this->m_resource != NULL) {
ansond 54:dfee8691c83a 68 return this->m_resource->logger();
ansond 54:dfee8691c83a 69 }
ansond 54:dfee8691c83a 70 return NULL;
ansond 54:dfee8691c83a 71 }