Austin Blackstone / Mbed 2 deprecated mbed-client-classic-example-lwip

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Fork of mbed-client-classic-example-lwip by sandbox

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 #ifndef M2M_TIMER_PIMPL_H__
00017 #define M2M_TIMER_PIMPL_H__
00018 
00019 #include <stdint.h>
00020 
00021 #include "mbed-client/m2mtimerobserver.h"
00022 #include "threadwrapper.h"
00023 
00024 
00025 class M2MTimerPimpl {
00026 private:
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 
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 private:
00083     /**
00084      * @brief Internal handler for timing
00085      */
00086     void timer_run();
00087 
00088 private:
00089     M2MTimerObserver&   _observer;
00090     bool                _single_shot;
00091     uint64_t            _interval;
00092     M2MTimerObserver::Type  _type;
00093 
00094     uint64_t            _intermediate_interval;
00095     uint64_t            _total_interval;
00096     uint8_t             _status;
00097     bool                _dtls_type;
00098 
00099     rtos::Thread        *_thread;
00100     bool                _running;
00101 
00102     friend class M2MTimer;
00103     friend class Test_M2MTimerPimpl_mbed;
00104 };
00105 
00106 #endif //M2M_TIMER_PIMPL_H__