/opt/workspace/qpid/tags/M2/Final/cpp/lib/common/sys/posix/EventChannelConnection.h

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

Generated on Mon Nov 26 19:13:17 2007 for Qpid by  doxygen 1.5.1