sbWin32FileSystemWatcher.h
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2009 POTI, Inc.
8 // http://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 
27 #ifndef sbWin32FileSystemWatcher_h_
28 #define sbWin32FileSystemWatcher_h_
29 
31 #include <sbFileSystemTree.h>
32 #include <nsStringAPI.h>
33 #include <nsIObserver.h>
34 #include <nsCOMPtr.h>
35 #include <nsITimer.h>
36 #include <windows.h>
37 #include <set>
38 
39 typedef std::set<nsString> sbStringSet;
40 typedef sbStringSet::iterator sbStringSetIter;
41 
42 
44  public nsIObserver,
45  public nsITimerCallback
46 {
47 public:
49  virtual ~sbWin32FileSystemWatcher();
50 
51  NS_DECL_ISUPPORTS_INHERITED
52  NS_DECL_NSIOBSERVER
53  NS_DECL_NSITIMERCALLBACK
54 
55  // sbBaseFileSystemWatcher
56  NS_IMETHOD Init(sbIFileSystemListener *aListener,
57  const nsAString & aRootPath,
58  PRBool aIsRecursive);
59  NS_IMETHOD StopWatching(PRBool aShouldSaveSession);
60 
61  // sbIFileSystemTreeListener
62  NS_IMETHOD OnTreeReady(const nsAString & aTreeRootPath,
63  sbStringArray & aDirPathArray);
64 
65  //
66  // \brief Accessor for the thread should run boolean. This returns
67  // true when the thread should be running, and false when the
68  // thread should stop.
69  //
70  PRBool GetShouldRunThread();
71 
72  //
73  // \brief Accessor for the thread is running boolean. This
74  // returns true when the thread is up and running.
75  //
76  PRBool GetIsThreadRunning();
77 
78  //
79  // \brief Setter to specify if the thread is up and running.
80  // Note: This method should only be called by the background thread.
81  //
82  void SetIsThreadRunning(PRBool aIsThreadRunning);
83 
84  //
85  // \brief Accessor for the event structure buffer.
86  // Note: This method should only be called by the background thread.
87  //
88  void* GetBuffer();
89 
90  //
91  // \brief Accessor for the event paths set.
92  //
94 
95  //
96  // \brief Accessor for the event paths set lock.
97  //
98  PRLock* GetEventPathsSetLock();
99 
100  //
101  // \brief Method to setup the chained call to |ReadDirectoryChangesW|.
102  // Note: This method should only be called by the background thread.
103  //
104  void WatchNextChange();
105 
106 protected:
107  friend DWORD WINAPI BackgroundThreadProc(void *p);
108  void Cleanup();
109  void InitRebuildThread();
110 
111 private:
112  nsCOMPtr<nsITimer> mTimer;
113  HANDLE mRootDirHandle;
114  HANDLE mWatcherThread;
115  nsCOMPtr<nsIThread> mRebuildThread;
116  void *mBuffer;
117  OVERLAPPED mOverlapped;
118  PRBool mShouldRunThread;
119  PRBool mIsThreadRunning;
120  sbStringSet mEventPathsSet;
121  PRLock *mEventPathsSetLock;
122  PRBool mShuttingDown;
123 };
124 
125 #endif // sbWin32FileSystemWatcher_h_
126 
NS_IMETHOD StopWatching(PRBool aShouldSaveSession)
NS_IMETHOD OnTreeReady(const nsAString &aTreeRootPath, sbStringArray &aDirPathArray)
nsTArray< nsString > sbStringArray
friend DWORD WINAPI BackgroundThreadProc(void *p)
sbStringSet::iterator sbStringSetIter
std::set< nsString > sbStringSet
NS_DECL_ISUPPORTS_INHERITED NS_DECL_NSIOBSERVER NS_DECL_NSITIMERCALLBACK NS_IMETHOD Init(sbIFileSystemListener *aListener, const nsAString &aRootPath, PRBool aIsRecursive)
void SetIsThreadRunning(PRBool aIsThreadRunning)
nsITimerCallback