00001 #ifndef _posix_EventChannelConnection_h
00002 #define _posix_EventChannelConnection_h
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
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 }}
00099
00100
00101
00102 #endif