Main Page | Class List | File List | Class Members | File Members

PingTarget.h

Go to the documentation of this file.
00001 // PingTarget.h
00002 
00003 #include <windows.h>
00004 #include <vector>
00005 #include <iosfwd>
00006 
00007 class PingTargets;
00008 
00015 class PingTarget
00016 {
00017 public:
00019   const char* GetName() const { return m_sName.c_str(); }
00021   const char* GetIpAddr() const;
00023   in_addr GetInetAddr() const { return m_inetAddr; }
00025   long GetId() const { return m_lId; }
00027   USHORT MakeSequence(long sequence) const;
00028   bool IsResponseAdded() const { return m_bResponseAdded; }
00030   long GetReceived() const { return m_lReceived; }
00032   long GetSkipped() const { return m_lSkipped; }
00034   long GetResponseCount() const { return m_lReceived+m_lSkipped; }
00039   double GetCurrent() const { return m_dCurrent; }
00041   double GetMin() const;
00043   double GetMax() const;
00045   double GetAvg() const;
00047   double GetStdDev() const;
00049   double GetSkippedPercent() const;
00050 
00051   friend std::ostream& operator << (std::ostream& os, const PingTarget& t);
00052 protected:
00053   PingTarget(PingTargets& targets, const char* name, in_addr inetAddr, long id);
00058   void AddResponseTime(double ms=-1.0);
00060   void ClearResponseFlag();
00061 
00062   std::string m_sName;
00063   in_addr m_inetAddr;
00064   long m_lId;
00066   bool m_bResponseAdded;
00067 
00069   long m_lReceived;
00071   long m_lSkipped;
00072 
00074   double m_dCurrent;
00076   double m_dMin;
00078   double m_dMax;
00080   double m_dSum;
00082   double m_dSumSquares;
00083 
00084   PingTargets& m_targets;
00085   friend class PingTargets;
00086 private:
00087   // Nobody should be allowed to do this
00088   PingTarget &operator=(PingTarget &);
00089 };
00090 
00095 class PingTargets
00096 {
00097 public:
00098   PingTargets();
00102   ~PingTargets();
00109   PingTarget* AddTarget(const char* name);
00114   bool AddTargets(std::istream& is);
00119   bool AddTargets(const char* pszFilename);
00121   long GetMaxTargets() const;
00123   PingTarget* Get(long id) const;
00129   bool AddResponse(long id, double ms);
00131   void ClearResponseFlags();
00133   void AddUnreachableResponses();
00138   long GetTargetId(USHORT sequence) const;
00143   long GetSequence(USHORT sequence) const;
00145   USHORT MakeSequence(long lId, long lSequence) const;
00147   long GetMaxSequence() const { return m_lSequenceMax; }
00148 
00149   typedef std::vector<PingTarget*>::const_iterator const_iterator;
00150   const_iterator begin() const { return m_targets.begin(); }
00151   const_iterator end() const { return m_targets.end(); }
00152   size_t size() const { return m_targets.size(); }
00153 
00155   void PrintStatisticsHeader(std::ostream& os, long lConsoleWidth=79) const;
00157   void PrintStatistics(std::ostream& os, long lConsoleWidth=79) const;
00162   void PrintLogHeader(std::ostream& os) const;
00167   void PrintLogCurrent(std::ostream& os, const SYSTEMTIME& systemtime) const;
00178   enum LOG_FILENAME_TYPE { LOG_FILENAME_PLAIN, LOG_FILENAME_DAILY, LOG_FILENAME_HOURLY };
00185   bool PrintLogCurrent(const char* pszFilename, const SYSTEMTIME& systemtime,
00186     LOG_FILENAME_TYPE FilenameType = LOG_FILENAME_PLAIN, bool bNewFile=false) const;
00188   long GetMaxNameWidth() const { return m_lMaxNameWidth; }
00189 
00190   friend std::ostream& operator << (std::ostream& os, const PingTargets& targets);
00191 protected:
00197   long m_lIdBits;
00199   long m_lIdMax;
00201   long m_lSequenceBits;
00203   USHORT m_uIdMask;
00205   USHORT m_uSeqMask;
00207   long m_lSequenceMax;
00209   long m_lMaxNameWidth;
00210 
00211   typedef std::vector<PingTarget*>::iterator iterator;
00212   std::vector<PingTarget*> m_targets;
00213 };

Generated on Sun Jun 26 13:43:46 2005 for pingem by  doxygen 1.4.3