Toyomasa Watarai / simple-mbed-cloud-client

Dependents:  

Committer:
MACRUM
Date:
Mon Jul 02 06:30:39 2018 +0000
Revision:
0:276e7a263c35
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MACRUM 0:276e7a263c35 1 /*
MACRUM 0:276e7a263c35 2 * Copyright (c) 2015 ARM Limited. All rights reserved.
MACRUM 0:276e7a263c35 3 * SPDX-License-Identifier: Apache-2.0
MACRUM 0:276e7a263c35 4 * Licensed under the Apache License, Version 2.0 (the License); you may
MACRUM 0:276e7a263c35 5 * not use this file except in compliance with the License.
MACRUM 0:276e7a263c35 6 * You may obtain a copy of the License at
MACRUM 0:276e7a263c35 7 *
MACRUM 0:276e7a263c35 8 * http://www.apache.org/licenses/LICENSE-2.0
MACRUM 0:276e7a263c35 9 *
MACRUM 0:276e7a263c35 10 * Unless required by applicable law or agreed to in writing, software
MACRUM 0:276e7a263c35 11 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
MACRUM 0:276e7a263c35 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
MACRUM 0:276e7a263c35 13 * See the License for the specific language governing permissions and
MACRUM 0:276e7a263c35 14 * limitations under the License.
MACRUM 0:276e7a263c35 15 */
MACRUM 0:276e7a263c35 16
MACRUM 0:276e7a263c35 17 #ifndef M2M_TIMER_PIMPL_H__
MACRUM 0:276e7a263c35 18 #define M2M_TIMER_PIMPL_H__
MACRUM 0:276e7a263c35 19
MACRUM 0:276e7a263c35 20 #include "ns_types.h"
MACRUM 0:276e7a263c35 21 #include "mbed-client/m2mtimerobserver.h"
MACRUM 0:276e7a263c35 22
MACRUM 0:276e7a263c35 23 class M2MTimerPimpl {
MACRUM 0:276e7a263c35 24 private:
MACRUM 0:276e7a263c35 25
MACRUM 0:276e7a263c35 26 // Prevents the use of assignment operator
MACRUM 0:276e7a263c35 27 M2MTimerPimpl& operator=(const M2MTimerPimpl& other);
MACRUM 0:276e7a263c35 28
MACRUM 0:276e7a263c35 29 // Prevents the use of copy constructor
MACRUM 0:276e7a263c35 30 M2MTimerPimpl(const M2MTimerPimpl& other);
MACRUM 0:276e7a263c35 31 public:
MACRUM 0:276e7a263c35 32
MACRUM 0:276e7a263c35 33 /**
MACRUM 0:276e7a263c35 34 * Constructor.
MACRUM 0:276e7a263c35 35 */
MACRUM 0:276e7a263c35 36 M2MTimerPimpl(M2MTimerObserver& _observer);
MACRUM 0:276e7a263c35 37
MACRUM 0:276e7a263c35 38 /**
MACRUM 0:276e7a263c35 39 * Destructor.
MACRUM 0:276e7a263c35 40 */
MACRUM 0:276e7a263c35 41 virtual ~M2MTimerPimpl();
MACRUM 0:276e7a263c35 42
MACRUM 0:276e7a263c35 43 /**
MACRUM 0:276e7a263c35 44 * Starts timer
MACRUM 0:276e7a263c35 45 * @param interval Timer's interval in milliseconds
MACRUM 0:276e7a263c35 46 * @param single_shot defines if timer is ticked
MACRUM 0:276e7a263c35 47 * once or is it restarted everytime timer is expired.
MACRUM 0:276e7a263c35 48 */
MACRUM 0:276e7a263c35 49 void start_timer(uint64_t interval, M2MTimerObserver::Type type, bool single_shot = true);
MACRUM 0:276e7a263c35 50
MACRUM 0:276e7a263c35 51 /**
MACRUM 0:276e7a263c35 52 * @brief Starts timer in DTLS manner
MACRUM 0:276e7a263c35 53 * @param intermediate_interval Intermediate interval to use, must be smaller than tiotal (usually 1/4 of total)
MACRUM 0:276e7a263c35 54 * @param total_interval Total interval to use; This is the timeout value of a DTLS packet
MACRUM 0:276e7a263c35 55 * @param type Type of the timer
MACRUM 0:276e7a263c35 56 */
MACRUM 0:276e7a263c35 57 void start_dtls_timer(uint64_t intermediate_interval, uint64_t total_interval, M2MTimerObserver::Type type);
MACRUM 0:276e7a263c35 58
MACRUM 0:276e7a263c35 59 /**
MACRUM 0:276e7a263c35 60 * Stops timer.
MACRUM 0:276e7a263c35 61 * This cancels the ongoing timer.
MACRUM 0:276e7a263c35 62 */
MACRUM 0:276e7a263c35 63 void stop_timer();
MACRUM 0:276e7a263c35 64
MACRUM 0:276e7a263c35 65 /**
MACRUM 0:276e7a263c35 66 * Callback function for timer completion.
MACRUM 0:276e7a263c35 67 */
MACRUM 0:276e7a263c35 68 void timer_expired();
MACRUM 0:276e7a263c35 69
MACRUM 0:276e7a263c35 70 /**
MACRUM 0:276e7a263c35 71 * @brief Checks if the intermediate interval has passed
MACRUM 0:276e7a263c35 72 * @return true if interval has passed, false otherwise
MACRUM 0:276e7a263c35 73 */
MACRUM 0:276e7a263c35 74 bool is_intermediate_interval_passed();
MACRUM 0:276e7a263c35 75
MACRUM 0:276e7a263c35 76 /**
MACRUM 0:276e7a263c35 77 * @brief Checks if the total interval has passed
MACRUM 0:276e7a263c35 78 * @return true if interval has passed, false otherwise
MACRUM 0:276e7a263c35 79 */
MACRUM 0:276e7a263c35 80 bool is_total_interval_passed();
MACRUM 0:276e7a263c35 81
MACRUM 0:276e7a263c35 82 /**
MACRUM 0:276e7a263c35 83 * @brief Start long period timer
MACRUM 0:276e7a263c35 84 */
MACRUM 0:276e7a263c35 85 void start_still_left_timer();
MACRUM 0:276e7a263c35 86
MACRUM 0:276e7a263c35 87 /**
MACRUM 0:276e7a263c35 88 * @brief Get timer id
MACRUM 0:276e7a263c35 89 * @return Timer id
MACRUM 0:276e7a263c35 90 */
MACRUM 0:276e7a263c35 91 inline int8_t get_timer_id() const;
MACRUM 0:276e7a263c35 92
MACRUM 0:276e7a263c35 93 /**
MACRUM 0:276e7a263c35 94 * @brief Get still left time
MACRUM 0:276e7a263c35 95 * @return Time left in milliseconds
MACRUM 0:276e7a263c35 96 */
MACRUM 0:276e7a263c35 97 uint64_t get_still_left_time() const;
MACRUM 0:276e7a263c35 98
MACRUM 0:276e7a263c35 99 private:
MACRUM 0:276e7a263c35 100
MACRUM 0:276e7a263c35 101 void start();
MACRUM 0:276e7a263c35 102 void cancel();
MACRUM 0:276e7a263c35 103
MACRUM 0:276e7a263c35 104 private:
MACRUM 0:276e7a263c35 105 M2MTimerObserver& _observer;
MACRUM 0:276e7a263c35 106 bool _single_shot;
MACRUM 0:276e7a263c35 107 uint64_t _interval;
MACRUM 0:276e7a263c35 108 M2MTimerObserver::Type _type;
MACRUM 0:276e7a263c35 109
MACRUM 0:276e7a263c35 110 uint64_t _intermediate_interval;
MACRUM 0:276e7a263c35 111 uint64_t _total_interval;
MACRUM 0:276e7a263c35 112 uint64_t _still_left;
MACRUM 0:276e7a263c35 113 uint8_t _status;
MACRUM 0:276e7a263c35 114 bool _dtls_type;
MACRUM 0:276e7a263c35 115
MACRUM 0:276e7a263c35 116 // this is the timer-id of this object, used to map the
MACRUM 0:276e7a263c35 117 // timer event callback to the correct object.
MACRUM 0:276e7a263c35 118 int8_t _timer_id;
MACRUM 0:276e7a263c35 119
MACRUM 0:276e7a263c35 120 static int8_t _tasklet_id;
MACRUM 0:276e7a263c35 121 static int8_t _next_timer_id;
MACRUM 0:276e7a263c35 122
MACRUM 0:276e7a263c35 123 friend class M2MTimer;
MACRUM 0:276e7a263c35 124 friend class Test_M2MTimerPimpl_classic;
MACRUM 0:276e7a263c35 125 };
MACRUM 0:276e7a263c35 126
MACRUM 0:276e7a263c35 127 inline int8_t M2MTimerPimpl::get_timer_id() const
MACRUM 0:276e7a263c35 128 {
MACRUM 0:276e7a263c35 129 return _timer_id;
MACRUM 0:276e7a263c35 130 }
MACRUM 0:276e7a263c35 131
MACRUM 0:276e7a263c35 132 #endif //M2M_TIMER_PIMPL_H__
MACRUM 0:276e7a263c35 133