Doug Anson / mbedConnectorInterface

Dependents:   IoT_LED_demo ServoTest uWater_Project hackathon ... more

Committer:
ansond
Date:
Wed Apr 08 23:03:39 2015 +0000
Revision:
35:f12e61aaf004
Parent:
34:03a8cc428b8b
updates

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ansond 30:113c2a1d8db2 1 /**
ansond 30:113c2a1d8db2 2 * @file TaskletResourceObserver.h
ansond 30:113c2a1d8db2 3 * @brief mbed CoAP DynamicResource Tasklet-based observer (header)
ansond 30:113c2a1d8db2 4 * @author Doug Anson/Chris Paola
ansond 30:113c2a1d8db2 5 * @version 1.0
ansond 30:113c2a1d8db2 6 * @see
ansond 30:113c2a1d8db2 7 *
ansond 30:113c2a1d8db2 8 * Copyright (c) 2014
ansond 30:113c2a1d8db2 9 *
ansond 30:113c2a1d8db2 10 * Licensed under the Apache License, Version 2.0 (the "License");
ansond 30:113c2a1d8db2 11 * you may not use this file except in compliance with the License.
ansond 30:113c2a1d8db2 12 * You may obtain a copy of the License at
ansond 30:113c2a1d8db2 13 *
ansond 30:113c2a1d8db2 14 * http://www.apache.org/licenses/LICENSE-2.0
ansond 30:113c2a1d8db2 15 *
ansond 30:113c2a1d8db2 16 * Unless required by applicable law or agreed to in writing, software
ansond 30:113c2a1d8db2 17 * distributed under the License is distributed on an "AS IS" BASIS,
ansond 30:113c2a1d8db2 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ansond 30:113c2a1d8db2 19 * See the License for the specific language governing permissions and
ansond 30:113c2a1d8db2 20 * limitations under the License.
ansond 30:113c2a1d8db2 21 */
ansond 30:113c2a1d8db2 22
ansond 30:113c2a1d8db2 23 #ifndef __TASKLET_RESOURCE_OBSERVER_H__
ansond 30:113c2a1d8db2 24 #define __TASKLET_RESOURCE_OBSERVER_H__
ansond 30:113c2a1d8db2 25
ansond 35:f12e61aaf004 26 // mbed support
ansond 35:f12e61aaf004 27 #include "mbed.h"
ansond 35:f12e61aaf004 28
ansond 35:f12e61aaf004 29 // mbedConnectorInterface configuration
ansond 35:f12e61aaf004 30 #include "mbedConnectorInterface.h"
ansond 35:f12e61aaf004 31
ansond 30:113c2a1d8db2 32 // Base class support
ansond 30:113c2a1d8db2 33 #include "ResourceObserver.h"
ansond 30:113c2a1d8db2 34
ansond 31:bacc63106754 35 // Tasklet support under network_stubs.h in mbedEndpointNetwork
ansond 31:bacc63106754 36 #ifdef CONNECTOR_USING_TASKLETS
ansond 31:bacc63106754 37 #include "network_stubs.h"
ansond 31:bacc63106754 38 #endif
ansond 31:bacc63106754 39
ansond 30:113c2a1d8db2 40 class TaskletResourceObserver : public ResourceObserver {
ansond 30:113c2a1d8db2 41 public:
ansond 30:113c2a1d8db2 42 /**
ansond 30:113c2a1d8db2 43 Default Constructor
ansond 30:113c2a1d8db2 44 @param resource input the resource to observe
ansond 31:bacc63106754 45 @param timer_id input the id for our timer (can be index value of each resource that is observed...)
ansond 31:bacc63106754 46 @param sleep_time input the time for the observation tasklet to sleep (in ms)
ansond 30:113c2a1d8db2 47 */
ansond 31:bacc63106754 48 TaskletResourceObserver(DynamicResource *resource,uint8_t timer_id, int sleep_time = NSP_RD_UPDATE_PERIOD);
ansond 30:113c2a1d8db2 49
ansond 30:113c2a1d8db2 50 /**
ansond 30:113c2a1d8db2 51 Copy Constructor
ansond 30:113c2a1d8db2 52 */
ansond 30:113c2a1d8db2 53 TaskletResourceObserver(const TaskletResourceObserver &observer);
ansond 30:113c2a1d8db2 54
ansond 30:113c2a1d8db2 55 /**
ansond 30:113c2a1d8db2 56 Destructor
ansond 30:113c2a1d8db2 57 */
ansond 30:113c2a1d8db2 58 virtual ~TaskletResourceObserver();
ansond 30:113c2a1d8db2 59
ansond 30:113c2a1d8db2 60 /**
ansond 30:113c2a1d8db2 61 begin the observation
ansond 30:113c2a1d8db2 62 */
ansond 30:113c2a1d8db2 63 virtual void beginObservation();
ansond 31:bacc63106754 64
ansond 31:bacc63106754 65 /**
ansond 31:bacc63106754 66 stop the observation
ansond 31:bacc63106754 67 */
ansond 31:bacc63106754 68 virtual void stopObservation();
ansond 31:bacc63106754 69
ansond 31:bacc63106754 70 #ifdef CONNECTOR_USING_TASKLETS
ansond 31:bacc63106754 71 /**
ansond 31:bacc63106754 72 tasklet invoke function (static)
ansond 31:bacc63106754 73 */
ansond 31:bacc63106754 74 static void _observation_notifier(arm_event_s *event);
ansond 34:03a8cc428b8b 75 #endif
ansond 34:03a8cc428b8b 76
ansond 34:03a8cc428b8b 77
ansond 34:03a8cc428b8b 78 #ifdef CONNECTOR_USING_TASKLETS
ansond 31:bacc63106754 79 /**
ansond 31:bacc63106754 80 set the current event
ansond 31:bacc63106754 81 @param event input the current event
ansond 31:bacc63106754 82 */
ansond 31:bacc63106754 83 void setEvent(arm_event_s *event);
ansond 31:bacc63106754 84 #endif
ansond 31:bacc63106754 85
ansond 31:bacc63106754 86 /**
ansond 31:bacc63106754 87 start the tasklet timer
ansond 31:bacc63106754 88 */
ansond 31:bacc63106754 89 void startTimer();
ansond 31:bacc63106754 90
ansond 31:bacc63106754 91 /**
ansond 31:bacc63106754 92 get the tasklet timer ID
ansond 31:bacc63106754 93 @return timer id
ansond 31:bacc63106754 94 */
ansond 31:bacc63106754 95 uint8_t getTimerID();
ansond 31:bacc63106754 96
ansond 30:113c2a1d8db2 97 private:
ansond 31:bacc63106754 98 int m_tasklet_id;
ansond 31:bacc63106754 99 #ifdef CONNECTOR_USING_TASKLETS
ansond 31:bacc63106754 100 arm_event_s *m_event;
ansond 31:bacc63106754 101 #endif
ansond 31:bacc63106754 102 uint8_t m_timer_id;
ansond 31:bacc63106754 103 bool m_timer_active;
ansond 30:113c2a1d8db2 104 };
ansond 30:113c2a1d8db2 105
ansond 30:113c2a1d8db2 106 #endif // __TASKLET_RESOURCE_OBSERVER_H__