2 * Copyright (C) 2012-2013 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, see
17 * <http://www.gnu.org/licenses/>.
21 #include "DatabaseManager.h"
22 #include "utils/log.h"
23 #include "addons/AddonDatabase.h"
24 #include "view/ViewDatabase.h"
25 #include "TextureDatabase.h"
26 #include "music/MusicDatabase.h"
27 #include "video/VideoDatabase.h"
28 #include "pvr/PVRDatabase.h"
29 #include "epg/EpgDatabase.h"
30 #include "settings/AdvancedSettings.h"
36 CDatabaseManager
&CDatabaseManager::Get()
38 static CDatabaseManager s_manager
;
42 CDatabaseManager::CDatabaseManager()
46 CDatabaseManager::~CDatabaseManager()
50 void CDatabaseManager::Initialize(bool addonsOnly
)
53 { CAddonDatabase db
; UpdateDatabase(db
); }
56 CLog::Log(LOGDEBUG
, "%s, updating databases...", __FUNCTION__
);
58 // NOTE: Order here is important. In particular, CTextureDatabase has to be updated
59 // before CVideoDatabase.
60 { CViewDatabase db
; UpdateDatabase(db
); }
61 { CTextureDatabase db
; UpdateDatabase(db
); }
62 { CMusicDatabase db
; UpdateDatabase(db
, &g_advancedSettings
.m_databaseMusic
); }
63 { CVideoDatabase db
; UpdateDatabase(db
, &g_advancedSettings
.m_databaseVideo
); }
64 { CPVRDatabase db
; UpdateDatabase(db
, &g_advancedSettings
.m_databaseTV
); }
65 { CEpgDatabase db
; UpdateDatabase(db
, &g_advancedSettings
.m_databaseEpg
); }
66 CLog::Log(LOGDEBUG
, "%s, updating databases... DONE", __FUNCTION__
);
69 void CDatabaseManager::Deinitialize()
71 CSingleLock
lock(m_section
);
75 bool CDatabaseManager::CanOpen(const std::string
&name
)
77 CSingleLock
lock(m_section
);
78 map
<string
, DB_STATUS
>::const_iterator i
= m_dbStatus
.find(name
);
79 if (i
!= m_dbStatus
.end())
80 return i
->second
== DB_READY
;
81 return false; // db isn't even attempted to update yet
84 void CDatabaseManager::UpdateDatabase(CDatabase
&db
, DatabaseSettings
*settings
)
86 std::string name
= db
.GetBaseDBName();
87 UpdateStatus(name
, DB_UPDATING
);
88 if (db
.Update(settings
? *settings
: DatabaseSettings()))
89 UpdateStatus(name
, DB_READY
);
91 UpdateStatus(name
, DB_FAILED
);
94 void CDatabaseManager::UpdateStatus(const std::string
&name
, DB_STATUS status
)
96 CSingleLock
lock(m_section
);
97 m_dbStatus
[name
] = status
;