gtkIOStream  1.7.0
GTK+ << C++ IOStream operators for GTK+. Now with ORBing, numerical computation, audio client and more ...
FileWatchThreaded Class Reference

#include <FileWatchThreaded.H>

Inheritance diagram for FileWatchThreaded:
[legend]
Collaboration diagram for FileWatchThreaded:
[legend]

Public Member Functions

 FileWatchThreaded ()
 Constructor. More...
 
virtual ~FileWatchThreaded ()
 Destructor. More...
 
virtual int add (std::string path)
 
virtual int addFile (std::string path)
 
- Public Member Functions inherited from ThreadedMethod
virtual int run (int priority=0)
 
- Public Member Functions inherited from Thread
 Thread (void)
 
virtual ~Thread (void)
 
void * stop (void)
 
int run (void *(*start_routine)(void *), void *data, int priority=0)
 
int setPriority (pthread_attr_t *attributes, int priority)
 
int getPriority ()
 
void * meetThread (void)
 
void exit (void *retVal)
 
bool running ()
 

Private Member Functions

char eventBuf [BUF_SIZE__attribute__ ((aligned(__alignof__(struct inotify_event))))
 The buffered events. More...
 
virtual void * threadMain (void)
 
virtual void modified (char *name)
 
virtual void closeWrite (char *name)
 

Private Attributes

int fd
 The inotify file descriptor. More...
 
std::map< std::string, int > pathFds
 This will contain a map between watch file descriptors and file/dir names. More...
 

Detailed Description

Class to watch a file and execute on state change - based on inotify Usage is like so :

fwt.add(fileOrDirName); // add the file system thing to watch
fwt.run();

At this point, a thread has started and it is watching the directorys or files you specified. If they change, then you can overload modified or closeWrite below to catch those events. Here is an example of a class which overloads those methods :

class Watcher : public FileWatchThread {
virtual void modified(char *name){
printf("modified occured \n");
}
virtual void closeWrite(char *name){
printf("close write occured \n");
}
};

Definition at line 47 of file FileWatchThreaded.H.

Constructor & Destructor Documentation

◆ FileWatchThreaded()

FileWatchThreaded::FileWatchThreaded ( )
inline

Constructor.

Definition at line 89 of file FileWatchThreaded.H.

Here is the call graph for this function:

◆ ~FileWatchThreaded()

virtual FileWatchThreaded::~FileWatchThreaded ( )
inlinevirtual

Destructor.

Definition at line 98 of file FileWatchThreaded.H.

Member Function Documentation

◆ __attribute__()

char eventBuf [BUF_SIZE] FileWatchThreaded::__attribute__ ( (aligned(__alignof__(struct inotify_event)))  )
private

The buffered events.

◆ add()

virtual int FileWatchThreaded::add ( std::string  path)
inlinevirtual

Add a file or directory to watch here

Parameters
pathThe directory or file to watch
Returns
0 on success

Definition at line 105 of file FileWatchThreaded.H.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addFile()

virtual int FileWatchThreaded::addFile ( std::string  path)
inlinevirtual

Add a file or directory to watch here, if it doesn't exist, then create

Parameters
pathThe directory or file to watch
Returns
0 on success

Definition at line 117 of file FileWatchThreaded.H.

Here is the call graph for this function:

◆ closeWrite()

virtual void FileWatchThreaded::closeWrite ( char *  name)
inlineprivatevirtual

Overload this function to deal with IN_CLOSE_WRITE events

Parameters
nameWhen watching a directory, the file name modified is given here

Definition at line 84 of file FileWatchThreaded.H.

Here is the caller graph for this function:

◆ modified()

virtual void FileWatchThreaded::modified ( char *  name)
inlineprivatevirtual

Overload this function to deal with IN_MODIFY events

Parameters
nameWhen watching a directory, the file name modified is given here

Definition at line 78 of file FileWatchThreaded.H.

Here is the caller graph for this function:

◆ threadMain()

virtual void* FileWatchThreaded::threadMain ( void  )
inlineprivatevirtual

The inheriting class implements the thread's main method.

Returns
A pointer to a return variable (only used if USE_GLIB_THREADS is not defined = pthread )

Implements ThreadedMethod.

Definition at line 55 of file FileWatchThreaded.H.

Here is the call graph for this function:

Member Data Documentation

◆ fd

int FileWatchThreaded::fd
private

The inotify file descriptor.

Definition at line 48 of file FileWatchThreaded.H.

◆ pathFds

std::map<std::string, int> FileWatchThreaded::pathFds
private

This will contain a map between watch file descriptors and file/dir names.

Definition at line 53 of file FileWatchThreaded.H.


The documentation for this class was generated from the following file:
gtkIOStream: FileWatchThreaded Class Reference
GTK+ IOStream  Beta