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