Fawkes API  Fawkes Development Version
fam_thread.cpp
1 
2 /***************************************************************************
3  * fam_thread.cpp - File Alteration Monitor Thread
4  *
5  * Created: Sat Jan 24 12:30:10 2009
6  * Copyright 2006-2009 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 
23 #include <utils/system/fam_thread.h>
24 
25 #include <unistd.h>
26 
27 namespace fawkes {
28 #if 0 /* just to make Emacs auto-indent happy */
29 }
30 #endif
31 
32 /** @class FamThread <utils/system/fam_thread.h>
33  * FileAlterationMonitor thread wrapper.
34  * This thread wraps a FileAlterationMonitor and runs it continuously possibly
35  * causing FAM events in this thread context. This thread is useful if you have
36  * no good place to call FileAlterationMonitor::process_events() in your
37  * part.
38  * @author Tim Niemueller
39  */
40 
41 /** Constructor.
42  * @param fam optional RefPtr to FileAlterationMonitor. If none is given
43  * one is instantiated by the FamThread instance.
44  */
46  : Thread("FileAlterationMonitorThread", Thread::OPMODE_CONTINUOUS)
47 {
48  __fam = fam;
49  if (! __fam) {
51  }
52 }
53 
54 /** Get FileAlterationMonitor.
55  * @return shared pointer to FileAlterationMonitor instance.
56  */
59 {
60  return __fam;
61 }
62 
63 
64 void
66 {
67  __fam->process_events(-1);
68  usleep(0);
69 }
70 
71 } // end of namespace fawkes
virtual void loop()
Code to execute in the thread.
Definition: fam_thread.cpp:65
Fawkes library namespace.
Thread class encapsulation of pthreads.
Definition: thread.h:42
FamThread(RefPtr< FileAlterationMonitor > fam=RefPtr< FileAlterationMonitor >())
Constructor.
Definition: fam_thread.cpp:45
RefPtr< FileAlterationMonitor > get_fam()
Get FileAlterationMonitor.
Definition: fam_thread.cpp:58
Monitors files for changes.
Definition: fam.h:71
RefPtr<> is a reference-counting shared smartpointer.
Definition: refptr.h:49