/* * SIPB service monitor * * Nickolai Zeldovich * May 2002 */ #include #include "sipbmon.h" service::service (str n, checker *c) : _name (n), chk (c), _ok (true), active (false), timecb (NULL) { chk->set_service (this); } void service::done (bool ok) { assert (active); active = false; chk->stop (); if (timecb) { timecb_remove (timecb); timecb = NULL; } if (_ok != ok) { _ok = ok; for (unsigned int i = 0; i < notify.size (); i++) { cbnotify cb = notify[i]; (*cb) (this); } } } void service::up () { done (true); } void service::down (str msg) { _errmsg = msg; done (false); } void service::timeout () { assert (timecb != NULL); timecb = NULL; down ("request timed out"); } str service::descr () { return chk->descr (); } void service::start () { if (!active) { active = true; timecb = delaycb (check_timeout, wrap (this, &service::timeout)); chk->start (); } }