fam_thread.cpp

00001 
00002 /***************************************************************************
00003  *  fam_thread.cpp - File Alteration Monitor Thread
00004  *
00005  *  Created: Sat Jan 24 12:30:10 2009
00006  *  Copyright  2006-2009  Tim Niemueller [www.niemueller.de]
00007  *
00008  ****************************************************************************/
00009 
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU Library General Public License for more details.
00019  *
00020  *  Read the full text in the LICENSE.GPL file in the doc directory.
00021  */
00022 
00023 #include <utils/system/fam_thread.h>
00024 
00025 #include <unistd.h>
00026 
00027 namespace fawkes {
00028 #if 0 /* just to make Emacs auto-indent happy */
00029 }
00030 #endif
00031 
00032 /** @class FamThread <utils/system/fam_thread.h>
00033  * FileAlterationMonitor thread wrapper.
00034  * This thread wraps a FileAlterationMonitor and runs it continuously possibly
00035  * causing FAM events in this thread context. This thread is useful if you have
00036  * no good place to call FileAlterationMonitor::process_events() in your
00037  * part.
00038  * @author Tim Niemueller
00039  */
00040 
00041 /** Constructor.
00042  * @param fam optional RefPtr to FileAlterationMonitor. If none is given
00043  * one is instantiated by the FamThread instance.
00044  */
00045 FamThread::FamThread(RefPtr<FileAlterationMonitor> fam)
00046   : Thread("FileAlterationMonitorThread", Thread::OPMODE_CONTINUOUS)
00047 {
00048   __fam = fam;
00049   if (! __fam) {
00050     __fam = RefPtr<FileAlterationMonitor>(new FileAlterationMonitor());
00051   }
00052 }
00053 
00054 /** Get FileAlterationMonitor.
00055  * @return shared pointer to FileAlterationMonitor instance.
00056  */
00057 RefPtr<FileAlterationMonitor>
00058 FamThread::get_fam()
00059 {
00060   return __fam;
00061 }
00062 
00063 
00064 void
00065 FamThread::loop()
00066 {
00067   __fam->process_events(-1);
00068   usleep(0);
00069 }
00070 
00071 } // end of namespace fawkes

Generated on 1 Mar 2011 for Fawkes API by  doxygen 1.6.1