my $buf = $conn->{msg};
$buf =~ s/\r/\\r/g;
$buf =~ s/\n/\\n/g;
- dbg "state $conn->{state} '$msg' '$buf'";
+
+ dbg "state $conn->{state} '$msg' '$buf'" if isdbg('wm7d');
+
+ $conn->{_wm7d} ||= [];
if ($conn->{state} eq 'waitfor') {
if ($msg =~ /utc$/ ) {
$conn->{state} = 'ending';
}
return if $msg =~ /^query->/;
- $conn->handle_raw($msg);
+ push @{$conn->{_wm7d}}, $msg;
} else {
return if $msg =~ /^query->/ || $msg =~ /bye/;
- $conn->handle_raw($msg);
+# $conn->handle_raw($msg);
+ push @{$conn->{_wm7d}}, $msg;
}
}
+sub on_disc
+{
+ my $conn = shift;
+ my $dxchan = shift;
+ $DB::single = 1;
+
+ $dxchan->send(map {"$conn->{prefix}$_"} @{$conn->{_wm7d}});
+}
+
# wm7d accepts only single callsign
sub handle
{
Log('call', "$call: show/wm7d \U$line");
my $conn = AsyncMsg->raw($self, $target, $port,
- handler => \&waitfor, prefix=>'wm7d> ');
+ handler => \&waitfor, prefix=>'wm7d> ', on_disc =>\&on_disc);
if ($conn) {
$conn->{state} = 'waitfor';
$conn->{target_call} = $line;
my %args = @_;
my $handler = delete $args{handler} || \&handle_raw;
+
my $conn = $pkg->new($call, $handler);
$conn->{prefix} = delete $args{prefix} if exists $args{prefix};
$conn->{prefix} ||= '';
+ $conn->{on_disconnect} = delete $args{on_disc} || delete $args{on_disconnect};
$r = $conn->connect($host, $port, on_connect => &_on_raw_connect);
return $r ? $conn : undef;
}