00001 #ifndef _ManagementObject_
00002 #define _ManagementObject_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "qpid/sys/Time.h"
00026 #include "qpid/sys/Mutex.h"
00027 #include <qpid/framing/Buffer.h>
00028 #include <map>
00029
00030 namespace qpid {
00031 namespace management {
00032
00033 class Manageable;
00034 class ManagementAgent;
00035 class ObjectId;
00036
00037
00038 class AgentAttachment {
00039 friend class ObjectId;
00040 private:
00041 uint64_t first;
00042 public:
00043 AgentAttachment() : first(0) {}
00044 void setBanks(uint32_t broker, uint32_t bank);
00045 uint64_t getFirst() const { return first; }
00046 };
00047
00048
00049 class ObjectId {
00050 protected:
00051 const AgentAttachment* agent;
00052 uint64_t first;
00053 uint64_t second;
00054 void fromString(const std::string&);
00055 public:
00056 ObjectId() : agent(0), first(0), second(0) {}
00057 ObjectId(framing::Buffer& buf) : agent(0) { decode(buf); }
00058 ObjectId(uint8_t flags, uint16_t seq, uint32_t broker, uint32_t bank, uint64_t object);
00059 ObjectId(AgentAttachment* _agent, uint8_t flags, uint16_t seq, uint64_t object);
00060 ObjectId(std::istream&);
00061 ObjectId(const std::string&);
00062 bool operator==(const ObjectId &other) const;
00063 bool operator<(const ObjectId &other) const;
00064 void encode(framing::Buffer& buffer);
00065 void decode(framing::Buffer& buffer);
00066 friend std::ostream& operator<<(std::ostream&, const ObjectId&);
00067 };
00068
00069 class ManagementItem {
00070 public:
00071 static const uint8_t TYPE_U8 = 1;
00072 static const uint8_t TYPE_U16 = 2;
00073 static const uint8_t TYPE_U32 = 3;
00074 static const uint8_t TYPE_U64 = 4;
00075 static const uint8_t TYPE_SSTR = 6;
00076 static const uint8_t TYPE_LSTR = 7;
00077 static const uint8_t TYPE_ABSTIME = 8;
00078 static const uint8_t TYPE_DELTATIME = 9;
00079 static const uint8_t TYPE_REF = 10;
00080 static const uint8_t TYPE_BOOL = 11;
00081 static const uint8_t TYPE_FLOAT = 12;
00082 static const uint8_t TYPE_DOUBLE = 13;
00083 static const uint8_t TYPE_UUID = 14;
00084 static const uint8_t TYPE_FTABLE = 15;
00085 static const uint8_t TYPE_S8 = 16;
00086 static const uint8_t TYPE_S16 = 17;
00087 static const uint8_t TYPE_S32 = 18;
00088 static const uint8_t TYPE_S64 = 19;
00089
00090 static const uint8_t ACCESS_RC = 1;
00091 static const uint8_t ACCESS_RW = 2;
00092 static const uint8_t ACCESS_RO = 3;
00093
00094 static const uint8_t DIR_I = 1;
00095 static const uint8_t DIR_O = 2;
00096 static const uint8_t DIR_IO = 3;
00097
00098 static const uint8_t FLAG_CONFIG = 0x01;
00099 static const uint8_t FLAG_INDEX = 0x02;
00100 static const uint8_t FLAG_END = 0x80;
00101
00102 const static uint8_t CLASS_KIND_TABLE = 1;
00103 const static uint8_t CLASS_KIND_EVENT = 2;
00104
00105
00106
00107 public:
00108 virtual ~ManagementItem() {}
00109 };
00110
00111 class ManagementObject : public ManagementItem
00112 {
00113 protected:
00114
00115 uint64_t createTime;
00116 uint64_t destroyTime;
00117 ObjectId objectId;
00118 bool configChanged;
00119 bool instChanged;
00120 bool deleted;
00121 Manageable* coreObject;
00122 sys::Mutex accessLock;
00123 ManagementAgent* agent;
00124 int maxThreads;
00125 uint32_t flags;
00126
00127 static int nextThreadIndex;
00128
00129 int getThreadIndex();
00130 void writeTimestamps (qpid::framing::Buffer& buf);
00131
00132 public:
00133 typedef void (*writeSchemaCall_t) (qpid::framing::Buffer&);
00134
00135 ManagementObject (ManagementAgent* _agent, Manageable* _core) :
00136 destroyTime(0), configChanged(true),
00137 instChanged(true), deleted(false), coreObject(_core), agent(_agent)
00138 { createTime = uint64_t (qpid::sys::Duration (qpid::sys::now ())); }
00139 virtual ~ManagementObject () {}
00140
00141 virtual writeSchemaCall_t getWriteSchemaCall (void) = 0;
00142 virtual void writeProperties(qpid::framing::Buffer& buf) = 0;
00143 virtual void writeStatistics(qpid::framing::Buffer& buf,
00144 bool skipHeaders = false) = 0;
00145 virtual void doMethod (std::string& methodName,
00146 qpid::framing::Buffer& inBuf,
00147 qpid::framing::Buffer& outBuf) = 0;
00148 virtual void setReference (ObjectId objectId);
00149
00150 virtual std::string& getClassName (void) const = 0;
00151 virtual std::string& getPackageName (void) const = 0;
00152 virtual uint8_t* getMd5Sum (void) const = 0;
00153
00154 void setObjectId (ObjectId oid) { objectId = oid; }
00155 ObjectId getObjectId (void) { return objectId; }
00156 inline bool getConfigChanged (void) { return configChanged; }
00157 virtual bool getInstChanged (void) { return instChanged; }
00158 inline void setAllChanged (void) {
00159 configChanged = true;
00160 instChanged = true;
00161 }
00162
00163 inline void resourceDestroy (void) {
00164 destroyTime = uint64_t (qpid::sys::Duration (qpid::sys::now ()));
00165 deleted = true;
00166 }
00167 inline bool isDeleted (void) { return deleted; }
00168 inline void setFlags(uint32_t f) { flags = f; }
00169 inline uint32_t getFlags() { return flags; }
00170 bool isSameClass(ManagementObject& other) {
00171 for (int idx = 0; idx < 16; idx++)
00172 if (other.getMd5Sum()[idx] != getMd5Sum()[idx])
00173 return false;
00174 return other.getClassName() == getClassName() &&
00175 other.getPackageName() == getPackageName();
00176 }
00177 };
00178
00179 typedef std::map<ObjectId, ManagementObject*> ManagementObjectMap;
00180
00181 }}
00182
00183
00184
00185 #endif