00001 #ifndef SHARECTL_H
00002 #define SHARECTL_H
00003
00012 #include "sharelib.h"
00013
00014 #include <string>
00015 #include <iostream>
00016
00017
00018 namespace Share {
00019
00024 class ArgParser {
00025 public:
00029 typedef enum {
00030 NONE = 0,
00031 HELP,
00032 CREATE,
00033 CREATE_AND_WAIT,
00034 NOTIFY_ATTACH,
00035 NOTIFY_DETACH,
00036 UNLINK,
00037 FORCE_DESTORY,
00038 ALLOC,
00039 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
00082
00083
00084
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;
00100 class SegmentHeader;
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