sbMediaItemControllerCleanup.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /*
3  *=BEGIN SONGBIRD GPL
4  *
5  * This file is part of the Songbird web player.
6  *
7  * Copyright(c) 2005-2010 POTI, Inc.
8  * http://www.songbirdnest.com
9  *
10  * This file may be licensed under the terms of of the
11  * GNU General Public License Version 2 (the ``GPL'').
12  *
13  * Software distributed under the License is distributed
14  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
15  * express or implied. See the GPL for the specific language
16  * governing rights and limitations.
17  *
18  * You should have received a copy of the GPL along with this
19  * program. If not, go to http://www.gnu.org/licenses/gpl.html
20  * or write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22  *
23  *=END SONGBIRD GPL
24  */
25 
26 #ifndef _SB_MEDIAITEMCONTROLLERCLEANUP_H_
27 #define _SB_MEDIAITEMCONTROLLERCLEANUP_H_
28 
35 #include <nsIGenericFactory.h>
36 #include <nsIObserver.h>
37 #include <nsIRunnable.h>
38 
39 #include <sbILibrary.h>
40 #include <sbILibraryManagerListener.h>
41 #include <sbIMediaListListener.h>
42 #include <sbIPropertyArray.h>
43 
44 #include <nsAutoPtr.h>
45 #include <nsCOMPtr.h>
46 
47 #include <map>
48 #include <set>
49 #include <string>
50 
51 class nsIEventTarget;
52 struct PRLock;
53 
55  public nsIRunnable,
57 {
59  NS_DECL_NSIOBSERVER
60  NS_DECL_NSIRUNNABLE
61  NS_DECL_SBILIBRARYMANAGERLISTENER
62 
63 public:
66 
67  static NS_METHOD RegisterSelf(nsIComponentManager* aCompMgr,
68  nsIFile* aPath,
69  const char* aLoaderStr,
70  const char* aType,
71  const nsModuleComponentInfo *aInfo);
72 
73 protected:
77  {
79  NS_DECL_SBIMEDIALISTENUMERATIONLISTENER
80  NS_DECL_SBIMEDIALISTBATCHCALLBACK
81  public:
91  sbIPropertyArray *aPropertiesToFilter,
92  sbIPropertyArray *aPropertiesToSet);
98  void Stop();
99 
104  void Resume();
105 
110  bool Completed();
111 
112  already_AddRefed<sbIMediaList> GetMediaList();
113 
114  protected:
115  nsCOMPtr<sbIMediaList> mList;
116  nsCOMPtr<sbIPropertyArray> mPropsToFilter;
117  nsCOMPtr<sbIPropertyArray> mPropsToSet;
118  bool mStop;
120  PRUint32 mCount;
121  };
122  nsRefPtr<sbEnumerationHelper> mListener;
123 
124 protected:
131  typedef std::map<std::string, bool> types_t;
132 
136  nsresult EnsureAvailableTypes();
137 
142  nsresult ProcessLibraries();
143 
146 
147  // whether we have been registered with the idle service
149 
150  // the set of libraries we need to process
151  template <class T> struct nsCOMPtrComp {
152  bool operator()(const nsCOMPtr<T> l, const nsCOMPtr<T> r) const {
153  return l.get() < r.get();
154  }
155  };
156  typedef std::map<nsCOMPtr<sbILibrary>, // key is the library
157  types_t, // value is interesting types
160 
164  nsCOMPtr<nsIEventTarget> mBackgroundEventTarget;
165 
169  enum {
170  STATE_IDLE, // nothing queued
171  STATE_QUEUED, // things queued, but not yet running
172  STATE_RUNNING, // the jobs have been dispatched to the event target and
173  // are not yet finished
174  STATE_STOPPING, // idle was interrupted and we should try to stop now
175  // (but it's still running; will probably go to QUEUED)
176  } mState;
177 
184  PRLock* mLock;
185 };
186 
187 #define SONGBIRD_MEDIAITEMCONTROLLERCLEANUP_CONTRACTID \
188  "@songbirdnest.com/Songbird/Library/MediaItemControllerCleanup;1"
189 #define SONGBIRD_MEDIAITEMCONTROLLERCLEANUP_CLASSNAME "sbMediaItemControllerCleanup"
190 #define SONGBIRD_MEDIAITEMCONTROLLERCLEANUP_CID \
191  /* {7F29A8D6-B4CF-4d6e-8F86-3145A3DEFF88} */ \
192  { 0x7f29a8d6, \
193  0xb4cf, \
194  0x4d6e, \
195  { 0x8f, 0x86, 0x31, 0x45, 0xa3, 0xde, 0xff, 0x88 } \
196  }
197 
198 
199 #endif /* _SB_MEDIAITEMCONTROLLERCLEANUP_H_ */
Manages the lifecycle of libraries in the system.
_updateCookies aPath
Interface used to enumerate the items in a media list.
static NS_METHOD RegisterSelf(nsIComponentManager *aCompMgr, nsIFile *aPath, const char *aLoaderStr, const char *aType, const nsModuleComponentInfo *aInfo)
enum sbMediaItemControllerCleanup::@5 mState
bool operator()(const nsCOMPtr< T > l, const nsCOMPtr< T > r) const
std::map< std::string, bool > types_t
A brief description of the contents of this interface.
nsCOMPtr< nsIEventTarget > mBackgroundEventTarget
std::map< nsCOMPtr< sbILibrary >, types_t, nsCOMPtrComp< sbILibrary > > libraries_t
sbEnumerationHelper(sbIMediaList *aMediaList, sbIPropertyArray *aPropertiesToFilter, sbIPropertyArray *aPropertiesToSet)
nsRefPtr< sbEnumerationHelper > mListener
An interface to carry around arrays of nsIProperty instances. Users of this interface should only QI ...