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