LCOV - code coverage report
Current view: top level - source - ITimer.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 4 4
Test Date: 2025-06-24 14:11:58 Functions: 100.0 % 4 4

            Line data    Source code
       1              : /*
       2              :  * Copyright (C) 2023 Sky UK
       3              :  *
       4              :  * This library is free software; you can redistribute it and/or
       5              :  * modify it under the terms of the GNU Lesser General Public
       6              :  * License as published by the Free Software Foundation;
       7              :  * version 2.1 of the License.
       8              :  *
       9              :  * This library is distributed in the hope that it will be useful,
      10              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      12              :  * Lesser General Public License for more details.
      13              :  *
      14              :  * You should have received a copy of the GNU Lesser General Public
      15              :  * License along with this library; if not, write to the Free Software
      16              :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
      17              :  */
      18              : 
      19              : #ifndef I_TIMER_H_
      20              : #define I_TIMER_H_
      21              : 
      22              : #include <chrono>
      23              : #include <functional>
      24              : #include <memory>
      25              : 
      26              : class ITimer;
      27              : 
      28              : enum class TimerType
      29              : {
      30              :     ONE_SHOT,
      31              :     PERIODIC
      32              : };
      33              : 
      34              : /**
      35              :  * @brief ITimerFactory factory class, returns a concrete implementation of ITimer
      36              :  */
      37              : class ITimerFactory
      38              : {
      39              : public:
      40           70 :     ITimerFactory() = default;
      41           70 :     virtual ~ITimerFactory() = default;
      42              : 
      43              :     /**
      44              :      * @brief Gets the ITimerFactory instance.
      45              :      *
      46              :      * @retval the factory instance or null on error.
      47              :      */
      48              :     static std::shared_ptr<ITimerFactory> getFactory();
      49              : 
      50              :     /**
      51              :      * @brief Creates an ITimer object.
      52              :      *
      53              :      * @param[in] timeout   : Timeout after which callback will be called
      54              :      * @param[in] callback  : Function which is called after timeout
      55              :      * @param[in] timerType : Type of timer
      56              :      *
      57              :      * @retval the new timer instance or null on error.
      58              :      */
      59              :     virtual std::unique_ptr<ITimer> createTimer(const std::chrono::milliseconds &timeout,
      60              :                                                 const std::function<void()> &callback,
      61              :                                                 TimerType timerType = TimerType::ONE_SHOT) const = 0;
      62              : };
      63              : 
      64              : class ITimer
      65              : {
      66              : public:
      67            8 :     ITimer() = default;
      68            8 :     virtual ~ITimer() = default;
      69              : 
      70              :     ITimer(const ITimer &) = delete;
      71              :     ITimer &operator=(const ITimer &) = delete;
      72              :     ITimer(ITimer &&) = delete;
      73              :     ITimer &operator=(ITimer &&) = delete;
      74              : 
      75              :     /**
      76              :      * @brief Cancels the timer
      77              :      */
      78              :     virtual void cancel() = 0;
      79              : 
      80              :     /**
      81              :      * @brief Checks if timer is active
      82              :      *
      83              :      * @retval true if timer is active, false otherwise
      84              :      */
      85              :     virtual bool isActive() const = 0;
      86              : };
      87              : 
      88              : #endif // I_TIMER_H_
        

Generated by: LCOV version 2.0-1