Apache Qpid - AMQP Messaging for Java JMS, C++, Python, Ruby, and .NET Apache Qpid Documentation
qpid/management/ManagementObject.h
Go to the documentation of this file.
00001 #ifndef _ManagementObject_
00002 #define _ManagementObject_
00003 
00004 /*
00005  *
00006  * Licensed to the Apache Software Foundation (ASF) under one
00007  * or more contributor license agreements.  See the NOTICE file
00008  * distributed with this work for additional information
00009  * regarding copyright ownership.  The ASF licenses this file
00010  * to you under the Apache License, Version 2.0 (the
00011  * "License"); you may not use this file except in compliance
00012  * with the License.  You may obtain a copy of the License at
00013  *
00014  *   http://www.apache.org/licenses/LICENSE-2.0
00015  *
00016  * Unless required by applicable law or agreed to in writing,
00017  * software distributed under the License is distributed on an
00018  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
00019  * KIND, either express or implied.  See the License for the
00020  * specific language governing permissions and limitations
00021  * under the License.
00022  *
00023  */
00024 #include "qpid/CommonImportExport.h"
00025 
00026 #include "qpid/management/Mutex.h"
00027 #include "qpid/types/Variant.h"
00028 
00029 #include <map>
00030 #include <vector>
00031 
00032 namespace qpid {
00033 namespace management {
00034 
00035 class Manageable;
00036 class ObjectId;
00037 class ManagementObject;
00038 
00039 
00040 class AgentAttachment {
00041     friend class ObjectId;
00042 private:
00043     uint64_t first;
00044 public:
00045     AgentAttachment() : first(0) {}
00046     QPID_COMMON_EXTERN void setBanks(uint32_t broker, uint32_t bank);
00047     uint64_t getFirst() const { return first; }
00048 };
00049 
00050 
00051 class ObjectId {
00052 protected:
00053     const AgentAttachment* agent;
00054     uint64_t first;
00055     uint64_t second;
00056     uint64_t agentEpoch;
00057     std::string v2Key;
00058     std::string agentName;
00059     void fromString(const std::string&);
00060 public:
00061     QPID_COMMON_INLINE_EXTERN ObjectId() : agent(0), first(0), second(0), agentEpoch(0) {}
00062     QPID_COMMON_INLINE_EXTERN ObjectId(const types::Variant& map) :
00063     agent(0), first(0), second(0), agentEpoch(0) { mapDecode(map.asMap()); }
00064     QPID_COMMON_EXTERN ObjectId(uint8_t flags, uint16_t seq, uint32_t broker);
00065     QPID_COMMON_EXTERN ObjectId(AgentAttachment* _agent, uint8_t flags, uint16_t seq);
00066     QPID_COMMON_EXTERN ObjectId(std::istream&);
00067     QPID_COMMON_EXTERN ObjectId(const std::string&);
00068     QPID_COMMON_INLINE_EXTERN ObjectId(const std::string& agentAddress, const std::string& key,
00069                                 uint64_t epoch=0) : agent(0), first(0), second(0),
00070       agentEpoch(epoch), v2Key(key), agentName(agentAddress) {}
00071 
00072     // Deprecated:
00073     QPID_COMMON_EXTERN ObjectId(uint8_t flags, uint16_t seq, uint32_t broker, uint64_t object);
00074     QPID_COMMON_EXTERN bool operator==(const ObjectId &other) const;
00075     QPID_COMMON_EXTERN bool operator<(const ObjectId &other) const;
00076     QPID_COMMON_EXTERN void mapEncode(types::Variant::Map& map) const;
00077     QPID_COMMON_EXTERN void mapDecode(const types::Variant::Map& map);
00078     QPID_COMMON_EXTERN operator types::Variant::Map() const;
00079     QPID_COMMON_INLINE_EXTERN uint32_t encodedSize() const { return 16; };
00080     QPID_COMMON_EXTERN void encode(std::string& buffer) const;
00081     QPID_COMMON_EXTERN void decode(const std::string& buffer);
00082     QPID_COMMON_EXTERN bool equalV1(const ObjectId &other) const;
00083     QPID_COMMON_INLINE_EXTERN void setV2Key(const std::string& _key) { v2Key = _key; }
00084     QPID_COMMON_EXTERN void setV2Key(const ManagementObject& object);
00085     QPID_COMMON_INLINE_EXTERN void setAgentName(const std::string& _name) { agentName = _name; }
00086     QPID_COMMON_INLINE_EXTERN const std::string& getAgentName() const { return agentName; }
00087     QPID_COMMON_INLINE_EXTERN const std::string& getV2Key() const { return v2Key; }
00088     friend QPID_COMMON_EXTERN std::ostream& operator<<(std::ostream&, const ObjectId&);
00089 };
00090 
00091 class ManagementItem {
00092 public:
00093     static const uint8_t TYPE_U8        = 1;
00094     static const uint8_t TYPE_U16       = 2;
00095     static const uint8_t TYPE_U32       = 3;
00096     static const uint8_t TYPE_U64       = 4;
00097     static const uint8_t TYPE_SSTR      = 6;
00098     static const uint8_t TYPE_LSTR      = 7;
00099     static const uint8_t TYPE_ABSTIME   = 8;
00100     static const uint8_t TYPE_DELTATIME = 9;
00101     static const uint8_t TYPE_REF       = 10;
00102     static const uint8_t TYPE_BOOL      = 11;
00103     static const uint8_t TYPE_FLOAT     = 12;
00104     static const uint8_t TYPE_DOUBLE    = 13;
00105     static const uint8_t TYPE_UUID      = 14;
00106     static const uint8_t TYPE_FTABLE    = 15;
00107     static const uint8_t TYPE_S8        = 16;
00108     static const uint8_t TYPE_S16       = 17;
00109     static const uint8_t TYPE_S32       = 18;
00110     static const uint8_t TYPE_S64       = 19;
00111     static const uint8_t TYPE_LIST      = 21;
00112 
00113     static const uint8_t ACCESS_RC = 1;
00114     static const uint8_t ACCESS_RW = 2;
00115     static const uint8_t ACCESS_RO = 3;
00116 
00117     static const uint8_t DIR_I     = 1;
00118     static const uint8_t DIR_O     = 2;
00119     static const uint8_t DIR_IO    = 3;
00120 
00121     static const uint8_t FLAG_CONFIG = 0x01;
00122     static const uint8_t FLAG_INDEX  = 0x02;
00123     static const uint8_t FLAG_END    = 0x80;
00124 
00125     const static uint8_t CLASS_KIND_TABLE = 1;
00126     const static uint8_t CLASS_KIND_EVENT = 2;
00127 
00128 
00129 
00130 public:
00131     virtual ~ManagementItem() {}
00132 };
00133 
00134 class QPID_COMMON_CLASS_EXTERN ManagementObject : public ManagementItem
00135 {
00136 protected:
00137 
00138     uint64_t         createTime;
00139     uint64_t         destroyTime;
00140     uint64_t         updateTime;
00141     ObjectId         objectId;
00142     mutable bool     configChanged;
00143     mutable bool     instChanged;
00144     bool             deleted;
00145     Manageable*      coreObject;
00146     mutable Mutex    accessLock;
00147     uint32_t         flags;
00148 
00149     static int nextThreadIndex;
00150     bool             forcePublish;
00151 
00152     QPID_COMMON_EXTERN int  getThreadIndex();
00153     QPID_COMMON_EXTERN void writeTimestamps(std::string& buf) const;
00154     QPID_COMMON_EXTERN void readTimestamps(const std::string& buf);
00155     QPID_COMMON_EXTERN uint32_t writeTimestampsSize() const;
00156 
00157   public:
00158     QPID_COMMON_EXTERN static const uint8_t MD5_LEN = 16;
00159     QPID_COMMON_EXTERN static int maxThreads;
00160     //typedef void (*writeSchemaCall_t) (qpid::framing::Buffer&);
00161     typedef void (*writeSchemaCall_t) (std::string&);
00162 
00163     QPID_COMMON_EXTERN ManagementObject(Manageable* _core);
00164     virtual ~ManagementObject() {}
00165 
00166     virtual writeSchemaCall_t getWriteSchemaCall() = 0;
00167     virtual std::string getKey() const = 0;
00168 
00169     // Encode & Decode the property and statistics values
00170     // for this object.
00171     virtual void mapEncodeValues(types::Variant::Map& map,
00172                                  bool includeProperties,
00173                                  bool includeStatistics) = 0;
00174     virtual void mapDecodeValues(const types::Variant::Map& map) = 0;
00175     virtual void doMethod(std::string&           methodName,
00176                           const types::Variant::Map& inMap,
00177                           types::Variant::Map& outMap,
00178                           const std::string& userId) = 0;
00179     QPID_COMMON_EXTERN void writeTimestamps(types::Variant::Map& map) const;
00180     QPID_COMMON_EXTERN void readTimestamps(const types::Variant::Map& buf);
00181 
00186     virtual uint32_t writePropertiesSize() const { return 0; }
00187     virtual void readProperties(const std::string&) {}
00188     virtual void writeProperties(std::string&) const {}
00189     virtual void writeStatistics(std::string&, bool = false) {}
00190     virtual void doMethod(std::string&, const std::string&, std::string&, const std::string&) {}
00191 
00192     QPID_COMMON_EXTERN virtual void setReference(ObjectId objectId);
00193 
00194     virtual std::string& getClassName() const = 0;
00195     virtual std::string& getPackageName() const = 0;
00196     virtual uint8_t*     getMd5Sum() const = 0;
00197 
00198     void         setObjectId(ObjectId oid) { objectId = oid; }
00199     ObjectId     getObjectId() { return objectId; }
00200     inline  bool getConfigChanged() { return configChanged; }
00201     virtual bool getInstChanged() { return instChanged; }
00202     virtual bool hasInst() { return true; }
00203     inline  void setForcePublish(bool f) { forcePublish = f; }
00204     inline  bool getForcePublish() { return forcePublish; }
00205     QPID_COMMON_EXTERN void setUpdateTime();
00206     QPID_COMMON_EXTERN void resourceDestroy();
00207     inline bool isDeleted() { return deleted; }
00208     inline void setFlags(uint32_t f) { flags = f; }
00209     inline uint32_t getFlags() { return flags; }
00210     bool isSameClass(ManagementObject& other) {
00211         for (int idx = 0; idx < MD5_LEN; idx++)
00212             if (other.getMd5Sum()[idx] != getMd5Sum()[idx])
00213                 return false;
00214         return other.getClassName() == getClassName() &&
00215             other.getPackageName() == getPackageName();
00216     }
00217 
00218     // QPID_COMMON_EXTERN void encode(qpid::framing::Buffer& buf) const { writeProperties(buf); }
00219     // QPID_COMMON_EXTERN void decode(qpid::framing::Buffer& buf) { readProperties(buf); }
00220     //QPID_COMMON_EXTERN uint32_t encodedSize() const { return writePropertiesSize(); }
00221 
00222     // Encode/Decode the entire object as a map
00223     //QPID_COMMON_EXTERN void mapEncode(types::Variant::Map& map,
00224     //bool includeProperties=true,
00225     //bool includeStatistics=true);
00226 
00227     //QPID_COMMON_EXTERN void mapDecode(const types::Variant::Map& map);
00228 };
00229 
00230 typedef std::map<ObjectId, ManagementObject*> ManagementObjectMap;
00231 typedef std::vector<ManagementObject*> ManagementObjectVector;
00232 
00233 }}
00234 
00235 
00236 
00237 #endif  

Qpid C++ API Reference
Generated on Mon Aug 22 2011 for Qpid C++ Client API by doxygen 1.7.4