sbLibraryManager.h
Go to the documentation of this file.
1 /*
2  *=BEGIN SONGBIRD GPL
3  *
4  * This file is part of the Songbird web player.
5  *
6  * Copyright(c) 2005-2010 POTI, Inc.
7  * http://www.songbirdnest.com
8  *
9  * This file may be licensed under the terms of of the
10  * GNU General Public License Version 2 (the ``GPL'').
11  *
12  * Software distributed under the License is distributed
13  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
14  * express or implied. See the GPL for the specific language
15  * governing rights and limitations.
16  *
17  * You should have received a copy of the GPL along with this
18  * program. If not, go to http://www.gnu.org/licenses/gpl.html
19  * or write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  *=END SONGBIRD GPL
23  */
24 
30 #ifndef __SB_LIBRARYMANAGER_H__
31 #define __SB_LIBRARYMANAGER_H__
32 
33 #include <nsIObserver.h>
34 #include <nsIThreadManager.h>
35 #include <sbILibrary.h>
36 #include <sbILibraryManager.h>
37 #include <sbILibraryUtils.h>
38 
39 #include <nsCategoryCache.h>
40 #include <nsAutoLock.h>
41 #include <nsCOMPtr.h>
42 #include <nsHashKeys.h>
43 #include <nsClassHashtable.h>
44 #include <nsInterfaceHashtable.h>
45 #include <prlock.h>
46 #include <sbILibraryLoader.h>
47 
48 #include <sbWeakReference.h>
49 
50 #define SB_PREFBRANCH_LIBRARY "songbird.library."
51 
52 #define SB_PREF_MAIN_LIBRARY SB_PREFBRANCH_LIBRARY "main"
53 #define SB_PREF_WEB_LIBRARY SB_PREFBRANCH_LIBRARY "web"
54 #define SB_PREF_PLAYQUEUE_LIBRARY SB_PREFBRANCH_LIBRARY "playqueue"
55 
56 class nsIComponentManager;
57 class nsIFile;
58 class nsIRDFDataSource;
59 class sbILibraryFactory;
60 class sbILibraryLoader;
62 
63 struct nsModuleComponentInfo;
64 
66  public sbILibraryUtils,
67  public nsIObserver,
69 {
70  struct sbLibraryInfo {
71  sbLibraryInfo(PRBool aLoadAtStartup = PR_FALSE)
72  : loader(nsnull),
73  loadAtStartup(aLoadAtStartup)
74  { }
75 
76  nsCOMPtr<sbILibrary> library;
77 
78  // Don't need an owning ref here because we already have one in
79  // mLoaderCache.
80  sbILibraryLoader* loader;
81 
82  PRBool loadAtStartup;
83  };
84 
85 public:
87  NS_DECL_NSIOBSERVER
88  NS_DECL_SBILIBRARYMANAGER
89  NS_DECL_SBILIBRARYUTILS
90 
92 
93  static NS_METHOD RegisterSelf(nsIComponentManager* aCompMgr,
94  nsIFile* aPath,
95  const char* aLoaderStr,
96  const char* aType,
97  const nsModuleComponentInfo *aInfo);
98 
99  nsresult Init();
100 
101 private:
102  ~sbLibraryManager();
103 
104  static PLDHashOperator PR_CALLBACK
105  AddLibrariesToCOMArrayCallback(nsStringHashKey::KeyType aKey,
106  sbLibraryInfo* aEntry,
107  void* aUserData);
108 
109  static PLDHashOperator PR_CALLBACK
110  AddStartupLibrariesToCOMArrayCallback(nsStringHashKey::KeyType aKey,
111  sbLibraryInfo* aEntry,
112  void* aUserData);
113 
114  static PLDHashOperator PR_CALLBACK
115  AddListenersToCOMArrayCallback(nsISupportsHashKey::KeyType aKey,
117  void* aUserData);
118 
119  static PLDHashOperator PR_CALLBACK
120  AssertAllLibrariesCallback(nsStringHashKey::KeyType aKey,
121  sbLibraryInfo* aEntry,
122  void* aUserData);
123 
124  static nsresult AssertLibrary(nsIRDFDataSource* aDataSource,
125  sbILibrary* aLibrary);
126 
127  static nsresult UnassertLibrary(nsIRDFDataSource* aDataSource,
128  sbILibrary* aLibrary);
129 
130  nsresult GenerateDataSource();
131 
132  void NotifyListenersLibraryRegistered(sbILibrary* aLibrary);
133 
134  void NotifyListenersLibraryUnregistered(sbILibrary* aLibrary);
135 
136  void InvokeLoaders();
137 
138  nsresult SetLibraryLoadsAtStartupInternal(sbILibrary* aLibrary,
139  PRBool aLoadAtStartup,
140  sbLibraryInfo** aInfo);
141 
142 private:
146  nsClassHashtable<nsStringHashKey, sbLibraryInfo> mLibraryTable;
147 
152  nsCOMPtr<nsIRDFDataSource> mDataSource;
153 
157  nsInterfaceHashtable<nsISupportsHashKey, sbILibraryManagerListener> mListeners;
158 
162  nsCategoryCache<sbILibraryLoader> mLoaderCache;
163 
164  nsCOMPtr<sbILibraryLoader> mCurrentLoader;
165 
166  PRLock* mLock;
167 
168  nsCOMPtr<nsIThreadManager> mThreadManager;
169 };
170 
171 #endif /* __SB_LIBRARYMANAGER_H__ */
Manages the lifecycle of libraries in the system.
_updateCookies aPath
NS_DECL_ISUPPORTS NS_DECL_NSIOBSERVER NS_DECL_SBILIBRARYMANAGER NS_DECL_SBILIBRARYUTILS sbLibraryManager()
Factory for new library instances.
nsresult Init()
Register with the Observer Service.
Manages the lifecycle of libraries in the system.
Media library abstraction.
Definition: sbILibrary.idl:82
[USER CODE SHOULD NOT REFERENCE THIS CLASS]
static NS_METHOD RegisterSelf(nsIComponentManager *aCompMgr, nsIFile *aPath, const char *aLoaderStr, const char *aType, const nsModuleComponentInfo *aInfo)
Set of library utilities.