Simple interface for Mbed Cloud Client

Dependents:  

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers m2mtimerpimpl.h Source File

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 "mbed-client/m2mtimerobserver.h"
00022 
00023 class M2MTimerPimpl {
00024 private:
00025 
00026     // Prevents the use of assignment operator
00027     M2MTimerPimpl& operator=(const M2MTimerPimpl& other);
00028 
00029     // Prevents the use of copy constructor
00030     M2MTimerPimpl(const M2MTimerPimpl& other);
00031 public:
00032 
00033     /**
00034      * Constructor.
00035      */
00036     M2MTimerPimpl(M2MTimerObserver& _observer);
00037 
00038     /**
00039      * Destructor.
00040      */
00041     virtual ~M2MTimerPimpl();
00042 
00043     /**
00044      * Starts timer
00045      * @param interval Timer's interval in milliseconds
00046      * @param single_shot defines if timer is ticked
00047      * once or is it restarted everytime timer is expired.
00048      */
00049     void start_timer(uint64_t interval, M2MTimerObserver::Type type, bool single_shot = true);
00050 
00051     /**
00052      * @brief Starts timer in DTLS manner
00053      * @param intermediate_interval Intermediate interval to use, must be smaller than tiotal (usually 1/4 of total)
00054      * @param total_interval Total interval to use; This is the timeout value of a DTLS packet
00055      * @param type Type of the timer
00056      */
00057     void start_dtls_timer(uint64_t intermediate_interval, uint64_t total_interval, M2MTimerObserver::Type type);
00058 
00059     /**
00060      * Stops timer.
00061      * This cancels the ongoing timer.
00062      */
00063     void stop_timer();
00064 
00065     /**
00066      * Callback function for timer completion.
00067      */
00068     void timer_expired();
00069 
00070     /**
00071      * @brief Checks if the intermediate interval has passed
00072      * @return true if interval has passed, false otherwise
00073      */
00074     bool is_intermediate_interval_passed();
00075 
00076     /**
00077      * @brief Checks if the total interval has passed
00078      * @return true if interval has passed, false otherwise
00079      */
00080     bool is_total_interval_passed();
00081 
00082     /**
00083      * @brief Start long period timer
00084      */
00085     void start_still_left_timer();
00086 
00087     /**
00088      * @brief Get timer id
00089      * @return Timer id
00090      */
00091     inline int8_t get_timer_id() const;
00092 
00093     /**
00094      * @brief Get still left time
00095      * @return Time left in milliseconds
00096      */
00097     uint64_t get_still_left_time() const;
00098 
00099 private:
00100 
00101     void start();
00102     void cancel();
00103 
00104 private:
00105     M2MTimerObserver&   _observer;
00106     bool                _single_shot;
00107     uint64_t            _interval;
00108     M2MTimerObserver::Type  _type;
00109 
00110     uint64_t            _intermediate_interval;
00111     uint64_t            _total_interval;
00112     uint64_t            _still_left;
00113     uint8_t             _status;
00114     bool                _dtls_type;
00115 
00116     // this is the timer-id of this object, used to map the
00117     // timer event callback to the correct object.
00118     int8_t              _timer_id;
00119 
00120     static int8_t       _tasklet_id;
00121     static int8_t       _next_timer_id;
00122 
00123     friend class M2MTimer;
00124     friend class Test_M2MTimerPimpl_classic;
00125 };
00126 
00127 inline int8_t M2MTimerPimpl::get_timer_id() const
00128 {
00129     return _timer_id;
00130 }
00131 
00132 #endif //M2M_TIMER_PIMPL_H__
00133