2 * Copyright (C) 2012 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
22 #include "DatabaseManager.h"
23 #include "utils/log.h"
24 #include "addons/AddonDatabase.h"
25 #include "ViewDatabase.h"
26 #include "TextureDatabase.h"
27 #include "music/MusicDatabase.h"
28 #include "video/VideoDatabase.h"
29 #include "pvr/PVRDatabase.h"
30 #include "epg/EpgDatabase.h"
31 #include "settings/AdvancedSettings.h"
37 CDatabaseManager &CDatabaseManager::Get()
39 static CDatabaseManager s_manager;
43 CDatabaseManager::CDatabaseManager()
47 CDatabaseManager::~CDatabaseManager()
51 void CDatabaseManager::Initialize(bool addonsOnly)
54 { CAddonDatabase db; UpdateDatabase(db); }
57 CLog::Log(LOGDEBUG, "%s, updating databases...", __FUNCTION__);
58 { CViewDatabase db; UpdateDatabase(db); }
59 { CTextureDatabase db; UpdateDatabase(db); }
60 { CMusicDatabase db; UpdateDatabase(db, &g_advancedSettings.m_databaseMusic); }
61 { CVideoDatabase db; UpdateDatabase(db, &g_advancedSettings.m_databaseVideo); }
62 { CPVRDatabase db; UpdateDatabase(db, &g_advancedSettings.m_databaseTV); }
63 { CEpgDatabase db; UpdateDatabase(db, &g_advancedSettings.m_databaseEpg); }
64 CLog::Log(LOGDEBUG, "%s, updating databases... DONE", __FUNCTION__);
67 void CDatabaseManager::Deinitialize()
69 CSingleLock lock(m_section);
73 bool CDatabaseManager::CanOpen(const std::string &name)
75 CSingleLock lock(m_section);
76 map<string, DB_STATUS>::const_iterator i = m_dbStatus.find(name);
77 if (i != m_dbStatus.end())
78 return i->second == DB_READY;
79 return false; // db isn't even attempted to update yet
82 void CDatabaseManager::UpdateDatabase(CDatabase &db, DatabaseSettings *settings)
84 std::string name = db.GetBaseDBName();
85 UpdateStatus(name, DB_UPDATING);
86 if (db.Update(settings ? *settings : DatabaseSettings()))
87 UpdateStatus(name, DB_READY);
89 UpdateStatus(name, DB_FAILED);
92 void CDatabaseManager::UpdateStatus(const std::string &name, DB_STATUS status)
94 CSingleLock lock(m_section);
95 m_dbStatus[name] = status;