| 1 |
/* |
| 2 |
* Copyright (C) 2005-2018 Team Kodi |
| 3 |
* This file is part of Kodi - https://kodi.tv |
| 4 |
* |
| 5 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 6 |
* See LICENSES/README.md for more information. |
| 7 |
*/ |
| 8 |
|
| 9 |
#pragma once |
| 10 |
|
| 11 |
#include "SkinTimer.h" |
| 12 |
|
| 13 |
#include <map> |
| 14 |
#include <memory> |
| 15 |
#include <string> |
| 16 |
|
| 17 |
class CGUIInfoManager; |
| 18 |
namespace tinyxml2 |
| 19 |
{ |
| 20 |
class XMLNode; |
| 21 |
} |
| 22 |
|
| 23 |
/*! \brief CSkinTimerManager is the container and manager for Skin timers. Its role is that of |
| 24 |
* checking if the timer boolean conditions are valid, start or stop timers and execute the respective |
| 25 |
* builtin actions linked to the timer lifecycle |
| 26 |
* \note This component should only be called by the main/rendering thread |
| 27 |
* \sa Skin_Timers |
| 28 |
* \sa CSkinTimer |
| 29 |
*/ |
| 30 |
class CSkinTimerManager |
| 31 |
{ |
| 32 |
public: |
| 33 |
/*! \brief Skin timer manager constructor |
| 34 |
* \param infoMgr reference to the infomanager |
| 35 |
*/ |
| 36 |
CSkinTimerManager(CGUIInfoManager& infoMgr); |
| 37 |
CSkinTimerManager() = delete; |
| 38 |
|
| 39 |
/*! \brief Default skin timer manager destructor */ |
| 40 |
~CSkinTimerManager() = default; |
| 41 |
|
| 42 |
/*! \brief Loads all the skin timers |
| 43 |
* \param path - the path for the skin Timers.xml file |
| 44 |
*/ |
| 45 |
void LoadTimers(const std::string& path); |
| 46 |
|
| 47 |
/*! \brief Stops the manager */ |
| 48 |
void Stop(); |
| 49 |
|
| 50 |
/*! \brief Gets the total number of timers registered in the manager |
| 51 |
* \return the timer count |
| 52 |
*/ |
| 53 |
size_t GetTimerCount() const; |
| 54 |
|
| 55 |
/*! \brief Checks if the timer with name `timer` exists |
| 56 |
* \param timer the name of the skin timer |
| 57 |
* \return true if the given timer exists, false otherwise |
| 58 |
*/ |
| 59 |
bool TimerExists(const std::string& timer) const; |
| 60 |
|
| 61 |
/*! \brief Move a given timer, removing it from the manager |
| 62 |
* \param timer the name of the skin timer |
| 63 |
* \return the timer (moved), nullptr if it doesn't exist |
| 64 |
*/ |
| 65 |
std::unique_ptr<CSkinTimer> GrabTimer(const std::string& timer); |
| 66 |
|
| 67 |
/*! \brief Checks if the timer with name `timer` is running |
| 68 |
\param timer the name of the skin timer |
| 69 |
\return true if the given timer exists and is running, false otherwise |
| 70 |
*/ |
| 71 |
bool TimerIsRunning(const std::string& timer) const; |
| 72 |
|
| 73 |
/*! \brief Get the elapsed seconds since the timer with name `timer` was started |
| 74 |
\param timer the name of the skin timer |
| 75 |
\return the elapsed time in seconds the given timer is running (0 if not running or if it does not exist) |
| 76 |
*/ |
| 77 |
float GetTimerElapsedSeconds(const std::string& timer) const; |
| 78 |
|
| 79 |
/*! \brief Starts/Enables a given skin timer |
| 80 |
\param timer the name of the skin timer |
| 81 |
*/ |
| 82 |
void TimerStart(const std::string& timer) const; |
| 83 |
|
| 84 |
/*! \brief Stops/Disables a given skin timer |
| 85 |
\param timer the name of the skin timer |
| 86 |
*/ |
| 87 |
void TimerStop(const std::string& timer) const; |
| 88 |
|
| 89 |
// CThread methods |
| 90 |
|
| 91 |
/*! \brief Run the main manager processing loop */ |
| 92 |
void Process(); |
| 93 |
|
| 94 |
private: |
| 95 |
/*! \brief Loads a specific timer |
| 96 |
* \note Called internally from LoadTimers |
| 97 |
* \param node - the XML representation of a skin timer object |
| 98 |
*/ |
| 99 |
void LoadTimerInternal(const tinyxml2::XMLNode* node); |
| 100 |
|
| 101 |
/*! Container for the skin timers */ |
| 102 |
std::map<std::string, std::unique_ptr<CSkinTimer>> m_timers; |
| 103 |
CGUIInfoManager& m_infoMgr; |
| 104 |
}; |