StatisticsDb.hxx
上传用户:sy_wanhua
上传日期:2013-07-25
资源大小:3048k
文件大小:6k
源码类别:

流媒体/Mpeg4/MP4

开发平台:

C/C++

  1. #if !defined(STATISTICS_DB_DOT_HXX)
  2. #define STATISTICS_DB_DOT_HXX
  3. /* ====================================================================
  4.  * The Vovida Software License, Version 1.0 
  5.  * 
  6.  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
  7.  * 
  8.  * Redistribution and use in source and binary forms, with or without
  9.  * modification, are permitted provided that the following conditions
  10.  * are met:
  11.  * 
  12.  * 1. Redistributions of source code must retain the above copyright
  13.  *    notice, this list of conditions and the following disclaimer.
  14.  * 
  15.  * 2. Redistributions in binary form must reproduce the above copyright
  16.  *    notice, this list of conditions and the following disclaimer in
  17.  *    the documentation and/or other materials provided with the
  18.  *    distribution.
  19.  * 
  20.  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
  21.  *    and "Vovida Open Communication Application Library (VOCAL)" must
  22.  *    not be used to endorse or promote products derived from this
  23.  *    software without prior written permission. For written
  24.  *    permission, please contact vocal@vovida.org.
  25.  *
  26.  * 4. Products derived from this software may not be called "VOCAL", nor
  27.  *    may "VOCAL" appear in their name, without prior written
  28.  *    permission of Vovida Networks, Inc.
  29.  * 
  30.  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
  31.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  32.  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
  33.  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
  34.  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
  35.  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
  36.  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  37.  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  38.  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  39.  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  40.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  41.  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  42.  * DAMAGE.
  43.  * 
  44.  * ====================================================================
  45.  * 
  46.  * This software consists of voluntary contributions made by Vovida
  47.  * Networks, Inc. and many individuals on behalf of Vovida Networks,
  48.  * Inc.  For more information on Vovida Networks, Inc., please see
  49.  * <http://www.vovida.org/>.
  50.  *
  51.  */
  52. static const char* const StatisticsDb_hxx_Version = 
  53.     "$Id: StatisticsDb.hxx,v 1.5 2001/03/23 19:43:21 icahoon Exp $";
  54. #include "Writer.hxx"
  55. #include "Data.hxx"
  56. #include "RWMutex.hxx"
  57. #include <map>
  58. /** Infrastructure common to VOCAL.<br><br>
  59.  */
  60. namespace Vocal 
  61. {
  62. /** Infrastructure in VOCAL to measuring, recording and reporting
  63.  *  statistics.<br><br>
  64.  */
  65. namespace Statistics
  66. {
  67. using Vocal::Threads::RWMutex;
  68. class Statistic;
  69. /** Using an unsigned int for simplicity.<br><br>
  70.  */
  71. typedef     u_int32_t     StatisticsDbKey;
  72. /** Never used as a database key.<br><br>
  73.  *
  74.  * All database keys will be greater than this value.
  75.  */
  76. extern const StatisticsDbKey  INVALID_STAT_DB_KEY;
  77. /** A statistics database.<br><br>
  78.  */
  79. class StatisticsDb : public Vocal::IO::Writer
  80. {
  81.     public:
  82. /** Create the statistics database, given the optional name 
  83.  *  of the database (defaults to "StatisticsDb").
  84.  */
  85. StatisticsDb(const char * name = 0);
  86. /** Destroy the statistics database.
  87.  */
  88. virtual ~StatisticsDb();
  89.     
  90.      /** Return the key given the label. If this is a new label,
  91.  *  a key will be allocated. Keys are not consistent across
  92.  *  different instances of the StatisticsDb.
  93.  */
  94.      StatisticsDbKey     key(const Data & label);
  95.      /** Return the label name of the given key. If the key doesn't exist,
  96.  *  the label for INVALID_STAT_DB_KEY is returned.
  97.  */
  98.      const Data & keyName(StatisticsDbKey) const;
  99.      /** Return the next key. All keys will be less than this value.
  100.  */
  101.      StatisticsDbKey     nextKey() const;
  102. /** Adds the statistic into the database. The statistic must be created 
  103.  *  using this database.
  104.  */
  105. virtual void record(const Statistic &);
  106. /** Finds the statistic in the database. Returns 0 if not found.
  107.  */
  108. virtual Statistic * find(const Statistic &) const;
  109. /** Erases the individual statistic from the database. 
  110.  */
  111. virtual void erase(const Statistic &);
  112.      /** Clear the entire database.
  113.  */
  114. virtual void clear();
  115.     
  116.      /** Dump the database to an ostream.
  117.  */
  118.         virtual ostream &   writeTo(ostream &) const;
  119. /** Returns the name of the database.
  120.  */
  121.      const Data & name() const;
  122.      /** Returns true if the databases are the same.
  123.  *  Since databases cannot be copied, this is an identity check.
  124.  */
  125. bool operator==(const StatisticsDb &) const;
  126.      /** The databases are ordered by their addresses.
  127.  */
  128. bool operator<(const StatisticsDb &) const;
  129.     private:
  130.      /** Mutlithreaded protection.
  131.  */
  132. mutable RWMutex     myLock;
  133.  
  134.     
  135.      /** Name of the database.
  136.  */
  137. Data myName;
  138.     
  139.      /** The next key to be allocated.
  140.  */
  141. StatisticsDbKey myNextKey;
  142.      /** 
  143.  */
  144.      typedef std::map<Data, StatisticsDbKey>  StatisticRegistrations;
  145.      /**
  146.  */
  147. StatisticRegistrations    myStatRegistrations;
  148.      /**
  149.  */
  150.      typedef vector<Data>  StatisticNames;
  151.      /**
  152.  */
  153. StatisticNames    myStatNames;
  154.      /**
  155.       */
  156.      typedef std::map<StatisticsDbKey, Statistic *>  Database;
  157. /**
  158.  */
  159. Database    m_db;
  160.     
  161.      /** Suppress copying
  162.  */
  163. StatisticsDb(const StatisticsDb &);
  164.      /** Suppress copying
  165.  */
  166. const StatisticsDb & operator=(const StatisticsDb &);
  167. };
  168. } // namespace Statistics
  169. } // namespace Vocal 
  170. #endif // !defined(STATISTICS_DB_DOT_HXX)