Panda3D
|
00001 // Filename: pStatServer.h 00002 // Created by: drose (09Jul00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef PSTATSERVER_H 00016 #define PSTATSERVER_H 00017 00018 #include "pandatoolbase.h" 00019 #include "pStatListener.h" 00020 #include "connectionManager.h" 00021 #include "vector_stdfloat.h" 00022 #include "pmap.h" 00023 #include "pdeque.h" 00024 00025 class PStatReader; 00026 00027 //////////////////////////////////////////////////////////////////// 00028 // Class : PStatServer 00029 // Description : The overall manager of the network connections. This 00030 // class gets the ball rolling; to use this package, you 00031 // need to derive from this and define make_monitor() to 00032 // allocate and return a PStatMonitor of the suitable 00033 // type. 00034 // 00035 // Then create just one PStatServer object and call 00036 // listen() with the port(s) you would like to listen 00037 // on. It will automatically create PStatMonitors as 00038 // connections are established and mark the connections 00039 // closed as they are lost. 00040 //////////////////////////////////////////////////////////////////// 00041 class PStatServer : public ConnectionManager { 00042 public: 00043 PStatServer(); 00044 ~PStatServer(); 00045 00046 bool listen(int port = -1); 00047 00048 void poll(); 00049 void main_loop(bool *interrupt_flag = NULL); 00050 00051 virtual PStatMonitor *make_monitor()=0; 00052 void add_reader(Connection *connection, PStatReader *reader); 00053 void remove_reader(Connection *connection, PStatReader *reader); 00054 00055 int get_udp_port(); 00056 void release_udp_port(int port); 00057 00058 int get_num_user_guide_bars() const; 00059 double get_user_guide_bar_height(int n) const; 00060 void move_user_guide_bar(int n, double height); 00061 int add_user_guide_bar(double height); 00062 void remove_user_guide_bar(int n); 00063 int find_user_guide_bar(double from_height, double to_height) const; 00064 00065 virtual bool is_thread_safe(); 00066 00067 protected: 00068 virtual void connection_reset(const PT(Connection) &connection, 00069 bool okflag); 00070 00071 private: 00072 void user_guide_bars_changed(); 00073 00074 PStatListener *_listener; 00075 00076 typedef pmap<PT(Connection), PStatReader *> Readers; 00077 Readers _readers; 00078 typedef pvector<PStatReader *> LostReaders; 00079 LostReaders _lost_readers; 00080 LostReaders _removed_readers; 00081 00082 typedef pdeque<int> Ports; 00083 Ports _available_udp_ports; 00084 int _next_udp_port; 00085 00086 typedef vector_stdfloat GuideBars; 00087 GuideBars _user_guide_bars; 00088 }; 00089 00090 #endif