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 #include <map>
00029 #include <vector>
00030 
00031 #ifdef _IN_QPID_BROKER
00032 #include <boost/shared_ptr.hpp>
00033 #endif
00034 
00035 namespace qpid {
00036 namespace management {
00037 
00038 class Manageable;
00039 class ObjectId;
00040 class ManagementObject;
00041 
00042 
00043 class AgentAttachment {
00044     friend class ObjectId;
00045 private:
00046     uint64_t first;
00047 public:
00048     AgentAttachment() : first(0) {}
00049     QPID_COMMON_EXTERN void setBanks(uint32_t broker, uint32_t bank);
00050     uint64_t getFirst() const { return first; }
00051 };
00052 
00053 
00054 class ObjectId {
00055 protected:
00056     const AgentAttachment* agent;
00057     uint64_t first;
00058     uint64_t second;
00059     uint64_t agentEpoch;
00060     std::string v2Key;
00061     std::string agentName;
00062     void fromString(const std::string&);
00063 public:
00064     QPID_COMMON_INLINE_EXTERN ObjectId() : agent(0), first(0), second(0), agentEpoch(0) {}
00065     QPID_COMMON_INLINE_EXTERN ObjectId(const types::Variant& map) :
00066     agent(0), first(0), second(0), agentEpoch(0) { mapDecode(map.asMap()); }
00067     QPID_COMMON_EXTERN ObjectId(uint8_t flags, uint16_t seq, uint32_t broker);
00068     QPID_COMMON_EXTERN ObjectId(AgentAttachment* _agent, uint8_t flags, uint16_t seq);
00069     QPID_COMMON_EXTERN ObjectId(std::istream&);
00070     QPID_COMMON_EXTERN ObjectId(const std::string&);
00071     QPID_COMMON_INLINE_EXTERN ObjectId(const std::string& agentAddress, const std::string& key,
00072                                 uint64_t epoch=0) : agent(0), first(0), second(0),
00073       agentEpoch(epoch), v2Key(key), agentName(agentAddress) {}
00074 
00075     // Deprecated:
00076     QPID_COMMON_EXTERN ObjectId(uint8_t flags, uint16_t seq, uint32_t broker, uint64_t object);
00077     QPID_COMMON_EXTERN bool operator==(const ObjectId &other) const;
00078     QPID_COMMON_EXTERN bool operator<(const ObjectId &other) const;
00079     QPID_COMMON_EXTERN void mapEncode(types::Variant::Map& map) const;
00080     QPID_COMMON_EXTERN void mapDecode(const types::Variant::Map& map);
00081     QPID_COMMON_EXTERN operator types::Variant::Map() const;
00082     QPID_COMMON_INLINE_EXTERN uint32_t encodedSize() const { return 16; };
00083     QPID_COMMON_EXTERN void encode(std::string& buffer) const;
00084     QPID_COMMON_EXTERN void decode(const std::string& buffer);
00085     QPID_COMMON_EXTERN bool equalV1(const ObjectId &other) const;
00086     QPID_COMMON_INLINE_EXTERN void setV2Key(const std::string& _key) { v2Key = _key; }
00087     QPID_COMMON_EXTERN void setV2Key(const ManagementObject& object);
00088     QPID_COMMON_INLINE_EXTERN void setAgentName(const std::string& _name) { agentName = _name; }
00089     QPID_COMMON_INLINE_EXTERN const std::string& getAgentName() const { return agentName; }
00090     QPID_COMMON_INLINE_EXTERN const std::string& getV2Key() const { return v2Key; }
00091     friend QPID_COMMON_EXTERN std::ostream& operator<<(std::ostream&, const ObjectId&);
00092 };
00093 
00094 class ManagementItem {
00095 public:
00096     static const uint8_t TYPE_U8        = 1;
00097     static const uint8_t TYPE_U16       = 2;
00098     static const uint8_t TYPE_U32       = 3;
00099     static const uint8_t TYPE_U64       = 4;
00100     static const uint8_t TYPE_SSTR      = 6;
00101     static const uint8_t TYPE_LSTR      = 7;
00102     static const uint8_t TYPE_ABSTIME   = 8;
00103     static const uint8_t TYPE_DELTATIME = 9;
00104     static const uint8_t TYPE_REF       = 10;
00105     static const uint8_t TYPE_BOOL      = 11;
00106     static const uint8_t TYPE_FLOAT     = 12;
00107     static const uint8_t TYPE_DOUBLE    = 13;
00108     static const uint8_t TYPE_UUID      = 14;
00109     static const uint8_t TYPE_FTABLE    = 15;
00110     static const uint8_t TYPE_S8        = 16;
00111     static const uint8_t TYPE_S16       = 17;
00112     static const uint8_t TYPE_S32       = 18;
00113     static const uint8_t TYPE_S64       = 19;
00114     static const uint8_t TYPE_LIST      = 21;
00115 
00116     static const uint8_t ACCESS_RC = 1;
00117     static const uint8_t ACCESS_RW = 2;
00118     static const uint8_t ACCESS_RO = 3;
00119 
00120     static const uint8_t DIR_I     = 1;
00121     static const uint8_t DIR_O     = 2;
00122     static const uint8_t DIR_IO    = 3;
00123 
00124     static const uint8_t FLAG_CONFIG = 0x01;
00125     static const uint8_t FLAG_INDEX  = 0x02;
00126     static const uint8_t FLAG_END    = 0x80;
00127 
00128     const static uint8_t CLASS_KIND_TABLE = 1;
00129     const static uint8_t CLASS_KIND_EVENT = 2;
00130 
00131 
00132 
00133 public:
00134     virtual ~ManagementItem() {}
00135 };
00136 
00137 class QPID_COMMON_CLASS_EXTERN ManagementObject : public ManagementItem
00138 {
00139 protected:
00140 
00141     uint64_t         createTime;
00142     uint64_t         destroyTime;
00143     uint64_t         updateTime;
00144     ObjectId         objectId;
00145     mutable bool     configChanged;
00146     mutable bool     instChanged;
00147     bool             deleted;
00148     Manageable*      coreObject;
00149     mutable Mutex    accessLock;
00150     uint32_t         flags;
00151 
00152     static int nextThreadIndex;
00153     bool             forcePublish;
00154 
00155     QPID_COMMON_EXTERN int  getThreadIndex();
00156     QPID_COMMON_EXTERN void writeTimestamps(std::string& buf) const;
00157     QPID_COMMON_EXTERN void readTimestamps(const std::string& buf);
00158     QPID_COMMON_EXTERN uint32_t writeTimestampsSize() const;
00159 
00160   public:
00161 #ifdef _IN_QPID_BROKER
00162     typedef boost::shared_ptr<ManagementObject> shared_ptr;
00163 #endif
00164 
00165     QPID_COMMON_EXTERN static const uint8_t MD5_LEN = 16;
00166     QPID_COMMON_EXTERN static int maxThreads;
00167     //typedef void (*writeSchemaCall_t) (qpid::framing::Buffer&);
00168     typedef void (*writeSchemaCall_t) (std::string&);
00169 
00170     QPID_COMMON_EXTERN ManagementObject(Manageable* _core);
00171     virtual ~ManagementObject() {}
00172 
00173     virtual writeSchemaCall_t getWriteSchemaCall() = 0;
00174     virtual std::string getKey() const = 0;
00175 
00176     // Encode & Decode the property and statistics values
00177     // for this object.
00178     virtual void mapEncodeValues(types::Variant::Map& map,
00179                                  bool includeProperties,
00180                                  bool includeStatistics) = 0;
00181     virtual void mapDecodeValues(const types::Variant::Map& map) = 0;
00182     virtual void doMethod(std::string&           methodName,
00183                           const types::Variant::Map& inMap,
00184                           types::Variant::Map& outMap,
00185                           const std::string& userId) = 0;
00186     QPID_COMMON_EXTERN void writeTimestamps(types::Variant::Map& map) const;
00187     QPID_COMMON_EXTERN void readTimestamps(const types::Variant::Map& buf);
00188 
00193     virtual uint32_t writePropertiesSize() const { return 0; }
00194     virtual void readProperties(const std::string&) {}
00195     virtual void writeProperties(std::string&) const {}
00196     virtual void writeStatistics(std::string&, bool = false) {}
00197     virtual void doMethod(std::string&, const std::string&, std::string&, const std::string&) {}
00198 
00199     QPID_COMMON_EXTERN virtual void setReference(ObjectId objectId);
00200 
00201     virtual std::string& getClassName() const = 0;
00202     virtual std::string& getPackageName() const = 0;
00203     virtual uint8_t*     getMd5Sum() const = 0;
00204 
00205     void         setObjectId(ObjectId oid) { objectId = oid; }
00206     ObjectId     getObjectId() { return objectId; }
00207     inline  bool getConfigChanged() { return configChanged; }
00208     virtual bool getInstChanged() { return instChanged; }
00209     virtual bool hasInst() { return true; }
00210     inline  void setForcePublish(bool f) { forcePublish = f; }
00211     inline  bool getForcePublish() { return forcePublish; }
00212     QPID_COMMON_EXTERN void setUpdateTime();
00213     QPID_COMMON_EXTERN void resourceDestroy();
00214     inline bool isDeleted() { return deleted; }
00215     inline void setFlags(uint32_t f) { flags = f; }
00216     inline uint32_t getFlags() { return flags; }
00217     bool isSameClass(ManagementObject& other) {
00218         for (int idx = 0; idx < MD5_LEN; idx++)
00219             if (other.getMd5Sum()[idx] != getMd5Sum()[idx])
00220                 return false;
00221         return other.getClassName() == getClassName() &&
00222             other.getPackageName() == getPackageName();
00223     }
00224 
00225     // QPID_COMMON_EXTERN void encode(qpid::framing::Buffer& buf) const { writeProperties(buf); }
00226     // QPID_COMMON_EXTERN void decode(qpid::framing::Buffer& buf) { readProperties(buf); }
00227     //QPID_COMMON_EXTERN uint32_t encodedSize() const { return writePropertiesSize(); }
00228 
00229     // Encode/Decode the entire object as a map
00230     //QPID_COMMON_EXTERN void mapEncode(types::Variant::Map& map,
00231     //bool includeProperties=true,
00232     //bool includeStatistics=true);
00233 
00234     //QPID_COMMON_EXTERN void mapDecode(const types::Variant::Map& map);
00235 };
00236 
00237 #ifdef _IN_QPID_BROKER
00238 typedef std::map<ObjectId, ManagementObject::shared_ptr> ManagementObjectMap;
00239 typedef std::vector<ManagementObject::shared_ptr> ManagementObjectVector;
00240 #endif
00241 
00242 }}
00243 
00244 
00245 
00246 #endif  

Qpid C++ API Reference
Generated on Fri Aug 23 2013 for Qpid C++ Client API by doxygen 1.7.5