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

wvfam.h

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

Generated on Wed Dec 15 15:08:11 2004 for WvStreams by  doxygen 1.3.9.1