Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

wvfam.h

00001 /* -*- Mode: C++ -*- */
00002 #ifndef __WVFAM_H
00003 #define __WVFAM_H
00004 
00005 #include "wvautoconf.h"
00006 
00007 #ifdef WITH_FAM
00008 
00009 #include "wvfdstream.h"
00010 #include "wvlog.h"
00011 #include "wvhashtable.h"
00012 #include "wvscatterhash.h"
00013 
00014 #include <fam.h>
00015 
00016 enum WvFamEvent
00017 {
00018     WvFamChanged = 1,
00019     WvFamDeleted = 2,
00020     WvFamCreated = 5,
00021 };
00022 
00023 typedef WvCallback<void, WvStringParm, WvFamEvent, bool> WvFamCallback;
00024 
00025 
00026 /*
00027  * The WvFamBase class is provided for efficiency. If you're going to
00028  * be keeping track of the stuff you're monitoring anyways then
00029  * there's no reason to have duplicate wvstrings/hashes. This class
00030  * accepts a pointer to a wvstring and returns the request id number
00031  * (which is needed to unmonitor).
00032  *
00033  * If you're not keeping a list of stuff you're monitoring around for
00034  * other reasons just ignore this and use the main WvFam class.
00035  */
00036 class WvFamBase
00037 {
00038 public:
00039     // These calls all take a pointer to a WvString. The WvString must exist and
00040     // be unmodified until the fam monitoring is removed for directory
00041     // monitoring.
00042     //
00043     // This is really evil, but if you're going to be monitoring a lot of files
00044     // then duplicating the strings can be quite wasteful. 
00045     int _monitordir(WvString *dir);
00046     int _monitorfile(WvString *file);
00047     void _unmonitor(int reqid);
00048 
00049 protected:
00050     FAMConnection fc;
00051     FAMRequest fr;
00052     FAMEvent fe;
00053     WvFamCallback cb;
00054 
00055     WvFDStream *s;
00056     WvLog log;
00057 
00058     void callback(WvStream &, void *) { _callback(); }
00059     void _callback();
00060 
00061 
00062 public:
00063     WvFamBase() : s(0), log("WvFAM") { setup(); }
00064     WvFamBase(WvFamCallback _cb) : cb(_cb), s(0), log("WvFam") { setup(); }
00065     ~WvFamBase() { close(); }
00066 
00067     void setup();
00068 
00073     void close();
00074 
00075     static bool fam_ok();
00076 
00077     bool isok() const;
00078 
00079     void setcallback(WvFamCallback _cb)
00080         { cb = _cb; }
00081 };
00082 
00083 
00084 
00089 class WvFam : public WvFamBase
00090 {
00091 public:
00092     WvFam() { }
00093     WvFam(WvFamCallback _cb) : WvFamBase(_cb) { }
00094 
00095     void monitordir(WvStringParm dir);
00096     void monitorfile(WvStringParm file);
00097     void monitor(WvStringParm path);
00098     void unmonitor(WvStringParm path);
00099 
00100 protected:
00101     typedef WvMapPair<WvString, int> WvFamReq;
00102     DeclareWvScatterDict2(WvFamReqDict, WvFamReq, WvString, key);
00103     WvFamReqDict reqs;
00104 };
00105 
00106 
00107 #endif /* WITH_FAM */
00108 #endif /*__WVFAM_H */

Generated on Sun Jul 10 14:05:52 2005 for WvStreams by  doxygen 1.4.0