diff options
Diffstat (limited to 'cpp/include/qpid/management')
| -rw-r--r-- | cpp/include/qpid/management/Args.h | 44 | ||||
| -rw-r--r-- | cpp/include/qpid/management/Buffer.h | 106 | ||||
| -rw-r--r-- | cpp/include/qpid/management/ConnectionSettings.h | 118 | ||||
| -rw-r--r-- | cpp/include/qpid/management/Manageable.h | 77 | ||||
| -rw-r--r-- | cpp/include/qpid/management/ManagementEvent.h | 53 | ||||
| -rw-r--r-- | cpp/include/qpid/management/ManagementObject.h | 237 | ||||
| -rw-r--r-- | cpp/include/qpid/management/Mutex.h | 67 |
7 files changed, 0 insertions, 702 deletions
diff --git a/cpp/include/qpid/management/Args.h b/cpp/include/qpid/management/Args.h deleted file mode 100644 index 5d1cb7e01d..0000000000 --- a/cpp/include/qpid/management/Args.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef _Args_ -#define _Args_ - -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - - -namespace qpid { -namespace management { - -class Args -{ - public: - - virtual ~Args (void) = 0; - -}; - -inline Args::~Args (void) {} - -class ArgsNone : public Args -{ -}; - -}} - - -#endif /*!_Args_*/ diff --git a/cpp/include/qpid/management/Buffer.h b/cpp/include/qpid/management/Buffer.h deleted file mode 100644 index c32494b8c0..0000000000 --- a/cpp/include/qpid/management/Buffer.h +++ /dev/null @@ -1,106 +0,0 @@ -#ifndef _Management_Buffer_ -#define _Management_Buffer_ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -#include "qpid/CommonImportExport.h" -#include "qpid/types/Exception.h" -#include "qpid/types/Variant.h" -#include <string> - -namespace qpid { -namespace framing { - class Buffer; -} - -namespace management { - -struct OutOfBounds : qpid::types::Exception { - OutOfBounds() : qpid::types::Exception(std::string("Out of Bounds")) {} -}; - - -/** - * This class is a wrapper around qpid::framing::Buffer that does not include any dependencies - * from boost or from qpid::framing. - */ -class Buffer -{ -public: - QPID_COMMON_EXTERN Buffer(char* data=0, uint32_t size=0); - QPID_COMMON_EXTERN ~Buffer(); - - QPID_COMMON_EXTERN void record(); - QPID_COMMON_EXTERN void restore(bool reRecord = false); - QPID_COMMON_EXTERN void reset(); - - QPID_COMMON_EXTERN uint32_t available(); - QPID_COMMON_EXTERN uint32_t getSize(); - QPID_COMMON_EXTERN uint32_t getPosition(); - QPID_COMMON_EXTERN char* getPointer(); - - QPID_COMMON_EXTERN void putOctet(uint8_t i); - QPID_COMMON_EXTERN void putShort(uint16_t i); - QPID_COMMON_EXTERN void putLong(uint32_t i); - QPID_COMMON_EXTERN void putLongLong(uint64_t i); - QPID_COMMON_EXTERN void putInt8(int8_t i); - QPID_COMMON_EXTERN void putInt16(int16_t i); - QPID_COMMON_EXTERN void putInt32(int32_t i); - QPID_COMMON_EXTERN void putInt64(int64_t i); - QPID_COMMON_EXTERN void putFloat(float f); - QPID_COMMON_EXTERN void putDouble(double f); - QPID_COMMON_EXTERN void putBin128(const uint8_t* b); - - QPID_COMMON_EXTERN uint8_t getOctet(); - QPID_COMMON_EXTERN uint16_t getShort(); - QPID_COMMON_EXTERN uint32_t getLong(); - QPID_COMMON_EXTERN uint64_t getLongLong(); - QPID_COMMON_EXTERN int8_t getInt8(); - QPID_COMMON_EXTERN int16_t getInt16(); - QPID_COMMON_EXTERN int32_t getInt32(); - QPID_COMMON_EXTERN int64_t getInt64(); - QPID_COMMON_EXTERN float getFloat(); - QPID_COMMON_EXTERN double getDouble(); - - QPID_COMMON_EXTERN void putShortString(const std::string& s); - QPID_COMMON_EXTERN void putMediumString(const std::string& s); - QPID_COMMON_EXTERN void putLongString(const std::string& s); - QPID_COMMON_EXTERN void getShortString(std::string& s); - QPID_COMMON_EXTERN void getMediumString(std::string& s); - QPID_COMMON_EXTERN void getLongString(std::string& s); - QPID_COMMON_EXTERN void getBin128(uint8_t* b); - - QPID_COMMON_EXTERN void putMap(const types::Variant::Map& map); - QPID_COMMON_EXTERN void putList(const types::Variant::List& list); - QPID_COMMON_EXTERN void getMap(types::Variant::Map& map); - QPID_COMMON_EXTERN void getList(types::Variant::List& list); - - QPID_COMMON_EXTERN void putRawData(const std::string& s); - QPID_COMMON_EXTERN void getRawData(std::string& s, uint32_t size); - - QPID_COMMON_EXTERN void putRawData(const uint8_t* data, size_t size); - QPID_COMMON_EXTERN void getRawData(uint8_t* data, size_t size); - -private: - framing::Buffer* impl; -}; - -}} // namespace qpid::management - -#endif diff --git a/cpp/include/qpid/management/ConnectionSettings.h b/cpp/include/qpid/management/ConnectionSettings.h deleted file mode 100644 index b631ffa658..0000000000 --- a/cpp/include/qpid/management/ConnectionSettings.h +++ /dev/null @@ -1,118 +0,0 @@ -#ifndef _management_ConnectionSettings_h -#define _management_ConnectionSettings_h -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -#include "qpid/CommonImportExport.h" -#include "qpid/types/Variant.h" -#include <string> - -namespace qpid { -namespace management { - -/** - * Settings for a Connection. - */ -struct ConnectionSettings { - - QPID_COMMON_EXTERN ConnectionSettings(); - QPID_COMMON_EXTERN virtual ~ConnectionSettings(); - - /** - * The protocol used for the connection (defaults to 'tcp') - */ - std::string protocol; - - /** - * The host (or ip address) to connect to (defaults to 'localhost'). - */ - std::string host; - /** - * The port to connect to (defaults to 5672). - */ - uint16_t port; - /** - * Allows an AMQP 'virtual host' to be specified for the - * connection. - */ - std::string virtualhost; - - /** - * The username to use when authenticating the connection. If not - * specified the current users login is used if available. - */ - std::string username; - /** - * The password to use when authenticating the connection. - */ - std::string password; - /** - * The SASL mechanism to use when authenticating the connection; - * the options are currently PLAIN or ANONYMOUS. - */ - std::string mechanism; - /** - * Allows a locale to be specified for the connection. - */ - std::string locale; - /** - * Allows a heartbeat frequency to be specified - */ - uint16_t heartbeat; - /** - * The maximum number of channels that the client will request for - * use on this connection. - */ - uint16_t maxChannels; - /** - * The maximum frame size that the client will request for this - * connection. - */ - uint16_t maxFrameSize; - /** - * Limit the size of the connections send buffer . The buffer - * is limited to bounds * maxFrameSize. - */ - unsigned int bounds; - /** - * If true, TCP_NODELAY will be set for the connection. - */ - bool tcpNoDelay; - /** - * SASL service name - */ - std::string service; - /** - * Minimum acceptable strength of any SASL negotiated security - * layer. 0 means no security layer required. - */ - unsigned int minSsf; - /** - * Maximum acceptable strength of any SASL negotiated security - * layer. 0 means no security layer allowed. - */ - unsigned int maxSsf; -}; - -}} - -#endif - diff --git a/cpp/include/qpid/management/Manageable.h b/cpp/include/qpid/management/Manageable.h deleted file mode 100644 index 1e5cd8bc42..0000000000 --- a/cpp/include/qpid/management/Manageable.h +++ /dev/null @@ -1,77 +0,0 @@ -#ifndef _Manageable_ -#define _Manageable_ - -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -#include "qpid/management/ManagementObject.h" -#include "qpid/management/Args.h" -#include <string> -#include "qpid/CommonImportExport.h" - -namespace qpid { -namespace management { - -class QPID_COMMON_EXTERN Manageable -{ - public: - - virtual ~Manageable(void) = 0; - - // status_t is a type used to pass completion status from the method handler. - // - typedef uint32_t status_t; - static std::string StatusText(status_t status, std::string text = std::string()); - - static const status_t STATUS_OK = 0; - static const status_t STATUS_UNKNOWN_OBJECT = 1; - static const status_t STATUS_UNKNOWN_METHOD = 2; - static const status_t STATUS_NOT_IMPLEMENTED = 3; - static const status_t STATUS_PARAMETER_INVALID = 4; - static const status_t STATUS_FEATURE_NOT_IMPLEMENTED = 5; - static const status_t STATUS_FORBIDDEN = 6; - static const status_t STATUS_EXCEPTION = 7; - static const status_t STATUS_USER = 0x00010000; - - // Every "Manageable" object must hold a reference to exactly one - // management object. This object is always of a class derived from - // the pure-virtual "ManagementObject". - // - // This accessor function returns a pointer to the management object. - // - virtual ManagementObject* GetManagementObject(void) const = 0; - - // Every "Manageable" object must implement ManagementMethod. This - // function is called when a remote management client invokes a method - // on this object. The input and output arguments are specific to the - // method being called and must be down-cast to the appropriate sub class - // before use. - virtual status_t ManagementMethod(uint32_t methodId, Args& args, std::string& text); - - // This optional method can be overridden to allow the agent application to - // authorize method invocations. Return true iff the authenticated user identified - // in userId us authorized to execute the method. - virtual bool AuthorizeMethod(uint32_t methodId, Args& args, const std::string& userId); -}; - -inline Manageable::~Manageable(void) {} - -}} - -#endif /*!_Manageable_*/ diff --git a/cpp/include/qpid/management/ManagementEvent.h b/cpp/include/qpid/management/ManagementEvent.h deleted file mode 100644 index e80175096f..0000000000 --- a/cpp/include/qpid/management/ManagementEvent.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef _ManagementEvent_ -#define _ManagementEvent_ - -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -#include "qpid/management/ManagementObject.h" -#include "qpid/types/Variant.h" -#include <string> - -namespace qpid { -namespace management { - -class ManagementAgent; - -class ManagementEvent : public ManagementItem { - public: - static const uint8_t MD5_LEN = 16; - //typedef void (*writeSchemaCall_t)(qpid::framing::Buffer&); - typedef void (*writeSchemaCall_t)(std::string&); - virtual ~ManagementEvent() {} - - virtual writeSchemaCall_t getWriteSchemaCall(void) = 0; - //virtual mapEncodeSchemaCall_t getMapEncodeSchemaCall(void) = 0; - virtual std::string& getEventName() const = 0; - virtual std::string& getPackageName() const = 0; - virtual uint8_t* getMd5Sum() const = 0; - virtual uint8_t getSeverity() const = 0; - virtual void encode(std::string&) const = 0; - virtual void mapEncode(qpid::types::Variant::Map&) const = 0; -}; - -}} - -#endif /*!_ManagementEvent_*/ diff --git a/cpp/include/qpid/management/ManagementObject.h b/cpp/include/qpid/management/ManagementObject.h deleted file mode 100644 index 16bf21038c..0000000000 --- a/cpp/include/qpid/management/ManagementObject.h +++ /dev/null @@ -1,237 +0,0 @@ -#ifndef _ManagementObject_ -#define _ManagementObject_ - -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -#include "qpid/CommonImportExport.h" - -#include "qpid/management/Mutex.h" -#include "qpid/types/Variant.h" - -#include <map> -#include <vector> - -namespace qpid { -namespace management { - -class Manageable; -class ObjectId; -class ManagementObject; - - -class AgentAttachment { - friend class ObjectId; -private: - uint64_t first; -public: - AgentAttachment() : first(0) {} - QPID_COMMON_EXTERN void setBanks(uint32_t broker, uint32_t bank); - uint64_t getFirst() const { return first; } -}; - - -class ObjectId { -protected: - const AgentAttachment* agent; - uint64_t first; - uint64_t second; - uint64_t agentEpoch; - std::string v2Key; - std::string agentName; - void fromString(const std::string&); -public: - QPID_COMMON_INLINE_EXTERN ObjectId() : agent(0), first(0), second(0), agentEpoch(0) {} - QPID_COMMON_INLINE_EXTERN ObjectId(const types::Variant& map) : - agent(0), first(0), second(0), agentEpoch(0) { mapDecode(map.asMap()); } - QPID_COMMON_EXTERN ObjectId(uint8_t flags, uint16_t seq, uint32_t broker); - QPID_COMMON_EXTERN ObjectId(AgentAttachment* _agent, uint8_t flags, uint16_t seq); - QPID_COMMON_EXTERN ObjectId(std::istream&); - QPID_COMMON_EXTERN ObjectId(const std::string&); - QPID_COMMON_INLINE_EXTERN ObjectId(const std::string& agentAddress, const std::string& key, - uint64_t epoch=0) : agent(0), first(0), second(0), - agentEpoch(epoch), v2Key(key), agentName(agentAddress) {} - - // Deprecated: - QPID_COMMON_EXTERN ObjectId(uint8_t flags, uint16_t seq, uint32_t broker, uint64_t object); - QPID_COMMON_EXTERN bool operator==(const ObjectId &other) const; - QPID_COMMON_EXTERN bool operator<(const ObjectId &other) const; - QPID_COMMON_EXTERN void mapEncode(types::Variant::Map& map) const; - QPID_COMMON_EXTERN void mapDecode(const types::Variant::Map& map); - QPID_COMMON_EXTERN operator types::Variant::Map() const; - QPID_COMMON_INLINE_EXTERN uint32_t encodedSize() const { return 16; }; - QPID_COMMON_EXTERN void encode(std::string& buffer) const; - QPID_COMMON_EXTERN void decode(const std::string& buffer); - QPID_COMMON_EXTERN bool equalV1(const ObjectId &other) const; - QPID_COMMON_INLINE_EXTERN void setV2Key(const std::string& _key) { v2Key = _key; } - QPID_COMMON_EXTERN void setV2Key(const ManagementObject& object); - QPID_COMMON_INLINE_EXTERN void setAgentName(const std::string& _name) { agentName = _name; } - QPID_COMMON_INLINE_EXTERN const std::string& getAgentName() const { return agentName; } - QPID_COMMON_INLINE_EXTERN const std::string& getV2Key() const { return v2Key; } - friend QPID_COMMON_EXTERN std::ostream& operator<<(std::ostream&, const ObjectId&); -}; - -class ManagementItem { -public: - static const uint8_t TYPE_U8 = 1; - static const uint8_t TYPE_U16 = 2; - static const uint8_t TYPE_U32 = 3; - static const uint8_t TYPE_U64 = 4; - static const uint8_t TYPE_SSTR = 6; - static const uint8_t TYPE_LSTR = 7; - static const uint8_t TYPE_ABSTIME = 8; - static const uint8_t TYPE_DELTATIME = 9; - static const uint8_t TYPE_REF = 10; - static const uint8_t TYPE_BOOL = 11; - static const uint8_t TYPE_FLOAT = 12; - static const uint8_t TYPE_DOUBLE = 13; - static const uint8_t TYPE_UUID = 14; - static const uint8_t TYPE_FTABLE = 15; - static const uint8_t TYPE_S8 = 16; - static const uint8_t TYPE_S16 = 17; - static const uint8_t TYPE_S32 = 18; - static const uint8_t TYPE_S64 = 19; - static const uint8_t TYPE_LIST = 21; - - static const uint8_t ACCESS_RC = 1; - static const uint8_t ACCESS_RW = 2; - static const uint8_t ACCESS_RO = 3; - - static const uint8_t DIR_I = 1; - static const uint8_t DIR_O = 2; - static const uint8_t DIR_IO = 3; - - static const uint8_t FLAG_CONFIG = 0x01; - static const uint8_t FLAG_INDEX = 0x02; - static const uint8_t FLAG_END = 0x80; - - const static uint8_t CLASS_KIND_TABLE = 1; - const static uint8_t CLASS_KIND_EVENT = 2; - - - -public: - virtual ~ManagementItem() {} -}; - -class QPID_COMMON_CLASS_EXTERN ManagementObject : public ManagementItem -{ -protected: - - uint64_t createTime; - uint64_t destroyTime; - uint64_t updateTime; - ObjectId objectId; - mutable bool configChanged; - mutable bool instChanged; - bool deleted; - Manageable* coreObject; - mutable Mutex accessLock; - uint32_t flags; - - static int nextThreadIndex; - bool forcePublish; - - QPID_COMMON_EXTERN int getThreadIndex(); - QPID_COMMON_EXTERN void writeTimestamps(std::string& buf) const; - QPID_COMMON_EXTERN void readTimestamps(const std::string& buf); - QPID_COMMON_EXTERN uint32_t writeTimestampsSize() const; - - public: - QPID_COMMON_EXTERN static const uint8_t MD5_LEN = 16; - QPID_COMMON_EXTERN static int maxThreads; - //typedef void (*writeSchemaCall_t) (qpid::framing::Buffer&); - typedef void (*writeSchemaCall_t) (std::string&); - - QPID_COMMON_EXTERN ManagementObject(Manageable* _core); - virtual ~ManagementObject() {} - - virtual writeSchemaCall_t getWriteSchemaCall() = 0; - virtual std::string getKey() const = 0; - - // Encode & Decode the property and statistics values - // for this object. - virtual void mapEncodeValues(types::Variant::Map& map, - bool includeProperties, - bool includeStatistics) = 0; - virtual void mapDecodeValues(const types::Variant::Map& map) = 0; - virtual void doMethod(std::string& methodName, - const types::Variant::Map& inMap, - types::Variant::Map& outMap, - const std::string& userId) = 0; - QPID_COMMON_EXTERN void writeTimestamps(types::Variant::Map& map) const; - QPID_COMMON_EXTERN void readTimestamps(const types::Variant::Map& buf); - - /** - * The following five methods are not pure-virtual because they will only - * be overridden in cases where QMFv1 is to be supported. - */ - virtual uint32_t writePropertiesSize() const { return 0; } - virtual void readProperties(const std::string&) {} - virtual void writeProperties(std::string&) const {} - virtual void writeStatistics(std::string&, bool = false) {} - virtual void doMethod(std::string&, const std::string&, std::string&, const std::string&) {} - - QPID_COMMON_EXTERN virtual void setReference(ObjectId objectId); - - virtual std::string& getClassName() const = 0; - virtual std::string& getPackageName() const = 0; - virtual uint8_t* getMd5Sum() const = 0; - - void setObjectId(ObjectId oid) { objectId = oid; } - ObjectId getObjectId() { return objectId; } - inline bool getConfigChanged() { return configChanged; } - virtual bool getInstChanged() { return instChanged; } - virtual bool hasInst() { return true; } - inline void setForcePublish(bool f) { forcePublish = f; } - inline bool getForcePublish() { return forcePublish; } - QPID_COMMON_EXTERN void setUpdateTime(); - QPID_COMMON_EXTERN void resourceDestroy(); - inline bool isDeleted() { return deleted; } - inline void setFlags(uint32_t f) { flags = f; } - inline uint32_t getFlags() { return flags; } - bool isSameClass(ManagementObject& other) { - for (int idx = 0; idx < MD5_LEN; idx++) - if (other.getMd5Sum()[idx] != getMd5Sum()[idx]) - return false; - return other.getClassName() == getClassName() && - other.getPackageName() == getPackageName(); - } - - // QPID_COMMON_EXTERN void encode(qpid::framing::Buffer& buf) const { writeProperties(buf); } - // QPID_COMMON_EXTERN void decode(qpid::framing::Buffer& buf) { readProperties(buf); } - //QPID_COMMON_EXTERN uint32_t encodedSize() const { return writePropertiesSize(); } - - // Encode/Decode the entire object as a map - //QPID_COMMON_EXTERN void mapEncode(types::Variant::Map& map, - //bool includeProperties=true, - //bool includeStatistics=true); - - //QPID_COMMON_EXTERN void mapDecode(const types::Variant::Map& map); -}; - -typedef std::map<ObjectId, ManagementObject*> ManagementObjectMap; -typedef std::vector<ManagementObject*> ManagementObjectVector; - -}} - - - -#endif /*!_ManagementObject_*/ diff --git a/cpp/include/qpid/management/Mutex.h b/cpp/include/qpid/management/Mutex.h deleted file mode 100644 index 67ae04bae9..0000000000 --- a/cpp/include/qpid/management/Mutex.h +++ /dev/null @@ -1,67 +0,0 @@ -#ifndef _management_Mutex_h -#define _management_Mutex_h - -/* - * - * Copyright (c) 2008 The Apache Software Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include "qpid/CommonImportExport.h" - -namespace qpid { - namespace sys { - class Mutex; - } - - namespace management { - - /** - * Scoped lock template: calls lock() in ctor, unlock() in dtor. - * L can be any class with lock() and unlock() functions. - */ - template <class L> class ScopedLockTemplate { - public: - ScopedLockTemplate(L& l) : mutex(l) { mutex.lock(); } - ~ScopedLockTemplate() { mutex.unlock(); } - private: - L& mutex; - }; - - template <class L> class ScopedUnlockTemplate { - public: - ScopedUnlockTemplate(L& l) : mutex(l) { mutex.unlock(); } - ~ScopedUnlockTemplate() { mutex.lock(); } - private: - L& mutex; - }; - - class Mutex { - public: - typedef ScopedLockTemplate<Mutex> ScopedLock; - typedef ScopedUnlockTemplate<Mutex> ScopedUnlock; - - QPID_COMMON_EXTERN Mutex(); - QPID_COMMON_EXTERN ~Mutex(); - QPID_COMMON_EXTERN void lock(); - QPID_COMMON_EXTERN void unlock(); - private: - sys::Mutex* impl; - }; - } -} - -#endif - |
