diff options
author | Rainer Hochecker <fernetmenta@online.de> | 2016-03-26 16:22:44 +0100 |
---|---|---|
committer | Rainer Hochecker <fernetmenta@online.de> | 2016-03-27 11:04:08 +0200 |
commit | c3b7c9d43dc0564c8b063ae7f671ebac1feb9172 (patch) | |
tree | a216b6e2f7358be3189b96ec40ceefaaedaa95b7 | |
parent | e164dd12d193722d9479060dc9e15992b8bf0a0e (diff) |
[pvr] - fix and improve connection handling
-rw-r--r-- | addons/resource.language.en_gb/resources/strings.po | 8 | ||||
-rw-r--r-- | xbmc/addons/PVRClient.cpp | 18 | ||||
-rw-r--r-- | xbmc/addons/PVRClient.h | 9 | ||||
-rw-r--r-- | xbmc/addons/binary/interfaces/api1/PVR/AddonCallbacksPVR.cpp | 48 | ||||
-rw-r--r-- | xbmc/addons/kodi-addon-dev-kit/include/kodi/xbmc_pvr_types.h | 1 | ||||
-rw-r--r-- | xbmc/pvr/PVRManager.cpp | 11 | ||||
-rw-r--r-- | xbmc/pvr/PVRManager.h | 21 | ||||
-rw-r--r-- | xbmc/pvr/addons/PVRClients.cpp | 90 | ||||
-rw-r--r-- | xbmc/pvr/addons/PVRClients.h | 3 |
9 files changed, 147 insertions, 62 deletions
diff --git a/addons/resource.language.en_gb/resources/strings.po b/addons/resource.language.en_gb/resources/strings.po index 960560b877..481828c08d 100644 --- a/addons/resource.language.en_gb/resources/strings.po +++ b/addons/resource.language.en_gb/resources/strings.po @@ -15661,7 +15661,13 @@ msgctxt "#35508" msgid "Access denied." msgstr "" -#empty strings from id 35509 to 35999 +#. connection state "connecting" (asynchronous addon start) +#: xbmc/addons/AddonCallbacksPVR.cpp +msgctxt "#35509" +msgid "Connecting to backend." +msgstr "" + +#empty strings from id 35510 to 35999 #: xbmc/peripherals/devices/PeripheralCecAdapter.cpp msgctxt "#36000" diff --git a/xbmc/addons/PVRClient.cpp b/xbmc/addons/PVRClient.cpp index 298fd03de9..c9c5b3c087 100644 --- a/xbmc/addons/PVRClient.cpp +++ b/xbmc/addons/PVRClient.cpp @@ -218,18 +218,16 @@ bool CPVRClient::ReadyToUse(void) const return m_bReadyToUse; } -void CPVRClient::SetConnectionState(PVR_CONNECTION_STATE state) +PVR_CONNECTION_STATE CPVRClient::GetConnectionState(void) const { - if (m_connectionState != state) - { - m_connectionState = state; + CSingleLock lock(m_critSection); + return m_connectionState; +} - if (state == PVR_CONNECTION_STATE_CONNECTED) - { - CLog::Log(LOGDEBUG, "PVRClient - %s - refetching addon properties", __FUNCTION__); - GetAddonProperties(); - } - } +void CPVRClient::SetConnectionState(PVR_CONNECTION_STATE state) +{ + CSingleLock lock(m_critSection); + m_connectionState = state; } int CPVRClient::GetID(void) const diff --git a/xbmc/addons/PVRClient.h b/xbmc/addons/PVRClient.h index f82c7cd846..565d129c81 100644 --- a/xbmc/addons/PVRClient.h +++ b/xbmc/addons/PVRClient.h @@ -109,7 +109,7 @@ namespace PVR * @brief Gets the backend connection state. * @return the backend connection state. */ - PVR_CONNECTION_STATE GetConnectionState(void) const { return m_connectionState; } + PVR_CONNECTION_STATE GetConnectionState(void) const; /*! * @brief Sets the backend connection state. @@ -617,6 +617,11 @@ namespace PVR */ bool IsRealTimeStream() const; + /*! + * @brief reads the client's properties + */ + bool GetAddonProperties(void); + private: /*! * @brief Checks whether the provided API version is compatible with XBMC @@ -645,8 +650,6 @@ namespace PVR */ void ResetProperties(int iClientId = PVR_INVALID_CLIENT_ID); - bool GetAddonProperties(void); - /*! * @brief Copy over group info from xbmcGroup to addonGroup. * @param xbmcGroup The group on XBMC's side. diff --git a/xbmc/addons/binary/interfaces/api1/PVR/AddonCallbacksPVR.cpp b/xbmc/addons/binary/interfaces/api1/PVR/AddonCallbacksPVR.cpp index a350af3de5..5a3d813809 100644 --- a/xbmc/addons/binary/interfaces/api1/PVR/AddonCallbacksPVR.cpp +++ b/xbmc/addons/binary/interfaces/api1/PVR/AddonCallbacksPVR.cpp @@ -341,53 +341,7 @@ void CAddonCallbacksPVR::PVRConnectionStateChange(void* addonData, const char* s client->SetConnectionState(newState); - int iMsg(-1); - bool bError(true); - bool bNotify(true); - - switch (newState) - { - case PVR_CONNECTION_STATE_SERVER_UNREACHABLE: - iMsg = 35505; // Server is unreachable - break; - case PVR_CONNECTION_STATE_SERVER_MISMATCH: - iMsg = 35506; // Server does not respond properly - break; - case PVR_CONNECTION_STATE_VERSION_MISMATCH: - iMsg = 35507; // Server version is not compatible - break; - case PVR_CONNECTION_STATE_ACCESS_DENIED: - iMsg = 35508; // Access denied - break; - case PVR_CONNECTION_STATE_CONNECTED: - iMsg = 36034; // Connection established - bError = false; - // No notification for the first successful connect. - bNotify = (prevState != PVR_CONNECTION_STATE_UNKNOWN); - break; - case PVR_CONNECTION_STATE_DISCONNECTED: - iMsg = 36030; // Connection lost - break; - default: - CLog::Log(LOGERROR, "PVR - %s - unknown connection state", __FUNCTION__); - return; - } - - // Use addon-supplied message, if present - std::string strMsg; - if (strMessage && strlen(strMessage) > 0) - strMsg = strMessage; - else - strMsg = g_localizeStrings.Get(iMsg); - - // Notify user. - if (bNotify && !CSettings::GetInstance().GetBool(CSettings::SETTING_PVRMANAGER_HIDECONNECTIONLOSTWARNING)) - CGUIDialogKaiToast::QueueNotification( - bError ? CGUIDialogKaiToast::Error : CGUIDialogKaiToast::Info, client->Name().c_str(), strMsg, 5000, true); - - // Write event log entry. - CEventLog::GetInstance().Add(EventPtr(new CNotificationEvent( - client->Name(), strMsg, client->Icon(), bError ? EventLevel::Error : EventLevel::Information))); + g_PVRManager.ConnectionStateChange(client->GetID(), std::string(strConnectionString), newState, std::string(strMessage)); } typedef struct EpgEventStateChange diff --git a/xbmc/addons/kodi-addon-dev-kit/include/kodi/xbmc_pvr_types.h b/xbmc/addons/kodi-addon-dev-kit/include/kodi/xbmc_pvr_types.h index 8d73310aa5..cb0cb00684 100644 --- a/xbmc/addons/kodi-addon-dev-kit/include/kodi/xbmc_pvr_types.h +++ b/xbmc/addons/kodi-addon-dev-kit/include/kodi/xbmc_pvr_types.h @@ -228,6 +228,7 @@ extern "C" { PVR_CONNECTION_STATE_ACCESS_DENIED = 4, /*!< @brief backend server is reachable, but denies client access (e.g. due to wrong credentials) */ PVR_CONNECTION_STATE_CONNECTED = 5, /*!< @brief connection to backend server is established */ PVR_CONNECTION_STATE_DISCONNECTED = 6, /*!< @brief no connection to backend server (e.g. due to network errors or client initiated disconnect)*/ + PVR_CONNECTION_STATE_CONNECTING = 7, /*!< @brief connecting to backend */ } PVR_CONNECTION_STATE; /*! diff --git a/xbmc/pvr/PVRManager.cpp b/xbmc/pvr/PVRManager.cpp index 664762ba4e..6d1c0b77e0 100644 --- a/xbmc/pvr/PVRManager.cpp +++ b/xbmc/pvr/PVRManager.cpp @@ -1690,6 +1690,11 @@ void CPVRManager::TriggerSearchMissingChannelIcons(void) CJobManager::GetInstance().AddJob(new CPVRSearchMissingChannelIconsJob(), NULL); } +void CPVRManager::ConnectionStateChange(int clientId, std::string connectString, PVR_CONNECTION_STATE state, std::string message) +{ + CJobManager::GetInstance().AddJob(new CPVRClientConnectionJob(clientId, connectString, state, message), NULL); +} + void CPVRManager::ExecutePendingJobs(void) { CSingleLock lock(m_critSectionTriggers); @@ -1737,6 +1742,12 @@ bool CPVRSearchMissingChannelIconsJob::DoWork(void) return true; } +bool CPVRClientConnectionJob::DoWork(void) +{ + g_PVRClients->ConnectionStateChange(m_clientId, m_connectString, m_state, m_message); + return true; +} + bool CPVRManager::CreateChannelEpgs(void) { if (EpgsCreated()) diff --git a/xbmc/pvr/PVRManager.h b/xbmc/pvr/PVRManager.h index f11592aa98..b9d3ce74cf 100644 --- a/xbmc/pvr/PVRManager.h +++ b/xbmc/pvr/PVRManager.h @@ -583,6 +583,11 @@ private: */ std::string GetPlayingTVGroupName(); + /*! + * @brief Signal a connection change of a client + */ + void ConnectionStateChange(int clientId, std::string connectString, PVR_CONNECTION_STATE state, std::string message); + protected: /*! * @brief Start the PVRManager, which loads all PVR data and starts some threads to update the PVR data. @@ -764,4 +769,20 @@ private: bool DoWork(); }; + + class CPVRClientConnectionJob : public CJob + { + public: + CPVRClientConnectionJob(int clientId, std::string connectString, PVR_CONNECTION_STATE state, std::string message) : + m_clientId(clientId), m_connectString(connectString), m_state(state), m_message(message) {} + virtual ~CPVRClientConnectionJob() {} + virtual const char *GetType() const { return "pvr-client-connection"; } + + virtual bool DoWork(); + private: + int m_clientId; + std::string m_connectString; + PVR_CONNECTION_STATE m_state; + std::string m_message; + }; } diff --git a/xbmc/pvr/addons/PVRClients.cpp b/xbmc/pvr/addons/PVRClients.cpp index a4dbf95d59..c763c4776d 100644 --- a/xbmc/pvr/addons/PVRClients.cpp +++ b/xbmc/pvr/addons/PVRClients.cpp @@ -29,6 +29,9 @@ #include "dialogs/GUIDialogExtendedProgressBar.h" #include "dialogs/GUIDialogOK.h" #include "dialogs/GUIDialogSelect.h" +#include "dialogs/GUIDialogKaiToast.h" +#include "events/EventLog.h" +#include "events/NotificationEvent.h" #include "guilib/GUIWindowManager.h" #include "GUIUserMessages.h" #include "messaging/ApplicationMessenger.h" @@ -235,7 +238,11 @@ bool CPVRClients::HasCreatedClients(void) const for (PVR_CLIENTMAP_CITR itr = m_clientMap.begin(); itr != m_clientMap.end(); itr++) if (itr->second->ReadyToUse()) - return true; + { + PVR_CONNECTION_STATE state = itr->second->GetConnectionState(); + if (state != PVR_CONNECTION_STATE_CONNECTING) + return true; + } return false; } @@ -330,6 +337,10 @@ int CPVRClients::GetCreatedClients(PVR_CLIENTMAP &clients) const { if (itr->second->ReadyToUse()) { + PVR_CONNECTION_STATE state = itr->second->GetConnectionState(); + if (state == PVR_CONNECTION_STATE_CONNECTING) + continue; + clients.insert(std::make_pair(itr->second->GetID(), itr->second)); ++iReturn; } @@ -1520,3 +1531,80 @@ bool CPVRClients::IsRealTimeStream(void) const return false; } +void CPVRClients::ConnectionStateChange(int clientId, std::string &strConnectionString, PVR_CONNECTION_STATE newState, + std::string &strMessage) +{ + PVR_CLIENT client; + if (!GetClient(clientId, client)) + { + CLog::Log(LOGDEBUG, "PVR - %s - invalid client id", __FUNCTION__); + return; + } + + if (strConnectionString.empty()) + { + CLog::Log(LOGERROR, "PVR - %s - invalid handler data", __FUNCTION__); + return; + } + + int iMsg(-1); + bool bError(true); + bool bNotify(true); + + switch (newState) + { + case PVR_CONNECTION_STATE_SERVER_UNREACHABLE: + iMsg = 35505; // Server is unreachable + break; + case PVR_CONNECTION_STATE_SERVER_MISMATCH: + iMsg = 35506; // Server does not respond properly + break; + case PVR_CONNECTION_STATE_VERSION_MISMATCH: + iMsg = 35507; // Server version is not compatible + break; + case PVR_CONNECTION_STATE_ACCESS_DENIED: + iMsg = 35508; // Access denied + break; + case PVR_CONNECTION_STATE_CONNECTED: + bError = false; + iMsg = 36034; // Connection established + break; + case PVR_CONNECTION_STATE_DISCONNECTED: + iMsg = 36030; // Connection lost + break; + case PVR_CONNECTION_STATE_CONNECTING: + bError = false; + iMsg = 35509; // Connecting + bNotify = false; + break; + default: + CLog::Log(LOGERROR, "PVR - %s - unknown connection state", __FUNCTION__); + return; + } + + // Use addon-supplied message, if present + std::string strMsg; + if (!strMessage.empty()) + strMsg = strMessage; + else + strMsg = g_localizeStrings.Get(iMsg); + + // Notify user. + if (bNotify && !CSettings::GetInstance().GetBool(CSettings::SETTING_PVRMANAGER_HIDECONNECTIONLOSTWARNING)) + CGUIDialogKaiToast::QueueNotification(bError ? CGUIDialogKaiToast::Error : CGUIDialogKaiToast::Info, client->Name().c_str(), + strMsg, 5000, true); + + // Write event log entry. + CEventLog::GetInstance().Add(EventPtr(new CNotificationEvent(client->Name(), strMsg, client->Icon(), + bError ? EventLevel::Error : EventLevel::Information))); + + if (newState == PVR_CONNECTION_STATE_CONNECTED) + { + // update properties on connect + if (!client->GetAddonProperties()) + { + CLog::Log(LOGERROR, "PVR - %s - error reading properties", __FUNCTION__); + } + g_PVRManager.Start(); + } +} diff --git a/xbmc/pvr/addons/PVRClients.h b/xbmc/pvr/addons/PVRClients.h index 1f6d1c4624..5cbb07b54f 100644 --- a/xbmc/pvr/addons/PVRClients.h +++ b/xbmc/pvr/addons/PVRClients.h @@ -676,6 +676,9 @@ namespace PVR bool IsRealTimeStream() const; + void ConnectionStateChange(int clientId, std::string &strConnectionString, PVR_CONNECTION_STATE newState, + std::string &strMessage); + private: /*! * @brief Update add-ons from the AddonManager |