Import isodate() from Utils.pm
[irspy-moved-to-github.git] / lib / ZOOM / IRSpy / Test / Ping.pm
1 # $Id: Ping.pm,v 1.16 2006-11-29 18:18:37 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 = qw(ZOOM::IRSpy::Test);
13
14 use ZOOM::IRSpy::Utils qw(isodate);
15
16
17 sub start {
18     my $class = shift();
19     my($conn) = @_;
20
21     $conn->irspy_connect(undef, {},
22                          ZOOM::Event::CONNECT, \&connected,
23                          exception => \&not_connected);
24 }
25
26
27 sub connected { maybe_connected(@_, 1) }
28 sub not_connected { maybe_connected(@_, 0) }
29
30 sub maybe_connected {
31     my($conn, $task, $__UNUSED_udata, $event, $ok) = @_;
32
33     $conn->log("irspy_test", ($ok ? "" : "not "), "connected");
34     my $rec = $conn->record();
35     $rec->append_entry("irspy:status", "<irspy:probe ok='$ok'>" .
36                        isodate(time()) . "</irspy:probe>");
37     return $ok ? ZOOM::IRSpy::Status::TEST_GOOD :
38                  ZOOM::IRSpy::Status::TEST_BAD;
39 }
40
41
42 1;