pStatClientImpl.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // Filename: pStatClientImpl.h
  2. // Created by: drose (23Dec04)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) Carnegie Mellon University. All rights reserved.
  8. //
  9. // All use of this software is subject to the terms of the revised BSD
  10. // license. You should have received a copy of this license along
  11. // with this source code in a file named "LICENSE."
  12. //
  13. ////////////////////////////////////////////////////////////////////
  14. #ifndef PSTATCLIENTIMPL_H
  15. #define PSTATCLIENTIMPL_H
  16. #include "pandabase.h"
  17. // This class doesn't exist at all unless DO_PSTATS is defined.
  18. #ifdef DO_PSTATS
  19. #include "pStatFrameData.h"
  20. #include "connectionManager.h"
  21. #include "queuedConnectionReader.h"
  22. #include "connectionWriter.h"
  23. #include "netAddress.h"
  24. #include "trueClock.h"
  25. #include "pmap.h"
  26. class PStatClient;
  27. class PStatServerControlMessage;
  28. class PStatCollector;
  29. class PStatCollectorDef;
  30. class PStatThread;
  31. ////////////////////////////////////////////////////////////////////
  32. // Class : PStatClientImpl
  33. // Description : This class is the implementation of the actual
  34. // PStatClient class (which is just for interface). All
  35. // of the stuff to manage sending stats up to the server
  36. // is handled by this class.
  37. //
  38. // This separation between PStatClient and
  39. // PStatClientImpl allows the global PStatClient to be
  40. // constructed at static init time, without having to
  41. // consult any config variables at that time. We don't
  42. // actually do any real work until someone explicitly
  43. // calls PStatClient::connect().
  44. //
  45. // This class doesn't exist at all unless DO_PSTATS is
  46. // defined.
  47. ////////////////////////////////////////////////////////////////////
  48. class EXPCL_PANDA_PSTATCLIENT PStatClientImpl : public ConnectionManager {
  49. public:
  50. PStatClientImpl(PStatClient *client);
  51. ~PStatClientImpl();
  52. INLINE void set_client_name(const string &name);
  53. INLINE string get_client_name() const;
  54. INLINE void set_max_rate(double rate);
  55. INLINE double get_max_rate() const;
  56. INLINE double get_real_time() const;
  57. INLINE void client_main_tick();
  58. bool client_connect(string hostname, int port);
  59. void client_disconnect();
  60. INLINE bool client_is_connected() const;
  61. INLINE void client_resume_after_pause();
  62. void new_frame(int thread_index);
  63. private:
  64. void transmit_frame_data(int thread_index, int frame_number,
  65. const PStatFrameData &frame_data);
  66. void transmit_control_data();
  67. TrueClock *_clock;
  68. double _delta;
  69. double _last_frame;
  70. // Networking stuff
  71. string get_hostname();
  72. void send_hello();
  73. void report_new_collectors();
  74. void report_new_threads();
  75. void handle_server_control_message(const PStatServerControlMessage &message);
  76. virtual void connection_reset(const PT(Connection) &connection,
  77. bool okflag);
  78. PStatClient *_client;
  79. bool _is_connected;
  80. bool _got_udp_port;
  81. NetAddress _server;
  82. QueuedConnectionReader _reader;
  83. ConnectionWriter _writer;
  84. PT(Connection) _tcp_connection;
  85. PT(Connection) _udp_connection;
  86. int _collectors_reported;
  87. int _threads_reported;
  88. string _hostname;
  89. string _client_name;
  90. double _max_rate;
  91. double _tcp_count_factor;
  92. double _udp_count_factor;
  93. unsigned int _tcp_count;
  94. unsigned int _udp_count;
  95. };
  96. #include "pStatClientImpl.I"
  97. #endif // DO_PSTATS
  98. #endif