lsmp/lsmp.hh

00001 /* -*- mode: c++; c-basic-offset: 4; -*- */
00002 //
00003 //   LSMP is the Ligo Shared Memory Partition object class
00004 //
00005 #ifndef LSMP_HH
00006 #define LSMP_HH
00007 
00008 #include <sys/types.h>
00009 #include <string>
00010 #include <iosfwd>
00011 
00012 #define LSMP_LNAME  16                      // maximum partition name length
00013 
00014 //--------------------------------------- Error code enumerator
00015 enum LSMP_error {
00016     NoError = 0,
00017     NotAttached,
00018     IncompatiblePartition,
00019     CantGetSem,
00020     NoFreeID,
00021     CantAttach,
00022     CantCreate,
00023     CantCreateSem,
00024     NoPriviledge,
00025     BadVersion
00026 };
00027 
00028 //---------------------------------------  Consumer flags.
00029 #define READALL  0x0001
00030 #define EVWAIT   0x0002
00031 #define NOWAIT   0x0004
00032 #define SHOWALL  0x0008
00033 
00043 class LSMP {
00044   public:
00045     typedef int eventid_type;
00046 
00047   public:
00049     LSMP_error error;
00050 
00053     bool valid() const {
00054          return accessed;}
00055 
00058     bool found() const {
00059          return attached;}
00060 
00066     void dump(int flg=0xff) const;
00067 
00082     void dump(std::ostream& Out, int flg=0xff) const;
00083 
00086     void rqsynch(bool on);
00087 
00100     void bufmode(int mode);
00101 
00107     void keep(bool flag=true);
00108 
00109 
00115     void lock(bool flag=true);
00116 
00119     const char *Error(void) const;
00120 
00124     int getBufferLength(void) const {return NByte;}
00125 
00129     int getBufferCount(void) const {return NBuff;}
00130 
00135     LSMP(void);
00136 
00141     LSMP(LSMP& copy);
00142 
00147     LSMP(const char* name);
00148 
00159     LSMP(const char* name, int nbuf, int size);
00160 
00166     ~LSMP(void);
00167 
00191      std::string getStat(const std::string& par) const;
00192 
00198      bool testFlag(int x) const;
00199 
00202      int getLockCount(void) const {return mLockCount;}
00203 
00206      void clrLockCount(void) {mLockCount=0;}
00207 
00208   protected:
00210     struct LSMP_global* pointer;
00211 
00213     struct LSMP_consbk* conptr;
00214 
00216     struct LSMP_buffer* bufptr;
00217 
00220     char* buffer_addr(int ibuf) const;
00221 
00224     int buffer_length(int ibuf) const;
00225 
00229     bool gate(bool close) const;
00230 
00235     void Zeuss(const char* name);
00236 
00237   private:
00239     bool access();
00240 
00242     void deaccess();
00243 
00245     bool find(const char *name);
00246 
00248     bool make(const char *name, int nbuf, int size);
00249 
00251     void release();
00252 
00253   private:
00257     bool attached;
00258 
00262     bool accessed;
00263 
00267     bool kpflg;
00268 
00272     int NByte;
00273 
00277     int NBuff;
00278 
00281     int ident;
00282 
00286     static LSMP* base;
00287 
00289     LSMP* link;
00290 
00292     mutable int  mLockCount;
00293 };
00294 
00295 
00301 class LSMP_ACCESS : public LSMP {
00302 
00303   //------------------------------------  Public data and methods
00304   public:
00309     LSMP_ACCESS();
00310 
00316     LSMP_ACCESS(const char *part);
00317 
00321     ~LSMP_ACCESS();
00322 
00329     void Repair(int ID=-1);
00330 
00338     void Spew(int jBuf, std::ostream& Out, int length=0);
00339 
00340   private:
00346     int free_consumer(int icon);
00347 };
00348 
00349 #endif // LSMP_HH

Generated on Sun Mar 8 19:20:51 2009 for dmt by  doxygen 1.5.4