You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by tr...@apache.org on 2008/12/19 21:22:04 UTC

svn commit: r728132 [2/2] - in /qpid/trunk/qpid/cpp: ./ examples/ examples/qmf-console/ src/ src/qpid/console/ src/qpid/framing/ src/qpid/sys/ src/qpid/sys/posix/ src/tests/

Added: qpid/trunk/qpid/cpp/src/qpid/console/SessionManager.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/console/SessionManager.cpp?rev=728132&view=auto
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/console/SessionManager.cpp (added)
+++ qpid/trunk/qpid/cpp/src/qpid/console/SessionManager.cpp Fri Dec 19 12:22:03 2008
@@ -0,0 +1,446 @@
+/*
+ *
+ * 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 "SessionManager.h"
+#include "Schema.h"
+#include "Agent.h"
+#include "qpid/console/ConsoleListener.h"
+#include "qpid/log/Statement.h"
+#include "qpid/sys/Time.h"
+#include "qpid/framing/Buffer.h"
+#include "qpid/framing/Uuid.h"
+#include "qpid/framing/FieldTable.h"
+
+using namespace qpid::console;
+using namespace qpid::sys;
+using namespace std;
+using qpid::framing::Buffer;
+using qpid::framing::FieldTable;
+
+SessionManager::SessionManager(ConsoleListener* _listener,
+                               bool _rcvObjects,
+                               bool _rcvEvents,
+                               bool _rcvHeartbeats,
+                               bool _manageConnections,
+                               bool _userBindings) :
+    listener(_listener),
+    rcvObjects((listener != 0) && _rcvObjects),
+    rcvEvents((listener != 0) && _rcvEvents),
+    rcvHeartbeats((listener != 0) && _rcvHeartbeats),
+    userBindings(_userBindings),
+    manageConnections(_manageConnections)
+{
+    bindingKeys();
+}
+
+Broker* SessionManager::addBroker(client::ConnectionSettings& settings)
+{
+    Broker* broker(new Broker(*this, settings));
+    {
+        Mutex::ScopedLock l(brokerListLock);
+        brokers.push_back(broker);
+    }
+    return broker;
+}
+
+void SessionManager::delBroker(Broker* broker)
+{
+    Mutex::ScopedLock l(brokerListLock);
+    for (vector<Broker*>::iterator iter = brokers.begin();
+         iter != brokers.end(); iter++)
+        if (*iter == broker) {
+            brokers.erase(iter);
+            return;
+        }
+}
+
+void SessionManager::getPackages(NameVector& packageNames)
+{
+    allBrokersStable();
+    packageNames.clear();
+    {
+        Mutex::ScopedLock l(lock);
+        for (map<string, Package*>::iterator iter = packages.begin();
+             iter != packages.end(); iter++)
+            packageNames.push_back(iter->first);
+    }
+}
+
+void SessionManager::getClasses(KeyVector& classKeys, const std::string& packageName)
+{
+    allBrokersStable();
+    classKeys.clear();
+    map<string, Package*>::iterator iter = packages.find(packageName);
+    if (iter == packages.end())
+        return;
+
+    Package& package = *(iter->second);
+    for (Package::ClassMap::const_iterator piter = package.classes.begin();
+         piter != package.classes.end(); piter++) {
+        ClassKey key(piter->second->getClassKey());
+        classKeys.push_back(key);
+    }
+}
+
+SchemaClass& SessionManager::getSchema(const ClassKey& classKey)
+{
+    allBrokersStable();
+    map<string, Package*>::iterator iter = packages.find(classKey.getPackageName());
+    if (iter == packages.end())
+        throw Exception("Unknown package");
+
+    Package& package = *(iter->second);
+    Package::NameHash key(classKey.getClassName(), classKey.getHash());
+    Package::ClassMap::iterator cIter = package.classes.find(key);
+    if (cIter == package.classes.end())
+        throw Exception("Unknown class");
+
+    return *(cIter->second);
+}
+
+void SessionManager::bindPackage(const std::string& packageName)
+{
+    stringstream key;
+    key << "console.obj.*.*." << packageName << ".#";
+    bindingKeyList.push_back(key.str());
+    for (vector<Broker*>::iterator iter = brokers.begin(); iter != brokers.end(); iter++)
+        (*iter)->addBinding(key.str());
+}
+
+void SessionManager::bindClass(const ClassKey& classKey)
+{
+    bindClass(classKey.getPackageName(), classKey.getClassName());
+}
+
+void SessionManager::bindClass(const std::string& packageName, const std::string& className)
+{
+    stringstream key;
+    key << "console.obj.*.*." << packageName << "." << className << ".#";
+    bindingKeyList.push_back(key.str());
+    for (vector<Broker*>::iterator iter = brokers.begin();
+         iter != brokers.end(); iter++)
+        (*iter)->addBinding(key.str());
+}
+
+void SessionManager::getAgents(Agent::Vector& agents, Broker* broker)
+{
+    agents.clear();
+    if (broker != 0) {
+        broker->appendAgents(agents);
+    } else {
+        for (vector<Broker*>::iterator iter = brokers.begin(); iter != brokers.end(); iter++) {
+            (*iter)->appendAgents(agents);
+        }
+    }
+}
+
+void SessionManager::getObjects(Object::Vector& objects, const std::string& className,
+                                Broker* _broker, Agent* _agent)
+{
+    Agent::Vector agentList;
+
+    if (_agent != 0) {
+        agentList.push_back(_agent);
+    } else {
+        if (_broker != 0) {
+            _broker->appendAgents(agentList);
+        } else {
+            Mutex::ScopedLock _lock(brokerListLock);
+            for (vector<Broker*>::iterator iter = brokers.begin(); iter != brokers.end(); iter++) {
+                (*iter)->appendAgents(agentList);
+            }
+        }
+    }
+
+    FieldTable ft;
+    uint32_t sequence;
+    ft.setString("_class", className);
+
+    getResult.clear();
+    syncSequenceList.clear();
+    error = string();
+
+    for (Agent::Vector::iterator iter = agentList.begin(); iter != agentList.end(); iter++) {
+        Agent* agent = *iter;
+        char rawbuffer[512];
+        Buffer buffer(rawbuffer, 512);
+        stringstream routingKey;
+        routingKey << "agent." << agent->getBrokerBank() << "." << agent->getAgentBank();
+        {
+            Mutex::ScopedLock _lock(lock);
+            sequence = sequenceManager.reserve("multiget");
+            syncSequenceList.insert(sequence);
+        }
+        agent->getBroker()->encodeHeader(buffer, 'G', sequence);
+        ft.encode(buffer);
+        uint32_t length = buffer.getPosition();
+        buffer.reset();
+        agent->getBroker()->connThreadBody.sendBuffer(buffer, length, "qpid.management", routingKey.str());
+    }
+
+    {
+        Mutex::ScopedLock _lock(lock);
+        while (!syncSequenceList.empty() && error.empty()) {
+            cv.wait(lock); // TODO put timeout in
+        }
+    }
+
+    objects = getResult;
+}
+
+void SessionManager::bindingKeys()
+{
+    bindingKeyList.push_back("schema.#");
+    if (rcvObjects && rcvEvents && rcvHeartbeats && !userBindings) {
+        bindingKeyList.push_back("console.#");
+    } else {
+        if (rcvObjects && !userBindings)
+            bindingKeyList.push_back("console.obj.#");
+        else
+            bindingKeyList.push_back("console.obj.*.*.org.apache.qpid.broker.agent");
+        if (rcvEvents)
+            bindingKeyList.push_back("console.event.#");
+        if (rcvHeartbeats)
+            bindingKeyList.push_back("console.heartbeat");
+    }
+}
+
+void SessionManager::allBrokersStable()
+{
+    Mutex::ScopedLock l(brokerListLock);
+    for (vector<Broker*>::iterator iter = brokers.begin();
+         iter != brokers.end(); iter++)
+        (*iter)->waitForStable();
+}
+
+void SessionManager::startProtocol(Broker* broker)
+{
+    char    rawbuffer[512];
+    Buffer  buffer(rawbuffer, 512);
+
+    broker->encodeHeader(buffer, 'B');
+    uint32_t length = 512 - buffer.available();
+    buffer.reset();
+    broker->connThreadBody.sendBuffer(buffer, length);
+}
+
+
+void SessionManager::handleBrokerResp(Broker* broker, Buffer& inBuffer, uint32_t)
+{
+    framing::Uuid brokerId;
+
+    brokerId.decode(inBuffer);
+    broker->setBrokerId(brokerId);
+
+    char    rawbuffer[512];
+    Buffer  buffer(rawbuffer, 512);
+
+    uint32_t sequence = sequenceManager.reserve("startup");
+    broker->encodeHeader(buffer, 'P', sequence);
+    uint32_t length = 512 - buffer.available();
+    buffer.reset();
+    broker->connThreadBody.sendBuffer(buffer, length);
+
+    if (listener != 0) {
+        listener->brokerInfo(*broker);
+    }
+}
+
+void SessionManager::handlePackageInd(Broker* broker, Buffer& inBuffer, uint32_t)
+{
+    string packageName;
+    inBuffer.getShortString(packageName);
+
+    {
+        Mutex::ScopedLock l(lock);
+        map<string, Package*>::iterator iter = packages.find(packageName);
+        if (iter == packages.end()) {
+            packages[packageName] = new Package(packageName);
+            if (listener != 0)
+                listener->newPackage(packageName);
+        }
+    }
+
+    broker->incOutstanding();
+    char    rawbuffer[512];
+    Buffer  buffer(rawbuffer, 512);
+
+    uint32_t sequence = sequenceManager.reserve("startup");
+    broker->encodeHeader(buffer, 'Q', sequence);
+    buffer.putShortString(packageName);
+    uint32_t length = 512 - buffer.available();
+    buffer.reset();
+    broker->connThreadBody.sendBuffer(buffer, length);
+}
+
+void SessionManager::handleCommandComplete(Broker* broker, Buffer& inBuffer, uint32_t sequence)
+{
+    Mutex::ScopedLock l(lock);
+    uint32_t resultCode = inBuffer.getLong();
+    string resultText;
+    inBuffer.getShortString(resultText);
+    string context = sequenceManager.release(sequence);
+    if (resultCode != 0)
+        QPID_LOG(debug, "Received error in completion: " << resultCode << " " << resultText);
+    if (context == "startup") {
+        broker->decOutstanding();
+    } else if (context == "multiget") {
+        if (syncSequenceList.count(sequence) == 1) {
+            syncSequenceList.erase(sequence);
+            if (syncSequenceList.empty()) {
+                cv.notify();
+            }
+        }
+    }
+    // TODO: Other context cases
+}
+
+void SessionManager::handleClassInd(Broker* broker, Buffer& inBuffer, uint32_t)
+{
+    uint8_t kind;
+    string packageName;
+    string className;
+    uint8_t hash[16];
+
+    kind = inBuffer.getOctet();
+    inBuffer.getShortString(packageName);
+    inBuffer.getShortString(className);
+    inBuffer.getBin128(hash);
+
+    {
+        Mutex::ScopedLock l(lock);
+        map<string, Package*>::iterator pIter = packages.find(packageName);
+        if (pIter == packages.end() || pIter->second->getClass(className, hash))
+            return;
+    }
+
+    broker->incOutstanding();
+    char    rawbuffer[512];
+    Buffer  buffer(rawbuffer, 512);
+
+    uint32_t sequence = sequenceManager.reserve("startup");
+    broker->encodeHeader(buffer, 'S', sequence);
+    buffer.putShortString(packageName);
+    buffer.putShortString(className);
+    buffer.putBin128(hash);
+    uint32_t length = 512 - buffer.available();
+    buffer.reset();
+    broker->connThreadBody.sendBuffer(buffer, length);
+}
+
+void SessionManager::handleMethodResp(Broker* broker, Buffer& buffer, uint32_t sequence)
+{
+    if (broker->methodObject) {
+        broker->methodObject->handleMethodResp(buffer, sequence);
+    }
+}
+
+void SessionManager::handleHeartbeatInd(Broker* /*broker*/, Buffer& /*inBuffer*/, uint32_t /*sequence*/)
+{
+}
+
+void SessionManager::handleEventInd(Broker* /*broker*/, Buffer& /*inBuffer*/, uint32_t /*sequence*/)
+{
+}
+
+void SessionManager::handleSchemaResp(Broker* broker, Buffer& inBuffer, uint32_t sequence)
+{
+    uint8_t kind;
+    string packageName;
+    string className;
+    uint8_t hash[16];
+
+    kind = inBuffer.getOctet();
+    inBuffer.getShortString(packageName);
+    inBuffer.getShortString(className);
+    inBuffer.getBin128(hash);
+
+    {
+        Mutex::ScopedLock l(lock);
+        map<string, Package*>::iterator pIter = packages.find(packageName);
+        if (pIter != packages.end() && !pIter->second->getClass(className, hash)) {
+            ClassKey key(packageName, className, hash);
+            SchemaClass* schemaClass(new SchemaClass(kind, key, inBuffer));
+            pIter->second->addClass(className, hash, schemaClass);
+            if (listener != 0) {
+                listener->newClass(schemaClass->getClassKey());
+            }
+        }
+    }
+
+    sequenceManager.release(sequence);
+    broker->decOutstanding();
+}
+
+void SessionManager::handleContentInd(Broker* broker, Buffer& buffer, uint32_t sequence, bool prop, bool stat)
+{
+    string packageName;
+    string className;
+    uint8_t hash[16];
+    SchemaClass* schemaClass;
+
+    buffer.getShortString(packageName);
+    buffer.getShortString(className);
+    buffer.getBin128(hash);
+
+    {
+        Mutex::ScopedLock l(lock);
+        map<string, Package*>::iterator pIter = packages.find(packageName);
+        if (pIter == packages.end())
+            return;
+        schemaClass = pIter->second->getClass(className, hash);
+        if (schemaClass == 0)
+            return;
+    }
+
+    Object object(broker, schemaClass, buffer, prop, stat);
+
+    if (prop && className == "agent" && packageName == "org.apache.qpid.broker")
+        broker->updateAgent(object);
+
+    {
+        Mutex::ScopedLock l(lock);
+        if (syncSequenceList.count(sequence) == 1) {
+            if (!object.isDeleted())
+                getResult.push_back(object);
+        }
+        return;
+    }
+
+    if (listener) {
+        if (prop)
+            listener->objectProps(*broker, object);
+        if (stat)
+            listener->objectStats(*broker, object);
+    }
+}
+
+void SessionManager::handleBrokerConnect(Broker* broker)
+{
+    if (listener != 0)
+        listener->brokerConnected(*broker);
+}
+
+void SessionManager::handleBrokerDisconnect(Broker* broker)
+{
+    if (listener != 0)
+        listener->brokerDisconnected(*broker);
+}
+

Added: qpid/trunk/qpid/cpp/src/qpid/console/SessionManager.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/console/SessionManager.h?rev=728132&view=auto
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/console/SessionManager.h (added)
+++ qpid/trunk/qpid/cpp/src/qpid/console/SessionManager.h Fri Dec 19 12:22:03 2008
@@ -0,0 +1,194 @@
+#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 "Broker.h"
+#include "Package.h"
+#include "SequenceManager.h"
+#include "ClassKey.h"
+#include "Schema.h"
+#include "Agent.h"
+#include "Object.h"
+#include "ObjectId.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;
+    ~SessionManager() {}
+
+    /** 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 rcvObjects Listener wishes to receive managed object data.
+     *@param rcvEvents Listener wishes to receive events.
+     *@param rcvHeartbeats Listener wishes to receive agent heartbeats.
+     *@param manageConnections SessionManager should retry dropped connections.
+     *@param 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.
+     */
+    SessionManager(ConsoleListener* listener = 0,
+                   bool rcvObjects = true,
+                   bool rcvEvents = true,
+                   bool rcvHeartbeats = true,
+                   bool manageConnections = false,
+                   bool userBindings = false);
+
+    /** Connect a broker to the console session
+     *
+     *@param settings Connection settings for client access
+     *@return broker object if operation is successful
+     *@exception If 'manageConnections' is disabled and the connection to the broker fails,
+     * an exception shall be thrown.
+     */
+    Broker* addBroker(client::ConnectionSettings& settings);
+
+    /** Disconnect a broker from the console session
+     *
+     *@param broker The broker object returned from an earlier call to addBroker.
+     */
+    void delBroker(Broker* broker);
+
+    /** Get a list of known management packages
+     *
+     *@param packages Vector of package names returned by the session manager.
+     */
+    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.
+     */
+    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.
+     */
+    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.
+     */
+    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.
+     */
+    void bindClass(const ClassKey& classKey);
+    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.
+     */
+    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.
+     */
+    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 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;
+    bool rcvObjects;
+    bool rcvEvents;
+    bool rcvHeartbeats;
+    bool userBindings;
+    bool manageConnections;
+    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*/

Added: qpid/trunk/qpid/cpp/src/qpid/console/Value.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/console/Value.cpp?rev=728132&view=auto
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/console/Value.cpp (added)
+++ qpid/trunk/qpid/cpp/src/qpid/console/Value.cpp Fri Dec 19 12:22:03 2008
@@ -0,0 +1,168 @@
+/*
+ *
+ * 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 "Value.h"
+#include "qpid/framing/Buffer.h"
+
+using namespace qpid::console;
+using namespace std;
+
+string NullValue::str() const
+{
+    return "<Null>";
+}
+
+RefValue::RefValue(framing::Buffer& buffer)
+{
+    uint64_t first = buffer.getLongLong();
+    uint64_t second = buffer.getLongLong();
+    value.setValue(first, second);
+}
+
+string RefValue::str() const
+{
+    stringstream s;
+    s << value;
+    return s.str();
+}
+
+string UintValue::str() const
+{
+    stringstream s;
+    s << value;
+    return s.str();
+}
+
+string IntValue::str() const
+{
+    stringstream s;
+    s << value;
+    return s.str();
+}
+
+string Uint64Value::str() const
+{
+    stringstream s;
+    s << value;
+    return s.str();
+}
+
+string Int64Value::str() const
+{
+    stringstream s;
+    s << value;
+    return s.str();
+}
+
+StringValue::StringValue(framing::Buffer& buffer, int tc)
+{
+    if (tc == 6)
+        buffer.getShortString(value);
+    else
+        buffer.getMediumString(value);
+}
+
+string BoolValue::str() const
+{
+    return value ? "T" : "F";
+}
+
+string FloatValue::str() const
+{
+    stringstream s;
+    s << value;
+    return s.str();
+}
+
+string DoubleValue::str() const
+{
+    stringstream s;
+    s << value;
+    return s.str();
+}
+
+UuidValue::UuidValue(framing::Buffer& buffer)
+{
+    value.decode(buffer);
+}
+
+string MapValue::str() const
+{
+    stringstream s;
+    s << value;
+    return s.str();
+}
+
+MapValue::MapValue(framing::Buffer& buffer)
+{
+    value.decode(buffer);
+}
+
+
+Value* ValueFactory::newValue(int typeCode, framing::Buffer& buffer)
+{
+    switch (typeCode) {
+    case 1:  return static_cast<Value*>(new UintValue(buffer.getOctet()));      // U8
+    case 2:  return static_cast<Value*>(new UintValue(buffer.getShort()));      // U16
+    case 3:  return static_cast<Value*>(new UintValue(buffer.getLong()));       // U32
+    case 4:  return static_cast<Value*>(new Uint64Value(buffer.getLongLong())); // U64
+    case 6:  return static_cast<Value*>(new StringValue(buffer, 6));            // SSTR
+    case 7:  return static_cast<Value*>(new StringValue(buffer, 7));            // LSTR
+    case 8:  return static_cast<Value*>(new Int64Value(buffer.getLongLong()));  // ABSTIME
+    case 9:  return static_cast<Value*>(new Uint64Value(buffer.getLongLong())); // DELTATIME
+    case 10: return static_cast<Value*>(new RefValue(buffer));                  // REF
+    case 11: return static_cast<Value*>(new BoolValue(buffer.getOctet()));      // BOOL
+    case 12: return static_cast<Value*>(new FloatValue(buffer.getFloat()));     // FLOAT
+    case 13: return static_cast<Value*>(new DoubleValue(buffer.getDouble()));   // DOUBLE
+    case 14: return static_cast<Value*>(new UuidValue(buffer));                 // UUID
+    case 15: return static_cast<Value*>(new MapValue(buffer));                  // MAP
+    case 16: return static_cast<Value*>(new IntValue(buffer.getOctet()));       // S8
+    case 17: return static_cast<Value*>(new IntValue(buffer.getShort()));       // S16
+    case 18: return static_cast<Value*>(new IntValue(buffer.getLong()));        // S32
+    case 19: return static_cast<Value*>(new Int64Value(buffer.getLongLong()));  // S64
+    }
+
+    return 0;
+}
+
+void ValueFactory::encodeValue(int typeCode, Value* value, framing::Buffer& buffer)
+{
+    switch (typeCode) {
+    case 1:  buffer.putOctet(value->asUint()); return;          // U8
+    case 2:  buffer.putShort(value->asUint()); return;          // U16
+    case 3:  buffer.putLong(value->asUint()); return;           // U32
+    case 4:  buffer.putLongLong(value->asUint64()); return;     // U64
+    case 6:  buffer.putShortString(value->asString()); return;  // SSTR
+    case 7:  buffer.putMediumString(value->asString()); return; // LSTR
+    case 8:  buffer.putLongLong(value->asInt64()); return;      // ABSTIME
+    case 9:  buffer.putLongLong(value->asUint64()); return;     // DELTATIME
+    case 10: value->asObjectId().encode(buffer); return;        // REF
+    case 11: buffer.putOctet(value->asBool() ? 1 : 0); return;  // BOOL
+    case 12: buffer.putFloat(value->asFloat()); return;         // FLOAT
+    case 13: buffer.putDouble(value->asDouble()); return;       // DOUBLE
+    case 14: value->asUuid().encode(buffer); return;            // UUID
+    case 15: value->asMap().encode(buffer); return;             // MAP
+    case 16: buffer.putOctet(value->asInt()); return;           // S8
+    case 17: buffer.putShort(value->asInt()); return;           // S16
+    case 18: buffer.putLong(value->asInt()); return;            // S32
+    case 19: buffer.putLongLong(value->asInt64()); return;      // S64
+    }
+}

Added: qpid/trunk/qpid/cpp/src/qpid/console/Value.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/console/Value.h?rev=728132&view=auto
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/console/Value.h (added)
+++ qpid/trunk/qpid/cpp/src/qpid/console/Value.h Fri Dec 19 12:22:03 2008
@@ -0,0 +1,205 @@
+/*
+ *
+ * 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 "ObjectId.h"
+
+namespace qpid {
+namespace framing {
+    class Buffer;
+}
+namespace console {
+
+    /**
+     * \ingroup qmfconsoleapi
+     */
+    class Value {
+
+    public:
+        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; }
+    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; }
+    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; }
+    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* newValue(int typeCode, framing::Buffer& buffer);
+        static void encodeValue(int typeCode, Value* value, framing::Buffer& buffer);
+    };
+}
+}
+
+#endif

Modified: qpid/trunk/qpid/cpp/src/qpid/framing/Uuid.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/framing/Uuid.cpp?rev=728132&r1=728131&r2=728132&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/framing/Uuid.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/framing/Uuid.cpp Fri Dec 19 12:22:03 2008
@@ -52,7 +52,7 @@
     return in;
 }
 
-std::string Uuid::str() {
+std::string Uuid::str() const {
     std::ostringstream os;
     os << *this;
     return os.str();

Modified: qpid/trunk/qpid/cpp/src/qpid/framing/Uuid.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/framing/Uuid.h?rev=728132&r1=728131&r2=728132&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/framing/Uuid.h (original)
+++ qpid/trunk/qpid/cpp/src/qpid/framing/Uuid.h Fri Dec 19 12:22:03 2008
@@ -68,7 +68,7 @@
     uint32_t encodedSize() const { return size(); }
 
     /** String value in format 1b4e28ba-2fa1-11d2-883f-b9a761bde3fb. */
-    std::string str();
+    std::string str() const;
 
     template <class S> void serialize(S& s) {
         s.raw(begin(), size());

Modified: qpid/trunk/qpid/cpp/src/qpid/sys/SystemInfo.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/sys/SystemInfo.h?rev=728132&r1=728131&r2=728132&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/sys/SystemInfo.h (original)
+++ qpid/trunk/qpid/cpp/src/qpid/sys/SystemInfo.h Fri Dec 19 12:22:03 2008
@@ -63,6 +63,17 @@
                       std::string &version,
                       std::string &machine);
 
+    /**
+     * Get the process ID of the current process.
+     */
+    uint32_t getProcessId();
+
+    /**
+     * Get the process ID of the parent of the current process.
+     */
+    uint32_t getParentProcessId();
+
+
 }}} // namespace qpid::sys::SystemInfo
 
 #endif  /*!QPID_SYS_SYSTEMINFO_H*/

Modified: qpid/trunk/qpid/cpp/src/qpid/sys/posix/SystemInfo.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/sys/posix/SystemInfo.cpp?rev=728132&r1=728131&r2=728132&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/sys/posix/SystemInfo.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/sys/posix/SystemInfo.cpp Fri Dec 19 12:22:03 2008
@@ -94,4 +94,16 @@
     }
 }
 
+uint32_t SystemInfo::getProcessId()
+{
+    return (uint32_t) ::getpid();
+}
+
+uint32_t SystemInfo::getParentProcessId()
+{
+    return (uint32_t) ::getppid();
+}
+
+
+
 }} // namespace qpid::sys

Added: qpid/trunk/qpid/cpp/src/tests/ConsoleTest.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/tests/ConsoleTest.cpp?rev=728132&view=auto
==============================================================================
--- qpid/trunk/qpid/cpp/src/tests/ConsoleTest.cpp (added)
+++ qpid/trunk/qpid/cpp/src/tests/ConsoleTest.cpp Fri Dec 19 12:22:03 2008
@@ -0,0 +1,43 @@
+/*
+ *
+ * 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/Package.h"
+#include "qpid/console/ClassKey.h"
+#include "unit_test.h"
+
+QPID_AUTO_TEST_SUITE(ConsoleTestSuite)
+
+using namespace qpid::framing;
+using namespace qpid::console;
+
+QPID_AUTO_TEST_CASE(testClassKey) {
+    uint8_t hash[16] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
+    ClassKey k("com.redhat.test", "class", hash);
+
+    BOOST_CHECK_EQUAL(k.getPackageName(), "com.redhat.test");
+    BOOST_CHECK_EQUAL(k.getClassName(), "class");
+    BOOST_CHECK_EQUAL(k.getHashString(), "00010203-04050607-08090a0b-0c0d0e0f");
+    BOOST_CHECK_EQUAL(k.str(), "com.redhat.test:class(00010203-04050607-08090a0b-0c0d0e0f)");
+}
+
+QPID_AUTO_TEST_SUITE_END()
+
+

Modified: qpid/trunk/qpid/cpp/src/tests/Makefile.am
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/tests/Makefile.am?rev=728132&r1=728131&r2=728132&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/tests/Makefile.am (original)
+++ qpid/trunk/qpid/cpp/src/tests/Makefile.am Fri Dec 19 12:22:03 2008
@@ -25,6 +25,7 @@
 lib_client = $(abs_builddir)/../libqpidclient.la
 lib_common = $(abs_builddir)/../libqpidcommon.la
 lib_broker = $(abs_builddir)/../libqpidbroker.la
+lib_console = $(abs_builddir)/../libqmfconsole.la
 # lib_amqp_0_10 = $(abs_builddir)/../libqpidamqp_0_10.la
 
 #
@@ -47,7 +48,7 @@
 TESTS+=unit_test
 check_PROGRAMS+=unit_test
 unit_test_LDADD=-lboost_unit_test_framework -lboost_regex  \
-	$(lib_client) $(lib_broker)
+	$(lib_client) $(lib_broker) $(lib_console)
 
 unit_test_SOURCES= unit_test.cpp unit_test.h \
 	BrokerFixture.h SocketProxy.h \
@@ -86,7 +87,8 @@
 	ConnectionOptions.h \
 	ForkedBroker.h \
 	ManagementTest.cpp \
-	MessageReplayTracker.cpp
+	MessageReplayTracker.cpp \
+	ConsoleTest.cpp
 
 if HAVE_XML
 unit_test_SOURCES+= XmlClientSessionTest.cpp