Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

BaseConnection.h

00001 #ifndef ERIS_BASE_CONNECTION_H
00002 #define ERIS_BASE_CONNECTION_H
00003 
00004 #include <iostream>
00005 #include <Atlas/Message/Object.h>
00006 #include <Atlas/Codec.h>
00007 
00008 #include <sigc++/object.h>
00009 #if SIGC_MAJOR_VERSION == 1 && SIGC_MINOR_VERSION == 0
00010 #include <sigc++/basic_signal.h>
00011 #else
00012 #include <sigc++/signal.h>
00013 #endif
00014 
00015 #include <Eris/Types.h>
00016 
00017 // Forward declarations
00018 namespace Atlas {
00019         namespace Objects { class Encoder; }
00020         namespace Net { class StreamConnect; }
00021         namespace Message { class Encoder; }
00022 }       
00023 
00024 // Forward declaration of the skstream type
00025 class tcp_socket_stream;
00026 
00027 namespace Eris
00028 {
00029 
00030 // Forward declarations 
00031 class Timeout;  
00032         
00034 class BaseConnection : 
00035         virtual public SigC::Object
00036 {
00037 public:
00039         virtual ~BaseConnection();
00040 
00043         virtual void connect(const std::string &host, short port);
00044 
00046         typedef enum {
00047                 INVALID_STATUS = 0,     
00048                 NEGOTIATE,              
00049                 CONNECTING,             
00050                 CONNECTED,              
00051                 DISCONNECTED,           
00052                 DISCONNECTING,          
00053                 
00054                 // doesn't really belong here, but enums aren't subclassable
00055                 QUERY_GET               
00056         } Status;
00057 
00059         Status getStatus() const
00060         { return _status; }
00061         
00063         bool isConnected() const
00064         { return (_status == CONNECTED) || (_status == DISCONNECTING);}
00065         
00069         int getFileDescriptor();
00070         
00072         SigC::Signal0<void> Connected;
00073         
00075         SigC::Signal0<void> Disconnected;
00076 protected:
00078 
00081         BaseConnection(const std::string &cnm, const std::string &id, Atlas::Bridge *br);       
00082 
00084         void recv();
00085 
00087         virtual void setStatus(Status sc);
00088 
00090         virtual void onConnect();
00091 
00093         virtual void handleFailure(const std::string &msg) = 0;
00094 
00096         virtual void bindTimeout(Timeout &t, Status sc) = 0;
00097 
00100         void hardDisconnect(bool emit);
00101 
00103     void nonblockingConnect();
00104 
00106         void pollNegotiation();
00107 
00108         Atlas::Objects::Encoder* _encode;       
00109         Atlas::Message::Encoder* _msgEncode;    
00110         Atlas::Net::StreamConnect* _sc;         
00111         Atlas::Codec<std::iostream>* _codec;            
00112 
00113         Status _status;                 
00114         const std::string _id;  
00115         
00116         tcp_socket_stream* _stream;             
00117         std::string _clientName;                
00118         
00121         Atlas::Bridge* _bridge; 
00122         Timeout* _timeout;              
00123         
00124     std::string _host;  
00125     short _port;        
00126 };
00127                 
00128 }       
00129 
00130 #endif
00131 

Generated on Thu May 22 08:01:02 2003 for Eris by doxygen1.3-rc3