sharectl/sharectl.h

Go to the documentation of this file.
00001 #ifndef SHARECTL_H
00002 #define SHARECTL_H
00003 
00012 #include "sharelib.h"
00013 
00014 #include <string>
00015 #include <iostream>
00016 // #include <map>
00017 
00018 namespace Share {
00019 
00024   class ArgParser {
00025     public:
00029       typedef enum {
00030         NONE = 0,         // No switch
00031         HELP,             // Display help
00032         CREATE,           // --create
00033         CREATE_AND_WAIT,  // --create-and-wait
00034         NOTIFY_ATTACH,    // --notify-attach
00035         NOTIFY_DETACH,    // --notify-detach
00036         UNLINK,           // --unlinnk
00037         FORCE_DESTORY,    // --force-destroy
00038         ALLOC,            // --alloc
00039         FREE              // --free
00040       } Action;
00041 
00047       ArgParser (int argc, char *argv[]) throw (ShareException);
00048       
00052       bool isNewSegment();
00053       
00057       const char* name();
00058       
00062       size_t size();
00063       
00067       Action action();
00068     private:
00069       std::string name_;
00070       size_t size_;
00071       Action action_;
00072   };
00073 
00078   class ArgSwitchChecker {
00079       typedef ArgParser::Action TAction;
00080 
00081       // STL map
00082       // typedef std::map<std::string, TAction> TMap;
00083 
00084       // Share library Map
00085       typedef Share::Map<std::string, TAction> TMap;
00086     public:
00087       ArgSwitchChecker();
00088       
00094       TAction checkSwitch (std::string str);
00095     private:
00096       TMap map_;
00097   };
00098 
00099   class SharedSegment;          // Platform-independent shared segment representation
00100   class SegmentHeader;          // Object placed at begin of shared segment
00101   
00106   class SharedSegmentWrapper {
00107     public:
00108       SharedSegmentWrapper();
00109       ~SharedSegmentWrapper();
00110       
00117       void create (const char *name, size_t size) throw (ShareException);
00118       
00124       void attach (const char *name) throw (ShareException);
00125       
00129       SegmentHeader* atAddr() throw (ShareException);
00130       
00134       void destroy();
00135     private:
00136       SharedSegment *segment_;
00137   };
00138 
00143   class SegmentDebuger {
00144     public:
00148       SegmentDebuger (SegmentHeader *shareManager);
00149       
00154       void refCountAction (ArgParser::Action action);
00155       
00159       bool shouldBeDestroyed();
00160       
00165       void alloc(size_t size);
00166       
00171       void free(size_t relativePointer);
00172     private:
00173       SegmentHeader *segmentManager_;
00174       friend std::ostream& operator<< (std::ostream &, SegmentDebuger&);
00175   };
00177   std::ostream& operator<< (std::ostream &, SegmentDebuger&);
00178 
00179 }
00180 #endif // SHARECTL_H

Generated on Sun Aug 26 17:42:59 2007 for ShareLibrary by  doxygen 1.5.2