~ubuntu-branches/ubuntu/utopic/sip-tester/utopic

« back to all changes in this revision

Viewing changes to watchdog.cpp

  • Committer: Package Import Robot
  • Author(s): Mark Purcell, Paul Belanger, Mark Purcell
  • Date: 2011-11-03 21:56:17 UTC
  • mfrom: (1.1.7)
  • Revision ID: package-import@ubuntu.com-20111103215617-nnxicj1oto9e8ix5
Tags: 1:3.2-1
[ Paul Belanger ]
* New Upstream Release (Closes: #623915).
* Switch to dpkg-source 3.0 (quilt) format
* Building with PCAP play.
* Switch back to Debhelper.
* debian/patches/spelling-error-in-binary: Fix lintian warning

[ Mark Purcell ]
* Drop pabs from Uploaders: at his request
* fix debhelper-overrides-need-versioned-build-depends
* fix description-synopsis-starts-with-article

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  This program is free software; you can redistribute it and/or modify
 
3
 *  it under the terms of the GNU General Public License as published by
 
4
 *  the Free Software Foundation; either version 2 of the License, or
 
5
 *  (at your option) any later version.
 
6
 *
 
7
 *  This program is distributed in the hope that it will be useful,
 
8
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
 *  GNU General Public License for more details.
 
11
 *
 
12
 *  You should have received a copy of the GNU General Public License
 
13
 *  along with this program; if not, write to the Free Software
 
14
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
 *
 
16
 *  Author : Richard GAYRAUD - 04 Nov 2003
 
17
 *           Marc LAMBERTON
 
18
 *           Olivier JACQUES
 
19
 *           Herve PELLAN
 
20
 *           David MANSUTTI
 
21
 *           Francois-Xavier Kowalski
 
22
 *           Gerard Lyonnaz
 
23
 *           From Hewlett Packard Company.
 
24
 *           F. Tarek Rogers
 
25
 *           Peter Higginson
 
26
 *           Vincent Luba
 
27
 *           Shriram Natarajan
 
28
 *           Guillaume Teissier from FTR&D
 
29
 *           Clement Chen
 
30
 *           Wolfgang Beck
 
31
 *           Charles P Wright from IBM Research
 
32
 */
 
33
#include "sipp.hpp"
 
34
 
 
35
void watchdog::dump() {
 
36
  WARNING("Watchdog Task: interval = %d, major_threshold = %d (%d triggers left), minor_threshold = %d (%d triggers left)", interval, major_threshold, major_maxtriggers, minor_threshold, minor_maxtriggers);
 
37
}
 
38
 
 
39
watchdog::watchdog(int interval, int reset_interval, int major_threshold, int major_maxtriggers, int minor_threshold, int minor_maxtriggers) {
 
40
  this->interval = interval;
 
41
  this->reset_interval = reset_interval;
 
42
  this->major_threshold = major_threshold;
 
43
  this->major_maxtriggers = major_maxtriggers;
 
44
  this->minor_threshold = minor_threshold;
 
45
  this->minor_maxtriggers = minor_maxtriggers;
 
46
  major_triggers = 0;
 
47
  minor_triggers = 0;
 
48
  last_trigger = last_fire = getmilliseconds();
 
49
}
 
50
 
 
51
bool watchdog::run() {
 
52
  getmilliseconds();
 
53
  if (last_fire + this->major_threshold < clock_tick) {
 
54
        CStat::globalStat(CStat::E_WATCHDOG_MAJOR);
 
55
        last_trigger = clock_tick;
 
56
        WARNING("The major watchdog timer %dms has been tripped (%d), %d trips remaining.", major_threshold, clock_tick - last_fire, major_maxtriggers - major_triggers);
 
57
        if ((this->major_maxtriggers != -1) && (++major_triggers > this->major_maxtriggers)) {
 
58
          ERROR("The watchdog timer has tripped the major threshold of %dms too many times (%d out of %d allowed) (%d out of %d minor %dms timeouts tripped)\n", major_threshold, major_triggers, major_maxtriggers, minor_threshold, minor_triggers, minor_maxtriggers);
 
59
        }
 
60
  } else if (last_fire + this->minor_threshold < clock_tick) {
 
61
        last_trigger = clock_tick;
 
62
        CStat::globalStat(CStat::E_WATCHDOG_MINOR);
 
63
        WARNING("The minor watchdog timer %dms has been tripped (%d), %d trips remaining.", minor_threshold, clock_tick - last_fire, minor_maxtriggers - minor_triggers);
 
64
        if ((this->minor_maxtriggers != -1) && (++minor_triggers > this->minor_maxtriggers)) {
 
65
          ERROR("The watchdog timer has tripped the minor threshold of %dms too many times (%d out of %d allowed) (%d out of %d major %dms timeouts tripped)\n", minor_threshold, minor_triggers, minor_maxtriggers, major_threshold, major_triggers, major_maxtriggers);
 
66
        }
 
67
  }
 
68
 
 
69
  if (reset_interval && (major_triggers || minor_triggers) && (last_trigger + reset_interval < clock_tick)) {
 
70
    WARNING("Resetting watchdog timer trigger counts, as it has not been triggered in over %dms.", clock_tick - last_trigger);
 
71
    major_triggers = minor_triggers = 0;
 
72
  }
 
73
 
 
74
  last_fire = clock_tick;
 
75
  setPaused();
 
76
  return true;
 
77
}
 
78
 
 
79
unsigned int watchdog::wake() {
 
80
  return last_fire + interval;
 
81
}