LCOV - code coverage report
Current view: top level - common/interface - ITimer.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 4 4
Test Date: 2025-02-18 13:13:53 Functions: 100.0 % 4 4

            Line data    Source code
       1              : /*
       2              :  * If not stated otherwise in this file or this component's LICENSE file the
       3              :  * following copyright and licenses apply:
       4              :  *
       5              :  * Copyright 2022 Sky UK
       6              :  *
       7              :  * Licensed under the Apache License, Version 2.0 (the "License");
       8              :  * you may not use this file except in compliance with the License.
       9              :  * You may obtain a copy of the License at
      10              :  *
      11              :  * http://www.apache.org/licenses/LICENSE-2.0
      12              :  *
      13              :  * Unless required by applicable law or agreed to in writing, software
      14              :  * distributed under the License is distributed on an "AS IS" BASIS,
      15              :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      16              :  * See the License for the specific language governing permissions and
      17              :  * limitations under the License.
      18              :  */
      19              : 
      20              : #ifndef FIREBOLT_RIALTO_COMMON_I_TIMER_H_
      21              : #define FIREBOLT_RIALTO_COMMON_I_TIMER_H_
      22              : 
      23              : #include <chrono>
      24              : #include <functional>
      25              : #include <memory>
      26              : 
      27              : namespace firebolt::rialto::common
      28              : {
      29              : class ITimer;
      30              : 
      31              : enum class TimerType
      32              : {
      33              :     ONE_SHOT,
      34              :     PERIODIC
      35              : };
      36              : 
      37              : /**
      38              :  * @brief ITimerFactory factory class, returns a concrete implementation of ITimer
      39              :  */
      40              : class ITimerFactory
      41              : {
      42              : public:
      43          445 :     ITimerFactory() = default;
      44          445 :     virtual ~ITimerFactory() = default;
      45              : 
      46              :     /**
      47              :      * @brief Gets the ITimerFactory instance.
      48              :      *
      49              :      * @retval the factory instance or null on error.
      50              :      */
      51              :     static std::shared_ptr<ITimerFactory> getFactory();
      52              : 
      53              :     /**
      54              :      * @brief Creates an ITimer object.
      55              :      *
      56              :      * @param[in] timeout   : Timeout after which callback will be called
      57              :      * @param[in] callback  : Function which is called after timeout
      58              :      * @param[in] timerType : Type of timer
      59              :      *
      60              :      * @retval the new timer instance or null on error.
      61              :      */
      62              :     virtual std::unique_ptr<ITimer> createTimer(const std::chrono::milliseconds &timeout,
      63              :                                                 const std::function<void()> &callback,
      64              :                                                 TimerType timerType = TimerType::ONE_SHOT) const = 0;
      65              : };
      66              : 
      67              : class ITimer
      68              : {
      69              : public:
      70          194 :     ITimer() = default;
      71          194 :     virtual ~ITimer() = default;
      72              : 
      73              :     ITimer(const ITimer &) = delete;
      74              :     ITimer &operator=(const ITimer &) = delete;
      75              :     ITimer(ITimer &&) = delete;
      76              :     ITimer &operator=(ITimer &&) = delete;
      77              : 
      78              :     /**
      79              :      * @brief Cancels the timer
      80              :      */
      81              :     virtual void cancel() = 0;
      82              : 
      83              :     /**
      84              :      * @brief Checks if timer is active
      85              :      *
      86              :      * @retval true if timer is active, false otherwise
      87              :      */
      88              :     virtual bool isActive() const = 0;
      89              : };
      90              : 
      91              : } // namespace firebolt::rialto::common
      92              : 
      93              : #endif // FIREBOLT_RIALTO_COMMON_I_TIMER_H_
        

Generated by: LCOV version 2.0-1