summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2007-01-31 19:07:04 +0000
committerAlan Conway <aconway@apache.org>2007-01-31 19:07:04 +0000
commit9cdf50e9bbf4aae222600245691f9b1d3acb3147 (patch)
tree0784a9860824c0d144e1615ad1f655ac2dea5916
parent754f8903943233604661b91b53defe39120e6ad5 (diff)
downloadqpid-python-9cdf50e9bbf4aae222600245691f9b1d3acb3147.tar.gz
* 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. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/branches/qpid.0-9@501948 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--cpp/lib/broker/Configuration.h9
-rw-r--r--cpp/lib/client/Connection.cpp4
-rw-r--r--cpp/lib/client/Connection.h6
-rw-r--r--cpp/lib/client/ResponseHandler.cpp6
-rw-r--r--cpp/lib/common/Exception.h27
-rw-r--r--cpp/lib/common/QpidError.cpp18
-rw-r--r--cpp/lib/common/QpidError.h19
-rw-r--r--cpp/lib/common/framing/AMQFrame.cpp2
-rw-r--r--cpp/lib/common/framing/ChannelAdapter.cpp27
-rw-r--r--cpp/lib/common/framing/ProtocolVersion.h2
-rw-r--r--cpp/lib/common/framing/ProtocolVersionException.cpp45
-rw-r--r--cpp/lib/common/framing/ProtocolVersionException.h24
-rw-r--r--cpp/lib/common/framing/Requester.cpp7
13 files changed, 90 insertions, 106 deletions
diff --git a/cpp/lib/broker/Configuration.h b/cpp/lib/broker/Configuration.h
index 15f2117f5e..27c743c8f0 100644
--- a/cpp/lib/broker/Configuration.h
+++ b/cpp/lib/broker/Configuration.h
@@ -122,15 +122,16 @@ class Configuration{
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) {}
};
diff --git a/cpp/lib/client/Connection.cpp b/cpp/lib/client/Connection.cpp
index 78e340eb11..0b2859387f 100644
--- a/cpp/lib/client/Connection.cpp
+++ b/cpp/lib/client/Connection.cpp
@@ -32,7 +32,6 @@
using namespace qpid::framing;
using namespace qpid::sys;
-using namespace qpid::sys;
namespace qpid {
@@ -101,7 +100,6 @@ void Connection::close(
}
}
-// 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::erase(ChannelId id) {
}
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::channelException(
}
void Connection::idleIn(){
- std::cout << "Connection timed out due to abscence of heartbeat." << std::endl;
connector->close();
}
diff --git a/cpp/lib/client/Connection.h b/cpp/lib/client/Connection.h
index 6a9a76eed2..57286092af 100644
--- a/cpp/lib/client/Connection.h
+++ b/cpp/lib/client/Connection.h
@@ -88,7 +88,7 @@ class Connection : public ConnectionForChannel
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 @@ class Connection : public ConnectionForChannel
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 @@ class Connection : public ConnectionForChannel
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
diff --git a/cpp/lib/client/ResponseHandler.cpp b/cpp/lib/client/ResponseHandler.cpp
index 8950138f5e..ea234ac321 100644
--- a/cpp/lib/client/ResponseHandler.cpp
+++ b/cpp/lib/client/ResponseHandler.cpp
@@ -66,10 +66,8 @@ void ResponseHandler::receive(ClassId c, MethodId m) {
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());
}
}
diff --git a/cpp/lib/common/Exception.h b/cpp/lib/common/Exception.h
index 61bbc0ab5f..a07e85e7e3 100644
--- a/cpp/lib/common/Exception.h
+++ b/cpp/lib/common/Exception.h
@@ -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 @@ class Exception : public std::exception
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 @@ class Exception : public std::exception
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_) {}
};
diff --git a/cpp/lib/common/QpidError.cpp b/cpp/lib/common/QpidError.cpp
index 7f4f9e2f34..9cd3051d1e 100644
--- a/cpp/lib/common/QpidError.cpp
+++ b/cpp/lib/common/QpidError.cpp
@@ -19,6 +19,8 @@
*
*/
+#include <boost/format.hpp>
+
#include <QpidError.h>
#include <sstream>
@@ -26,19 +28,15 @@ using namespace qpid;
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);
+}
+
+
diff --git a/cpp/lib/common/QpidError.h b/cpp/lib/common/QpidError.h
index 30d9d27076..2a0395ab79 100644
--- a/cpp/lib/common/QpidError.h
+++ b/cpp/lib/common/QpidError.h
@@ -23,6 +23,7 @@
#include <string>
#include <memory>
#include <ostream>
+
#include <Exception.h>
namespace qpid {
@@ -36,17 +37,27 @@ struct SrcLine {
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();
};
diff --git a/cpp/lib/common/framing/AMQFrame.cpp b/cpp/lib/common/framing/AMQFrame.cpp
index f1461b6bb3..9c5e295e22 100644
--- a/cpp/lib/common/framing/AMQFrame.cpp
+++ b/cpp/lib/common/framing/AMQFrame.cpp
@@ -114,7 +114,7 @@ void AMQFrame::decodeBody(Buffer& buffer, uint32_t size)
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);
}
diff --git a/cpp/lib/common/framing/ChannelAdapter.cpp b/cpp/lib/common/framing/ChannelAdapter.cpp
index 653e47048e..ce59cbd0cc 100644
--- a/cpp/lib/common/framing/ChannelAdapter.cpp
+++ b/cpp/lib/common/framing/ChannelAdapter.cpp
@@ -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 @@ void ChannelAdapter::handleMethod(AMQMethodBody::shared_ptr method) {
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
diff --git a/cpp/lib/common/framing/ProtocolVersion.h b/cpp/lib/common/framing/ProtocolVersion.h
index 331cf53555..6aba87c6f5 100644
--- a/cpp/lib/common/framing/ProtocolVersion.h
+++ b/cpp/lib/common/framing/ProtocolVersion.h
@@ -32,7 +32,7 @@ class ProtocolVersion
{
private:
u_int8_t major_;
- u_int8_t minor_;
+ u_int8_t minor_;
public:
ProtocolVersion();
diff --git a/cpp/lib/common/framing/ProtocolVersionException.cpp b/cpp/lib/common/framing/ProtocolVersionException.cpp
index 8249a88f4b..9088422f6f 100644
--- a/cpp/lib/common/framing/ProtocolVersionException.cpp
+++ b/cpp/lib/common/framing/ProtocolVersionException.cpp
@@ -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();
-}
diff --git a/cpp/lib/common/framing/ProtocolVersionException.h b/cpp/lib/common/framing/ProtocolVersionException.h
index 32b5bc7ef4..aff0cd91d6 100644
--- a/cpp/lib/common/framing/ProtocolVersionException.h
+++ b/cpp/lib/common/framing/ProtocolVersionException.h
@@ -36,16 +36,20 @@ 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
+ ~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
diff --git a/cpp/lib/common/framing/Requester.cpp b/cpp/lib/common/framing/Requester.cpp
index 7e1da505c6..37b2d37c86 100644
--- a/cpp/lib/common/framing/Requester.cpp
+++ b/cpp/lib/common/framing/Requester.cpp
@@ -16,6 +16,8 @@
*
*/
+#include <boost/format.hpp>
+
#include "Requester.h"
#include "QpidError.h"
@@ -39,8 +41,9 @@ void Requester::processed(const AMQResponseBody::Data& response) {
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);
}
}
}