mbed client lightswitch demo
Dependencies: mbed Socket lwip-eth lwip-sys lwip
Fork of mbed-client-classic-example-lwip by
mbed-client-classic/mbed-client-classic/m2mtimerpimpl.h@11:cada08fc8a70, 2016-06-09 (annotated)
- Committer:
- mbedAustin
- Date:
- Thu Jun 09 17:08:36 2016 +0000
- Revision:
- 11:cada08fc8a70
Commit for public Consumption
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedAustin | 11:cada08fc8a70 | 1 | /* |
mbedAustin | 11:cada08fc8a70 | 2 | * Copyright (c) 2015 ARM Limited. All rights reserved. |
mbedAustin | 11:cada08fc8a70 | 3 | * SPDX-License-Identifier: Apache-2.0 |
mbedAustin | 11:cada08fc8a70 | 4 | * Licensed under the Apache License, Version 2.0 (the License); you may |
mbedAustin | 11:cada08fc8a70 | 5 | * not use this file except in compliance with the License. |
mbedAustin | 11:cada08fc8a70 | 6 | * You may obtain a copy of the License at |
mbedAustin | 11:cada08fc8a70 | 7 | * |
mbedAustin | 11:cada08fc8a70 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
mbedAustin | 11:cada08fc8a70 | 9 | * |
mbedAustin | 11:cada08fc8a70 | 10 | * Unless required by applicable law or agreed to in writing, software |
mbedAustin | 11:cada08fc8a70 | 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
mbedAustin | 11:cada08fc8a70 | 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mbedAustin | 11:cada08fc8a70 | 13 | * See the License for the specific language governing permissions and |
mbedAustin | 11:cada08fc8a70 | 14 | * limitations under the License. |
mbedAustin | 11:cada08fc8a70 | 15 | */ |
mbedAustin | 11:cada08fc8a70 | 16 | #ifndef M2M_TIMER_PIMPL_H__ |
mbedAustin | 11:cada08fc8a70 | 17 | #define M2M_TIMER_PIMPL_H__ |
mbedAustin | 11:cada08fc8a70 | 18 | |
mbedAustin | 11:cada08fc8a70 | 19 | #include <stdint.h> |
mbedAustin | 11:cada08fc8a70 | 20 | |
mbedAustin | 11:cada08fc8a70 | 21 | #include "mbed-client/m2mtimerobserver.h" |
mbedAustin | 11:cada08fc8a70 | 22 | #include "threadwrapper.h" |
mbedAustin | 11:cada08fc8a70 | 23 | |
mbedAustin | 11:cada08fc8a70 | 24 | |
mbedAustin | 11:cada08fc8a70 | 25 | class M2MTimerPimpl { |
mbedAustin | 11:cada08fc8a70 | 26 | private: |
mbedAustin | 11:cada08fc8a70 | 27 | // Prevents the use of assignment operator |
mbedAustin | 11:cada08fc8a70 | 28 | M2MTimerPimpl& operator=(const M2MTimerPimpl& other); |
mbedAustin | 11:cada08fc8a70 | 29 | |
mbedAustin | 11:cada08fc8a70 | 30 | // Prevents the use of copy constructor |
mbedAustin | 11:cada08fc8a70 | 31 | M2MTimerPimpl(const M2MTimerPimpl& other); |
mbedAustin | 11:cada08fc8a70 | 32 | |
mbedAustin | 11:cada08fc8a70 | 33 | /** |
mbedAustin | 11:cada08fc8a70 | 34 | * Constructor. |
mbedAustin | 11:cada08fc8a70 | 35 | */ |
mbedAustin | 11:cada08fc8a70 | 36 | M2MTimerPimpl(M2MTimerObserver& observer); |
mbedAustin | 11:cada08fc8a70 | 37 | |
mbedAustin | 11:cada08fc8a70 | 38 | /** |
mbedAustin | 11:cada08fc8a70 | 39 | * Destructor. |
mbedAustin | 11:cada08fc8a70 | 40 | */ |
mbedAustin | 11:cada08fc8a70 | 41 | virtual ~M2MTimerPimpl(); |
mbedAustin | 11:cada08fc8a70 | 42 | |
mbedAustin | 11:cada08fc8a70 | 43 | /** |
mbedAustin | 11:cada08fc8a70 | 44 | * Starts timer |
mbedAustin | 11:cada08fc8a70 | 45 | * @param interval Timer's interval in milliseconds |
mbedAustin | 11:cada08fc8a70 | 46 | * @param single_shot defines if timer is ticked |
mbedAustin | 11:cada08fc8a70 | 47 | * once or is it restarted everytime timer is expired. |
mbedAustin | 11:cada08fc8a70 | 48 | */ |
mbedAustin | 11:cada08fc8a70 | 49 | void start_timer(uint64_t interval, M2MTimerObserver::Type type, bool single_shot = true); |
mbedAustin | 11:cada08fc8a70 | 50 | |
mbedAustin | 11:cada08fc8a70 | 51 | /** |
mbedAustin | 11:cada08fc8a70 | 52 | * @brief Starts timer in DTLS manner |
mbedAustin | 11:cada08fc8a70 | 53 | * @param intermediate_interval Intermediate interval to use, must be smaller than tiotal (usually 1/4 of total) |
mbedAustin | 11:cada08fc8a70 | 54 | * @param total_interval Total interval to use; This is the timeout value of a DTLS packet |
mbedAustin | 11:cada08fc8a70 | 55 | * @param type Type of the timer |
mbedAustin | 11:cada08fc8a70 | 56 | */ |
mbedAustin | 11:cada08fc8a70 | 57 | void start_dtls_timer(uint64_t intermediate_interval, uint64_t total_interval, M2MTimerObserver::Type type); |
mbedAustin | 11:cada08fc8a70 | 58 | |
mbedAustin | 11:cada08fc8a70 | 59 | /** |
mbedAustin | 11:cada08fc8a70 | 60 | * Stops timer. |
mbedAustin | 11:cada08fc8a70 | 61 | * This cancels the ongoing timer. |
mbedAustin | 11:cada08fc8a70 | 62 | */ |
mbedAustin | 11:cada08fc8a70 | 63 | void stop_timer(); |
mbedAustin | 11:cada08fc8a70 | 64 | |
mbedAustin | 11:cada08fc8a70 | 65 | /** |
mbedAustin | 11:cada08fc8a70 | 66 | * Callback function for timer completion. |
mbedAustin | 11:cada08fc8a70 | 67 | */ |
mbedAustin | 11:cada08fc8a70 | 68 | //void timer_expired(); |
mbedAustin | 11:cada08fc8a70 | 69 | |
mbedAustin | 11:cada08fc8a70 | 70 | /** |
mbedAustin | 11:cada08fc8a70 | 71 | * @brief Checks if the intermediate interval has passed |
mbedAustin | 11:cada08fc8a70 | 72 | * @return true if interval has passed, false otherwise |
mbedAustin | 11:cada08fc8a70 | 73 | */ |
mbedAustin | 11:cada08fc8a70 | 74 | bool is_intermediate_interval_passed(); |
mbedAustin | 11:cada08fc8a70 | 75 | |
mbedAustin | 11:cada08fc8a70 | 76 | /** |
mbedAustin | 11:cada08fc8a70 | 77 | * @brief Checks if the total interval has passed |
mbedAustin | 11:cada08fc8a70 | 78 | * @return true if interval has passed, false otherwise |
mbedAustin | 11:cada08fc8a70 | 79 | */ |
mbedAustin | 11:cada08fc8a70 | 80 | bool is_total_interval_passed(); |
mbedAustin | 11:cada08fc8a70 | 81 | |
mbedAustin | 11:cada08fc8a70 | 82 | private: |
mbedAustin | 11:cada08fc8a70 | 83 | /** |
mbedAustin | 11:cada08fc8a70 | 84 | * @brief Internal handler for timing |
mbedAustin | 11:cada08fc8a70 | 85 | */ |
mbedAustin | 11:cada08fc8a70 | 86 | void timer_run(); |
mbedAustin | 11:cada08fc8a70 | 87 | |
mbedAustin | 11:cada08fc8a70 | 88 | private: |
mbedAustin | 11:cada08fc8a70 | 89 | M2MTimerObserver& _observer; |
mbedAustin | 11:cada08fc8a70 | 90 | bool _single_shot; |
mbedAustin | 11:cada08fc8a70 | 91 | uint64_t _interval; |
mbedAustin | 11:cada08fc8a70 | 92 | M2MTimerObserver::Type _type; |
mbedAustin | 11:cada08fc8a70 | 93 | |
mbedAustin | 11:cada08fc8a70 | 94 | uint64_t _intermediate_interval; |
mbedAustin | 11:cada08fc8a70 | 95 | uint64_t _total_interval; |
mbedAustin | 11:cada08fc8a70 | 96 | uint8_t _status; |
mbedAustin | 11:cada08fc8a70 | 97 | bool _dtls_type; |
mbedAustin | 11:cada08fc8a70 | 98 | |
mbedAustin | 11:cada08fc8a70 | 99 | rtos::Thread *_thread; |
mbedAustin | 11:cada08fc8a70 | 100 | bool _running; |
mbedAustin | 11:cada08fc8a70 | 101 | |
mbedAustin | 11:cada08fc8a70 | 102 | friend class M2MTimer; |
mbedAustin | 11:cada08fc8a70 | 103 | friend class Test_M2MTimerPimpl_mbed; |
mbedAustin | 11:cada08fc8a70 | 104 | }; |
mbedAustin | 11:cada08fc8a70 | 105 | |
mbedAustin | 11:cada08fc8a70 | 106 | #endif //M2M_TIMER_PIMPL_H__ |