00001 // Filename: pStatServer.h 00002 // Created by: drose (09Jul00) 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 PSTATSERVER_H 00020 #define PSTATSERVER_H 00021 00022 #include <pandatoolbase.h> 00023 00024 #include "pStatListener.h" 00025 00026 #include <connectionManager.h> 00027 00028 #include "pmap.h" 00029 #include "pdeque.h" 00030 00031 class PStatReader; 00032 00033 //////////////////////////////////////////////////////////////////// 00034 // Class : PStatServer 00035 // Description : The overall manager of the network connections. This 00036 // class gets the ball rolling; to use this package, you 00037 // need to derive from this and define make_monitor() to 00038 // allocate and return a PStatMonitor of the suitable 00039 // type. 00040 // 00041 // Then create just one PStatServer object and call 00042 // listen() with the port(s) you would like to listen 00043 // on. It will automatically create PStatMonitors as 00044 // connections are established and mark the connections 00045 // closed as they are lost. 00046 //////////////////////////////////////////////////////////////////// 00047 class PStatServer : public ConnectionManager { 00048 public: 00049 PStatServer(); 00050 ~PStatServer(); 00051 00052 bool listen(int port = -1); 00053 00054 void poll(); 00055 void main_loop(bool *interrupt_flag = NULL); 00056 00057 virtual PStatMonitor *make_monitor()=0; 00058 void add_reader(Connection *connection, PStatReader *reader); 00059 void remove_reader(Connection *connection, PStatReader *reader); 00060 00061 int get_udp_port(); 00062 void release_udp_port(int port); 00063 00064 virtual bool is_thread_safe(); 00065 00066 private: 00067 virtual void connection_reset(const PT(Connection) &connection); 00068 00069 PStatListener *_listener; 00070 00071 typedef pmap<PT(Connection), PStatReader *> Readers; 00072 Readers _readers; 00073 typedef pvector<PStatReader *> LostReaders; 00074 LostReaders _lost_readers; 00075 LostReaders _removed_readers; 00076 00077 typedef pdeque<int> Ports; 00078 Ports _available_udp_ports; 00079 int _next_udp_port; 00080 }; 00081 00082 #endif