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 2006/12/01 06:11:53 UTC

svn commit: r481159 [9/12] - in /incubator/qpid/trunk/qpid/cpp: ./ build-aux/ gen/ lib/ lib/broker/ lib/client/ lib/common/ lib/common/framing/ lib/common/sys/ lib/common/sys/apr/ lib/common/sys/posix/ m4/ src/ src/qpid/ src/qpid/apr/ src/qpid/broker/ ...

Added: incubator/qpid/trunk/qpid/cpp/lib/common/framing/Buffer.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/lib/common/framing/Buffer.cpp?view=auto&rev=481159
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/lib/common/framing/Buffer.cpp (added)
+++ incubator/qpid/trunk/qpid/cpp/lib/common/framing/Buffer.cpp Thu Nov 30 21:11:45 2006
@@ -0,0 +1,174 @@
+/*
+ *
+ * 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 <Buffer.h>
+#include <FieldTable.h> 
+
+qpid::framing::Buffer::Buffer(u_int32_t _size) : size(_size), owner(true), position(0), limit(_size){
+    data = new char[size];
+}
+
+qpid::framing::Buffer::Buffer(char* _data, u_int32_t _size) : size(_size), owner(false), data(_data), position(0), limit(_size){
+}
+
+qpid::framing::Buffer::~Buffer(){
+    if(owner) delete[] data;
+}
+
+void qpid::framing::Buffer::flip(){
+    limit = position;
+    position = 0;
+}
+
+void qpid::framing::Buffer::clear(){
+    limit = size;
+    position = 0;
+}
+
+void qpid::framing::Buffer::compact(){
+    u_int32_t p = limit - position;
+    //copy p chars from position to 0
+    memmove(data, data + position, p);
+    limit = size;
+    position = p;
+}
+
+void qpid::framing::Buffer::record(){
+    r_position = position;
+    r_limit = limit;
+}
+
+void qpid::framing::Buffer::restore(){
+    position = r_position;
+    limit = r_limit;
+}
+
+u_int32_t qpid::framing::Buffer::available(){
+    return limit - position;
+}
+
+char* qpid::framing::Buffer::start(){
+    return data + position;
+}
+
+void qpid::framing::Buffer::move(u_int32_t bytes){
+    position += bytes;
+}
+    
+void qpid::framing::Buffer::putOctet(u_int8_t i){
+    data[position++] = i;
+}
+
+void qpid::framing::Buffer::putShort(u_int16_t i){
+    u_int16_t b = i;
+    data[position++] = (u_int8_t) (0xFF & (b >> 8));
+    data[position++] = (u_int8_t) (0xFF & b);
+}
+
+void qpid::framing::Buffer::putLong(u_int32_t i){
+    u_int32_t b = i;
+    data[position++] = (u_int8_t) (0xFF & (b >> 24));
+    data[position++] = (u_int8_t) (0xFF & (b >> 16));
+    data[position++] = (u_int8_t) (0xFF & (b >> 8));
+    data[position++] = (u_int8_t) (0xFF & b);
+}
+
+void qpid::framing::Buffer::putLongLong(u_int64_t i){
+    u_int32_t hi = i >> 32;
+    u_int32_t lo = i;
+    putLong(hi);
+    putLong(lo);
+}
+
+u_int8_t qpid::framing::Buffer::getOctet(){ 
+    return (u_int8_t) data[position++]; 
+}
+
+u_int16_t qpid::framing::Buffer::getShort(){ 
+    u_int16_t hi = (unsigned char) data[position++];
+    hi = hi << 8;
+    hi |= (unsigned char) data[position++];
+    return hi;
+}
+
+u_int32_t qpid::framing::Buffer::getLong(){ 
+    u_int32_t a = (unsigned char) data[position++];
+    u_int32_t b = (unsigned char) data[position++];
+    u_int32_t c = (unsigned char) data[position++];
+    u_int32_t d = (unsigned char) data[position++];
+    a = a << 24;
+    a |= b << 16;
+    a |= c << 8;
+    a |= d;
+    return a;
+}
+
+u_int64_t qpid::framing::Buffer::getLongLong(){
+    u_int64_t hi = getLong();
+    u_int64_t lo = getLong();
+    hi = hi << 32;
+    return hi | lo;
+}
+
+
+void qpid::framing::Buffer::putShortString(const string& s){
+    u_int8_t len = s.length();
+    putOctet(len);
+    s.copy(data + position, len);
+    position += len;    
+}
+
+void qpid::framing::Buffer::putLongString(const string& s){
+    u_int32_t len = s.length();
+    putLong(len);
+    s.copy(data + position, len);
+    position += len;    
+}
+
+void qpid::framing::Buffer::getShortString(string& s){
+    u_int8_t len = getOctet();
+    s.assign(data + position, len);
+    position += len;
+}
+
+void qpid::framing::Buffer::getLongString(string& s){
+    u_int32_t len = getLong();
+    s.assign(data + position, len);
+    position += len;
+}
+
+void qpid::framing::Buffer::putFieldTable(const FieldTable& t){
+    t.encode(*this);
+}
+
+void qpid::framing::Buffer::getFieldTable(FieldTable& t){
+    t.decode(*this);
+}
+
+void qpid::framing::Buffer::putRawData(const string& s){
+    u_int32_t len = s.length();
+    s.copy(data + position, len);
+    position += len;    
+}
+
+void qpid::framing::Buffer::getRawData(string& s, u_int32_t len){
+    s.assign(data + position, len);
+    position += len;
+}

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/framing/Buffer.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/framing/Buffer.cpp
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/lib/common/framing/Buffer.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/lib/common/framing/Buffer.h?view=auto&rev=481159
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/lib/common/framing/Buffer.h (added)
+++ incubator/qpid/trunk/qpid/cpp/lib/common/framing/Buffer.h Thu Nov 30 21:11:45 2006
@@ -0,0 +1,83 @@
+/*
+ *
+ * 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 <amqp_types.h>
+
+#ifndef _Buffer_
+#define _Buffer_
+
+namespace qpid {
+namespace framing {
+
+class FieldTable;
+
+class Buffer
+{
+    const u_int32_t size;
+    const bool owner;//indicates whether the data is owned by this instance
+    char* data;
+    u_int32_t position;
+    u_int32_t limit;
+    u_int32_t r_position;
+    u_int32_t r_limit;
+
+public:
+
+    Buffer(u_int32_t size);
+    Buffer(char* data, u_int32_t size);
+    ~Buffer();
+
+    void flip();
+    void clear();
+    void compact();
+    void record();
+    void restore();
+    u_int32_t available();
+    char* start();
+    void move(u_int32_t bytes);
+    
+    void putOctet(u_int8_t i);
+    void putShort(u_int16_t i);
+    void putLong(u_int32_t i);
+    void putLongLong(u_int64_t i);
+
+    u_int8_t getOctet();
+    u_int16_t getShort(); 
+    u_int32_t getLong();
+    u_int64_t getLongLong();
+
+    void putShortString(const string& s);
+    void putLongString(const string& s);
+    void getShortString(string& s);
+    void getLongString(string& s);
+
+    void putFieldTable(const FieldTable& t);
+    void getFieldTable(FieldTable& t);
+
+    void putRawData(const string& s);
+    void getRawData(string& s, u_int32_t size);
+
+};
+
+}
+}
+
+
+#endif

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/framing/Buffer.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/framing/Buffer.h
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/lib/common/framing/FieldTable.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/lib/common/framing/FieldTable.cpp?view=auto&rev=481159
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/lib/common/framing/FieldTable.cpp (added)
+++ incubator/qpid/trunk/qpid/cpp/lib/common/framing/FieldTable.cpp Thu Nov 30 21:11:45 2006
@@ -0,0 +1,150 @@
+/*
+ *
+ * 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 <FieldTable.h>
+#include <QpidError.h>
+#include <Buffer.h>
+#include <Value.h>
+#include <assert.h>
+
+namespace qpid {
+namespace framing {
+
+FieldTable::~FieldTable() {}
+
+u_int32_t FieldTable::size() const {
+    u_int32_t len(4);
+    for(ValueMap::const_iterator i = values.begin(); i != values.end(); ++i) {
+        // 2 = shortstr_len_byyte + type_char_byte
+	len += 2 + (i->first).size() + (i->second)->size();
+    }
+    return len;
+}
+
+int FieldTable::count() const {
+    return values.size();
+}
+
+namespace 
+{
+std::ostream& operator<<(std::ostream& out, const FieldTable::ValueMap::value_type& i) {
+    return out << i.first << ":" << *i.second;
+}
+}
+
+std::ostream& operator<<(std::ostream& out, const FieldTable& t) {
+    out << "{";
+    FieldTable::ValueMap::const_iterator i = t.getMap().begin();
+    if (i != t.getMap().end()) out << *i++;
+    while (i != t.getMap().end()) 
+    {
+        out << "," << *i++;
+    }
+    return out << "}";
+}
+
+void FieldTable::setString(const std::string& name, const std::string& value){
+    values[name] = ValuePtr(new StringValue(value));
+}
+
+void FieldTable::setInt(const std::string& name, int value){
+    values[name] = ValuePtr(new IntegerValue(value));
+}
+
+void FieldTable::setTimestamp(const std::string& name, u_int64_t value){
+    values[name] = ValuePtr(new TimeValue(value));
+}
+
+void FieldTable::setTable(const std::string& name, const FieldTable& value){
+    values[name] = ValuePtr(new FieldTableValue(value));
+}
+
+namespace {
+template <class T> T default_value() { return T(); }
+template <> int default_value<int>() { return 0; }
+template <> u_int64_t default_value<u_int64_t>() { return 0; }
+}
+
+template <class T>
+T FieldTable::getValue(const std::string& name) const
+{
+    ValueMap::const_iterator i = values.find(name);
+    if (i == values.end()) return default_value<T>();
+    const ValueOps<T> *vt = dynamic_cast<const ValueOps<T>*>(i->second.get());
+    return vt->getValue();
+}
+
+std::string FieldTable::getString(const std::string& name) const {
+    return getValue<std::string>(name);
+}
+
+int FieldTable::getInt(const std::string& name) const {
+    return getValue<int>(name);
+}
+
+u_int64_t FieldTable::getTimestamp(const std::string& name) const {
+    return getValue<u_int64_t>(name);
+}
+
+void FieldTable::getTable(const std::string& name, FieldTable& value) const {
+    value = getValue<FieldTable>(name);
+}
+
+void FieldTable::encode(Buffer& buffer) const{
+    buffer.putLong(size() - 4);
+    for (ValueMap::const_iterator i = values.begin(); i!=values.end(); ++i) {
+        buffer.putShortString(i->first);
+        buffer.putOctet(i->second->getType());
+	i->second->encode(buffer);
+    }
+}
+
+void FieldTable::decode(Buffer& buffer){
+    u_int32_t len = buffer.getLong();
+    u_int32_t available = buffer.available();
+    if (available < len)
+        THROW_QPID_ERROR(FRAMING_ERROR, "Not enough data for  field table.");
+    u_int32_t leftover = available - len;
+    while(buffer.available() > leftover){
+        std::string name;
+        buffer.getShortString(name);
+        std::auto_ptr<Value> value(Value::decode_value(buffer));
+        values[name] = ValuePtr(value.release());
+    }    
+}
+
+
+bool FieldTable::operator==(const FieldTable& x) const {
+    if (values.size() != x.values.size()) return false;
+    for (ValueMap::const_iterator i =  values.begin(); i != values.end(); ++i) {
+        ValueMap::const_iterator j = x.values.find(i->first);
+        if (j == x.values.end()) return false;
+        if (*(i->second) != *(j->second)) return false;
+    }
+    return true;
+}
+
+void FieldTable::erase(const std::string& name) 
+{
+    values.erase(values.find(name));
+}
+
+}
+}

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/framing/FieldTable.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/framing/FieldTable.cpp
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/lib/common/framing/FieldTable.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/lib/common/framing/FieldTable.h?view=auto&rev=481159
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/lib/common/framing/FieldTable.h (added)
+++ incubator/qpid/trunk/qpid/cpp/lib/common/framing/FieldTable.h Thu Nov 30 21:11:45 2006
@@ -0,0 +1,80 @@
+/*
+ *
+ * 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 <iostream>
+#include <vector>
+#include <boost/shared_ptr.hpp>
+#include <map>
+#include <amqp_types.h>
+
+#ifndef _FieldTable_
+#define _FieldTable_
+
+namespace qpid {
+namespace framing {
+
+class Value;
+class Buffer;
+
+class FieldTable
+{
+  public:
+    typedef boost::shared_ptr<Value> ValuePtr;
+    typedef std::map<std::string, ValuePtr> ValueMap;
+
+    ~FieldTable();
+    u_int32_t size() const;
+    int count() const;
+    void setString(const std::string& name, const std::string& value);
+    void setInt(const std::string& name, int value);
+    void setTimestamp(const std::string& name, u_int64_t value);
+    void setTable(const std::string& name, const FieldTable& value);
+    //void setDecimal(string& name, xxx& value);
+    std::string getString(const std::string& name) const;
+    int getInt(const std::string& name) const;
+    u_int64_t getTimestamp(const std::string& name) const;
+    void getTable(const std::string& name, FieldTable& value) const;
+    //void getDecimal(string& name, xxx& value);
+    void erase(const std::string& name);
+    
+    void encode(Buffer& buffer) const;
+    void decode(Buffer& buffer);
+
+    bool operator==(const FieldTable& other) const;
+
+    // TODO aconway 2006-09-26: Yeuch! Rework FieldTable to  have
+    // a map-like interface.
+    const ValueMap& getMap() const { return values; }
+    ValueMap& getMap() { return values; }
+    
+  private:
+  friend std::ostream& operator<<(std::ostream& out, const FieldTable& body);
+    ValueMap values;
+    template<class T> T getValue(const std::string& name) const;
+};
+
+class FieldNotFoundException{};
+class UnknownFieldName : public FieldNotFoundException{};
+class IncorrectFieldType : public FieldNotFoundException{};
+}
+}
+
+
+#endif

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/framing/FieldTable.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/framing/FieldTable.h
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/lib/common/framing/HeaderProperties.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/lib/common/framing/HeaderProperties.h?view=auto&rev=481159
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/lib/common/framing/HeaderProperties.h (added)
+++ incubator/qpid/trunk/qpid/cpp/lib/common/framing/HeaderProperties.h Thu Nov 30 21:11:45 2006
@@ -0,0 +1,46 @@
+/*
+ *
+ * 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 <amqp_types.h>
+#include <Buffer.h>
+
+#ifndef _HeaderProperties_
+#define _HeaderProperties_
+
+namespace qpid {
+namespace framing {
+
+    enum header_classes{BASIC = 60};
+
+    class HeaderProperties
+    {
+	
+    public:
+	inline virtual ~HeaderProperties(){}
+	virtual u_int8_t classId() = 0;
+	virtual u_int32_t size() const = 0;
+	virtual void encode(Buffer& buffer) const = 0;
+	virtual void decode(Buffer& buffer, u_int32_t size) = 0;
+    };
+}
+}
+
+
+#endif

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/framing/HeaderProperties.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/framing/HeaderProperties.h
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/lib/common/framing/InitiationHandler.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/lib/common/framing/InitiationHandler.cpp?view=auto&rev=481159
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/lib/common/framing/InitiationHandler.cpp (added)
+++ incubator/qpid/trunk/qpid/cpp/lib/common/framing/InitiationHandler.cpp Thu Nov 30 21:11:45 2006
@@ -0,0 +1,24 @@
+/*
+ *
+ * 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 <InitiationHandler.h>
+
+qpid::framing::InitiationHandler::~InitiationHandler() {}

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/framing/InitiationHandler.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/framing/InitiationHandler.cpp
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/lib/common/framing/InitiationHandler.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/lib/common/framing/InitiationHandler.h?view=auto&rev=481159
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/lib/common/framing/InitiationHandler.h (added)
+++ incubator/qpid/trunk/qpid/cpp/lib/common/framing/InitiationHandler.h Thu Nov 30 21:11:45 2006
@@ -0,0 +1,41 @@
+/*
+ *
+ * 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 <string>
+
+#ifndef _InitiationHandler_
+#define _InitiationHandler_
+
+#include <ProtocolInitiation.h>
+
+namespace qpid {
+namespace framing {
+
+    class InitiationHandler{
+    public:
+        virtual ~InitiationHandler();
+	virtual void initiated(ProtocolInitiation* header) = 0;
+    };
+
+}
+}
+
+
+#endif

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/framing/InitiationHandler.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/framing/InitiationHandler.h
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/lib/common/framing/InputHandler.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/lib/common/framing/InputHandler.h?view=auto&rev=481159
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/lib/common/framing/InputHandler.h (added)
+++ incubator/qpid/trunk/qpid/cpp/lib/common/framing/InputHandler.h Thu Nov 30 21:11:45 2006
@@ -0,0 +1,39 @@
+#ifndef _InputHandler_
+#define _InputHandler_
+/*
+ *
+ * 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 <AMQFrame.h>
+#include <boost/noncopyable.hpp>
+
+namespace qpid {
+namespace framing {
+
+class InputHandler : private boost::noncopyable {
+  public:
+    virtual ~InputHandler() {}
+    virtual void received(AMQFrame* frame) = 0;
+};
+
+}}
+
+
+#endif

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/framing/InputHandler.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/framing/InputHandler.h
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/lib/common/framing/OutputHandler.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/lib/common/framing/OutputHandler.h?view=auto&rev=481159
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/lib/common/framing/OutputHandler.h (added)
+++ incubator/qpid/trunk/qpid/cpp/lib/common/framing/OutputHandler.h Thu Nov 30 21:11:45 2006
@@ -0,0 +1,39 @@
+#ifndef _OutputHandler_
+#define _OutputHandler_
+
+/*
+ *
+ * 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 <boost/noncopyable.hpp>
+#include <AMQFrame.h>
+
+namespace qpid {
+namespace framing {
+
+class OutputHandler : private boost::noncopyable {
+  public:
+    virtual ~OutputHandler() {}
+    virtual void send(AMQFrame* frame) = 0;
+};
+
+}}
+
+
+#endif

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/framing/OutputHandler.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/framing/OutputHandler.h
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/lib/common/framing/ProtocolInitiation.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/lib/common/framing/ProtocolInitiation.cpp?view=auto&rev=481159
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/lib/common/framing/ProtocolInitiation.cpp (added)
+++ incubator/qpid/trunk/qpid/cpp/lib/common/framing/ProtocolInitiation.cpp Thu Nov 30 21:11:45 2006
@@ -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.
+ *
+ */
+#include <ProtocolInitiation.h>
+
+qpid::framing::ProtocolInitiation::ProtocolInitiation(){}
+
+qpid::framing::ProtocolInitiation::ProtocolInitiation(u_int8_t _major, u_int8_t _minor) : version(_major, _minor) {}
+
+qpid::framing::ProtocolInitiation::ProtocolInitiation(const qpid::framing::ProtocolVersion& p) : version(p) {}
+
+qpid::framing::ProtocolInitiation::~ProtocolInitiation(){}
+
+void qpid::framing::ProtocolInitiation::encode(Buffer& buffer){
+    buffer.putOctet('A');
+    buffer.putOctet('M');
+    buffer.putOctet('Q');
+    buffer.putOctet('P');
+    buffer.putOctet(1);//class
+    buffer.putOctet(1);//instance
+    buffer.putOctet(version.getMajor());
+    buffer.putOctet(version.getMinor());    
+}
+
+bool qpid::framing::ProtocolInitiation::decode(Buffer& buffer){
+    if(buffer.available() >= 8){
+	buffer.getOctet();//A
+	buffer.getOctet();//M
+	buffer.getOctet();//Q
+	buffer.getOctet();//P
+	buffer.getOctet();//class
+	buffer.getOctet();//instance
+	version.setMajor(buffer.getOctet());
+	version.setMinor(buffer.getOctet());
+	return true;
+    }else{
+	return false;
+    }
+}
+
+//TODO: this should prbably be generated from the spec at some point to keep the version numbers up to date

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/framing/ProtocolInitiation.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/framing/ProtocolInitiation.cpp
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/lib/common/framing/ProtocolInitiation.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/lib/common/framing/ProtocolInitiation.h?view=auto&rev=481159
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/lib/common/framing/ProtocolInitiation.h (added)
+++ incubator/qpid/trunk/qpid/cpp/lib/common/framing/ProtocolInitiation.h Thu Nov 30 21:11:45 2006
@@ -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.
+ *
+ */
+#include <amqp_types.h>
+#include <Buffer.h>
+#include <AMQDataBlock.h>
+#include <ProtocolVersion.h>
+
+#ifndef _ProtocolInitiation_
+#define _ProtocolInitiation_
+
+namespace qpid {
+namespace framing {
+
+class ProtocolInitiation : virtual public AMQDataBlock
+{
+private:
+    ProtocolVersion version;
+        
+public:
+    ProtocolInitiation();
+    ProtocolInitiation(u_int8_t major, u_int8_t minor);
+    ProtocolInitiation(const ProtocolVersion& p);
+    virtual ~ProtocolInitiation();
+    virtual void encode(Buffer& buffer); 
+    virtual bool decode(Buffer& buffer); 
+    inline virtual u_int32_t size() const { return 8; }
+    inline u_int8_t getMajor() const { return version.getMajor(); }
+    inline u_int8_t getMinor() const { return version.getMinor(); }
+    inline const ProtocolVersion& getVersion() const { return version; }
+};
+
+}
+}
+
+
+#endif

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/framing/ProtocolInitiation.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/framing/ProtocolInitiation.h
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/lib/common/framing/ProtocolVersion.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/lib/common/framing/ProtocolVersion.cpp?view=auto&rev=481159
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/lib/common/framing/ProtocolVersion.cpp (added)
+++ incubator/qpid/trunk/qpid/cpp/lib/common/framing/ProtocolVersion.cpp Thu Nov 30 21:11:45 2006
@@ -0,0 +1,64 @@
+/*
+ *
+ * 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 <ProtocolVersion.h>
+#include <sstream>
+
+using namespace qpid::framing;
+
+ProtocolVersion::ProtocolVersion() {}
+
+ProtocolVersion::ProtocolVersion(u_int8_t _major, u_int8_t _minor) : 
+    major_(_major),
+    minor_(_minor)
+{}
+
+ProtocolVersion::ProtocolVersion(const ProtocolVersion::ProtocolVersion& p):
+    major_(p.major_),
+    minor_(p.minor_)
+{}
+
+ProtocolVersion::~ProtocolVersion()
+{}
+
+bool  ProtocolVersion::equals(u_int8_t _major, u_int8_t _minor) const
+{
+    return major_ == _major && minor_ == _minor;
+}
+
+bool ProtocolVersion::equals(const ProtocolVersion::ProtocolVersion& p) const
+{
+    return major_ == p.major_ && minor_ == p.minor_;
+}
+
+const std::string ProtocolVersion::toString() const
+{
+    std::stringstream ss;
+    ss << major_ << "-" << minor_;
+    return ss.str();
+}
+
+ProtocolVersion::ProtocolVersion ProtocolVersion::operator=(const ProtocolVersion& p)
+{
+    major_ = p.major_;
+    minor_ = p.minor_;
+    return *this;
+}
+

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/framing/ProtocolVersion.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/framing/ProtocolVersion.cpp
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/lib/common/framing/ProtocolVersion.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/lib/common/framing/ProtocolVersion.h?view=auto&rev=481159
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/lib/common/framing/ProtocolVersion.h (added)
+++ incubator/qpid/trunk/qpid/cpp/lib/common/framing/ProtocolVersion.h Thu Nov 30 21:11:45 2006
@@ -0,0 +1,57 @@
+/*
+ *
+ * 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 _ProtocolVersion_
+#define _ProtocolVersion_
+
+#include <amqp_types.h>
+
+namespace qpid
+{
+namespace framing
+{
+
+class ProtocolVersion
+{
+private:
+    u_int8_t major_;
+	u_int8_t minor_;
+    
+public:
+    ProtocolVersion();
+    ProtocolVersion(u_int8_t _major, u_int8_t _minor);
+    ProtocolVersion(const ProtocolVersion& p);
+    virtual ~ProtocolVersion();
+
+    inline u_int8_t getMajor() const { return major_; }
+    inline void setMajor(u_int8_t major) { major_ = major; }
+    inline u_int8_t getMinor() const { return minor_; }
+    inline void setMinor(u_int8_t minor) { minor_ = minor; }
+    virtual bool equals(u_int8_t _major, u_int8_t _minor) const;
+    virtual bool equals(const ProtocolVersion& p) const;
+    virtual const std::string toString() const;
+    ProtocolVersion operator=(const ProtocolVersion& p);
+};
+
+} // namespace framing
+} // namespace qpid
+
+
+#endif // ifndef _ProtocolVersion_

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/framing/ProtocolVersion.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/framing/ProtocolVersion.h
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/lib/common/framing/ProtocolVersionException.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/lib/common/framing/ProtocolVersionException.cpp?view=auto&rev=481159
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/lib/common/framing/ProtocolVersionException.cpp (added)
+++ incubator/qpid/trunk/qpid/cpp/lib/common/framing/ProtocolVersionException.cpp Thu Nov 30 21:11:45 2006
@@ -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.
+ *
+ */
+#include <ProtocolVersionException.h>
+#include <sstream>
+
+using namespace qpid::framing;
+
+ProtocolVersionException::ProtocolVersionException() throw ()
+{
+}
+
+ProtocolVersionException::ProtocolVersionException(const std::string& str) throw () : Exception(str)
+{
+}
+
+ProtocolVersionException::ProtocolVersionException(const char* str) throw () : Exception(str)
+{
+}
+
+ProtocolVersionException::ProtocolVersionException(const ProtocolVersion& versionFound_, const std::string& str) throw () : Exception(str)
+
+{
+    versionFound = versionFound_;
+}
+
+ProtocolVersionException::ProtocolVersionException(const ProtocolVersion& versionFound_, const char* str) throw () : Exception(str)
+
+{
+    versionFound = versionFound_;
+}
+
+ProtocolVersionException::~ProtocolVersionException() throw ()
+{
+}
+
+const char* ProtocolVersionException::what() const throw()
+{
+    std::stringstream ss;
+    ss << "ProtocolVersionException: AMQP Version " << versionFound.toString() << " found: " << whatStr;
+    return ss.str().c_str();
+}
+
+std::string ProtocolVersionException::toString() const throw()
+{
+    std::stringstream ss;
+    ss << "ProtocolVersionException: AMQP Version " << versionFound.toString() << " found: " << whatStr;
+    return ss.str();
+}

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/framing/ProtocolVersionException.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/framing/ProtocolVersionException.cpp
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/lib/common/framing/ProtocolVersionException.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/lib/common/framing/ProtocolVersionException.h?view=auto&rev=481159
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/lib/common/framing/ProtocolVersionException.h (added)
+++ incubator/qpid/trunk/qpid/cpp/lib/common/framing/ProtocolVersionException.h Thu Nov 30 21:11:45 2006
@@ -0,0 +1,55 @@
+/*
+ *
+ * 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 _ProtocolVersionException_
+#define _ProtocolVersionException_
+
+#include <Exception.h>
+#include <ProtocolVersion.h>
+#include <string>
+#include <vector>
+
+namespace qpid
+{
+namespace framing
+{
+
+class ProtocolVersionException : virtual public qpid::Exception
+{
+protected:
+    ProtocolVersion versionFound;
+     
+public:
+    ProtocolVersionException() throw ();
+    ProtocolVersionException(const std::string& str) throw ();
+    ProtocolVersionException(const char* str) throw ();
+	ProtocolVersionException(const ProtocolVersion& versionFound_, const std::string& str) throw ();
+	ProtocolVersionException(const ProtocolVersion& versionFound_, const char* str) throw ();
+    virtual ~ProtocolVersionException() throw ();
+      
+    virtual const char* what() const throw();
+    virtual std::string toString() const throw();
+}; // class ProtocolVersionException
+
+} // namespace framing
+} // namespace qpid
+
+#endif //ifndef _ProtocolVersionException_

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/framing/ProtocolVersionException.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/framing/ProtocolVersionException.h
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/lib/common/framing/Value.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/lib/common/framing/Value.cpp?view=auto&rev=481159
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/lib/common/framing/Value.cpp (added)
+++ incubator/qpid/trunk/qpid/cpp/lib/common/framing/Value.cpp Thu Nov 30 21:11:45 2006
@@ -0,0 +1,114 @@
+/*
+ *
+ * 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 <Buffer.h>
+#include <FieldTable.h>
+#include <QpidError.h>
+
+namespace qpid {
+namespace framing {
+
+Value::~Value() {}
+
+void StringValue::encode(Buffer& buffer){
+    buffer.putLongString(value);
+}
+void StringValue::decode(Buffer& buffer){
+    buffer.getLongString(value);
+}
+
+void IntegerValue::encode(Buffer& buffer){
+    buffer.putLong((u_int32_t) value);
+}
+void IntegerValue::decode(Buffer& buffer){
+    value = buffer.getLong();
+}
+
+void TimeValue::encode(Buffer& buffer){
+    buffer.putLongLong(value);
+}
+void TimeValue::decode(Buffer& buffer){
+    value = buffer.getLongLong();
+}
+
+void DecimalValue::encode(Buffer& buffer){
+    buffer.putOctet(value.decimals);
+    buffer.putLong(value.value);
+}
+void DecimalValue::decode(Buffer& buffer){
+    value = Decimal(buffer.getLong(), buffer.getOctet());
+}
+
+void FieldTableValue::encode(Buffer& buffer){
+    buffer.putFieldTable(value);
+}
+void FieldTableValue::decode(Buffer& buffer){
+    buffer.getFieldTable(value);
+}
+
+std::auto_ptr<Value> Value::decode_value(Buffer& buffer)
+{
+    std::auto_ptr<Value> value;
+    u_int8_t type = buffer.getOctet();
+    switch(type){
+      case 'S':
+        value.reset(new StringValue());
+	break;
+      case 'I':
+        value.reset(new IntegerValue());
+	break;
+      case 'D':
+        value.reset(new DecimalValue());
+	break;
+      case 'T':
+        value.reset(new TimeValue());
+	break;
+      case 'F':
+        value.reset(new FieldTableValue());
+	break;
+      default:
+	THROW_QPID_ERROR(FRAMING_ERROR, "Unknown field table value type");
+    }
+    value->decode(buffer);
+    return value;
+}
+
+EmptyValue::~EmptyValue() {}
+
+void EmptyValue::print(std::ostream& out) const 
+{
+    out << "<empty field value>";
+}
+
+std::ostream& operator<<(std::ostream& out, const Value& v) {
+    v.print(out);
+    return out;
+}
+
+std::ostream& operator<<(std::ostream& out, const Decimal& d) 
+{
+    return out << "Decimal(" << d.value << "," << d.decimals << ")";
+}
+
+}}
+
+
+

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/framing/Value.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/framing/Value.cpp
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/lib/common/framing/Value.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/lib/common/framing/Value.h?view=auto&rev=481159
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/lib/common/framing/Value.h (added)
+++ incubator/qpid/trunk/qpid/cpp/lib/common/framing/Value.h Thu Nov 30 21:11:45 2006
@@ -0,0 +1,163 @@
+/*
+ *
+ * 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 <iostream>
+#include <vector>
+#include <amqp_types.h>
+#include <FieldTable.h>
+
+#ifndef _Value_
+#define _Value_
+
+namespace qpid {
+namespace framing {
+
+class Buffer;
+
+/**
+ * Represents a decimal value.
+ * No arithmetic functionality for now, we only care about encoding/decoding.
+ */
+struct Decimal {
+    u_int32_t value;
+    u_int8_t decimals;
+
+    Decimal(u_int32_t value_=0, u_int8_t decimals_=0) : value(value_), decimals(decimals_) {}
+    bool operator==(const Decimal& d) const {
+        return decimals == d.decimals && value == d.value;
+    }
+    bool operator!=(const Decimal& d) const { return !(*this == d); }
+};
+
+std::ostream& operator<<(std::ostream& out, const Decimal& d);
+
+/**
+ * Polymorpic base class for values.
+ */
+class Value {
+  public:
+    virtual ~Value();
+    virtual u_int32_t size() const = 0;
+    virtual char getType() const = 0;
+    virtual void encode(Buffer& buffer) = 0;
+    virtual void decode(Buffer& buffer) = 0;
+    virtual bool operator==(const Value&) const = 0;
+    bool operator!=(const Value& v) const { return !(*this == v); }
+    virtual void print(std::ostream& out) const = 0;
+
+    /** Create a new value by decoding from the buffer */
+    static std::auto_ptr<Value> decode_value(Buffer& buffer);
+};
+
+std::ostream& operator<<(std::ostream& out, const Value& d);
+
+
+/**
+ * Template for common operations on Value sub-classes.
+ */
+template <class T>
+class ValueOps : public Value
+{
+  protected:
+    T value;
+  public:
+    ValueOps() {}
+    ValueOps(const T& v) : value(v) {}
+    const T& getValue() const { return value; }
+    T& getValue() { return value; }
+
+    virtual bool operator==(const Value& v) const {
+        const ValueOps<T>* vo = dynamic_cast<const ValueOps<T>*>(&v);
+        if (vo == 0) return false;
+        else return value == vo->value;
+    }
+
+    void print(std::ostream& out) const { out << value; }
+};
+
+
+class StringValue : public ValueOps<std::string> {
+  public:
+    StringValue(const std::string& v) : ValueOps<std::string>(v) {}
+    StringValue() {}
+    virtual u_int32_t size() const { return 4 + value.length(); }
+    virtual char getType() const { return 'S'; }
+    virtual void encode(Buffer& buffer);
+    virtual void decode(Buffer& buffer);
+};
+
+class IntegerValue : public ValueOps<int> {
+  public:
+    IntegerValue(int v) : ValueOps<int>(v) {}
+    IntegerValue(){}
+    virtual u_int32_t size() const { return 4; }
+    virtual char getType() const { return 'I'; }
+    virtual void encode(Buffer& buffer);
+    virtual void decode(Buffer& buffer);
+};
+
+class TimeValue : public ValueOps<u_int64_t> {
+  public:
+    TimeValue(u_int64_t v) : ValueOps<u_int64_t>(v){}
+    TimeValue(){}
+    virtual u_int32_t size() const { return 8; }
+    virtual char getType() const { return 'T'; }
+    virtual void encode(Buffer& buffer);
+    virtual void decode(Buffer& buffer);
+};
+
+class DecimalValue : public ValueOps<Decimal> {
+  public:
+    DecimalValue(const Decimal& d) : ValueOps<Decimal>(d) {} 
+    DecimalValue(u_int32_t value_=0, u_int8_t decimals_=0) :
+        ValueOps<Decimal>(Decimal(value_, decimals_)){}
+    virtual u_int32_t size() const { return 5; }
+    virtual char getType() const { return 'D'; }
+    virtual void encode(Buffer& buffer);
+    virtual void decode(Buffer& buffer);
+};
+
+
+class FieldTableValue : public ValueOps<FieldTable> {
+  public:
+    FieldTableValue(const FieldTable& v) : ValueOps<FieldTable>(v){}
+    FieldTableValue(){}
+    virtual u_int32_t size() const { return 4 + value.size(); }
+    virtual char getType() const { return 'F'; }
+    virtual void encode(Buffer& buffer);
+    virtual void decode(Buffer& buffer);
+};
+
+class EmptyValue : public Value {
+  public:
+    ~EmptyValue();
+    virtual u_int32_t size() const { return 0; }
+    virtual char getType() const { return 0; }
+    virtual void encode(Buffer& ) {}
+    virtual void decode(Buffer& ) {}
+    virtual bool operator==(const Value& v) const {
+        return dynamic_cast<const EmptyValue*>(&v);
+    }
+    virtual void print(std::ostream& out) const;
+};
+
+}} // qpid::framing
+
+#endif

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/framing/Value.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/framing/Value.h
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/lib/common/framing/amqp_framing.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/lib/common/framing/amqp_framing.h?view=auto&rev=481159
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/lib/common/framing/amqp_framing.h (added)
+++ incubator/qpid/trunk/qpid/cpp/lib/common/framing/amqp_framing.h Thu Nov 30 21:11:45 2006
@@ -0,0 +1,36 @@
+/*
+ *
+ * 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 <amqp_types.h>
+#include <AMQFrame.h>
+#include <AMQBody.h>
+#include <BodyHandler.h>
+#include <AMQMethodBody.h>
+#include <AMQHeaderBody.h>
+#include <AMQContentBody.h>
+#include <AMQHeartbeatBody.h>
+#include <AMQP_MethodVersionMap.h>
+#include <InputHandler.h>
+#include <OutputHandler.h>
+#include <InitiationHandler.h>
+#include <ProtocolInitiation.h>
+#include <BasicHeaderProperties.h>
+#include <ProtocolVersion.h>
+#include <ProtocolVersionException.h>

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/framing/amqp_framing.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/framing/amqp_framing.h
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/lib/common/framing/amqp_types.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/lib/common/framing/amqp_types.h?view=auto&rev=481159
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/lib/common/framing/amqp_types.h (added)
+++ incubator/qpid/trunk/qpid/cpp/lib/common/framing/amqp_types.h Thu Nov 30 21:11:45 2006
@@ -0,0 +1,45 @@
+/*
+ *
+ * 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 <string>
+#ifdef _WINDOWS
+#include "windows.h"
+typedef unsigned char  u_int8_t;
+typedef unsigned short u_int16_t;
+typedef unsigned int   u_int32_t;
+typedef unsigned __int64 u_int64_t;
+#endif
+#ifndef _WINDOWS
+#include "stdint.h"
+#endif
+
+#ifndef AMQP_TYPES_H
+#define AMQP_TYPES_H
+
+namespace qpid 
+{
+namespace framing 
+{
+
+using std::string;
+
+}
+}
+#endif

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/framing/amqp_types.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/framing/amqp_types.h
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/lib/common/sys/Acceptor.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/lib/common/sys/Acceptor.h?view=auto&rev=481159
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/lib/common/sys/Acceptor.h (added)
+++ incubator/qpid/trunk/qpid/cpp/lib/common/sys/Acceptor.h Thu Nov 30 21:11:45 2006
@@ -0,0 +1,47 @@
+#ifndef _sys_Acceptor_h
+#define _sys_Acceptor_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 <stdint.h>
+#include <SharedObject.h>
+
+namespace qpid {
+namespace sys {
+
+class SessionHandlerFactory;
+
+class Acceptor : public qpid::SharedObject<Acceptor>
+{
+  public:
+    static Acceptor::shared_ptr create(int16_t port, int backlog, int threads, bool trace = false);
+    virtual ~Acceptor() = 0;
+    virtual int16_t getPort() const = 0;
+    virtual void run(qpid::sys::SessionHandlerFactory* factory) = 0;
+    virtual void shutdown() = 0;
+};
+
+}}
+
+
+    
+#endif  /*!_sys_Acceptor_h*/

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/sys/Acceptor.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/sys/Acceptor.h
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/lib/common/sys/AtomicCount.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/lib/common/sys/AtomicCount.h?view=auto&rev=481159
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/lib/common/sys/AtomicCount.h (added)
+++ incubator/qpid/trunk/qpid/cpp/lib/common/sys/AtomicCount.h Thu Nov 30 21:11:45 2006
@@ -0,0 +1,71 @@
+#ifndef _posix_AtomicCount_h
+#define _posix_AtomicCount_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 <boost/detail/atomic_count.hpp>
+#include <boost/noncopyable.hpp>
+
+namespace qpid {
+namespace sys {
+
+/**
+ * Atomic counter.
+ */
+class AtomicCount : boost::noncopyable {
+  public:
+    class ScopedDecrement : boost::noncopyable {
+      public:
+        /** Decrement counter in constructor and increment in destructor. */
+        ScopedDecrement(AtomicCount& c) : count(c) { value = --count; }
+        ~ScopedDecrement() { ++count; }
+        /** Return the value returned by the decrement. */
+        operator long() { return value; }
+      private:
+        AtomicCount& count;
+        long value;
+    };
+
+    class ScopedIncrement : boost::noncopyable {
+      public:
+        /** Increment counter in constructor and increment in destructor. */
+        ScopedIncrement(AtomicCount& c) : count(c) { ++count; }
+        ~ScopedIncrement() { --count; }
+      private:
+        AtomicCount& count;
+    };
+
+    AtomicCount(long value = 0) : count(value) {}
+    
+    void operator++() { ++count ; }
+    
+    long operator--() { return --count; }
+    
+    operator long() const { return count; }
+
+    
+  private:
+    boost::detail::atomic_count  count;
+};
+
+
+}}
+
+
+#endif // _posix_AtomicCount_h

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/sys/AtomicCount.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/sys/AtomicCount.h
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/lib/common/sys/Module.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/lib/common/sys/Module.h?view=auto&rev=481159
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/lib/common/sys/Module.h (added)
+++ incubator/qpid/trunk/qpid/cpp/lib/common/sys/Module.h Thu Nov 30 21:11:45 2006
@@ -0,0 +1,161 @@
+#ifndef _sys_Module_h
+#define _sys_Module_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 <boost/noncopyable.hpp>
+#include <iostream>
+#include <QpidError.h>
+
+namespace qpid {
+namespace sys {
+#if USE_APR
+#include <apr_dso.h>
+    typedef apr_dso_handle_t* dso_handle_t;
+#else 
+    typedef void* dso_handle_t;
+#endif
+
+    template <class T> class Module : private boost::noncopyable
+    {
+        typedef T* create_t();
+        typedef void destroy_t(T*);
+        
+        dso_handle_t handle;
+        destroy_t* destroy;
+        T* ptr;
+
+        void load(const std::string& name);
+        void unload();
+        void* getSymbol(const std::string& name);
+
+    public:
+        Module(const std::string& name);
+        T* operator->(); 
+        T* get(); 
+        ~Module() throw();
+    };
+
+}
+}
+
+using namespace qpid::sys;
+
+template <class T> Module<T>::Module(const std::string& module) : destroy(0), ptr(0) 
+{
+    load(module);
+    //TODO: need a better strategy for symbol names to allow multiple
+    //modules to be loaded without clashes...
+
+    //Note: need the double cast to avoid errors in casting from void* to function pointer with -pedantic
+    create_t* create = reinterpret_cast<create_t*>(reinterpret_cast<intptr_t>(getSymbol("create")));
+    destroy = reinterpret_cast<destroy_t*>(reinterpret_cast<intptr_t>(getSymbol("destroy")));
+    ptr = create();
+}
+
+template <class T> T* Module<T>::operator->() 
+{ 
+    return ptr; 
+}
+
+template <class T> T* Module<T>::get() 
+{ 
+    return ptr; 
+}
+
+template <class T> Module<T>::~Module() throw()
+{
+    try {
+        if (handle && ptr) {
+            destroy(ptr);
+        }
+        if (handle) unload();
+    } catch (std::exception& e) {
+        std::cout << "Error while destroying module: " << e.what() << std::endl;
+    }
+    destroy = 0;
+    handle = 0;
+    ptr = 0;
+}
+
+// APR ================================================================
+#if USE_APR
+
+#include <apr/APRBase.h>
+#include <apr/APRPool.h>
+
+template <class T> void Module<T>::load(const std::string& name)
+{
+    CHECK_APR_SUCCESS(apr_dso_load(&handle, name.c_str(), APRPool::get()));
+}
+
+template <class T> void Module<T>::unload()
+{
+    CHECK_APR_SUCCESS(apr_dso_unload(handle));
+}
+
+template <class T> void* Module<T>::getSymbol(const std::string& name)
+{
+    apr_dso_handle_sym_t symbol;
+    CHECK_APR_SUCCESS(apr_dso_sym(&symbol, handle, name.c_str()));
+    return (void*) symbol;
+}
+
+// POSIX================================================================
+#else 
+
+#include <dlfcn.h>
+
+template <class T> void Module<T>::load(const std::string& name)
+{
+    dlerror();
+    handle = dlopen(name.c_str(), RTLD_NOW);
+    const char* error = dlerror();
+    if (error) {
+        THROW_QPID_ERROR(INTERNAL_ERROR, error);
+    }
+}
+
+template <class T> void Module<T>::unload()
+{
+    dlerror();
+    dlclose(handle);
+    const char* error = dlerror();
+    if (error) {
+        THROW_QPID_ERROR(INTERNAL_ERROR, error);
+    }
+}
+
+template <class T> void* Module<T>::getSymbol(const std::string& name)
+{
+    dlerror();
+    void* sym = dlsym(handle, name.c_str());
+    const char* error = dlerror();
+    if (error) {
+        THROW_QPID_ERROR(INTERNAL_ERROR, error);
+    }
+    return sym;
+}
+
+#endif //if USE_APR
+
+#endif //ifndef _sys_Module_h
+

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/sys/Module.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/sys/Module.h
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/lib/common/sys/Monitor.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/lib/common/sys/Monitor.h?view=auto&rev=481159
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/lib/common/sys/Monitor.h (added)
+++ incubator/qpid/trunk/qpid/cpp/lib/common/sys/Monitor.h Thu Nov 30 21:11:45 2006
@@ -0,0 +1,127 @@
+#ifndef _sys_Monitor_h
+#define _sys_Monitor_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 <sys/errno.h>
+#include <boost/noncopyable.hpp>
+#include <sys/Mutex.h>
+#include <sys/Time.h>
+
+#ifdef USE_APR
+#  include <apr_thread_cond.h>
+#endif
+
+namespace qpid {
+namespace sys {
+
+/**
+ * A monitor is a condition variable and a mutex
+ */
+class Monitor : public Mutex
+{
+  public:
+    inline Monitor();
+    inline ~Monitor();
+    inline void wait();
+    inline bool wait(const Time& absoluteTime);
+    inline void notify();
+    inline void notifyAll();
+
+  private:
+#ifdef USE_APR
+    apr_thread_cond_t* condition;
+#else
+    pthread_cond_t condition;
+#endif
+};
+
+
+// APR ================================================================
+#ifdef USE_APR
+
+Monitor::Monitor() {
+    CHECK_APR_SUCCESS(apr_thread_cond_create(&condition, APRPool::get()));
+}
+
+Monitor::~Monitor() {
+    CHECK_APR_SUCCESS(apr_thread_cond_destroy(condition));
+}
+
+void Monitor::wait() {
+    CHECK_APR_SUCCESS(apr_thread_cond_wait(condition, mutex));
+}
+
+bool Monitor::wait(const Time& absoluteTime){
+    // APR uses microseconds.
+    apr_status_t status =
+        apr_thread_cond_timedwait(condition, mutex, absoluteTime/TIME_USEC);
+    if(status != APR_TIMEUP) CHECK_APR_SUCCESS(status);
+    return status == 0;
+}
+
+void Monitor::notify(){
+    CHECK_APR_SUCCESS(apr_thread_cond_signal(condition));
+}
+
+void Monitor::notifyAll(){
+    CHECK_APR_SUCCESS(apr_thread_cond_broadcast(condition));
+}
+
+#else
+// POSIX ================================================================
+
+Monitor::Monitor() {
+    QPID_POSIX_THROW_IF(pthread_cond_init(&condition, 0));
+}
+
+Monitor::~Monitor() {
+    QPID_POSIX_THROW_IF(pthread_cond_destroy(&condition));
+}
+
+void Monitor::wait() {
+    QPID_POSIX_THROW_IF(pthread_cond_wait(&condition, &mutex));
+}
+
+bool Monitor::wait(const Time& absoluteTime){
+    struct timespec ts;
+    toTimespec(ts, absoluteTime);
+    int status = pthread_cond_timedwait(&condition, &mutex, &ts);
+    if (status != 0) {
+        if (status == ETIMEDOUT) return false;
+        throw QPID_POSIX_ERROR(status);
+    }
+    return true;
+}
+
+void Monitor::notify(){
+    QPID_POSIX_THROW_IF(pthread_cond_signal(&condition));
+}
+
+void Monitor::notifyAll(){
+    QPID_POSIX_THROW_IF(pthread_cond_broadcast(&condition));
+}
+#endif  /*USE_APR*/
+
+
+}}
+#endif  /*!_sys_Monitor_h*/

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/sys/Monitor.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/sys/Monitor.h
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/lib/common/sys/Mutex.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/lib/common/sys/Mutex.h?view=auto&rev=481159
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/lib/common/sys/Mutex.h (added)
+++ incubator/qpid/trunk/qpid/cpp/lib/common/sys/Mutex.h Thu Nov 30 21:11:45 2006
@@ -0,0 +1,151 @@
+#ifndef _sys_Mutex_h
+#define _sys_Mutex_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.
+ *
+ */
+
+#ifdef USE_APR
+#  include <apr_thread_mutex.h>
+#  include <apr/APRBase.h>
+#  include <apr/APRPool.h>
+#else
+#  include <pthread.h>
+#  include <posix/check.h>
+#endif
+#include <boost/noncopyable.hpp>
+
+namespace qpid {
+namespace sys {
+
+/**
+ * Scoped lock template: calls lock() in ctor, unlock() in dtor.
+ * L can be any class with lock() and unlock() functions.
+ */
+template <class L>
+class ScopedLock
+{
+  public:
+    ScopedLock(L& l) : mutex(l) { l.lock(); }
+    ~ScopedLock() { mutex.unlock(); }
+  private:
+    L& mutex;
+};
+
+/**
+ * Mutex lock.
+ */
+class Mutex : private boost::noncopyable {
+  public:
+    typedef ScopedLock<Mutex> ScopedLock;
+    
+    inline Mutex();
+    inline ~Mutex();
+    inline void lock();
+    inline void unlock();
+    inline void trylock();
+
+  protected:
+#ifdef USE_APR
+    apr_thread_mutex_t* mutex;
+#else
+    pthread_mutex_t mutex;
+#endif
+};
+
+#ifdef USE_APR
+// APR ================================================================
+
+Mutex::Mutex() {
+    CHECK_APR_SUCCESS(apr_thread_mutex_create(&mutex, APR_THREAD_MUTEX_NESTED, APRPool::get()));
+}
+
+Mutex::~Mutex(){
+    CHECK_APR_SUCCESS(apr_thread_mutex_destroy(mutex));
+}
+
+void Mutex::lock() {
+    CHECK_APR_SUCCESS(apr_thread_mutex_lock(mutex));
+}
+void Mutex::unlock() {
+    CHECK_APR_SUCCESS(apr_thread_mutex_unlock(mutex));
+}
+
+void Mutex::trylock() {
+    CHECK_APR_SUCCESS(apr_thread_mutex_trylock(mutex));
+}
+
+#else
+// POSIX ================================================================
+
+/**
+ * PODMutex is a POD, can be static-initialized with
+ * PODMutex m = QPID_PODMUTEX_INITIALIZER
+ */
+struct PODMutex 
+{
+    typedef ScopedLock<PODMutex> ScopedLock;
+
+    inline void lock();
+    inline void unlock();
+    inline void trylock();
+
+    // Must be public to be a POD:
+    pthread_mutex_t mutex;
+};
+
+#define QPID_MUTEX_INITIALIZER { PTHREAD_MUTEX_INITIALIZER }
+
+
+void PODMutex::lock() {
+    QPID_POSIX_THROW_IF(pthread_mutex_lock(&mutex));
+}
+void PODMutex::unlock() {
+    QPID_POSIX_THROW_IF(pthread_mutex_unlock(&mutex));
+}
+
+void PODMutex::trylock() {
+    QPID_POSIX_THROW_IF(pthread_mutex_trylock(&mutex));
+}
+
+
+Mutex::Mutex() {
+    QPID_POSIX_THROW_IF(pthread_mutex_init(&mutex, 0));
+}
+
+Mutex::~Mutex(){
+    QPID_POSIX_THROW_IF(pthread_mutex_destroy(&mutex));
+}
+
+void Mutex::lock() {
+    QPID_POSIX_THROW_IF(pthread_mutex_lock(&mutex));
+}
+void Mutex::unlock() {
+    QPID_POSIX_THROW_IF(pthread_mutex_unlock(&mutex));
+}
+
+void Mutex::trylock() {
+    QPID_POSIX_THROW_IF(pthread_mutex_trylock(&mutex));
+}
+
+#endif // USE_APR
+
+}}
+
+
+
+#endif  /*!_sys_Mutex_h*/

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/sys/Mutex.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/sys/Mutex.h
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/lib/common/sys/Runnable.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/lib/common/sys/Runnable.cpp?view=auto&rev=481159
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/lib/common/sys/Runnable.cpp (added)
+++ incubator/qpid/trunk/qpid/cpp/lib/common/sys/Runnable.cpp Thu Nov 30 21:11:45 2006
@@ -0,0 +1,32 @@
+/*
+ *
+ * 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 "Runnable.h"
+#include <boost/bind.hpp>
+
+namespace qpid {
+namespace sys {
+
+Runnable::~Runnable() {}
+
+Runnable::Functor Runnable::functor() 
+{
+    return boost::bind(&Runnable::run, this);
+}
+
+}}

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/sys/Runnable.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/sys/Runnable.cpp
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/lib/common/sys/Runnable.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/lib/common/sys/Runnable.h?view=auto&rev=481159
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/lib/common/sys/Runnable.h (added)
+++ incubator/qpid/trunk/qpid/cpp/lib/common/sys/Runnable.h Thu Nov 30 21:11:45 2006
@@ -0,0 +1,50 @@
+#ifndef _Runnable_
+#define _Runnable_
+/*
+ *
+ * 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 <boost/function.hpp>
+
+namespace qpid {
+namespace sys {
+
+/**
+ * Interface for objects that can be run, e.g. in a thread.
+ */
+class Runnable
+{
+  public:
+    /** Type to represent a runnable as a Functor */
+    typedef boost::function0<void> Functor;
+    
+    virtual ~Runnable();
+
+    /** Derived classes override run(). */
+    virtual void run() = 0;
+
+    /** Create a functor object that will call this->run(). */
+    Functor functor();
+};
+
+}}
+
+
+#endif

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/sys/Runnable.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/sys/Runnable.h
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/lib/common/sys/SessionContext.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/lib/common/sys/SessionContext.h?view=auto&rev=481159
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/lib/common/sys/SessionContext.h (added)
+++ incubator/qpid/trunk/qpid/cpp/lib/common/sys/SessionContext.h Thu Nov 30 21:11:45 2006
@@ -0,0 +1,41 @@
+/*
+ *
+ * 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 _SessionContext_
+#define _SessionContext_
+
+#include <OutputHandler.h>
+
+namespace qpid {
+namespace sys {
+
+/**
+ * Provides the output handler associated with a connection.
+ */
+class SessionContext : public virtual qpid::framing::OutputHandler 
+{
+  public:
+    virtual void close() = 0;
+};
+
+}}
+
+
+#endif

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/sys/SessionContext.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/sys/SessionContext.h
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/lib/common/sys/SessionHandler.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/lib/common/sys/SessionHandler.h?view=auto&rev=481159
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/lib/common/sys/SessionHandler.h (added)
+++ incubator/qpid/trunk/qpid/cpp/lib/common/sys/SessionHandler.h Thu Nov 30 21:11:45 2006
@@ -0,0 +1,45 @@
+/*
+ *
+ * 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 _SessionHandler_
+#define _SessionHandler_
+
+#include <InputHandler.h>
+#include <InitiationHandler.h>
+#include <ProtocolInitiation.h>
+#include <sys/TimeoutHandler.h>
+
+namespace qpid {
+namespace sys {
+
+    class SessionHandler :
+        public qpid::framing::InitiationHandler,
+        public qpid::framing::InputHandler, 
+        public TimeoutHandler
+    {
+    public:
+        virtual void closed() = 0;
+    };
+
+}
+}
+
+
+#endif

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/sys/SessionHandler.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/sys/SessionHandler.h
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/lib/common/sys/SessionHandlerFactory.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/lib/common/sys/SessionHandlerFactory.h?view=auto&rev=481159
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/lib/common/sys/SessionHandlerFactory.h (added)
+++ incubator/qpid/trunk/qpid/cpp/lib/common/sys/SessionHandlerFactory.h Thu Nov 30 21:11:45 2006
@@ -0,0 +1,46 @@
+/*
+ *
+ * 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 _SessionHandlerFactory_
+#define _SessionHandlerFactory_
+
+#include <boost/noncopyable.hpp>
+
+namespace qpid {
+namespace sys {
+
+class SessionContext;
+class SessionHandler;
+
+/**
+ * Callback interface used by the Acceptor to
+ * create a SessionHandler for each new connection.
+ */
+class SessionHandlerFactory : private boost::noncopyable
+{
+  public:
+    virtual SessionHandler* create(SessionContext* ctxt) = 0;
+    virtual ~SessionHandlerFactory(){}
+};
+
+}}
+
+
+#endif

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/sys/SessionHandlerFactory.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/sys/SessionHandlerFactory.h
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/lib/common/sys/ShutdownHandler.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/lib/common/sys/ShutdownHandler.h?view=auto&rev=481159
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/lib/common/sys/ShutdownHandler.h (added)
+++ incubator/qpid/trunk/qpid/cpp/lib/common/sys/ShutdownHandler.h Thu Nov 30 21:11:45 2006
@@ -0,0 +1,37 @@
+/*
+ *
+ * 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 _ShutdownHandler_
+#define _ShutdownHandler_
+
+namespace qpid {
+namespace sys {
+
+    class ShutdownHandler
+    {
+    public:
+	virtual void shutdown() = 0;
+	virtual ~ShutdownHandler(){}
+    };
+
+}
+}
+
+#endif

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/sys/ShutdownHandler.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/lib/common/sys/ShutdownHandler.h
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/lib/common/sys/Socket.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/lib/common/sys/Socket.h?view=auto&rev=481159
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/lib/common/sys/Socket.h (added)
+++ incubator/qpid/trunk/qpid/cpp/lib/common/sys/Socket.h Thu Nov 30 21:11:45 2006
@@ -0,0 +1,88 @@
+#ifndef _sys_Socket_h
+#define _sys_Socket_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 <string>
+#include <sys/Time.h>
+
+#ifdef USE_APR
+#  include <apr_network_io.h>
+#endif
+
+namespace qpid {
+namespace sys {
+
+class Socket
+{
+  public:
+    /** Create an initialized TCP socket */
+    static Socket createTcp();
+
+    /** Create a socket wrapper for descriptor. */
+#ifdef USE_APR
+    Socket(apr_socket_t* descriptor = 0);
+#else
+    Socket(int descriptor = 0);
+#endif
+    
+    /** Set timeout for read and write */
+    void setTimeout(Time interval);
+
+    void connect(const std::string& host, int port);
+
+    void close();
+
+    enum { SOCKET_TIMEOUT=-2, SOCKET_EOF=-3 } ErrorCode;
+
+    /** Returns bytes sent or an ErrorCode value < 0. */
+    ssize_t send(const void* data, size_t size);
+
+    /**
+     * Returns bytes received, an ErrorCode value < 0 or 0
+     * if the connection closed in an orderly manner.
+     */
+    ssize_t recv(void* data, size_t size);
+
+    /** Bind to a port and start listening.
+     *@param port 0 means choose an available port.
+     *@param backlog maximum number of pending connections.
+     *@return The bound port.
+     */
+    int listen(int port = 0, int backlog = 10);
+
+    /** Get file descriptor */
+    int fd(); 
+    
+  private:
+#ifdef USE_APR    
+    apr_socket_t* socket;
+#else
+    void init() const;
+    mutable int socket;         // Initialized on demand. 
+#endif
+};
+
+}}
+
+
+#endif  /*!_sys_Socket_h*/