00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _LFSessionContext_
00022 #define _LFSessionContext_
00023
00024 #include <queue>
00025
00026 #include <apr_network_io.h>
00027 #include <apr_poll.h>
00028 #include <apr_time.h>
00029
00030 #include "qpid/framing/AMQFrame.h"
00031 #include "qpid/framing/Buffer.h"
00032 #include "qpid/sys/Monitor.h"
00033 #include "qpid/sys/ConnectionOutputHandler.h"
00034 #include "qpid/sys/ConnectionInputHandler.h"
00035
00036 #include "APRSocket.h"
00037 #include "LFProcessor.h"
00038
00039 namespace qpid {
00040 namespace sys {
00041
00042
00043 class LFSessionContext : public virtual qpid::sys::ConnectionOutputHandler
00044 {
00045 const bool debug;
00046 APRSocket socket;
00047 bool initiated;
00048
00049 qpid::framing::Buffer in;
00050 qpid::framing::Buffer out;
00051
00052 qpid::sys::ConnectionInputHandler* handler;
00053 LFProcessor* const processor;
00054
00055 apr_pollfd_t fd;
00056
00057 std::queue<qpid::framing::AMQFrame*> framesToWrite;
00058 qpid::sys::Mutex writeLock;
00059
00060 bool processing;
00061 bool closing;
00062
00063 static qpid::sys::Mutex logLock;
00064 void log(const std::string& desc,
00065 qpid::framing::AMQFrame* const frame);
00066
00067
00068 public:
00069 LFSessionContext(apr_pool_t* pool, apr_socket_t* socket,
00070 LFProcessor* const processor,
00071 bool debug = false);
00072 virtual ~LFSessionContext();
00073 virtual void send(qpid::framing::AMQFrame* frame);
00074 virtual void close();
00075 void read();
00076 void write();
00077 void init(qpid::sys::ConnectionInputHandler* handler);
00078 void startProcessing();
00079 void stopProcessing();
00080 void handleClose();
00081 void shutdown();
00082 inline apr_pollfd_t* const getFd(){ return &fd; }
00083 inline bool isClosed(){ return !socket.isOpen(); }
00084 };
00085
00086 }
00087 }
00088
00089
00090 #endif