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
00023
00024
00025 #include <boost/ptr_container/ptr_deque.hpp>
00026
00027 #include "EventChannelThreads.h"
00028 #include "sys/Monitor.h"
00029 #include "sys/SessionContext.h"
00030 #include "sys/SessionHandler.h"
00031 #include "sys/AtomicCount.h"
00032 #include "framing/AMQFrame.h"
00033
00034 namespace qpid {
00035 namespace sys {
00036
00037 class SessionHandlerFactory;
00038
00046 class EventChannelConnection : public SessionContext {
00047 public:
00048 EventChannelConnection(
00049 EventChannelThreads::shared_ptr threads,
00050 SessionHandlerFactory& factory,
00051 int readDescriptor,
00052 int writeDescriptor = 0,
00053 bool isTrace = false
00054 );
00055
00056
00057 virtual void send(qpid::framing::AMQFrame* frame) {
00058 send(std::auto_ptr<qpid::framing::AMQFrame>(frame));
00059 }
00060
00061 virtual void send(std::auto_ptr<qpid::framing::AMQFrame> frame);
00062
00063 virtual void close();
00064
00065 private:
00066 typedef boost::ptr_deque<qpid::framing::AMQFrame> FrameQueue;
00067 typedef void (EventChannelConnection::*MemberFnPtr)();
00068 struct ScopedBusy;
00069
00070 void startWrite();
00071 void endWrite();
00072 void startRead();
00073 void endInitRead();
00074 void endRead();
00075 void closeNoThrow();
00076 void closeOnException(MemberFnPtr);
00077 bool shouldContinue(bool& flag);
00078
00079 static const size_t bufferSize;
00080
00081 Monitor monitor;
00082
00083 int readFd, writeFd;
00084 ReadEvent readEvent;
00085 WriteEvent writeEvent;
00086 Event::Callback readCallback;
00087 bool isWriting;
00088 bool isClosed;
00089 AtomicCount busyThreads;
00090
00091 EventChannelThreads::shared_ptr threads;
00092 std::auto_ptr<SessionHandler> handler;
00093 qpid::framing::Buffer in, out;
00094 FrameQueue writeFrames;
00095 bool isTrace;
00096
00097 friend struct ScopedBusy;
00098 };
00099
00100
00101 }}
00102
00103
00104
00105 #endif