/opt/workspace/qpid/tags/M2/Final/cpp/lib/client/Connector.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 _Connector_
00022 #define _Connector_
00023 
00024 
00025 #include <framing/InputHandler.h>
00026 #include <framing/OutputHandler.h>
00027 #include <framing/InitiationHandler.h>
00028 #include <framing/ProtocolInitiation.h>
00029 #include <ProtocolVersion.h>
00030 #include <sys/ShutdownHandler.h>
00031 #include <sys/TimeoutHandler.h>
00032 #include <sys/Thread.h>
00033 #include <sys/Monitor.h>
00034 #include <sys/Socket.h>
00035 
00036 namespace qpid {
00037 namespace client {
00038 
00039     class Connector : public qpid::framing::OutputHandler, 
00040                       private qpid::sys::Runnable
00041     {
00042         const bool debug;
00043         const int receive_buffer_size;
00044         const int send_buffer_size;
00045         qpid::framing::ProtocolVersion version;
00046 
00047         volatile bool closed;
00048 
00049         int64_t lastIn;
00050         int64_t lastOut;
00051         int64_t timeout;
00052         u_int32_t idleIn;
00053         u_int32_t idleOut;
00054 
00055         qpid::sys::TimeoutHandler* timeoutHandler;
00056         qpid::sys::ShutdownHandler* shutdownHandler;
00057         qpid::framing::InputHandler* input;
00058         qpid::framing::InitiationHandler* initialiser;
00059         qpid::framing::OutputHandler* output;
00060         
00061         qpid::framing::Buffer inbuf;
00062         qpid::framing::Buffer outbuf;
00063 
00064         qpid::sys::Mutex writeLock;
00065         qpid::sys::Thread receiver;
00066 
00067         qpid::sys::Socket socket;
00068         
00069         void checkIdle(ssize_t status);
00070         void writeBlock(qpid::framing::AMQDataBlock* data);
00071         void writeToSocket(char* data, size_t available);
00072         void setSocketTimeout();
00073 
00074         void run();
00075         void handleClosed();
00076         bool markClosed();
00077 
00078     public:
00079         Connector(const qpid::framing::ProtocolVersion& pVersion, bool debug = false, u_int32_t buffer_size = 1024);
00080         virtual ~Connector();
00081         virtual void connect(const std::string& host, int port, bool tcpNoDelay=false);
00082         virtual void init(qpid::framing::ProtocolInitiation* header);
00083         virtual void close();
00084         virtual void setInputHandler(qpid::framing::InputHandler* handler);
00085         virtual void setTimeoutHandler(qpid::sys::TimeoutHandler* handler);
00086         virtual void setShutdownHandler(qpid::sys::ShutdownHandler* handler);
00087         virtual qpid::framing::OutputHandler* getOutputHandler();
00088         virtual void send(qpid::framing::AMQFrame* frame);
00089         virtual void setReadTimeout(u_int16_t timeout);
00090         virtual void setWriteTimeout(u_int16_t timeout);
00091     };
00092 
00093 }
00094 }
00095 
00096 
00097 #endif

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