LCOV - code coverage report
Current view: top level - util/random - qid_gen.cc (source / functions) Hit Total Coverage
Test: report.info Lines: 14 14 100.0 %
Date: 2012-05-15 Functions: 5 5 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : // Copyright (C) 2011  Internet Systems Consortium, Inc. ("ISC")
       2                 :            : //
       3                 :            : // Permission to use, copy, modify, and/or distribute this software for any
       4                 :            : // purpose with or without fee is hereby granted, provided that the above
       5                 :            : // copyright notice and this permission notice appear in all copies.
       6                 :            : //
       7                 :            : // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
       8                 :            : // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
       9                 :            : // AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
      10                 :            : // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
      11                 :            : // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
      12                 :            : // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
      13                 :            : // PERFORMANCE OF THIS SOFTWARE.
      14                 :            : 
      15                 :            : // qid_gen defines a generator for query id's
      16                 :            : //
      17                 :            : // We probably want to merge this with the weighted random in the nsas
      18                 :            : // (and other parts where we need randomness, perhaps another thing
      19                 :            : // for a general libutil?)
      20                 :            : 
      21                 :            : #include <util/random/qid_gen.h>
      22                 :            : 
      23                 :            : #include <sys/time.h>
      24                 :            : 
      25                 :            : namespace isc {
      26                 :            : namespace util {
      27                 :            : namespace random {
      28                 :            : 
      29                 :        169 : QidGenerator qid_generator_instance;
      30                 :            : 
      31                 :            : QidGenerator&
      32                 :         68 : QidGenerator::getInstance() {
      33                 :         68 :     return (qid_generator_instance);
      34                 :            : }
      35                 :            : 
      36                 :        169 : QidGenerator::QidGenerator() : dist_(0, 65535),
      37                 :        507 :                                vgen_(generator_, dist_)
      38                 :            : {
      39                 :        169 :     seed();
      40                 :        169 : }
      41                 :            : 
      42                 :            : void
      43                 :        169 : QidGenerator::seed() {
      44                 :            :     struct timeval tv;
      45                 :        169 :     gettimeofday(&tv, 0);
      46                 :        169 :     generator_.seed((tv.tv_sec * 1000000) + tv.tv_usec);
      47                 :        169 : }
      48                 :            : 
      49                 :            : uint16_t
      50                 :         68 : QidGenerator::generateQid() {
      51                 :         68 :     return (vgen_());
      52                 :            : }
      53                 :            : 
      54                 :            : 
      55                 :            : } // namespace random
      56                 :            : } // namespace util
      57                 :        169 : } // namespace isc

Generated by: LCOV version 1.9