/home/aconway/svn/qpid/cpp/src/qpid/sys/apr/LFSessionContext.h

00001 /*
00002  *
00003  * Licensed to the Apache Software Foundation (ASF) under one
00004  * or more contributor license agreements.  See the NOTICE file
00005  * distributed with this work for additional information
00006  * regarding copyright ownership.  The ASF licenses this file
00007  * to you under the Apache License, Version 2.0 (the
00008  * "License"); you may not use this file except in compliance
00009  * with the License.  You may obtain a copy of the License at
00010  * 
00011  *   http://www.apache.org/licenses/LICENSE-2.0
00012  * 
00013  * Unless required by applicable law or agreed to in writing,
00014  * software distributed under the License is distributed on an
00015  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
00016  * KIND, either express or implied.  See the License for the
00017  * specific language governing permissions and limitations
00018  * under the License.
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

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