Simulated product dispenser
Fork of mbed-cloud-workshop-connect-HTS221 by
m2mtimerpimpl.h
00001 /* 00002 * Copyright (c) 2015 ARM Limited. All rights reserved. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * Licensed under the Apache License, Version 2.0 (the License); you may 00005 * not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an AS IS BASIS, WITHOUT 00012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef M2M_TIMER_PIMPL_H__ 00018 #define M2M_TIMER_PIMPL_H__ 00019 00020 #include "ns_types.h" 00021 #include "eventOS_event.h" 00022 #include "mbed-client/m2mtimerobserver.h" 00023 00024 class M2MTimerPimpl { 00025 private: 00026 00027 // Prevents the use of assignment operator 00028 M2MTimerPimpl& operator=(const M2MTimerPimpl& other); 00029 00030 // Prevents the use of copy constructor 00031 M2MTimerPimpl(const M2MTimerPimpl& other); 00032 public: 00033 00034 /** 00035 * Constructor. 00036 */ 00037 M2MTimerPimpl(M2MTimerObserver& _observer); 00038 00039 /** 00040 * Destructor. 00041 */ 00042 virtual ~M2MTimerPimpl(); 00043 00044 /** 00045 * Starts timer 00046 * @param interval Timer's interval in milliseconds 00047 * @param single_shot defines if timer is ticked 00048 * once or is it restarted everytime timer is expired. 00049 */ 00050 void start_timer(uint64_t interval, M2MTimerObserver::Type type, bool single_shot = true); 00051 00052 /** 00053 * @brief Starts timer in DTLS manner 00054 * @param intermediate_interval Intermediate interval to use, must be smaller than tiotal (usually 1/4 of total) 00055 * @param total_interval Total interval to use; This is the timeout value of a DTLS packet 00056 * @param type Type of the timer 00057 */ 00058 void start_dtls_timer(uint64_t intermediate_interval, uint64_t total_interval, M2MTimerObserver::Type type); 00059 00060 /** 00061 * Stops timer. 00062 * This cancels the ongoing timer. 00063 */ 00064 void stop_timer(); 00065 00066 /** 00067 * @brief Checks if the intermediate interval has passed 00068 * @return true if interval has passed, false otherwise 00069 */ 00070 bool is_intermediate_interval_passed() const; 00071 00072 /** 00073 * @brief Checks if the total interval has passed 00074 * @return true if interval has passed, false otherwise 00075 */ 00076 bool is_total_interval_passed() const; 00077 00078 /** 00079 * @brief Get still left time 00080 * @return Time left in milliseconds 00081 */ 00082 uint64_t get_still_left_time() const; 00083 00084 /** 00085 * Tasklet's internal event handler, which needs to be public as it is used from C wrapper side. 00086 * This makes it possible to at least keep the member variables private. 00087 */ 00088 void handle_timer_event(const arm_event_s &event); 00089 00090 private: 00091 00092 /** 00093 * Second phase of initialization, which will create the tasklet upon first call to 00094 * to any of the M2MTimerPimpl instances a start_timer() or start_dtls_timer(). 00095 */ 00096 void initialize_tasklet(); 00097 00098 /** 00099 * @brief Start long period timer 00100 */ 00101 void start_still_left_timer(); 00102 00103 /** 00104 * Function handling the timer completion. 00105 */ 00106 void timer_expired(); 00107 00108 void start(); 00109 void cancel(); 00110 00111 /** 00112 * Internal helper to request a event after given amount of milliseconds. 00113 * @param delay_ms requested delay in milliseconds 00114 */ 00115 void request_event_in(int32_t delay_ms); 00116 00117 private: 00118 M2MTimerObserver& _observer; 00119 uint64_t _interval; 00120 00121 uint64_t _intermediate_interval; 00122 uint64_t _total_interval; 00123 uint64_t _still_left; 00124 00125 // pointer to the current timer event pending, NULL if none is in flight 00126 arm_event_storage_t *_timer_event; 00127 00128 M2MTimerObserver::Type _type : 4; 00129 00130 unsigned int _status : 2; 00131 00132 bool _dtls_type : 1; 00133 00134 bool _single_shot : 1; 00135 00136 static int8_t _tasklet_id; 00137 00138 friend class M2MTimer; 00139 friend class Test_M2MTimerPimpl_classic; 00140 }; 00141 00142 #endif //M2M_TIMER_PIMPL_H__ 00143
Generated on Tue Jul 12 2022 19:12:13 by 1.7.2