forked from xbmc/xbmc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request xbmc#1128 from jmarshallnz/separate_db_update
Separate db update from CDatabase::Open()
- Loading branch information
Showing
12 changed files
with
262 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright (C) 2012 Team XBMC | ||
* http://www.xbmc.org | ||
* | ||
* This Program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2, or (at your option) | ||
* any later version. | ||
* | ||
* This Program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with XBMC; see the file COPYING. If not, write to | ||
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | ||
* http://www.gnu.org/copyleft/gpl.html | ||
* | ||
*/ | ||
|
||
#include "DatabaseManager.h" | ||
#include "utils/log.h" | ||
#include "addons/AddonDatabase.h" | ||
#include "ViewDatabase.h" | ||
#include "TextureDatabase.h" | ||
#include "programs/ProgramDatabase.h" | ||
#include "music/MusicDatabase.h" | ||
#include "video/VideoDatabase.h" | ||
#include "settings/AdvancedSettings.h" | ||
|
||
using namespace std; | ||
|
||
CDatabaseManager &CDatabaseManager::Get() | ||
{ | ||
static CDatabaseManager s_manager; | ||
return s_manager; | ||
} | ||
|
||
CDatabaseManager::CDatabaseManager() | ||
{ | ||
} | ||
|
||
CDatabaseManager::~CDatabaseManager() | ||
{ | ||
} | ||
|
||
void CDatabaseManager::Initialize(bool addonsOnly) | ||
{ | ||
Deinitialize(); | ||
{ CAddonDatabase db; UpdateDatabase(db); } | ||
if (addonsOnly) | ||
return; | ||
CLog::Log(LOGDEBUG, "%s, updating databases...", __FUNCTION__); | ||
{ CViewDatabase db; UpdateDatabase(db); } | ||
{ CTextureDatabase db; UpdateDatabase(db); } | ||
{ CProgramDatabase db; UpdateDatabase(db); } | ||
{ CMusicDatabase db; UpdateDatabase(db, &g_advancedSettings.m_databaseMusic); } | ||
{ CVideoDatabase db; UpdateDatabase(db, &g_advancedSettings.m_databaseVideo); } | ||
CLog::Log(LOGDEBUG, "%s, updating databases... DONE", __FUNCTION__); | ||
} | ||
|
||
void CDatabaseManager::Deinitialize() | ||
{ | ||
CSingleLock lock(m_section); | ||
m_dbStatus.clear(); | ||
} | ||
|
||
bool CDatabaseManager::CanOpen(const std::string &name) | ||
{ | ||
CSingleLock lock(m_section); | ||
map<string, DB_STATUS>::const_iterator i = m_dbStatus.find(name); | ||
if (i != m_dbStatus.end()) | ||
return i->second == DB_READY; | ||
return false; // db isn't even attempted to update yet | ||
} | ||
|
||
void CDatabaseManager::UpdateDatabase(CDatabase &db, DatabaseSettings *settings) | ||
{ | ||
std::string name = db.GetBaseDBName(); | ||
UpdateStatus(name, DB_UPDATING); | ||
if (db.Update(settings ? *settings : DatabaseSettings())) | ||
UpdateStatus(name, DB_READY); | ||
else | ||
UpdateStatus(name, DB_FAILED); | ||
} | ||
|
||
void CDatabaseManager::UpdateStatus(const std::string &name, DB_STATUS status) | ||
{ | ||
CSingleLock lock(m_section); | ||
m_dbStatus[name] = status; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright (C) 2012 Team XBMC | ||
* http://www.xbmc.org | ||
* | ||
* This Program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2, or (at your option) | ||
* any later version. | ||
* | ||
* This Program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with XBMC; see the file COPYING. If not, write to | ||
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | ||
* http://www.gnu.org/copyleft/gpl.html | ||
* | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <map> | ||
#include <string> | ||
#include "threads/CriticalSection.h" | ||
#include "threads/Event.h" | ||
|
||
class CDatabase; | ||
class DatabaseSettings; | ||
|
||
/*! | ||
\ingroup database | ||
\brief Database manager class for handling database updating | ||
Ensures that databases used in XBMC are up to date, and if a database can't be | ||
opened, ensures we don't continuously try it. | ||
*/ | ||
class CDatabaseManager | ||
{ | ||
public: | ||
/*! | ||
\brief The only way through which the global instance of the CDatabaseManager should be accessed. | ||
\return the global instance. | ||
*/ | ||
static CDatabaseManager &Get(); | ||
|
||
/*! \brief Initalize the database manager | ||
Checks that all databases are up to date, otherwise updates them. | ||
*/ | ||
void Initialize(bool addonsOnly = false); | ||
|
||
/*! \brief Deinitialize the database manager | ||
*/ | ||
void Deinitialize(); | ||
|
||
/*! \brief Check whether we can open a database. | ||
Checks whether the database has been updated correctly, if so returns true. | ||
If the database update failed, returns false immediately. | ||
If the database update is in progress, returns false. | ||
\param name the name of the database to check. | ||
\return true if the database can be opened, false otherwise. | ||
*/ | ||
bool CanOpen(const std::string &name); | ||
|
||
private: | ||
// private construction, and no assignements; use the provided singleton methods | ||
CDatabaseManager(); | ||
CDatabaseManager(const CDatabaseManager&); | ||
CDatabaseManager const& operator=(CDatabaseManager const&); | ||
virtual ~CDatabaseManager(); | ||
|
||
enum DB_STATUS { DB_CLOSED, DB_UPDATING, DB_READY, DB_FAILED }; | ||
void UpdateStatus(const std::string &name, DB_STATUS status); | ||
void UpdateDatabase(CDatabase &db, DatabaseSettings *settings = NULL); | ||
|
||
CCriticalSection m_section; ///< Critical section protecting m_dbStatus. | ||
std::map<std::string, DB_STATUS> m_dbStatus; ///< Our database status map. | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.