mbed client lightswitch demo
Dependencies: mbed Socket lwip-eth lwip-sys lwip
Fork of mbed-client-classic-example-lwip by
Diff: mbed-client-classic/mbed-client-classic/m2mtimerpimpl.h
- Revision:
- 11:cada08fc8a70
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-client-classic/mbed-client-classic/m2mtimerpimpl.h Thu Jun 09 17:08:36 2016 +0000 @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2015 ARM Limited. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef M2M_TIMER_PIMPL_H__ +#define M2M_TIMER_PIMPL_H__ + +#include <stdint.h> + +#include "mbed-client/m2mtimerobserver.h" +#include "threadwrapper.h" + + +class M2MTimerPimpl { +private: + // Prevents the use of assignment operator + M2MTimerPimpl& operator=(const M2MTimerPimpl& other); + + // Prevents the use of copy constructor + M2MTimerPimpl(const M2MTimerPimpl& other); + + /** + * Constructor. + */ + M2MTimerPimpl(M2MTimerObserver& observer); + + /** + * Destructor. + */ + virtual ~M2MTimerPimpl(); + + /** + * Starts timer + * @param interval Timer's interval in milliseconds + * @param single_shot defines if timer is ticked + * once or is it restarted everytime timer is expired. + */ + void start_timer(uint64_t interval, M2MTimerObserver::Type type, bool single_shot = true); + + /** + * @brief Starts timer in DTLS manner + * @param intermediate_interval Intermediate interval to use, must be smaller than tiotal (usually 1/4 of total) + * @param total_interval Total interval to use; This is the timeout value of a DTLS packet + * @param type Type of the timer + */ + void start_dtls_timer(uint64_t intermediate_interval, uint64_t total_interval, M2MTimerObserver::Type type); + + /** + * Stops timer. + * This cancels the ongoing timer. + */ + void stop_timer(); + + /** + * Callback function for timer completion. + */ + //void timer_expired(); + + /** + * @brief Checks if the intermediate interval has passed + * @return true if interval has passed, false otherwise + */ + bool is_intermediate_interval_passed(); + + /** + * @brief Checks if the total interval has passed + * @return true if interval has passed, false otherwise + */ + bool is_total_interval_passed(); + +private: + /** + * @brief Internal handler for timing + */ + void timer_run(); + +private: + M2MTimerObserver& _observer; + bool _single_shot; + uint64_t _interval; + M2MTimerObserver::Type _type; + + uint64_t _intermediate_interval; + uint64_t _total_interval; + uint8_t _status; + bool _dtls_type; + + rtos::Thread *_thread; + bool _running; + + friend class M2MTimer; + friend class Test_M2MTimerPimpl_mbed; +}; + +#endif //M2M_TIMER_PIMPL_H__