LCOV - code coverage report
Current view: top level - media/server/main/interface - IMainThread.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 4 4
Test Date: 2026-06-17 06:35:35 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_SERVER_I_MAIN_THREAD_H_
      21              : #define FIREBOLT_RIALTO_SERVER_I_MAIN_THREAD_H_
      22              : 
      23              : #include <functional>
      24              : #include <memory>
      25              : #include <utility>
      26              : 
      27              : namespace firebolt::rialto::server
      28              : {
      29              : class IMainThread;
      30              : 
      31              : /**
      32              :  * @brief IMainThread factory class, gets the concrete implementation of IMainThread
      33              :  */
      34              : class IMainThreadFactory
      35              : {
      36              : public:
      37          345 :     IMainThreadFactory() = default;
      38          345 :     virtual ~IMainThreadFactory() = default;
      39              : 
      40              :     /**
      41              :      * @brief Create a IMainThreadFactory instance.
      42              :      *
      43              :      * @retval the factory instance or null on error.
      44              :      */
      45              :     static std::shared_ptr<IMainThreadFactory> createFactory();
      46              : 
      47              :     /**
      48              :      * @brief IMainThread factory method, gets a concrete implementation of IMainThread
      49              :      *
      50              :      * @retval the main thread instance or null on error.
      51              :      */
      52              :     virtual std::shared_ptr<IMainThread> getMainThread() const = 0;
      53              : };
      54              : 
      55              : /**
      56              :  * @brief The definition of the IMainThread interface.
      57              :  */
      58              : class IMainThread
      59              : {
      60              : public:
      61              :     using Task = std::function<void()>;
      62              : 
      63          325 :     IMainThread() = default;
      64          325 :     virtual ~IMainThread() = default;
      65              : 
      66              :     IMainThread(const IMainThread &) = delete;
      67              :     IMainThread(IMainThread &&) = delete;
      68              :     IMainThread &operator=(const IMainThread &) = delete;
      69              :     IMainThread &operator=(IMainThread &&) = delete;
      70              : 
      71              :     /**
      72              :      * @brief Register a client on the main thread.
      73              :      *
      74              :      * Required by clients who want to enqueue tasks on the main thread.
      75              :      *
      76              :      * @retval The registered client id.
      77              :      */
      78              :     virtual int32_t registerClient() = 0;
      79              : 
      80              :     /**
      81              :      * @brief Unregister a client on the main thread.
      82              :      *
      83              :      * Should be called on the main thread.
      84              :      * After been called the client will no longer be able to enqueue tasks.
      85              :      *
      86              :      * @param[in]  clientId : The id of the registered client.
      87              :      */
      88              :     virtual void unregisterClient(uint32_t clientId) = 0;
      89              : 
      90              :     /**
      91              :      * @brief Enqueue a task on the main thread and return.
      92              :      *
      93              :      * @param[in]  clientId : The id of the registered client.
      94              :      * @param[in]  task     : Task to queue.
      95              :      */
      96              :     virtual void enqueueTask(uint32_t clientId, const Task &task) = 0;
      97              : 
      98              :     /**
      99              :      * @brief Enqueue a task on the main thread and wait for it to finish before returning.
     100              :      *
     101              :      * @param[in]  clientId : The id of the registered client.
     102              :      * @param[in]  task     : Task to queue.
     103              :      */
     104              :     virtual void enqueueTaskAndWait(uint32_t clientId, const Task &task) = 0;
     105              : 
     106              :     /**
     107              :      * @brief Enqueue a priority task on the main thread and wait for it to finish before returning.
     108              :      *
     109              :      * @param[in]  clientId : The id of the registered client.
     110              :      * @param[in]  task     : Task to queue.
     111              :      */
     112              :     virtual void enqueuePriorityTaskAndWait(uint32_t clientId, const Task &task) = 0;
     113              : };
     114              : } // namespace firebolt::rialto::server
     115              : 
     116              : #endif // FIREBOLT_RIALTO_SERVER_I_MAIN_THREAD_H_
        

Generated by: LCOV version 2.0-1