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/01/31 20:07:05 UTC
svn commit: r501948 - in /incubator/qpid/branches/qpid.0-9/cpp/lib: broker/
client/ common/ common/framing/
Author: aconway
Date: Wed Jan 31 11:07:04 2007
New Revision: 501948
URL: http://svn.apache.org/viewvc?view=rev&rev=501948
Log:
* framing/ChannelAdapter.cpp: Enable channel state assertions.
* common/Exception & others: Exception template constructors that
accept any object that supports ostream operator<< as messages.
E.g. can pass a boost::format object directly, no need to call str().
* Fixed up various exception messges to use boost::format.
* framing/Requester.cpp: Exception on invalid response id.
* client/Connection.h: Remove extra getVersion() function.
Modified:
incubator/qpid/branches/qpid.0-9/cpp/lib/broker/Configuration.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/ResponseHandler.cpp
incubator/qpid/branches/qpid.0-9/cpp/lib/common/Exception.h
incubator/qpid/branches/qpid.0-9/cpp/lib/common/QpidError.cpp
incubator/qpid/branches/qpid.0-9/cpp/lib/common/QpidError.h
incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQFrame.cpp
incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/ChannelAdapter.cpp
incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/ProtocolVersion.h
incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/ProtocolVersionException.cpp
incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/ProtocolVersionException.h
incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/Requester.cpp
Modified: incubator/qpid/branches/qpid.0-9/cpp/lib/broker/Configuration.h
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/lib/broker/Configuration.h?view=diff&rev=501948&r1=501947&r2=501948
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/broker/Configuration.h (original)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/broker/Configuration.h Wed Jan 31 11:07:04 2007
@@ -122,15 +122,16 @@
public:
- struct BadOptionException : public qpid::Exception {
- BadOptionException(const std::string& msg)
- : qpid::Exception(msg) {}
+ struct BadOptionException : public Exception {
+ template<class T>
+ BadOptionException(const T& msg) : Exception(msg) {}
};
class ParseException : public Exception {
public:
- ParseException(const std::string& msg) : Exception(msg) {}
+ template <class T>
+ ParseException(const T& msg) : Exception(msg) {}
};
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=501948&r1=501947&r2=501948
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/client/Connection.cpp (original)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/client/Connection.cpp Wed Jan 31 11:07:04 2007
@@ -32,7 +32,6 @@
using namespace qpid::framing;
using namespace qpid::sys;
-using namespace qpid::sys;
namespace qpid {
@@ -101,7 +100,6 @@
}
}
-// FIXME aconway 2007-01-26: make channels owned and created by connection?
void Connection::openChannel(Channel& channel) {
ChannelId id = ++channelIdCounter;
assert (channels.find(id) == channels.end());
@@ -115,7 +113,6 @@
}
void Connection::received(AMQFrame* frame){
- // FIXME aconway 2007-01-25: Mutex
ChannelId id = frame->getChannel();
Channel* channel = channels[id];
// FIXME aconway 2007-01-26: Exception thrown here is hanging the
@@ -149,7 +146,6 @@
}
void Connection::idleIn(){
- std::cout << "Connection timed out due to abscence of heartbeat." << std::endl;
connector->close();
}
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=501948&r1=501947&r2=501948
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/client/Connection.h (original)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/client/Connection.h Wed Jan 31 11:07:04 2007
@@ -88,7 +88,7 @@
static framing::ChannelId channelIdCounter;
static const std::string OK;
-
+
framing::ProtocolVersion version;
const u_int32_t max_frame_size;
ChannelMap channels;
@@ -107,8 +107,6 @@
friend class Channel;
public:
- const framing::ProtocolVersion& getVersion() const { return version; }
-
/**
* Creates a connection object, but does not open the
* connection.
@@ -187,7 +185,7 @@
inline u_int32_t getMaxFrameSize(){ return max_frame_size; }
/** @return protocol version in use on this connection. */
- const framing::ProtocolVersion& getVersion() { return version; }
+ const framing::ProtocolVersion& getVersion() const { return version; }
};
}} // namespace qpid::client
Modified: incubator/qpid/branches/qpid.0-9/cpp/lib/client/ResponseHandler.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/lib/client/ResponseHandler.cpp?view=diff&rev=501948&r1=501947&r2=501948
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/client/ResponseHandler.cpp (original)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/client/ResponseHandler.cpp Wed Jan 31 11:07:04 2007
@@ -66,10 +66,8 @@
if(!validate(response->amqpClassId(), response->amqpMethodId())) {
THROW_QPID_ERROR(
PROTOCOL_ERROR,
- (boost::format(
- "Expected class:method %d:%d, got %d:%d")
- % c % m % response->amqpClassId() % response->amqpMethodId()
- ).str());
+ boost::format("Expected class:method %d:%d, got %d:%d")
+ % c % m % response->amqpClassId() % response->amqpMethodId());
}
}
Modified: incubator/qpid/branches/qpid.0-9/cpp/lib/common/Exception.h
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/lib/common/Exception.h?view=diff&rev=501948&r1=501947&r2=501948
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/common/Exception.h (original)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/common/Exception.h Wed Jan 31 11:07:04 2007
@@ -21,11 +21,13 @@
* under the License.
*
*/
-
#include <exception>
#include <string>
#include <memory>
#include <boost/shared_ptr.hpp>
+#include <boost/lexical_cast.hpp>
+
+#include "amqp_types.h"
namespace qpid
{
@@ -43,6 +45,11 @@
Exception(const char* str) throw();
Exception(const std::exception&) throw();
+ /** Allow any type that has ostream operator<< to act as message */
+ template <class T>
+ Exception(const T& message)
+ : whatStr(boost::lexical_cast<std::string>(message)) {}
+
virtual ~Exception() throw();
virtual const char* what() const throw();
@@ -54,16 +61,18 @@
typedef boost::shared_ptr<Exception> shared_ptr;
};
-struct ChannelException : public qpid::Exception {
- u_int16_t code;
- ChannelException(u_int16_t _code, std::string _text)
- : Exception(_text), code(_code) {}
+struct ChannelException : public Exception {
+ framing::ReplyCode code;
+ template <class T>
+ ChannelException(framing::ReplyCode code_, const T& message)
+ : Exception(message), code(code_) {}
};
-struct ConnectionException : public qpid::Exception {
- u_int16_t code;
- ConnectionException(u_int16_t _code, std::string _text)
- : Exception(_text), code(_code) {}
+struct ConnectionException : public Exception {
+ framing::ReplyCode code;
+ template <class T>
+ ConnectionException(framing::ReplyCode code_, const T& message)
+ : Exception(message), code(code_) {}
};
Modified: incubator/qpid/branches/qpid.0-9/cpp/lib/common/QpidError.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/lib/common/QpidError.cpp?view=diff&rev=501948&r1=501947&r2=501948
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/common/QpidError.cpp (original)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/common/QpidError.cpp Wed Jan 31 11:07:04 2007
@@ -19,6 +19,8 @@
*
*/
+#include <boost/format.hpp>
+
#include <QpidError.h>
#include <sstream>
@@ -26,19 +28,15 @@
QpidError::QpidError() : code(0) {}
-QpidError::QpidError(int _code, const std::string& _msg,
- const SrcLine& _loc) throw()
- : code(_code), msg(_msg), location(_loc)
-{
- std::ostringstream os;
- os << "Error [" << code << "] " << msg << " ("
- << location.file << ":" << location.line << ")";
- whatStr = os.str();
-}
-
QpidError::~QpidError() throw() {}
Exception* QpidError::clone() const throw() { return new QpidError(*this); }
void QpidError::throwSelf() const { throw *this; }
+
+void QpidError::init() {
+ whatStr = boost::str(boost::format("Error [%d] %s (%s:%d)")
+ % code % msg % loc.file % loc.line);
+}
+
Modified: incubator/qpid/branches/qpid.0-9/cpp/lib/common/QpidError.h
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/lib/common/QpidError.h?view=diff&rev=501948&r1=501947&r2=501948
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/common/QpidError.h (original)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/common/QpidError.h Wed Jan 31 11:07:04 2007
@@ -23,6 +23,7 @@
#include <string>
#include <memory>
#include <ostream>
+
#include <Exception.h>
namespace qpid {
@@ -36,17 +37,27 @@
int line;
};
-class QpidError : public Exception {
+class QpidError : public Exception
+{
public:
const int code;
- const std::string msg;
- const SrcLine location;
+ SrcLine loc;
+ std::string msg;
QpidError();
- QpidError(int _code, const std::string& _msg, const SrcLine& _loc) throw();
+
+ template <class T>
+ QpidError(int code_, const T& msg_, const SrcLine& loc_) throw()
+ : code(code_), loc(loc_), msg(boost::lexical_cast<std::string>(msg_))
+ { init(); }
+
~QpidError() throw();
Exception* clone() const throw();
void throwSelf() const;
+
+ private:
+
+ void init();
};
Modified: incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQFrame.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQFrame.cpp?view=diff&rev=501948&r1=501947&r2=501948
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQFrame.cpp (original)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQFrame.cpp Wed Jan 31 11:07:04 2007
@@ -114,7 +114,7 @@
default:
THROW_QPID_ERROR(
FRAMING_ERROR,
- (boost::format("Unknown frame type %d")%type).str());
+ boost::format("Unknown frame type %d") % type);
}
body->decode(buffer, size);
}
Modified: incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/ChannelAdapter.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/ChannelAdapter.cpp?view=diff&rev=501948&r1=501947&r2=501948
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/ChannelAdapter.cpp (original)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/ChannelAdapter.cpp Wed Jan 31 11:07:04 2007
@@ -15,10 +15,13 @@
* limitations under the License.
*
*/
+#include <boost/format.hpp>
#include "ChannelAdapter.h"
#include "AMQFrame.h"
+using boost::format;
+
namespace qpid {
namespace framing {
@@ -77,26 +80,22 @@
handleMethodInContext(method, context);
}
-void ChannelAdapter::assertMethodOk(AMQMethodBody& /*method*/) const {
- // No connection methods allowed on a non-zero channel
- // Subclass ChannelZero overrides for 0 channels.
- // FIXME aconway 2007-01-25: with ctors
-// assertChannelOpen();
-// if (method.amqpClassId() == ConnectionOpenBody::CLASS_ID)
-// throw ConnectionException(
-// 504, "Connection method on non-0 channel.");
+void ChannelAdapter::assertMethodOk(AMQMethodBody& method) const {
+ if (getId() != 0 && method.amqpClassId() == ConnectionOpenBody::CLASS_ID)
+ throw ConnectionException(
+ 504, format("Connection method on non-0 channel %d.")%getId());
}
void ChannelAdapter::assertChannelOpen() const {
- // FIXME aconway 2007-01-25: with ctors
-// if (!isOpen())
-// throw ConnectionException(504, "Channel is not open");
+ if (getId() != 0 && !isOpen())
+ throw ConnectionException(
+ 504, format("Channel %d is not open.")%getId());
}
void ChannelAdapter::assertChannelNotOpen() const {
- // FIXME aconway 2007-01-25: with ctors
-// if (isOpen())
-// throw ConnectionException(504, "Channel is already open");
+ if (getId() != 0 && isOpen())
+ throw ConnectionException(
+ 504, format("Channel %d is already open.") % getId());
}
}} // namespace qpid::framing
Modified: incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/ProtocolVersion.h
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/ProtocolVersion.h?view=diff&rev=501948&r1=501947&r2=501948
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/ProtocolVersion.h (original)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/ProtocolVersion.h Wed Jan 31 11:07:04 2007
@@ -32,7 +32,7 @@
{
private:
u_int8_t major_;
- u_int8_t minor_;
+ u_int8_t minor_;
public:
ProtocolVersion();
Modified: incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/ProtocolVersionException.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/ProtocolVersionException.cpp?view=diff&rev=501948&r1=501947&r2=501948
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/ProtocolVersionException.cpp (original)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/ProtocolVersionException.cpp Wed Jan 31 11:07:04 2007
@@ -18,49 +18,16 @@
* under the License.
*
*/
+#include <boost/format.hpp>
#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 ()
-{
-}
+using namespace qpid::framing;
-const char* ProtocolVersionException::what() const throw()
+void ProtocolVersionException::init(const std::string& msg)
{
- std::stringstream ss;
- ss << "ProtocolVersionException: AMQP Version " << versionFound.toString() << " found: " << whatStr;
- return ss.str().c_str();
+ whatStr = boost::str(
+ boost::format("ProtocolVersionException: %s found: %s")
+ % versionFound.toString() % msg);
}
-std::string ProtocolVersionException::toString() const throw()
-{
- std::stringstream ss;
- ss << "ProtocolVersionException: AMQP Version " << versionFound.toString() << " found: " << whatStr;
- return ss.str();
-}
Modified: incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/ProtocolVersionException.h
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/ProtocolVersionException.h?view=diff&rev=501948&r1=501947&r2=501948
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/ProtocolVersionException.h (original)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/ProtocolVersionException.h Wed Jan 31 11:07:04 2007
@@ -36,16 +36,20 @@
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
+ ~ProtocolVersionException() throw() {}
+
+ template <class T>
+ ProtocolVersionException(
+ const ProtocolVersion& ver, const T& msg) throw () : versionFound(ver)
+ { init(boost::lexical_cast<std::string>(msg)); }
+
+ template <class T>
+ ProtocolVersionException(const T& msg) throw ()
+ { init(boost::lexical_cast<std::string>(msg)); }
+
+ private:
+ void init(const std::string& msg);
+};
}} // namespace qpid::framing
Modified: incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/Requester.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/Requester.cpp?view=diff&rev=501948&r1=501947&r2=501948
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/Requester.cpp (original)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/Requester.cpp Wed Jan 31 11:07:04 2007
@@ -16,6 +16,8 @@
*
*/
+#include <boost/format.hpp>
+
#include "Requester.h"
#include "QpidError.h"
@@ -39,8 +41,9 @@
if (i != requests.end())
requests.erase(i);
else {
- // FIXME aconway 2007-01-16: Uncomment exception when ids are propagating.
-// THROW_QPID_ERROR(PROTOCOL_ERROR, "Invalid response.");
+ THROW_QPID_ERROR(
+ PROTOCOL_ERROR,
+ boost::format("Response with non-existent request id=%d")%id);
}
}
}