/home/aconway/svn/qpid/cpp/src/qpid/framing/ChannelAdapter.h

00001 #ifndef _ChannelAdapter_
00002 #define _ChannelAdapter_
00003 
00004 /*
00005  *
00006  * Licensed to the Apache Software Foundation (ASF) under one
00007  * or more contributor license agreements.  See the NOTICE file
00008  * distributed with this work for additional information
00009  * regarding copyright ownership.  The ASF licenses this file
00010  * to you under the Apache License, Version 2.0 (the
00011  * "License"); you may not use this file except in compliance
00012  * with the License.  You may obtain a copy of the License at
00013  * 
00014  *   http://www.apache.org/licenses/LICENSE-2.0
00015  * 
00016  * Unless required by applicable law or agreed to in writing,
00017  * software distributed under the License is distributed on an
00018  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
00019  * KIND, either express or implied.  See the License for the
00020  * specific language governing permissions and limitations
00021  * under the License.
00022  *
00023  */
00024 
00025 #include "qpid/shared_ptr.h"
00026 #include "BodyHandler.h"
00027 #include "Requester.h"
00028 #include "Responder.h"
00029 #include "Correlator.h"
00030 #include "amqp_types.h"
00031 
00032 namespace qpid {
00033 namespace framing {
00034 
00035 class MethodContext;
00036 
00037 // FIXME aconway 2007-02-20: Rename as ChannelBase or just Channel.
00038 
00053 class ChannelAdapter : public BodyHandler {
00054   public:
00058     ChannelAdapter(ChannelId id_=0, OutputHandler* out_=0,
00059                    ProtocolVersion ver=ProtocolVersion())
00060         : id(id_), out(out_), version(ver)  {}
00061 
00063     void init(ChannelId, OutputHandler&, ProtocolVersion);
00064 
00065     ChannelId getId() const { return id; }
00066     ProtocolVersion getVersion() const { return version; }
00067 
00075     RequestId send(shared_ptr<AMQBody> body,
00076                    Correlator::Action action=Correlator::Action());
00077 
00078     // TODO aconway 2007-04-05:  remove and use make_shared_ptr at call sites.
00080     RequestId send(AMQBody* body) { return send(AMQBody::shared_ptr(body)); }
00081 
00082     void handleMethod(shared_ptr<AMQMethodBody>);
00083     void handleRequest(shared_ptr<AMQRequestBody>);
00084     void handleResponse(shared_ptr<AMQResponseBody>);
00085 
00086     virtual bool isOpen() const = 0;
00087     
00088   protected:
00089     void assertMethodOk(AMQMethodBody& method) const;
00090     void assertChannelOpen() const;
00091     void assertChannelNotOpen() const;
00092 
00093     virtual void handleMethodInContext(
00094         shared_ptr<AMQMethodBody> method,
00095         const MethodContext& context) = 0;
00096 
00097     RequestId getFirstAckRequest() { return requester.getFirstAckRequest(); }
00098     RequestId getLastAckRequest() { return requester.getLastAckRequest(); }
00099     RequestId getNextSendRequestId() { return requester.getNextId(); }
00100 
00101   private:
00102     ChannelId id;
00103     OutputHandler* out;
00104     ProtocolVersion version;
00105     Requester requester;
00106     Responder responder;
00107     Correlator correlator;
00108 };
00109 
00110 }}
00111 
00112 
00113 #endif

Generated on Tue Apr 17 14:22:03 2007 for Qpid by  doxygen 1.4.7