/usr/share/cruisecontrol-bin-2.6.1/projects/qpid-trunk/cpp/src/qpid/client/ConnectionHandler.h

00001 /*
00002  *
00003  * Licensed to the Apache Software Foundation (ASF) under one
00004  * or more contributor license agreements.  See the NOTICE file
00005  * distributed with this work for additional information
00006  * regarding copyright ownership.  The ASF licenses this file
00007  * to you under the Apache License, Version 2.0 (the
00008  * "License"); you may not use this file except in compliance
00009  * with the License.  You may obtain a copy of the License at
00010  * 
00011  *   http://www.apache.org/licenses/LICENSE-2.0
00012  * 
00013  * Unless required by applicable law or agreed to in writing,
00014  * software distributed under the License is distributed on an
00015  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
00016  * KIND, either express or implied.  See the License for the
00017  * specific language governing permissions and limitations
00018  * under the License.
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

Generated on Thu Apr 10 11:08:17 2008 for Qpid by  doxygen 1.4.7