00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _ConnectionHandler_
00022 #define _ConnectionHandler_
00023
00024 #include "Connector.h"
00025 #include "StateManager.h"
00026 #include "ChainableFrameHandler.h"
00027 #include "qpid/framing/InputHandler.h"
00028 #include "qpid/framing/FieldTable.h"
00029 #include "qpid/framing/AMQMethodBody.h"
00030
00031 namespace qpid {
00032 namespace client {
00033
00034 struct ConnectionProperties
00035 {
00036 std::string uid;
00037 std::string pwd;
00038 std::string vhost;
00039 framing::FieldTable properties;
00040 std::string mechanism;
00041 std::string locale;
00042 std::string capabilities;
00043 uint16_t heartbeat;
00044 uint16_t maxChannels;
00045 uint64_t maxFrameSize;
00046 bool insist;
00047 framing::ProtocolVersion version;
00048 };
00049
00050 class ConnectionHandler : private StateManager,
00051 public ConnectionProperties,
00052 public ChainableFrameHandler,
00053 public framing::InputHandler
00054 {
00055 enum STATES {NOT_STARTED, NEGOTIATING, OPENING, OPEN, CLOSING, CLOSED, FAILED};
00056 std::set<int> ESTABLISHED;
00057
00058 void handle(framing::AMQMethodBody* method);
00059 void send(const framing::AMQBody& body);
00060 void error(uint16_t code, const std::string& message, uint16_t classId = 0, uint16_t methodId = 0);
00061 void error(uint16_t code, const std::string& message, framing::AMQBody* body);
00062
00063 public:
00064 using InputHandler::handle;
00065 typedef boost::function<void()> CloseListener;
00066 typedef boost::function<void(uint16_t, const std::string&)> ErrorListener;
00067
00068 ConnectionHandler();
00069
00070 void received(framing::AMQFrame& f) { incoming(f); }
00071
00072 void incoming(framing::AMQFrame& frame);
00073 void outgoing(framing::AMQFrame& frame);
00074
00075 void waitForOpen();
00076 void close();
00077 void fail(const std::string& message);
00078
00079 CloseListener onClose;
00080 ErrorListener onError;
00081 };
00082
00083 }}
00084
00085 #endif