diff options
author | Alan Conway <aconway@apache.org> | 2009-07-15 16:45:21 +0000 |
---|---|---|
committer | Alan Conway <aconway@apache.org> | 2009-07-15 16:45:21 +0000 |
commit | 366916dc747b462858252271a6993d244f59768a (patch) | |
tree | de0f1a27ff50058c6f8e084c9ac1595892032f00 /cpp/include/qpid/console | |
parent | 6bcc8e7c8591c623fdcc5c75f6e3759bbe27eeca (diff) | |
download | qpid-python-366916dc747b462858252271a6993d244f59768a.tar.gz |
Merge branch 'move_public_h_to_include' into trunk
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@794325 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/include/qpid/console')
-rw-r--r-- | cpp/include/qpid/console/Agent.h | 58 | ||||
-rw-r--r-- | cpp/include/qpid/console/Broker.h | 133 | ||||
-rw-r--r-- | cpp/include/qpid/console/ClassKey.h | 66 | ||||
-rw-r--r-- | cpp/include/qpid/console/ConsoleImportExport.h | 33 | ||||
-rw-r--r-- | cpp/include/qpid/console/ConsoleListener.h | 97 | ||||
-rw-r--r-- | cpp/include/qpid/console/Event.h | 86 | ||||
-rw-r--r-- | cpp/include/qpid/console/Object.h | 123 | ||||
-rw-r--r-- | cpp/include/qpid/console/ObjectId.h | 69 | ||||
-rw-r--r-- | cpp/include/qpid/console/Package.h | 78 | ||||
-rw-r--r-- | cpp/include/qpid/console/Schema.h | 105 | ||||
-rw-r--r-- | cpp/include/qpid/console/SequenceManager.h | 54 | ||||
-rw-r--r-- | cpp/include/qpid/console/SessionManager.h | 205 | ||||
-rw-r--r-- | cpp/include/qpid/console/Value.h | 213 |
13 files changed, 1320 insertions, 0 deletions
diff --git a/cpp/include/qpid/console/Agent.h b/cpp/include/qpid/console/Agent.h new file mode 100644 index 0000000000..97d75da250 --- /dev/null +++ b/cpp/include/qpid/console/Agent.h @@ -0,0 +1,58 @@ +/* + * + * 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. + * + */ +#ifndef _QPID_CONSOLE_AGENT_H_ +#define _QPID_CONSOLE_AGENT_H_ + +#include "qpid/console/Broker.h" +#include "qpid/console/ConsoleImportExport.h" + +namespace qpid { +namespace console { + + /** + * + * \ingroup qmfconsoleapi + */ + class QPID_CONSOLE_EXTERN Agent { + public: + typedef std::vector<Agent*> Vector; + + Agent(Broker* _broker, uint32_t _bank, const std::string& _label) : + broker(_broker), brokerBank(broker->getBrokerBank()), + agentBank(_bank), label(_label) {} + Broker* getBroker() const { return broker; } + uint32_t getBrokerBank() const { return brokerBank; } + uint32_t getAgentBank() const { return agentBank; } + const std::string& getLabel() const { return label; } + + private: + Broker* broker; + const uint32_t brokerBank; + const uint32_t agentBank; + const std::string label; + }; + + QPID_CONSOLE_EXTERN std::ostream& operator<<(std::ostream& o, const Agent& agent); +} +} + + +#endif diff --git a/cpp/include/qpid/console/Broker.h b/cpp/include/qpid/console/Broker.h new file mode 100644 index 0000000000..af163b8bfd --- /dev/null +++ b/cpp/include/qpid/console/Broker.h @@ -0,0 +1,133 @@ +/* + * + * 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. + * + */ +#ifndef _QPID_CONSOLE_BROKER_H_ +#define _QPID_CONSOLE_BROKER_H_ + +#include "qpid/console/ConsoleImportExport.h" +#include "qpid/client/Connection.h" +#include "qpid/client/ConnectionSettings.h" +#include "qpid/client/SubscriptionManager.h" +#include "qpid/client/Session.h" +#include "qpid/client/AsyncSession.h" +#include "qpid/client/Message.h" +#include "qpid/client/MessageListener.h" +#include "qpid/sys/Thread.h" +#include "qpid/sys/Runnable.h" +#include "qpid/sys/Mutex.h" +#include "qpid/sys/Condition.h" +#include "qpid/Url.h" +#include "qpid/framing/Buffer.h" +#include "qpid/framing/Uuid.h" +#include <string> +#include <iostream> + +namespace qpid { +namespace console { + class SessionManager; + class Agent; + class Object; + + /** + * + * \ingroup qpidconsoleapi + */ + class Broker : public client::MessageListener { + public: + QPID_CONSOLE_EXTERN Broker(SessionManager& sm, + client::ConnectionSettings& settings); + QPID_CONSOLE_EXTERN ~Broker(); + + bool isConnected() const { return connected; } + const std::string& getError() const { return error; } + const std::string& getSessionId() const { return amqpSessionId; } + const framing::Uuid& getBrokerId() const { return brokerId; } + uint32_t getBrokerBank() const { return 1; } + void addBinding(const std::string& key) { + connThreadBody.bindExchange("qpid.management", key); + } + QPID_CONSOLE_EXTERN std::string getUrl() const; + + private: + friend class SessionManager; + friend class Object; + typedef std::map<uint64_t,Agent*> AgentMap; + static const int SYNC_TIME = 60; + + SessionManager& sessionManager; + AgentMap agents; + bool connected; + std::string error; + std::string amqpSessionId; + client::ConnectionSettings connectionSettings; + sys::Mutex lock; + sys::Condition cond; + framing::Uuid brokerId; + uint32_t reqsOutstanding; + bool syncInFlight; + bool topicBound; + Object* methodObject; + + friend class ConnectionThread; + class ConnectionThread : public sys::Runnable { + bool operational; + bool shuttingDown; + Broker& broker; + framing::Uuid sessionId; + client::Connection connection; + client::Session session; + client::SubscriptionManager* subscriptions; + std::stringstream queueName; + sys::Mutex connLock; + void run(); + public: + ConnectionThread(Broker& _broker) : + operational(false), shuttingDown(false), broker(_broker), subscriptions(0) {} + ~ConnectionThread(); + void sendBuffer(qpid::framing::Buffer& buf, + uint32_t length, + const std::string& exchange = "qpid.management", + const std::string& routingKey = "broker"); + void bindExchange(const std::string& exchange, const std::string& key); + void shutdown(); + }; + + ConnectionThread connThreadBody; + sys::Thread connThread; + + void encodeHeader(framing::Buffer& buf, uint8_t opcode, uint32_t seq = 0) const; + bool checkHeader(framing::Buffer& buf, uint8_t *opcode, uint32_t *seq) const; + void received(client::Message& msg); + void resetAgents(); + void updateAgent(const Object& object); + void waitForStable(); + void incOutstanding(); + void decOutstanding(); + void setBrokerId(const framing::Uuid& id) { brokerId = id; } + void appendAgents(std::vector<Agent*>& agents) const; + + friend QPID_CONSOLE_EXTERN std::ostream& operator<<(std::ostream& o, const Broker& k); + }; + + QPID_CONSOLE_EXTERN std::ostream& operator<<(std::ostream& o, const Broker& k); +} +} + +#endif diff --git a/cpp/include/qpid/console/ClassKey.h b/cpp/include/qpid/console/ClassKey.h new file mode 100644 index 0000000000..95cd2627f1 --- /dev/null +++ b/cpp/include/qpid/console/ClassKey.h @@ -0,0 +1,66 @@ +/* + * + * 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. + * + */ +#ifndef _QPID_CONSOLE_CLASSKEY_H_ +#define _QPID_CONSOLE_CLASSKEY_H_ + +#include <string> +#include "qpid/console/ConsoleImportExport.h" +#include "qpid/console/Package.h" +#include "qpid/framing/Buffer.h" + +namespace qpid { +namespace console { + + /** + * + * \ingroup qmfconsoleapi + */ + class QPID_CONSOLE_EXTERN ClassKey { + public: + static const int HASH_SIZE = 16; + + ClassKey(const std::string& package, const std::string& name, const uint8_t* hash); + + const std::string& getPackageName() const { return package; } + const std::string& getClassName() const { return name; } + const uint8_t* getHash() const { return hash; } + std::string getHashString() const; + std::string str() const; + bool operator==(const ClassKey& other) const; + bool operator!=(const ClassKey& other) const; + bool operator<(const ClassKey& other) const; + bool operator>(const ClassKey& other) const; + bool operator<=(const ClassKey& other) const; + bool operator>=(const ClassKey& other) const; + void encode(framing::Buffer& buffer) const; + + private: + std::string package; + std::string name; + uint8_t hash[HASH_SIZE]; + }; + + QPID_CONSOLE_EXTERN std::ostream& operator<<(std::ostream& o, const ClassKey& k); +} +} + + +#endif diff --git a/cpp/include/qpid/console/ConsoleImportExport.h b/cpp/include/qpid/console/ConsoleImportExport.h new file mode 100644 index 0000000000..c2d7cb3a14 --- /dev/null +++ b/cpp/include/qpid/console/ConsoleImportExport.h @@ -0,0 +1,33 @@ +#ifndef QPID_CONSOLE_IMPORT_EXPORT_H +#define QPID_CONSOLE_IMPORT_EXPORT_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. + */ + +#if defined(WIN32) && !defined(QPID_DECLARE_STATIC) +#if defined(CONSOLE_EXPORT) || defined (qmfconsole_EXPORTS) +#define QPID_CONSOLE_EXTERN __declspec(dllexport) +#else +#define QPID_CONSOLE_EXTERN __declspec(dllimport) +#endif +#else +#define QPID_CONSOLE_EXTERN +#endif + +#endif diff --git a/cpp/include/qpid/console/ConsoleListener.h b/cpp/include/qpid/console/ConsoleListener.h new file mode 100644 index 0000000000..7a649da657 --- /dev/null +++ b/cpp/include/qpid/console/ConsoleListener.h @@ -0,0 +1,97 @@ +/* + * + * 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. + * + */ +#ifndef _QPID_CONSOLE_CONSOLE_LISTENER_H_ +#define _QPID_CONSOLE_CONSOLE_LISTENER_H_ + +#include <string> +#include "qpid/console/ConsoleImportExport.h" +#include "qpid/console/Broker.h" +#include "qpid/console/ClassKey.h" +#include "qpid/console/Object.h" +#include "qpid/console/Event.h" + +namespace qpid { +namespace console { + + /** + * Implement a subclass of ConsoleListener and subscribe it using + * the SessionManager to receive indications. + * + * \ingroup qmfconsoleapi + */ + class QPID_CONSOLE_EXTERN ConsoleListener{ + public: + virtual ~ConsoleListener() {}; + + /** Invoked when a connection is established to a broker + */ + virtual void brokerConnected(const Broker&) {} + + /** Invoked when the connection to a broker is lost + */ + virtual void brokerDisconnected(const Broker&) {} + + /** Invoked when a QMF package is discovered. + */ + virtual void newPackage(const std::string&) {} + + /** Invoked when a new class is discovered. Session.getSchema can be + * used to obtain details about the class. + */ + virtual void newClass(const ClassKey&) {} + + /** Invoked when a QMF agent is discovered. + */ + virtual void newAgent(const Agent&) {} + + /** Invoked when a QMF agent disconects. + */ + virtual void delAgent(const Agent&) {} + + /** Invoked when an object is updated. + */ + virtual void objectProps(Broker&, Object&) {} + + /** Invoked when an object is updated. + */ + virtual void objectStats(Broker&, Object&) {} + + /** Invoked when an event is raised. + */ + virtual void event(Event&) {} + + /** + */ + //virtual void heartbeat(Agent&, uint64_t) {} + + /** + */ + virtual void brokerInfo(Broker&) {} + + /** + */ + //virtual void methodResponse(Broker&, uint32_t seq, MethodResponse&) {} + }; +} +} + + +#endif diff --git a/cpp/include/qpid/console/Event.h b/cpp/include/qpid/console/Event.h new file mode 100644 index 0000000000..ef4ecc791c --- /dev/null +++ b/cpp/include/qpid/console/Event.h @@ -0,0 +1,86 @@ +/* + * + * 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. + * + */ +#ifndef _QPID_CONSOLE_EVENT_H_ +#define _QPID_CONSOLE_EVENT_H_ + +#include "qpid/console/ConsoleImportExport.h" +#include "qpid/console/Object.h" +#include "qpid/framing/Uuid.h" +#include "qpid/framing/FieldTable.h" + +namespace qpid { +namespace framing { + class Buffer; +} +namespace console { + + class Broker; + struct SchemaClass; + class ClassKey; + + /** + * + * \ingroup qmfconsoleapi + */ + class Event { + public: + typedef enum { + SEV_EMERGENCY = 0, SEV_ALERT = 1, SEV_CRITICAL = 2, SEV_ERROR = 3, + SEV_WARNING = 4, SEV_NOTICE = 5, SEV_INFO = 6, SEV_DEBUG = 7 + } Severity; + + QPID_CONSOLE_EXTERN Event(Broker* broker, + SchemaClass* schemaClass, + framing::Buffer& buffer); + Broker* getBroker() const { return broker; } + QPID_CONSOLE_EXTERN const ClassKey& getClassKey() const; + SchemaClass* getSchema() const { return schema; } + const Object::AttributeMap& getAttributes() const { return attributes; } + uint64_t getTimestamp() const { return timestamp; } + uint8_t getSeverity() const { return severity; } + QPID_CONSOLE_EXTERN std::string getSeverityString() const; + + QPID_CONSOLE_EXTERN ObjectId attrRef(const std::string& key) const; + QPID_CONSOLE_EXTERN uint32_t attrUint(const std::string& key) const; + QPID_CONSOLE_EXTERN int32_t attrInt(const std::string& key) const; + QPID_CONSOLE_EXTERN uint64_t attrUint64(const std::string& key) const; + QPID_CONSOLE_EXTERN int64_t attrInt64(const std::string& key) const; + QPID_CONSOLE_EXTERN std::string attrString(const std::string& key) const; + QPID_CONSOLE_EXTERN bool attrBool(const std::string& key) const; + QPID_CONSOLE_EXTERN float attrFloat(const std::string& key) const; + QPID_CONSOLE_EXTERN double attrDouble(const std::string& key) const; + QPID_CONSOLE_EXTERN framing::Uuid attrUuid(const std::string& key) const; + QPID_CONSOLE_EXTERN framing::FieldTable attrMap(const std::string& key) const; + + private: + Broker* broker; + SchemaClass* schema; + uint64_t timestamp; + Severity severity; + Object::AttributeMap attributes; + }; + + QPID_CONSOLE_EXTERN std::ostream& operator<<(std::ostream& o, const Event& event); +} +} + + +#endif diff --git a/cpp/include/qpid/console/Object.h b/cpp/include/qpid/console/Object.h new file mode 100644 index 0000000000..5a29fdf792 --- /dev/null +++ b/cpp/include/qpid/console/Object.h @@ -0,0 +1,123 @@ +/* + * + * 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. + * + */ +#ifndef _QPID_CONSOLE_OBJECT_H_ +#define _QPID_CONSOLE_OBJECT_H_ + +#include "qpid/console/ConsoleImportExport.h" +#include "qpid/console/ObjectId.h" +#include "qpid/framing/Uuid.h" +#include "qpid/framing/FieldTable.h" +#include <boost/shared_ptr.hpp> +#include <map> +#include <set> +#include <vector> + +namespace qpid { +namespace framing { + class Buffer; +} +namespace console { + + class Broker; + struct SchemaClass; + struct SchemaMethod; + class ObjectId; + class ClassKey; + class Value; + + /** + * \ingroup qmfconsoleapi + */ + struct MethodResponse { + uint32_t code; + std::string text; + std::map<std::string, boost::shared_ptr<Value> > arguments; + }; + + class Object { + public: + typedef std::vector<Object> Vector; + struct AttributeMap : public std::map<std::string, boost::shared_ptr<Value> > { + QPID_CONSOLE_EXTERN void addRef(const std::string& key, const ObjectId& val); + QPID_CONSOLE_EXTERN void addUint(const std::string& key, uint32_t val); + QPID_CONSOLE_EXTERN void addInt(const std::string& key, int32_t val); + QPID_CONSOLE_EXTERN void addUint64(const std::string& key, uint64_t val); + QPID_CONSOLE_EXTERN void addInt64(const std::string& key, int64_t val); + QPID_CONSOLE_EXTERN void addString(const std::string& key, const std::string& val); + QPID_CONSOLE_EXTERN void addBool(const std::string& key, bool val); + QPID_CONSOLE_EXTERN void addFloat(const std::string& key, float val); + QPID_CONSOLE_EXTERN void addDouble(const std::string& key, double val); + QPID_CONSOLE_EXTERN void addUuid(const std::string& key, const framing::Uuid& val); + QPID_CONSOLE_EXTERN void addMap(const std::string& key, const framing::FieldTable& val); + }; + + QPID_CONSOLE_EXTERN Object(Broker* broker, SchemaClass* schemaClass, framing::Buffer& buffer, bool prop, bool stat); + QPID_CONSOLE_EXTERN ~Object(); + + Broker* getBroker() const { return broker; } + const ObjectId& getObjectId() const { return objectId; } + QPID_CONSOLE_EXTERN const ClassKey& getClassKey() const; + SchemaClass* getSchema() const { return schema; } + uint64_t getCurrentTime() const { return currentTime; } + uint64_t getCreateTime() const { return createTime; } + uint64_t getDeleteTime() const { return deleteTime; } + bool isDeleted() const { return deleteTime != 0; } + QPID_CONSOLE_EXTERN std::string getIndex() const; + QPID_CONSOLE_EXTERN void mergeUpdate(const Object& updated); + const AttributeMap& getAttributes() const { return attributes; } + QPID_CONSOLE_EXTERN void invokeMethod(const std::string name, + const AttributeMap& args, + MethodResponse& result); + QPID_CONSOLE_EXTERN void handleMethodResp(framing::Buffer& buffer, + uint32_t sequence); + + QPID_CONSOLE_EXTERN ObjectId attrRef(const std::string& key) const; + QPID_CONSOLE_EXTERN uint32_t attrUint(const std::string& key) const; + QPID_CONSOLE_EXTERN int32_t attrInt(const std::string& key) const; + QPID_CONSOLE_EXTERN uint64_t attrUint64(const std::string& key) const; + QPID_CONSOLE_EXTERN int64_t attrInt64(const std::string& key) const; + QPID_CONSOLE_EXTERN std::string attrString(const std::string& key) const; + QPID_CONSOLE_EXTERN bool attrBool(const std::string& key) const; + QPID_CONSOLE_EXTERN float attrFloat(const std::string& key) const; + QPID_CONSOLE_EXTERN double attrDouble(const std::string& key) const; + QPID_CONSOLE_EXTERN framing::Uuid attrUuid(const std::string& key) const; + QPID_CONSOLE_EXTERN framing::FieldTable attrMap(const std::string& key) const; + + private: + Broker* broker; + SchemaClass* schema; + ObjectId objectId; + uint64_t currentTime; + uint64_t createTime; + uint64_t deleteTime; + AttributeMap attributes; + SchemaMethod* pendingMethod; + MethodResponse methodResponse; + + void parsePresenceMasks(framing::Buffer& buffer, std::set<std::string>& excludeList); + }; + + QPID_CONSOLE_EXTERN std::ostream& operator<<(std::ostream& o, const Object& object); +} +} + + +#endif diff --git a/cpp/include/qpid/console/ObjectId.h b/cpp/include/qpid/console/ObjectId.h new file mode 100644 index 0000000000..7904c85598 --- /dev/null +++ b/cpp/include/qpid/console/ObjectId.h @@ -0,0 +1,69 @@ +/* + * + * 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. + * + */ +#ifndef _QPID_CONSOLE_OBJECTID_H +#define _QPID_CONSOLE_OBJECTID_H + +#include <iostream> +#include "qpid/console/ConsoleImportExport.h" +#include "qpid/sys/IntegerTypes.h" + +namespace qpid { +namespace framing { + class Buffer; +} +namespace console { + + /** + * + * \ingroup qmfconsoleapi + */ + class QPID_CONSOLE_EXTERN ObjectId { + public: + ObjectId() : first(0), second(0) {} + ObjectId(framing::Buffer& buffer); + + uint8_t getFlags() const { return (first & 0xF000000000000000LL) >> 60; } + uint16_t getSequence() const { return (first & 0x0FFF000000000000LL) >> 48; } + uint32_t getBrokerBank() const { return (first & 0x0000FFFFF0000000LL) >> 28; } + uint32_t getAgentBank() const { return first & 0x000000000FFFFFFFLL; } + uint64_t getObject() const { return second; } + bool isDurable() const { return getSequence() == 0; } + void decode(framing::Buffer& buffer); + void encode(framing::Buffer& buffer); + void setValue(uint64_t f, uint64_t s) { first = f; second = s; } + + bool operator==(const ObjectId& other) const; + bool operator!=(const ObjectId& other) const; + bool operator<(const ObjectId& other) const; + bool operator>(const ObjectId& other) const; + bool operator<=(const ObjectId& other) const; + bool operator>=(const ObjectId& other) const; + + private: + uint64_t first; + uint64_t second; + }; + + QPID_CONSOLE_EXTERN std::ostream& operator<<(std::ostream& o, const ObjectId& id); +} +} + +#endif diff --git a/cpp/include/qpid/console/Package.h b/cpp/include/qpid/console/Package.h new file mode 100644 index 0000000000..3b59e366ff --- /dev/null +++ b/cpp/include/qpid/console/Package.h @@ -0,0 +1,78 @@ +/* + * + * 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. + * + */ +#ifndef _QPID_CONSOLE_PACKAGE_H_ +#define _QPID_CONSOLE_PACKAGE_H_ + +#include <string> +#include <map> +#include "qpid/console/ConsoleImportExport.h" +#include "qpid/sys/IntegerTypes.h" + +namespace qpid { +namespace console { + struct SchemaClass; + + /** + * + * \ingroup qmfconsoleapi + */ + class Package { + public: + Package(const std::string& n) : name(n) {} + const std::string& getName() const { return name; } + + private: + friend class SessionManager; + struct NameHash { + std::string name; + uint8_t hash[16]; + NameHash(const std::string& n, const uint8_t* h) : name(n) { + for (int i = 0; i < 16; i++) + hash[i] = h[i]; + } + }; + + struct NameHashComp { + bool operator() (const NameHash& lhs, const NameHash& rhs) const + { + if (lhs.name != rhs.name) + return lhs.name < rhs.name; + else + for (int i = 0; i < 16; i++) + if (lhs.hash[i] != rhs.hash[i]) + return lhs.hash[i] < rhs.hash[i]; + return false; + } + }; + + typedef std::map<NameHash, SchemaClass*, NameHashComp> ClassMap; + + const std::string name; + ClassMap classes; + + SchemaClass* getClass(const std::string& className, uint8_t* hash); + void addClass(const std::string& className, uint8_t* hash, + SchemaClass* schemaClass); + }; +} +} + +#endif diff --git a/cpp/include/qpid/console/Schema.h b/cpp/include/qpid/console/Schema.h new file mode 100644 index 0000000000..6d4e41ab3e --- /dev/null +++ b/cpp/include/qpid/console/Schema.h @@ -0,0 +1,105 @@ +/* + * + * 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. + * + */ +#ifndef _QPID_CONSOLE_SCHEMA_H_ +#define _QPID_CONSOLE_SCHEMA_H_ + +#include "qpid/console/ClassKey.h" +#include <boost/shared_ptr.hpp> +#include <vector> + +namespace qpid { +namespace framing { + class Buffer; +} +namespace console { + class Value; + + struct SchemaArgument { + SchemaArgument(framing::Buffer& buffer, bool forMethod = false); + boost::shared_ptr<Value> decodeValue(framing::Buffer& buffer); + + std::string name; + uint8_t typeCode; + bool dirInput; + bool dirOutput; + std::string unit; + int min; + int max; + int maxLen; + std::string desc; + std::string defaultVal; + }; + + struct SchemaProperty { + SchemaProperty(framing::Buffer& buffer); + boost::shared_ptr<Value> decodeValue(framing::Buffer& buffer); + + std::string name; + uint8_t typeCode; + uint8_t accessCode; + bool isIndex; + bool isOptional; + std::string unit; + int min; + int max; + int maxLen; + std::string desc; + }; + + struct SchemaStatistic { + SchemaStatistic(framing::Buffer& buffer); + boost::shared_ptr<Value> decodeValue(framing::Buffer& buffer); + + std::string name; + uint8_t typeCode; + std::string unit; + std::string desc; + }; + + struct SchemaMethod { + SchemaMethod(framing::Buffer& buffer); + ~SchemaMethod(); + + std::string name; + std::string desc; + std::vector<SchemaArgument*> arguments; + }; + + struct SchemaClass { + static const uint8_t KIND_TABLE = 1; + static const uint8_t KIND_EVENT = 2; + + SchemaClass(const uint8_t kind, const ClassKey& key, framing::Buffer& buffer); + ~SchemaClass(); + const ClassKey& getClassKey() const { return key; } + + const uint8_t kind; + const ClassKey key; + std::vector<SchemaProperty*> properties; + std::vector<SchemaStatistic*> statistics; + std::vector<SchemaMethod*> methods; + std::vector<SchemaArgument*> arguments; + }; +} +} + + +#endif diff --git a/cpp/include/qpid/console/SequenceManager.h b/cpp/include/qpid/console/SequenceManager.h new file mode 100644 index 0000000000..ea0ccf3f77 --- /dev/null +++ b/cpp/include/qpid/console/SequenceManager.h @@ -0,0 +1,54 @@ +/* + * + * 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. + * + */ +#ifndef _QPID_CONSOLE_SEQUENCEMANAGER_H_ +#define _QPID_CONSOLE_SEQUENCEMANAGER_H_ + +#include "qpid/console/ConsoleImportExport.h" +#include "qpid/sys/Mutex.h" +#include <map> +#include <string> +#include <set> + +namespace qpid { +namespace console { + + /** + * + * \ingroup qpidconsoleapi + */ + class SequenceManager { + public: + typedef std::set<uint32_t> set; + + SequenceManager() : sequence(0) {} + QPID_CONSOLE_EXTERN uint32_t reserve(const std::string& context = ""); + QPID_CONSOLE_EXTERN std::string release(uint32_t seq); + + private: + sys::Mutex lock; + uint32_t sequence; + std::map<uint32_t, std::string> pending; + }; +} +} + + +#endif diff --git a/cpp/include/qpid/console/SessionManager.h b/cpp/include/qpid/console/SessionManager.h new file mode 100644 index 0000000000..f27037a559 --- /dev/null +++ b/cpp/include/qpid/console/SessionManager.h @@ -0,0 +1,205 @@ +#ifndef _QPID_CONSOLE_SESSION_MANAGER_H +#define _QPID_CONSOLE_SESSION_MANAGER_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/console/ConsoleImportExport.h" +#include "qpid/console/Broker.h" +#include "qpid/console/Package.h" +#include "qpid/console/SequenceManager.h" +#include "qpid/console/ClassKey.h" +#include "qpid/console/Schema.h" +#include "qpid/console/Agent.h" +#include "qpid/console/Object.h" +#include "qpid/console/ObjectId.h" +#include "qpid/console/Value.h" +#include "qpid/sys/Mutex.h" +#include "qpid/sys/Condition.h" +#include "qpid/client/ConnectionSettings.h" +#include <string> +#include <vector> + +namespace qpid { +namespace console { + +class ConsoleListener; + +/** + * + * \ingroup qmfconsoleapi + */ +class SessionManager +{ + public: + typedef std::vector<std::string> NameVector; + typedef std::vector<ClassKey> KeyVector; + QPID_CONSOLE_EXTERN ~SessionManager(); + + struct Settings { + bool rcvObjects; + bool rcvEvents; + bool rcvHeartbeats; + bool userBindings; + uint32_t methodTimeout; + uint32_t getTimeout; + + Settings() : rcvObjects(true), rcvEvents(true), rcvHeartbeats(true), + userBindings(false), methodTimeout(20), getTimeout(20) + {} + }; + + /** Create a new SessionManager + * + * Provide your own subclass of ConsoleListener to receive updates and indications + * asynchronously or leave it as its default and use only synchronous methods. + * + *@param listener Listener object to receive asynchronous indications. + *@param settings.rcvObjects Listener wishes to receive managed object data. + *@param settings.rcvEvents Listener wishes to receive events. + *@param settings.rcvHeartbeats Listener wishes to receive agent heartbeats. + *@param settings.userBindings If rcvObjects is true, userBindings allows the + * console client to control which object classes are received. See the bindPackage + * and bindClass methods. If userBindings is false, the listener will receive + * updates for all object classes. + */ + QPID_CONSOLE_EXTERN SessionManager(ConsoleListener* listener = 0, + Settings settings = Settings()); + + /** Connect a broker to the console session + * + *@param settings Connection settings for client access + *@return broker object if operation is successful + * an exception shall be thrown. + */ + QPID_CONSOLE_EXTERN Broker* addBroker(client::ConnectionSettings& settings); + + /** Disconnect a broker from the console session + * + *@param broker The broker object returned from an earlier call to addBroker. + */ + QPID_CONSOLE_EXTERN void delBroker(Broker* broker); + + /** Get a list of known management packages + * + *@param packages Vector of package names returned by the session manager. + */ + QPID_CONSOLE_EXTERN void getPackages(NameVector& packages); + + /** Get a list of class keys associated with a package + * + *@param classKeys List of class keys returned by the session manager. + *@param packageName Name of package being queried. + */ + QPID_CONSOLE_EXTERN void getClasses(KeyVector& classKeys, + const std::string& packageName); + + /** Get the schema of a class given its class key + * + *@param classKey Class key of the desired schema. + */ + QPID_CONSOLE_EXTERN SchemaClass& getSchema(const ClassKey& classKey); + + /** Request that updates be received for all classes within a package + * + * Note that this method is only meaningful if a ConsoleListener was provided at session + * creation and if the 'userBindings' flag was set to true. + * + *@param packageName Name of the package to which to bind. + */ + QPID_CONSOLE_EXTERN void bindPackage(const std::string& packageName); + + /** Request update to be received for a particular class + * + * Note that this method is only meaningful if a ConsoleListener was provided at session + * creation and if the 'userBindings' flag was set to true. + * + *@param classKey Class key of class to which to bind. + */ + QPID_CONSOLE_EXTERN void bindClass(const ClassKey& classKey); + QPID_CONSOLE_EXTERN void bindClass(const std::string& packageName, + const std::string& className); + + /** Get a list of qmf agents known to the session manager. + * + *@param agents Vector of Agent objects returned by the session manager. + *@param broker Return agents registered with this broker only. If NULL, return agents + * from all connected brokers. + */ + QPID_CONSOLE_EXTERN void getAgents(Agent::Vector& agents, + Broker* broker = 0); + + /** Get objects from agents. There are four variants of this method with different ways of + * specifying from which class objects are being queried. + * + *@param objects List of objects received. + *@param classKey ClassKey object identifying class to be queried. + *@param className Class name identifying class to be queried. + *@param objectId Object Id of the single object to be queried. + *@param broker Restrict the query to this broker, or all brokers if NULL. + *@param agent Restrict the query to this agent, or all agents if NULL. + */ + QPID_CONSOLE_EXTERN void getObjects(Object::Vector& objects, + const std::string& className, + Broker* broker = 0, + Agent* agent = 0); + //void getObjects(Object::Vector& objects, const ClassKey& classKey, + // Broker* broker = 0, Agent* agent = 0); + //void getObjects(Object::Vector& objects, const ObjectId& objectId, + // Broker* broker = 0, Agent* agent = 0); + +private: + friend class Broker; + friend class Broker::ConnectionThread; + friend class Object; + sys::Mutex lock; + sys::Mutex brokerListLock; + ConsoleListener* listener; + std::vector<Broker*> brokers; + std::map<std::string, Package*> packages; + SequenceManager sequenceManager; + sys::Condition cv; + SequenceManager::set syncSequenceList; + Object::Vector getResult; + std::string error; + Settings settings; + NameVector bindingKeyList; + + void bindingKeys(); + void allBrokersStable(); + void startProtocol(Broker* broker); + void handleBrokerResp(Broker* broker, framing::Buffer& inBuffer, uint32_t sequence); + void handlePackageInd(Broker* broker, framing::Buffer& inBuffer, uint32_t sequence); + void handleCommandComplete(Broker* broker, framing::Buffer& inBuffer, uint32_t sequence); + void handleClassInd(Broker* broker, framing::Buffer& inBuffer, uint32_t sequence); + void handleMethodResp(Broker* broker, framing::Buffer& inBuffer, uint32_t sequence); + void handleHeartbeatInd(Broker* broker, framing::Buffer& inBuffer, uint32_t sequence); + void handleEventInd(Broker* broker, framing::Buffer& inBuffer, uint32_t sequence); + void handleSchemaResp(Broker* broker, framing::Buffer& inBuffer, uint32_t sequence); + void handleContentInd(Broker* broker, framing::Buffer& inBuffer, uint32_t sequence, bool prop, bool stat); + void handleBrokerConnect(Broker* broker); + void handleBrokerDisconnect(Broker* broker); + +}; + +}} // namespace qpid::console + +#endif /*!_QPID_CONSOLE_SESSION_MANAGER_H*/ diff --git a/cpp/include/qpid/console/Value.h b/cpp/include/qpid/console/Value.h new file mode 100644 index 0000000000..d9eb65053b --- /dev/null +++ b/cpp/include/qpid/console/Value.h @@ -0,0 +1,213 @@ +/* + * + * 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. + * + */ +#ifndef _QPID_CONSOLE_VALUE_H_ +#define _QPID_CONSOLE_VALUE_H_ + +#include "qpid/Exception.h" +#include "qpid/framing/Uuid.h" +#include "qpid/framing/FieldTable.h" +#include "qpid/console/ObjectId.h" +#include <boost/shared_ptr.hpp> + +namespace qpid { +namespace framing { + class Buffer; +} +namespace console { + + /** + * \ingroup qmfconsoleapi + */ + class Value { + + public: + typedef boost::shared_ptr<Value> Ptr; + virtual ~Value() {} + virtual std::string str() const = 0; + + virtual bool isNull() const { return false; } + virtual bool isObjectId() const { return false; } + virtual bool isUint() const { return false; } + virtual bool isInt() const { return false; } + virtual bool isUint64() const { return false; } + virtual bool isInt64() const { return false; } + virtual bool isString() const { return false; } + virtual bool isBool() const { return false; } + virtual bool isFloat() const { return false; } + virtual bool isDouble() const { return false; } + virtual bool isUuid() const { return false; } + virtual bool isMap() const { return false; } + + virtual ObjectId asObjectId() const { incompatible(); return ObjectId(); } + virtual uint32_t asUint() const { incompatible(); return 0; } + virtual int32_t asInt() const { incompatible(); return 0; } + virtual uint64_t asUint64() const { incompatible(); return 0; } + virtual int64_t asInt64() const { incompatible(); return 0; } + virtual std::string asString() const { incompatible(); return std::string(); } + virtual bool asBool() const { incompatible(); return false; } + virtual float asFloat() const { incompatible(); return 0.0; } + virtual double asDouble() const { incompatible(); return 0.0; } + virtual framing::Uuid asUuid() const { incompatible(); return framing::Uuid(); } + virtual framing::FieldTable asMap() const { incompatible(); return framing::FieldTable(); } + + private: + void incompatible() const { + throw Exception("Incompatible Type"); + } + }; + + class NullValue : public Value { + public: + NullValue() {} + std::string str() const; + bool isNull() const { return true; } + }; + + class RefValue : public Value { + public: + RefValue(ObjectId v) : value(v) {} + RefValue(framing::Buffer& buffer); + std::string str() const; + bool isObjectId() const { return true; } + ObjectId asObjectId() const { return value; } + private: + ObjectId value; + }; + + class UintValue : public Value { + public: + UintValue(uint32_t v) : value(v) {} + std::string str() const; + bool isUint() const { return true; } + uint32_t asUint() const { return value; } + bool isUint64() const { return true; } + uint64_t asUint64() const { return (uint64_t) value; } + private: + uint32_t value; + }; + + class IntValue : public Value { + public: + IntValue(int32_t v) : value(v) {} + std::string str() const; + bool isInt() const { return true; } + int32_t asInt() const { return value; } + bool isInt64() const { return true; } + int64_t asInt64() const { return (int64_t) value; } + private: + int32_t value; + }; + + class Uint64Value : public Value { + public: + Uint64Value(uint64_t v) : value(v) {} + std::string str() const; + bool isUint64() const { return true; } + uint64_t asUint64() const { return value; } + private: + uint64_t value; + }; + + class Int64Value : public Value { + public: + Int64Value(int64_t v) : value(v) {} + std::string str() const; + bool isInt64() const { return true; } + int64_t asInt64() const { return value; } + private: + int64_t value; + }; + + class StringValue : public Value { + public: + StringValue(const std::string& v) : value(v) {} + StringValue(framing::Buffer& buffer, int tc); + std::string str() const { return value; } + bool isString() const { return true; } + std::string asString() const { return value; } + private: + std::string value; + }; + + class BoolValue : public Value { + public: + BoolValue(bool v) : value(v) {} + BoolValue(uint8_t v) : value(v != 0) {} + std::string str() const; + bool isBool() const { return true; } + bool asBool() const { return value; } + private: + bool value; + }; + + class FloatValue : public Value { + public: + FloatValue(float v) : value(v) {} + std::string str() const; + bool isFloat() const { return true; } + float asFloat() const { return value; } + bool isDouble() const { return true; } + double asDouble() const { return (double) value; } + private: + float value; + }; + + class DoubleValue : public Value { + public: + DoubleValue(double v) : value(v) {} + std::string str() const; + bool isDouble() const { return true; } + double asDouble() const { return value; } + private: + double value; + }; + + class UuidValue : public Value { + public: + UuidValue(const framing::Uuid& v) : value(v) {} + UuidValue(framing::Buffer& buffer); + std::string str() const { return value.str(); } + bool isUuid() const { return true; } + framing::Uuid asUuid() const { return value; } + private: + framing::Uuid value; + }; + + class MapValue : public Value { + public: + MapValue(const framing::FieldTable& v) : value(v) {} + MapValue(framing::Buffer& buffer); + std::string str() const; + bool isMap() const { return true; } + framing::FieldTable asMap() const { return value; } + private: + framing::FieldTable value; + }; + + class ValueFactory { + public: + static Value::Ptr newValue(int typeCode, framing::Buffer& buffer); + static void encodeValue(int typeCode, Value::Ptr value, framing::Buffer& buffer); + }; +} +} + +#endif |