a105a28094017a535bdc59c787b79074009e58ba
[irspy-moved-to-github.git] / lib / ZOOM / IRSpy / Test / Ping.pm
1 # $Id: Ping.pm,v 1.9 2006-07-24 16:16:29 mike Exp $
2
3 # See the "Main" test package for documentation
4
5 package ZOOM::IRSpy::Test::Ping;
6
7 use 5.008;
8 use strict;
9 use warnings;
10
11 use ZOOM::IRSpy::Test;
12 our @ISA;
13 @ISA = qw(ZOOM::IRSpy::Test);
14
15
16 sub run {
17     my $this = shift();
18     my $irspy = $this->irspy();
19     my $pod = $irspy->pod();
20
21     $pod->callback(ZOOM::Event::CONNECT, \&connected);
22     $pod->callback("exception", \&not_connected);
23     my $err = $pod->wait($irspy);
24
25     return 0;
26 }
27
28
29 sub connected { maybe_connected(@_, 1) }
30 sub not_connected { maybe_connected(@_, 0) }
31
32 sub maybe_connected {
33     my($conn, $irspy, $rs, $event, $ok) = @_;
34
35     my $rec = $irspy->record($conn);
36     $irspy->log("irspy_test", $conn->option("host"),
37                 ($ok ? "" : " not"), " connected");
38     $rec->append_entry("irspy:status", "<irspy:probe ok='$ok'>" .
39                        isodate(time()) . "</irspy:probe>");
40     $conn->option(pod_omit => 1) if !$ok;
41     return 0;
42 }
43
44
45 sub isodate {
46     my($time) = @_;
47
48     my($sec, $min, $hour, $mday, $mon, $year) = localtime($time);
49     return sprintf("%04d-%02d-%02dT%02d:%02d:%02d",
50                    $year+1900, $mon+1, $mday, $hour, $min, $sec);
51 }
52
53
54 1;