Skip to content

Commit

Permalink
[PVR] Block addon calls early when pvr manager stops to ensure quicke…
Browse files Browse the repository at this point in the history
…st shutdown possible.
  • Loading branch information
ksooo committed Nov 11, 2017
1 parent 2a62ed2 commit 5b54914
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 2 deletions.
15 changes: 15 additions & 0 deletions xbmc/addons/PVRClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ void CPVRClient::ResetProperties(int iClientId /* = PVR_INVALID_CLIENT_ID */)
m_strUserPath = CSpecialProtocol::TranslatePath(Profile());
m_strClientPath = CSpecialProtocol::TranslatePath(Path());
m_bReadyToUse = false;
m_bBlockAddonCalls = false;
m_connectionState = PVR_CONNECTION_STATE_UNKNOWN;
m_prevConnectionState = PVR_CONNECTION_STATE_UNKNOWN;
m_ignoreClient = false;
Expand Down Expand Up @@ -192,6 +193,7 @@ void CPVRClient::Destroy(void)
{
if (!m_bReadyToUse)
return;

m_bReadyToUse = false;

/* reset 'ready to use' to false */
Expand All @@ -204,6 +206,16 @@ void CPVRClient::Destroy(void)
ResetProperties();
}

void CPVRClient::Stop()
{
m_bBlockAddonCalls = true;
}

void CPVRClient::Continue()
{
m_bBlockAddonCalls = false;
}

void CPVRClient::ReCreate(void)
{
int iClientID(m_iClientId);
Expand Down Expand Up @@ -1278,6 +1290,9 @@ PVR_ERROR CPVRClient::DoAddonCall(const char* strFunctionName, std::function<PVR
if (!bIsImplemented)
return PVR_ERROR_NOT_IMPLEMENTED;

if (m_bBlockAddonCalls)
return PVR_ERROR_SERVER_ERROR;

if (!m_bReadyToUse && bCheckReadyToUse)
return PVR_ERROR_SERVER_ERROR;

Expand Down
14 changes: 13 additions & 1 deletion xbmc/addons/PVRClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*
*/

#include <atomic>
#include <functional>
#include <memory>
#include <string>
Expand Down Expand Up @@ -231,6 +232,16 @@ namespace PVR
*/
bool DllLoaded(void) const;

/*!
* @brief Stop this add-on instance. No more client add-on access after this call.
*/
void Stop();

/*!
* @brief Continue this add-on instance. Client add-on access is okay again after this call.
*/
void Continue();

/*!
* @brief Destroy the instance of this add-on.
*/
Expand Down Expand Up @@ -1073,7 +1084,8 @@ namespace PVR
static xbmc_codec_t cb_get_codec_by_name(const void* kodiInstance, const char* strCodecName);
//@}

bool m_bReadyToUse; /*!< true if this add-on is initialised (ADDON_Create returned true), false otherwise */
std::atomic<bool> m_bReadyToUse; /*!< true if this add-on is initialised (ADDON_Create returned true), false otherwise */
std::atomic<bool> m_bBlockAddonCalls; /*!< true if no add-on API calls are allowed */
PVR_CONNECTION_STATE m_connectionState; /*!< the backend connection state */
PVR_CONNECTION_STATE m_prevConnectionState; /*!< the previous backend connection state */
bool m_ignoreClient; /*!< signals to PVRManager to ignore this client until it has been connected */
Expand Down
2 changes: 2 additions & 0 deletions xbmc/pvr/PVRManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ void CPVRManager::Stop(void)
CLog::Log(LOGNOTICE, "PVR Manager: Stopping");
SetState(ManagerStateStopping);

m_addons->Stop();
m_pendingUpdates.Stop();
m_epgContainer.Stop();
m_guiInfo->Stop();
Expand Down Expand Up @@ -407,6 +408,7 @@ void CPVRManager::PublishEvent(PVREvent event)

void CPVRManager::Process(void)
{
m_addons->Continue();
m_database->Open();

/* load the pvr data from the db and clients if it's not already loaded */
Expand Down
18 changes: 18 additions & 0 deletions xbmc/pvr/addons/PVRClients.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,24 @@ void CPVRClients::Start(void)
UpdateAddons();
}

void CPVRClients::Stop()
{
CSingleLock lock(m_critSection);
for (const auto &client : m_clientMap)
{
client.second->Stop();
}
}

void CPVRClients::Continue()
{
CSingleLock lock(m_critSection);
for (const auto &client : m_clientMap)
{
client.second->Continue();
}
}

bool CPVRClients::IsCreatedClient(int iClientId) const
{
CPVRClientPtr client;
Expand Down
12 changes: 11 additions & 1 deletion xbmc/pvr/addons/PVRClients.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,20 @@ namespace PVR
~CPVRClients(void) override;

/*!
* @brief Start the backend.
* @brief Start all clients.
*/
void Start(void);

/*!
* @brief Stop all clients.
*/
void Stop();

/*!
* @brief Continue all clients.
*/
void Continue();

/*!
* @brief Update add-ons from the AddonManager
* @param changedAddonId The id of the changed addon, empty string denotes 'any addon'.
Expand Down

0 comments on commit 5b54914

Please sign in to comment.