diff options
| author | Gordon Sim <gsim@apache.org> | 2008-04-24 21:07:34 +0000 |
|---|---|---|
| committer | Gordon Sim <gsim@apache.org> | 2008-04-24 21:07:34 +0000 |
| commit | 1c86294add5cbb640aac7f458c4de693de48dd9f (patch) | |
| tree | 22d7774e00c7514c4b76be5cf8b50727b74fe4e3 /cpp/src/qpid/client | |
| parent | 96f12949244b5af2b717156823309b66fe7bfb84 (diff) | |
| download | qpid-python-1c86294add5cbb640aac7f458c4de693de48dd9f.tar.gz | |
Generate c++ code from final 0-10 spec
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@651423 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/client')
| -rw-r--r-- | cpp/src/qpid/client/Channel.cpp | 5 | ||||
| -rw-r--r-- | cpp/src/qpid/client/ConnectionHandler.cpp | 1 | ||||
| -rw-r--r-- | cpp/src/qpid/client/ConnectionHandler.h | 6 | ||||
| -rw-r--r-- | cpp/src/qpid/client/ConnectionImpl.cpp | 11 | ||||
| -rw-r--r-- | cpp/src/qpid/client/Session.h | 4 | ||||
| -rw-r--r-- | cpp/src/qpid/client/SessionImpl.cpp | 26 | ||||
| -rw-r--r-- | cpp/src/qpid/client/SessionImpl.h | 25 |
7 files changed, 47 insertions, 31 deletions
diff --git a/cpp/src/qpid/client/Channel.cpp b/cpp/src/qpid/client/Channel.cpp index f32b5e2614..3bcba8983c 100644 --- a/cpp/src/qpid/client/Channel.cpp +++ b/cpp/src/qpid/client/Channel.cpp @@ -32,6 +32,7 @@ #include <boost/format.hpp> #include <boost/bind.hpp> #include "qpid/framing/all_method_bodies.h" +#include "qpid/framing/reply_exceptions.h" using namespace std; using namespace boost; @@ -75,7 +76,7 @@ void Channel::open(const Session& s) { Mutex::ScopedLock l(stopLock); if (isOpen()) - throw ChannelBusyException(); + throw SessionBusyException(); active = true; session = s; if(isTransactional()) { @@ -146,7 +147,7 @@ void Channel::consume( Mutex::ScopedLock l(lock); ConsumerMap::iterator i = consumers.find(tag); if (i != consumers.end()) - throw NotAllowedException(QPID_MSG("Consumer already exists with tag " << tag )); + throw PreconditionFailedException(QPID_MSG("Consumer already exists with tag " << tag )); Consumer& c = consumers[tag]; c.listener = listener; c.ackMode = ackMode; diff --git a/cpp/src/qpid/client/ConnectionHandler.cpp b/cpp/src/qpid/client/ConnectionHandler.cpp index 83cc357ded..df27942008 100644 --- a/cpp/src/qpid/client/ConnectionHandler.cpp +++ b/cpp/src/qpid/client/ConnectionHandler.cpp @@ -25,6 +25,7 @@ #include "qpid/framing/AMQP_HighestVersion.h" #include "qpid/framing/all_method_bodies.h" #include "qpid/framing/ClientInvoker.h" +#include "qpid/framing/reply_exceptions.h" using namespace qpid::client; using namespace qpid::framing; diff --git a/cpp/src/qpid/client/ConnectionHandler.h b/cpp/src/qpid/client/ConnectionHandler.h index 2ce36d6991..d7ab97ce31 100644 --- a/cpp/src/qpid/client/ConnectionHandler.h +++ b/cpp/src/qpid/client/ConnectionHandler.h @@ -55,9 +55,9 @@ class ConnectionHandler : private StateManager, public ConnectionProperties, public ChainableFrameHandler, public framing::InputHandler, - private framing::AMQP_ClientOperations::Connection010Handler + private framing::AMQP_ClientOperations::ConnectionHandler { - typedef framing::AMQP_ClientOperations::Connection010Handler ConnectionOperations; + typedef framing::AMQP_ClientOperations::ConnectionHandler ConnectionOperations; enum STATES {NOT_STARTED, NEGOTIATING, OPENING, OPEN, CLOSING, CLOSED, FAILED}; std::set<int> ESTABLISHED; @@ -70,7 +70,7 @@ class ConnectionHandler : private StateManager, }; Adapter outHandler; - framing::AMQP_ServerProxy::Connection010 proxy; + framing::AMQP_ServerProxy::Connection proxy; uint16_t errorCode; std::string errorText; diff --git a/cpp/src/qpid/client/ConnectionImpl.cpp b/cpp/src/qpid/client/ConnectionImpl.cpp index d1fd66ff26..ce95e43f58 100644 --- a/cpp/src/qpid/client/ConnectionImpl.cpp +++ b/cpp/src/qpid/client/ConnectionImpl.cpp @@ -32,6 +32,7 @@ using namespace qpid::client; using namespace qpid::framing; using namespace qpid::sys; +using namespace qpid::framing::connection;//for connection error codes ConnectionImpl::ConnectionImpl(boost::shared_ptr<Connector> c) : connector(c), isClosed(false), isClosing(false) @@ -39,7 +40,7 @@ ConnectionImpl::ConnectionImpl(boost::shared_ptr<Connector> c) handler.in = boost::bind(&ConnectionImpl::incoming, this, _1); handler.out = boost::bind(&Connector::send, connector, _1); handler.onClose = boost::bind(&ConnectionImpl::closed, this, - REPLY_SUCCESS, std::string()); + NORMAL, std::string()); handler.onError = boost::bind(&ConnectionImpl::closed, this, _1, _2); connector->setInputHandler(&handler); connector->setTimeoutHandler(this); @@ -57,7 +58,7 @@ void ConnectionImpl::addSession(const boost::shared_ptr<SessionImpl>& session) { Mutex::ScopedLock l(lock); boost::weak_ptr<SessionImpl>& s = sessions[session->getChannel()]; - if (s.lock()) throw ChannelBusyException(); + if (s.lock()) throw SessionBusyException(); s = session; } @@ -74,7 +75,7 @@ void ConnectionImpl::incoming(framing::AMQFrame& frame) s = sessions[frame.getChannel()].lock(); } if (!s) - throw ChannelErrorException(QPID_MSG("Invalid channel: " << frame.getChannel())); + throw NotAttachedException(QPID_MSG("Invalid channel: " << frame.getChannel())); s->in(frame); } @@ -113,7 +114,7 @@ void ConnectionImpl::close() Mutex::ScopedUnlock u(lock); handler.close(); } - closed(REPLY_SUCCESS, "Closed by client"); + closed(NORMAL, "Closed by client"); } // Set closed flags and erase the sessions map, but keep the contents @@ -149,7 +150,7 @@ void ConnectionImpl::shutdown() handler.fail(CONN_CLOSED); Mutex::ScopedUnlock u(lock); std::for_each(save.begin(), save.end(), - boost::bind(&SessionImpl::connectionBroke, _1, INTERNAL_ERROR, CONN_CLOSED)); + boost::bind(&SessionImpl::connectionBroke, _1, CONNECTION_FORCED, CONN_CLOSED)); } void ConnectionImpl::erase(uint16_t ch) { diff --git a/cpp/src/qpid/client/Session.h b/cpp/src/qpid/client/Session.h index 5d91f289e2..fc4175ef22 100644 --- a/cpp/src/qpid/client/Session.h +++ b/cpp/src/qpid/client/Session.h @@ -21,7 +21,7 @@ * under the License. * */ -#include "qpid/client/Session_99_0.h" +#include "qpid/client/Session_0_10.h" namespace qpid { namespace client { @@ -31,7 +31,7 @@ namespace client { * * \ingroup clientapi */ -typedef Session_99_0 Session; +typedef Session_0_10 Session; }} // namespace qpid::client diff --git a/cpp/src/qpid/client/SessionImpl.cpp b/cpp/src/qpid/client/SessionImpl.cpp index 4f3869319c..571d54df0c 100644 --- a/cpp/src/qpid/client/SessionImpl.cpp +++ b/cpp/src/qpid/client/SessionImpl.cpp @@ -30,16 +30,18 @@ #include "qpid/framing/FrameSet.h" #include "qpid/framing/MethodContent.h" #include "qpid/framing/SequenceSet.h" +#include "qpid/framing/reply_exceptions.h" #include "qpid/log/Statement.h" #include <boost/bind.hpp> -namespace { const std::string OK="ok"; } +namespace { const std::string EMPTY; } namespace qpid { namespace client { using namespace qpid::framing; +using namespace qpid::framing::session;//for detach codes typedef sys::Monitor::ScopedLock Lock; typedef sys::Monitor::ScopedUnlock UnLock; @@ -47,8 +49,9 @@ typedef sys::Monitor::ScopedUnlock UnLock; SessionImpl::SessionImpl(shared_ptr<ConnectionImpl> conn, uint16_t ch, uint64_t _maxFrameSize) - : code(REPLY_SUCCESS), - text(OK), + : error(OK), + code(NORMAL), + text(EMPTY), state(INACTIVE), syncMode(false), detachedLifetime(0), @@ -250,6 +253,7 @@ void SessionImpl::markCompleted(const SequenceNumber& id, bool cumulative, bool void SessionImpl::connectionClosed(uint16_t _code, const std::string& _text) { Lock l(state); + error = CONNECTION_CLOSE; code = _code; text = _text; setState(DETACHED); @@ -379,6 +383,7 @@ void SessionImpl::handleIn(AMQFrame& frame) // network thread //TODO: proper 0-10 exception handling QPID_LOG(error, "Session exception:" << e.what()); Lock l(state); + error = EXCEPTION; code = e.code; text = e.what(); } @@ -443,6 +448,7 @@ void SessionImpl::detached(const std::string& _name, uint8_t _code) //TODO: make sure this works with execution.exception - don't //want to overwrite the code from that QPID_LOG(error, "Session detached by peer: " << name << " " << code); + error = SESSION_DETACH; code = _code; text = "Session detached by peer"; } @@ -545,14 +551,14 @@ void SessionImpl::gap(const framing::SequenceSet& /*commands*/) void SessionImpl::sync() {} -void SessionImpl::result(uint32_t commandId, const std::string& value) +void SessionImpl::result(const framing::SequenceNumber& commandId, const std::string& value) { Lock l(state); results.received(commandId, value); } void SessionImpl::exception(uint16_t errorCode, - uint32_t commandId, + const framing::SequenceNumber& commandId, uint8_t classCode, uint8_t commandCode, uint8_t /*fieldIndex*/, @@ -563,6 +569,7 @@ void SessionImpl::exception(uint16_t errorCode, << " [caused by " << commandId << " " << classCode << ":" << commandCode << "]"); Lock l(state); + error = EXCEPTION; code = errorCode; text = description; if (detachedLifetime) { @@ -589,8 +596,11 @@ inline void SessionImpl::waitFor(State s) //call with lock held void SessionImpl::check() const //call with lock held. { - if (code != REPLY_SUCCESS) { - throwReplyException(code, text); + switch (error) { + case OK: break; + case CONNECTION_CLOSE: throw ConnectionException(code, text); + case SESSION_DETACH: throw ChannelException(code, text); + case EXCEPTION: throwExecutionException(code, text); } } @@ -598,7 +608,7 @@ void SessionImpl::checkOpen() const //call with lock held. { check(); if (state != ATTACHED) { - throwReplyException(0, "Session isn't attached"); + throw NotAttachedException("Session isn't attached"); } } diff --git a/cpp/src/qpid/client/SessionImpl.h b/cpp/src/qpid/client/SessionImpl.h index 86820dbb92..3b2e80fefd 100644 --- a/cpp/src/qpid/client/SessionImpl.h +++ b/cpp/src/qpid/client/SessionImpl.h @@ -54,8 +54,8 @@ class ConnectionImpl; class SessionImpl : public framing::FrameHandler::InOutHandler, public Execution, - private framing::AMQP_ClientOperations::Session010Handler, - private framing::AMQP_ClientOperations::Execution010Handler + private framing::AMQP_ClientOperations::SessionHandler, + private framing::AMQP_ClientOperations::ExecutionHandler { public: SessionImpl(shared_ptr<ConnectionImpl>, uint16_t channel, uint64_t maxFrameSize); @@ -95,6 +95,12 @@ public: void connectionBroke(uint16_t code, const std::string& text); private: + enum ErrorType { + OK, + CONNECTION_CLOSE, + SESSION_DETACH, + EXCEPTION + }; enum State { INACTIVE, ATTACHING, @@ -102,8 +108,8 @@ private: DETACHING, DETACHED }; - typedef framing::AMQP_ClientOperations::Session010Handler SessionHandler; - typedef framing::AMQP_ClientOperations::Execution010Handler ExecutionHandler; + typedef framing::AMQP_ClientOperations::SessionHandler SessionHandler; + typedef framing::AMQP_ClientOperations::ExecutionHandler ExecutionHandler; typedef sys::StateMonitor<State, DETACHED> StateMonitor; typedef StateMonitor::Set States; @@ -145,19 +151,16 @@ private: // Note: Following methods are called by network thread in // response to execution commands from the broker void sync(); - void result(uint32_t commandId, const std::string& value); + void result(const framing::SequenceNumber& commandId, const std::string& value); void exception(uint16_t errorCode, - uint32_t commandId, + const framing::SequenceNumber& commandId, uint8_t classCode, uint8_t commandCode, uint8_t fieldIndex, const std::string& description, const framing::FieldTable& errorInfo); - - //hack for old generator: - void commandPoint(uint32_t id, uint64_t offset) { commandPoint(framing::SequenceNumber(id), offset); } - + ErrorType error; int code; // Error code std::string text; // Error text mutable StateMonitor state; @@ -170,7 +173,7 @@ private: shared_ptr<ConnectionImpl> connection; framing::ChannelHandler channel; - framing::AMQP_ServerProxy::Session010 proxy; + framing::AMQP_ServerProxy::Session proxy; Results results; Demux demux; |
