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

panda/src/net/connectionManager.h

Go to the documentation of this file.
00001 // Filename: connectionManager.h
00002 // Created by:  jns (07Feb00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifndef CONNECTIONMANAGER_H
00020 #define CONNECTIONMANAGER_H
00021 
00022 #include <pandabase.h>
00023 
00024 #include "netDatagram.h"
00025 #include "connection.h"
00026 
00027 #include <pointerTo.h>
00028 
00029 #include <prlock.h>
00030 #include "pset.h"
00031 
00032 class NetAddress;
00033 class ConnectionReader;
00034 class ConnectionWriter;
00035 
00036 ////////////////////////////////////////////////////////////////////
00037 //       Class : ConnectionManager
00038 // Description : The primary interface to the low-level networking
00039 //               layer in this package.  A ConnectionManager is used
00040 //               to establish and destroy TCP and UDP connections.
00041 //               Communication on these connections, once established,
00042 //               is handled via ConnectionReader, ConnectionWriter,
00043 //               and ConnectionListener.
00044 //
00045 //               This is actually an abstract class, since it does not
00046 //               define what to do when a connection is externally
00047 //               reset (i.e. closed on the other end, or dropped
00048 //               because of network errors).  See
00049 //               QueuedConnectionManager.
00050 ////////////////////////////////////////////////////////////////////
00051 class EXPCL_PANDA ConnectionManager {
00052 PUBLISHED:
00053   ConnectionManager();
00054   virtual ~ConnectionManager();
00055 
00056   PT(Connection) open_UDP_connection(int port = 0);
00057 
00058   PT(Connection) open_TCP_server_rendezvous(int port, int backlog);
00059   PT(Connection) open_TCP_client_connection(const NetAddress &address,
00060                                             int timeout_ms);
00061   PT(Connection) open_TCP_client_connection(const string &hostname, int port,
00062                                             int timeout_ms);
00063 
00064   bool close_connection(const PT(Connection) &connection);
00065 
00066   static string get_host_name();
00067 
00068 protected:
00069   void new_connection(const PT(Connection) &connection);
00070   virtual void connection_reset(const PT(Connection) &connection)=0;
00071 
00072   void add_reader(ConnectionReader *reader);
00073   void remove_reader(ConnectionReader *reader);
00074   void add_writer(ConnectionWriter *writer);
00075   void remove_writer(ConnectionWriter *writer);
00076 
00077   typedef pset< PT(Connection) > Connections;
00078   typedef pset<ConnectionReader *> Readers;
00079   typedef pset<ConnectionWriter *> Writers;
00080   Connections _connections;
00081   Readers _readers;
00082   Writers _writers;
00083   PRLock *_set_mutex;
00084 
00085 private:
00086   friend class ConnectionReader;
00087   friend class ConnectionWriter;
00088   friend class ConnectionListener;
00089   friend class Connection;
00090 };
00091 
00092 #endif

Generated on Fri May 2 00:40:33 2003 for Panda by doxygen1.3