Merge pull request #1067 from nuka1195/python_sorttitle
[vuplus_xbmc] / xbmc / DatabaseManager.h
1 /*
2  *      Copyright (C) 2012 Team XBMC
3  *      http://www.xbmc.org
4  *
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)
8  *  any later version.
9  *
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.
14  *
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
19  *
20  */
21
22 #pragma once
23
24 #include <map>
25 #include <string>
26 #include "threads/CriticalSection.h"
27 #include "threads/Event.h"
28
29 class CDatabase;
30 class DatabaseSettings;
31
32 /*!
33  \ingroup database
34  \brief Database manager class for handling database updating
35
36  Ensures that databases used in XBMC are up to date, and if a database can't be
37  opened, ensures we don't continuously try it.
38
39  */
40 class CDatabaseManager
41 {
42 public:
43   /*!
44    \brief The only way through which the global instance of the CDatabaseManager should be accessed.
45    \return the global instance.
46    */
47   static CDatabaseManager &Get();
48
49   /*! \brief Initalize the database manager
50    Checks that all databases are up to date, otherwise updates them.
51    */
52   void Initialize(bool addonsOnly = false);
53
54   /*! \brief Deinitialize the database manager
55    */
56   void Deinitialize();
57
58   /*! \brief Check whether we can open a database.
59
60    Checks whether the database has been updated correctly, if so returns true.
61    If the database update failed, returns false immediately.
62    If the database update is in progress, returns false.
63
64    \param name the name of the database to check.
65    \return true if the database can be opened, false otherwise.
66    */ 
67   bool CanOpen(const std::string &name);
68
69 private:
70   // private construction, and no assignements; use the provided singleton methods
71   CDatabaseManager();
72   CDatabaseManager(const CDatabaseManager&);
73   CDatabaseManager const& operator=(CDatabaseManager const&);
74   virtual ~CDatabaseManager();
75
76   enum DB_STATUS { DB_CLOSED, DB_UPDATING, DB_READY, DB_FAILED };
77   void UpdateStatus(const std::string &name, DB_STATUS status);
78   void UpdateDatabase(CDatabase &db, DatabaseSettings *settings = NULL);
79
80   CCriticalSection            m_section;     ///< Critical section protecting m_dbStatus.
81   std::map<std::string, DB_STATUS> m_dbStatus;    ///< Our database status map.
82 };