/home/aconway/svn/qpid/cpp/src/qpid/sys/posix/EventChannelConnection.h

00001 #ifndef _posix_EventChannelConnection_h
00002 #define _posix_EventChannelConnection_h
00003 
00004 /*
00005  *
00006  * Copyright (c) 2006 The Apache Software Foundation
00007  *
00008  * Licensed under the Apache License, Version 2.0 (the "License");
00009  * you may not use this file except in compliance with the License.
00010  * You may obtain a copy of the License at
00011  *
00012  *    http://www.apache.org/licenses/LICENSE-2.0
00013  *
00014  * Unless required by applicable law or agreed to in writing, software
00015  * distributed under the License is distributed on an "AS IS" BASIS,
00016  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00017  * See the License for the specific language governing permissions and
00018  * limitations under the License.
00019  *
00020  */
00021 
00022 #include <boost/ptr_container/ptr_deque.hpp>
00023 
00024 #include "EventChannelThreads.h"
00025 #include "qpid/sys/Monitor.h"
00026 #include "qpid/sys/ConnectionOutputHandler.h"
00027 #include "qpid/sys/ConnectionInputHandler.h"
00028 #include "qpid/sys/AtomicCount.h"
00029 #include "qpid/framing/AMQFrame.h"
00030 
00031 namespace qpid {
00032 namespace sys {
00033 
00034 class ConnectionInputHandlerFactory;
00035 
00043 class EventChannelConnection : public ConnectionOutputHandler {
00044   public:
00045     EventChannelConnection(
00046         EventChannelThreads::shared_ptr threads, 
00047         ConnectionInputHandlerFactory& factory,
00048         int readDescriptor, 
00049         int writeDescriptor = 0,
00050         bool isTrace = false
00051     );
00052 
00053     // TODO aconway 2006-11-30: ConnectionOutputHandler::send should take auto_ptr
00054     virtual void send(qpid::framing::AMQFrame* frame) {
00055         send(std::auto_ptr<qpid::framing::AMQFrame>(frame));
00056     }
00057             
00058     virtual void send(std::auto_ptr<qpid::framing::AMQFrame> frame);
00059 
00060     virtual void close();
00061 
00062   private:
00063     typedef boost::ptr_deque<qpid::framing::AMQFrame> FrameQueue;
00064     typedef void (EventChannelConnection::*MemberFnPtr)();
00065     struct ScopedBusy;
00066 
00067     void startWrite();
00068     void endWrite();
00069     void startRead();
00070     void endInitRead();
00071     void endRead();
00072     void closeNoThrow();
00073     void closeOnException(MemberFnPtr);
00074     bool shouldContinue(bool& flag);
00075 
00076     static const size_t bufferSize;
00077 
00078     Monitor monitor;
00079 
00080     int readFd, writeFd;
00081     ReadEvent readEvent;
00082     WriteEvent writeEvent;
00083     Event::Callback readCallback;
00084     bool isWriting;
00085     bool isClosed;
00086     AtomicCount busyThreads;
00087 
00088     EventChannelThreads::shared_ptr threads;
00089     std::auto_ptr<ConnectionInputHandler> handler;
00090     qpid::framing::Buffer in, out;
00091     FrameQueue writeFrames;
00092     bool isTrace;
00093     
00094   friend struct ScopedBusy;
00095 };
00096     
00097 
00098 }} // namespace qpid::sys
00099 
00100 
00101 
00102 #endif  

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