You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2007/02/17 04:46:45 UTC

svn commit: r508705 - in /incubator/qpid/branches/qpid.0-9/cpp: docs/api/ lib/client/ lib/common/ lib/common/framing/ lib/common/sys/ tests/

Author: aconway
Date: Fri Feb 16 19:46:44 2007
New Revision: 508705

URL: http://svn.apache.org/viewvc?view=rev&rev=508705
Log:
* cpp/lib/client/ClientMessage.h/.cpp: Added Message constructor taking data.
* cpp/lib/client/IncomingMessage.cpp: Simplified message aggregation.
* cpp/lib/common/framing/AMQ*Body.h: remove unnecessary virtual inheritance.
* cpp/lib/common/framing/AMQMethodBody.h: add bool isRequest, isResponse
* cpp/lib/common/sys/Mutex.h (class ScopedUnlock): Added ScopedUnlock
* cpp/lib/common/sys/ThreadSafeQueue.h: Thread-safe queue template.
* cpp/tests/BrokerChannelTest.cpp: Renamed from ChannelTest.
* cpp/tests/ClientChannelTest.cpp: Test client API.
* cpp/tests/RequestResponseTest.cpp: Removed empty test.
* cpp/lib/client/Connection.h,.cpp:
 - non-static channelIdCounter
 - No close() in dtor.

Added:
    incubator/qpid/branches/qpid.0-9/cpp/lib/common/sys/ThreadSafeQueue.h   (with props)
    incubator/qpid/branches/qpid.0-9/cpp/tests/BrokerChannelTest.cpp
      - copied, changed from r508066, incubator/qpid/branches/qpid.0-9/cpp/tests/ChannelTest.cpp
    incubator/qpid/branches/qpid.0-9/cpp/tests/ClientChannelTest.cpp   (with props)
Removed:
    incubator/qpid/branches/qpid.0-9/cpp/tests/ChannelTest.cpp
    incubator/qpid/branches/qpid.0-9/cpp/tests/RequestResponseTest.cpp
Modified:
    incubator/qpid/branches/qpid.0-9/cpp/docs/api/developer.doxygen
    incubator/qpid/branches/qpid.0-9/cpp/lib/client/ClientChannel.cpp
    incubator/qpid/branches/qpid.0-9/cpp/lib/client/ClientMessage.cpp
    incubator/qpid/branches/qpid.0-9/cpp/lib/client/ClientMessage.h
    incubator/qpid/branches/qpid.0-9/cpp/lib/client/Connection.cpp
    incubator/qpid/branches/qpid.0-9/cpp/lib/client/Connection.h
    incubator/qpid/branches/qpid.0-9/cpp/lib/client/IncomingMessage.cpp
    incubator/qpid/branches/qpid.0-9/cpp/lib/client/IncomingMessage.h
    incubator/qpid/branches/qpid.0-9/cpp/lib/common/ExceptionHolder.h
    incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQContentBody.h
    incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQHeaderBody.h
    incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQHeartbeatBody.h
    incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQMethodBody.h
    incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQRequestBody.h
    incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQResponseBody.h
    incubator/qpid/branches/qpid.0-9/cpp/lib/common/sys/Mutex.h
    incubator/qpid/branches/qpid.0-9/cpp/tests/InProcessBroker.h
    incubator/qpid/branches/qpid.0-9/cpp/tests/Makefile.am

Modified: incubator/qpid/branches/qpid.0-9/cpp/docs/api/developer.doxygen
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/docs/api/developer.doxygen?view=diff&rev=508705&r1=508704&r2=508705
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/docs/api/developer.doxygen (original)
+++ incubator/qpid/branches/qpid.0-9/cpp/docs/api/developer.doxygen Fri Feb 16 19:46:44 2007
@@ -35,7 +35,7 @@
 # If a relative path is entered, it will be relative to the location 
 # where doxygen was started. If left blank the current directory will be used.
 
-OUTPUT_DIRECTORY       = dev
+OUTPUT_DIRECTORY       = .
 
 # If the CREATE_SUBDIRS tag is set to YES, then doxygen will create 
 # 4096 sub-directories (in 2 levels) under the output directory of each output 
@@ -438,7 +438,7 @@
 # wrong or incomplete parameter documentation, but not about the absence of 
 # documentation.
 
-WARN_NO_PARAMDOC       = NO
+WARN_NO_PARAMDOC       = YES
 
 # The WARN_FORMAT tag determines the format of the warning messages that 
 # doxygen can produce. The string should contain the $file, $line, and $text 
@@ -453,7 +453,7 @@
 # and error messages should be written. If left blank the output is written 
 # to stderr.
 
-WARN_LOGFILE           = 
+WARN_LOGFILE           = doxygen.log
 
 #---------------------------------------------------------------------------
 # configuration options related to the input files

Modified: incubator/qpid/branches/qpid.0-9/cpp/lib/client/ClientChannel.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/lib/client/ClientChannel.cpp?view=diff&rev=508705&r1=508704&r2=508705
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/client/ClientChannel.cpp (original)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/client/ClientChannel.cpp Fri Feb 16 19:46:44 2007
@@ -245,7 +245,7 @@
 
     msg.header = retrieved->getHeader();
     msg.deliveryTag = retrieved->getDeliveryTag();
-    retrieved->getData(msg.data);
+    msg.data = retrieved->getData();
     delete retrieved;
     retrieved = 0;
 }
@@ -446,7 +446,7 @@
         if(incomingMsg){
             //Note: msg is currently only valid for duration of this call
             Message msg(incomingMsg->getHeader());
-            incomingMsg->getData(msg.data);
+            msg.data = incomingMsg->getData();
             if(incomingMsg->isReturn()){
                 if(returnsHandler == 0){
                     //print warning to log/console

Modified: incubator/qpid/branches/qpid.0-9/cpp/lib/client/ClientMessage.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/lib/client/ClientMessage.cpp?view=diff&rev=508705&r1=508704&r2=508705
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/client/ClientMessage.cpp (original)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/client/ClientMessage.cpp Fri Feb 16 19:46:44 2007
@@ -23,8 +23,15 @@
 using namespace qpid::client;
 using namespace qpid::framing;
 
-Message::Message(){
-    header = AMQHeaderBody::shared_ptr(new AMQHeaderBody(BASIC));
+Message::Message(const std::string& d)
+    : header(new AMQHeaderBody(BASIC))
+{
+    setData(d);
+}
+
+void Message::setData(const std::string& d) {
+    data = d;
+    header->setContentSize(d.size());
 }
 
 Message::Message(AMQHeaderBody::shared_ptr& _header) : header(_header){

Modified: incubator/qpid/branches/qpid.0-9/cpp/lib/client/ClientMessage.h
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/lib/client/ClientMessage.h?view=diff&rev=508705&r1=508704&r2=508705
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/client/ClientMessage.h (original)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/client/ClientMessage.h Fri Feb 16 19:46:44 2007
@@ -41,8 +41,9 @@
 
         qpid::framing::BasicHeaderProperties* getHeaderProperties();
 	Message(qpid::framing::AMQHeaderBody::shared_ptr& header);
+        
     public:
-	Message();
+	Message(const std::string& data=std::string());
 	~Message();
 	
         /**
@@ -51,14 +52,15 @@
          * 
          * @return a string representing the data of the message
          */
-	inline std::string getData(){ return data; }
+	std::string getData() const { return data; }
+
         /**
          * Allows the application to set the content of messages to be
          * sent.
          * 
          * @param data a string representing the data of the message
          */
-	inline void setData(const std::string& _data){ data = _data; }
+	void setData(const std::string& _data);
 
         /**
          * @return true if this message was delivered previously (to
@@ -103,10 +105,10 @@
 	void setClusterId(const std::string& clusterId);
 
 
-	friend class Channel;
+        // TODO aconway 2007-02-15: remove friendships.
+      friend class Channel;
     };
 
-}
-}
+}}
 
 #endif  /*!_client_ClientMessage_h*/

Modified: incubator/qpid/branches/qpid.0-9/cpp/lib/client/Connection.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/lib/client/Connection.cpp?view=diff&rev=508705&r1=508704&r2=508705
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/client/Connection.cpp (original)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/client/Connection.cpp Fri Feb 16 19:46:44 2007
@@ -37,23 +37,19 @@
 namespace qpid {
 namespace client {
 
-ChannelId Connection::channelIdCounter;
-
 const std::string Connection::OK("OK");
 
 Connection::Connection(
     bool _debug, u_int32_t _max_frame_size,
     framing::ProtocolVersion _version
-) : version(_version), max_frame_size(_max_frame_size),
+) : channelIdCounter(0), version(_version), max_frame_size(_max_frame_size),
     defaultConnector(version, _debug, _max_frame_size),
     isOpen(false), debug(_debug)
 {
     setConnector(defaultConnector);
 }
 
-Connection::~Connection(){
-    close();
-}
+Connection::~Connection(){}
 
 void Connection::setConnector(Connector& con)
 {

Modified: incubator/qpid/branches/qpid.0-9/cpp/lib/client/Connection.h
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/lib/client/Connection.h?view=diff&rev=508705&r1=508704&r2=508705
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/client/Connection.h (original)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/client/Connection.h Fri Feb 16 19:46:44 2007
@@ -86,7 +86,7 @@
 {
     typedef std::map<framing::ChannelId, Channel*> ChannelMap;
 
-    static framing::ChannelId channelIdCounter;
+    framing::ChannelId channelIdCounter;
     static const std::string OK;
 
     framing::ProtocolVersion version;

Modified: incubator/qpid/branches/qpid.0-9/cpp/lib/client/IncomingMessage.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/lib/client/IncomingMessage.cpp?view=diff&rev=508705&r1=508704&r2=508705
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/client/IncomingMessage.cpp (original)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/client/IncomingMessage.cpp Fri Feb 16 19:46:44 2007
@@ -36,12 +36,12 @@
     this->header = _header;
 }
 
-void IncomingMessage::addContent(AMQContentBody::shared_ptr _content){
-    this->content.push_back(_content);
+void IncomingMessage::addContent(AMQContentBody::shared_ptr content){
+    data.append(content->getData());
 }
 
 bool IncomingMessage::isComplete(){
-    return header != 0 && header->getContentSize() == contentSize();
+    return header != 0 && header->getContentSize() == data.size();
 }
 
 bool IncomingMessage::isReturn(){
@@ -70,19 +70,7 @@
     return header;
 }
 
-void IncomingMessage::getData(string& s){
-    int count(content.size());
-    for(int i = 0; i < count; i++){
-        if(i == 0) s = content[i]->getData();
-	else s += content[i]->getData();
-    }
+std::string IncomingMessage::getData() const {
+    return data;
 }
 
-u_int64_t IncomingMessage::contentSize(){
-    u_int64_t size(0);
-    u_int64_t count(content.size());
-    for(u_int64_t i = 0; i < count; i++){
-	size += content[i]->size();
-    }
-    return size;
-}

Modified: incubator/qpid/branches/qpid.0-9/cpp/lib/client/IncomingMessage.h
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/lib/client/IncomingMessage.h?view=diff&rev=508705&r1=508704&r2=508705
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/client/IncomingMessage.h (original)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/client/IncomingMessage.h Fri Feb 16 19:46:44 2007
@@ -36,9 +36,7 @@
 	qpid::framing::BasicReturnBody::shared_ptr returned;
 	qpid::framing::BasicGetOkBody::shared_ptr response;
 	qpid::framing::AMQHeaderBody::shared_ptr header;
-	std::vector<qpid::framing::AMQContentBody::shared_ptr> content;
-
-	u_int64_t contentSize();
+	std::string data;
     public:
 	IncomingMessage(qpid::framing::BasicDeliverBody::shared_ptr intro);
 	IncomingMessage(qpid::framing::BasicReturnBody::shared_ptr intro);
@@ -53,7 +51,7 @@
 	const std::string& getConsumerTag();//only relevant if isDelivery()
 	qpid::framing::AMQHeaderBody::shared_ptr& getHeader();
         u_int64_t getDeliveryTag();
-	void getData(std::string& data);
+	std::string getData() const;
     };
 
 }

Modified: incubator/qpid/branches/qpid.0-9/cpp/lib/common/ExceptionHolder.h
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/lib/common/ExceptionHolder.h?view=diff&rev=508705&r1=508704&r2=508705
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/common/ExceptionHolder.h (original)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/common/ExceptionHolder.h Fri Feb 16 19:46:44 2007
@@ -53,6 +53,7 @@
     std::string toString() const throw() { return (*this)->toString(); }
     virtual Exception* clone() const throw() { return (*this)->clone(); }
     virtual void throwSelf() const { (*this)->throwSelf(); }
+    virtual void throwIf() const { if (*this) (*this)->throwSelf(); }
 };
 
 } // namespace qpid

Modified: incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQContentBody.h
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQContentBody.h?view=diff&rev=508705&r1=508704&r2=508705
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQContentBody.h (original)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQContentBody.h Fri Feb 16 19:46:44 2007
@@ -28,7 +28,7 @@
 namespace qpid {
 namespace framing {
 
-class AMQContentBody : virtual public AMQBody
+class AMQContentBody : public AMQBody
 {
     string data;
 

Modified: incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQHeaderBody.h
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQHeaderBody.h?view=diff&rev=508705&r1=508704&r2=508705
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQHeaderBody.h (original)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQHeaderBody.h Fri Feb 16 19:46:44 2007
@@ -29,7 +29,7 @@
 namespace qpid {
 namespace framing {
 
-class AMQHeaderBody : virtual public AMQBody
+class AMQHeaderBody :  public AMQBody
 {
     HeaderProperties* properties;
     u_int16_t weight;

Modified: incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQHeartbeatBody.h
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQHeartbeatBody.h?view=diff&rev=508705&r1=508704&r2=508705
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQHeartbeatBody.h (original)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQHeartbeatBody.h Fri Feb 16 19:46:44 2007
@@ -28,7 +28,7 @@
 namespace qpid {
 namespace framing {
 
-class AMQHeartbeatBody : virtual public AMQBody
+class AMQHeartbeatBody :  public AMQBody
 {
 public:
     typedef boost::shared_ptr<AMQHeartbeatBody> shared_ptr;

Modified: incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQMethodBody.h
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQMethodBody.h?view=diff&rev=508705&r1=508704&r2=508705
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQMethodBody.h (original)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQMethodBody.h Fri Feb 16 19:46:44 2007
@@ -60,6 +60,9 @@
     /** Return request ID or response correlationID */
     virtual RequestId getRequestId() const { return 0; }
 
+    virtual bool isRequest() const { return false; }
+    virtual bool isResponse() const { return false; }
+
   protected:
     static u_int32_t baseSize() { return 4; }
 

Modified: incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQRequestBody.h
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQRequestBody.h?view=diff&rev=508705&r1=508704&r2=508705
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQRequestBody.h (original)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQRequestBody.h Fri Feb 16 19:46:44 2007
@@ -62,6 +62,7 @@
     void setRequestId(RequestId id) { data.requestId=id; }
     void setResponseMark(ResponseId mark) { data.responseMark=mark; }
 
+    bool isRequest()const { return true; }
   protected:
     static const u_int32_t baseSize() { return AMQMethodBody::baseSize()+20; }
     void printPrefix(std::ostream& out) const;

Modified: incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQResponseBody.h
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQResponseBody.h?view=diff&rev=508705&r1=508704&r2=508705
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQResponseBody.h (original)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQResponseBody.h Fri Feb 16 19:46:44 2007
@@ -69,6 +69,7 @@
     void setRequestId(RequestId id) { data.requestId = id; }
     void setBatchOffset(BatchOffset id) { data.batchOffset = id; }
 
+    bool isResponse() const { return true; }
   protected:
     static const u_int32_t baseSize() { return AMQMethodBody::baseSize()+20; }
     void printPrefix(std::ostream& out) const;

Modified: incubator/qpid/branches/qpid.0-9/cpp/lib/common/sys/Mutex.h
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/lib/common/sys/Mutex.h?view=diff&rev=508705&r1=508704&r2=508705
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/common/sys/Mutex.h (original)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/common/sys/Mutex.h Fri Feb 16 19:46:44 2007
@@ -46,12 +46,23 @@
     L& mutex;
 };
 
+template <class L>
+class ScopedUnlock
+{
+  public:
+    ScopedUnlock(L& l) : mutex(l) { l.unlock(); }
+    ~ScopedUnlock() { mutex.lock(); }
+  private:
+    L& mutex;
+};
+    
 /**
  * Mutex lock.
  */
 class Mutex : private boost::noncopyable {
   public:
     typedef ScopedLock<Mutex> ScopedLock;
+    typedef ScopedUnlock<Mutex> ScopedUnlock;
     
     inline Mutex();
     inline ~Mutex();

Added: incubator/qpid/branches/qpid.0-9/cpp/lib/common/sys/ThreadSafeQueue.h
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/lib/common/sys/ThreadSafeQueue.h?view=auto&rev=508705
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/common/sys/ThreadSafeQueue.h (added)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/common/sys/ThreadSafeQueue.h Fri Feb 16 19:46:44 2007
@@ -0,0 +1,99 @@
+#ifndef _sys_ThreadSafeQueue_h
+#define _sys_ThreadSafeQueue_h
+
+/*
+ *
+ * Copyright (c) 2006 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 <deque>
+#include "ProducerConsumer.h"
+#include "Exception.h"
+
+namespace qpid {
+namespace sys {
+
+/**
+ * A thread safe queue template.
+ */
+template <class T, class ContainerType=std::deque<T> >
+class ThreadSafeQueue
+{
+  public:
+    struct QueueStoppedException : public Exception {};
+
+    ThreadSafeQueue() {}
+
+    /** Push a value onto the back of the queue */
+    void push(const T& value) {
+        ProducerConsumer::ProducerLock producer(pc);
+        if (producer.isOk()) {
+            producer.confirm();
+            container.push_back(value);
+        }
+    }
+
+    /** Pop a value from the front of the queue. Waits till value is available.
+     *@throw QueueStoppedException if queue is stopped while waiting.
+     */
+    T pop() {
+        ProducerConsumer::ConsumerLock consumer(pc);
+        if (consumer.isOk()) {
+            consumer.confirm();
+            T value(container.front());
+            container.pop_front();
+            return value;
+        }
+        throw QueueStoppedException();
+    }
+
+    /**
+     * If a value becomes available within the timeout, set outValue
+     * and return true. Otherwise return false;
+     */
+    bool pop(T& outValue, const Time& timeout) {
+        ProducerConsumer::ConsumerLock consumer(pc, timeout);
+        if (consumer.isOk()) {
+            consumer.confirm();
+            outValue = container.front();
+            container.pop_front();
+            return true;
+        }
+        return false;
+    }
+
+    /** Interrupt threads waiting in pop() */
+    void stop() { pc.stop(); }
+
+    /** True if queue is stopped */
+    bool isStopped() { return pc.isStopped(); }
+
+    /** Size of the queue */
+    size_t size() { ProducerConsumer::Lock l(pc); return container.size(); }
+
+    /** True if queue is empty */
+    bool empty() { ProducerConsumer::Lock l(pc); return container.empty(); }
+
+  private:
+    ProducerConsumer pc;
+    ContainerType container;
+};
+
+}} // namespace qpid::sys
+
+
+
+#endif  /*!_sys_ThreadSafeQueue_h*/

Propchange: incubator/qpid/branches/qpid.0-9/cpp/lib/common/sys/ThreadSafeQueue.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/branches/qpid.0-9/cpp/lib/common/sys/ThreadSafeQueue.h
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Copied: incubator/qpid/branches/qpid.0-9/cpp/tests/BrokerChannelTest.cpp (from r508066, incubator/qpid/branches/qpid.0-9/cpp/tests/ChannelTest.cpp)
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/tests/BrokerChannelTest.cpp?view=diff&rev=508705&p1=incubator/qpid/branches/qpid.0-9/cpp/tests/ChannelTest.cpp&r1=508066&p2=incubator/qpid/branches/qpid.0-9/cpp/tests/BrokerChannelTest.cpp&r2=508705
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/tests/ChannelTest.cpp (original)
+++ incubator/qpid/branches/qpid.0-9/cpp/tests/BrokerChannelTest.cpp Fri Feb 16 19:46:44 2007
@@ -48,9 +48,9 @@
 };
 
 
-class ChannelTest : public CppUnit::TestCase  
+class BrokerChannelTest : public CppUnit::TestCase  
 {
-    CPPUNIT_TEST_SUITE(ChannelTest);
+    CPPUNIT_TEST_SUITE(BrokerChannelTest);
     CPPUNIT_TEST(testConsumerMgmt);
     CPPUNIT_TEST(testDeliveryNoAck);
     CPPUNIT_TEST(testDeliveryAndRecovery);
@@ -142,7 +142,7 @@
 
   public:
 
-    ChannelTest() :
+    BrokerChannelTest() :
         broker(Broker::create()),
         connection(&handler, *broker)
     {
@@ -353,4 +353,4 @@
 
 // Make this test suite a plugin.
 CPPUNIT_PLUGIN_IMPLEMENT();
-CPPUNIT_TEST_SUITE_REGISTRATION(ChannelTest);
+CPPUNIT_TEST_SUITE_REGISTRATION(BrokerChannelTest);

Added: incubator/qpid/branches/qpid.0-9/cpp/tests/ClientChannelTest.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/tests/ClientChannelTest.cpp?view=auto&rev=508705
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/tests/ClientChannelTest.cpp (added)
+++ incubator/qpid/branches/qpid.0-9/cpp/tests/ClientChannelTest.cpp Fri Feb 16 19:46:44 2007
@@ -0,0 +1,82 @@
+/*
+ *
+ * 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_test_plugin.h"
+#include "InProcessBroker.h"
+#include "ClientChannel.h"
+#include "ClientMessage.h"
+#include "ClientQueue.h"
+#include "ClientExchange.h"
+
+using namespace std;
+using namespace boost;
+using namespace qpid::client;
+using namespace qpid::framing;
+
+/**
+ * Test client API using an in-process broker.
+ */
+class ClientChannelTest : public CppUnit::TestCase  
+{
+    CPPUNIT_TEST_SUITE(ClientChannelTest);
+    CPPUNIT_TEST(testGet);
+    CPPUNIT_TEST(testConsume);
+    CPPUNIT_TEST_SUITE_END();
+
+    InProcessBrokerClient connection; // client::connection + local broker
+    Channel channel;
+    const std::string key;
+    const std::string data;
+    Queue queue;
+    Exchange exchange;
+
+  public:
+
+    ClientChannelTest()
+        : key("testq"), data("hello"),
+          queue(key, true), exchange("", Exchange::DIRECT_EXCHANGE)
+    {
+        connection.openChannel(channel);
+        CPPUNIT_ASSERT(channel.getId() != 0);
+        channel.declareQueue(queue);
+    }
+
+    void testGet() {
+        // FIXME aconway 2007-02-16: Must fix thread safety bug
+        // in ClientChannel::get for this to pass.
+        return;
+
+        Message pubMsg(data);
+        channel.publish(pubMsg, exchange, key);
+        Message getMsg;
+        channel.get(getMsg, queue);
+        CPPUNIT_ASSERT_EQUAL(data, getMsg.getData());
+    }
+
+    void testConsume() {
+    }
+    
+
+    // FIXME aconway 2007-02-15: Cover full channel API
+};
+
+// Make this test suite a plugin.
+CPPUNIT_PLUGIN_IMPLEMENT();
+CPPUNIT_TEST_SUITE_REGISTRATION(ClientChannelTest);

Propchange: incubator/qpid/branches/qpid.0-9/cpp/tests/ClientChannelTest.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/branches/qpid.0-9/cpp/tests/ClientChannelTest.cpp
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/qpid/branches/qpid.0-9/cpp/tests/InProcessBroker.h
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/tests/InProcessBroker.h?view=diff&rev=508705&r1=508704&r2=508705
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/tests/InProcessBroker.h (original)
+++ incubator/qpid/branches/qpid.0-9/cpp/tests/InProcessBroker.h Fri Feb 16 19:46:44 2007
@@ -152,19 +152,18 @@
 class InProcessBrokerClient : public qpid::client::Connection {
   public:
     qpid::broker::InProcessBroker broker;
+    qpid::broker::InProcessBroker::Conversation& conversation;
     
     /** Constructor creates broker and opens client connection. */
     InProcessBrokerClient(qpid::framing::ProtocolVersion version=
                           qpid::framing::highestProtocolVersion
-    ) : broker(version)
+    ) : broker(version), conversation(broker.conversation)
     {
         setConnector(broker);
         open("");
     }
 
-    ~InProcessBrokerClient() {
-        close();                // close before broker is deleted.
-    }
+    ~InProcessBrokerClient() {}
 };
 
 #endif // _tests_InProcessBroker_h

Modified: incubator/qpid/branches/qpid.0-9/cpp/tests/Makefile.am
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/tests/Makefile.am?view=diff&rev=508705&r1=508704&r2=508705
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/tests/Makefile.am (original)
+++ incubator/qpid/branches/qpid.0-9/cpp/tests/Makefile.am Fri Feb 16 19:46:44 2007
@@ -9,15 +9,11 @@
   -I$(top_srcdir)/lib/common/framing	\
   $(APR_CXXFLAGS)
 
-client_exe_tests =	\
-  client_test		\
-  echo_service		\
-  topic_listener	\
-  topic_publisher
+# Unit tests
 
 broker_tests =		\
   AccumulatedAckTest	\
-  ChannelTest		\
+  BrokerChannelTest 	\
   ConfigurationTest	\
   ExchangeTest		\
   HeadersExchangeTest	\
@@ -34,12 +30,10 @@
   TxBufferTest		\
   TxPublishTest		\
   ValueTest		\
-  MessageHandlerTest 
+  MessageHandlerTest 	
 
-# Tests that use the in-process BrokerSingleton to test client-broker
-# interaction. Not strictly unit tests.
-round_trip_tests =	\
-  RequestResponseTest
+client_tests =		\
+  ClientChannelTest
 
 framing_tests =		\
   FieldTableTest	\
@@ -48,17 +42,25 @@
 
 misc_tests =		\
   ExceptionTest		\
-	  ProducerConsumerTest
+  ProducerConsumerTest
 
 posix_tests =		\
   EventChannelTest	\
   EventChannelThreadsTest
 
 unit_tests =		\
-b  $(broker_tests)	\
+  $(broker_tests)	\
+  $(client_tests)	\
   $(framing_tests)	\
-  $(misc_tests) 	\
-  $(round_trip_tests)
+  $(misc_tests) 	
+
+# Executable client tests
+
+client_exe_tests =	\
+  client_test		\
+  echo_service		\
+  topic_listener	\
+  topic_publisher
 
 noinst_PROGRAMS = $(client_exe_tests)