--- AnyEvent-GPSD/GPSD.pm 2008/07/02 05:21:58 1.3 +++ AnyEvent-GPSD/GPSD.pm 2008/07/18 01:31:12 1.4 @@ -155,6 +155,7 @@ my ($self) = @_; delete $self->{fh}; + delete $self->{command}; Scalar::Util::weaken $self; $self->{retry_w} = AnyEvent->timer (after => 1, cb => sub { @@ -208,6 +209,7 @@ on_eof => sub { $! = &Errno::EPIPE; $self->event ("error"); + $self->log ("disconnect"); $self->retry; }, on_read => sub { @@ -224,6 +226,7 @@ $self->send ("c"); $self->event ("connect"); + $self->log ("connect"); } else { $self->event ("error"); } @@ -253,6 +256,9 @@ $self->{now} = AnyEvent->now; + $self->log (raw => $line) + if $self->{logfh}; + unless ($line =~ /^GPSD,(.)=(.*)$/) { $! = &Errno::EBADMSG; $self->event ("error"); @@ -261,6 +267,8 @@ my ($type, $data) = ($1, $2); + #warn "$type=$data\n";#d# + $self->{state}{$type} = [$data => $self->{now}]; if ($type eq "O") { @@ -350,6 +358,24 @@ } } +sub log { + my ($self, @arg) = @_; + + syswrite $self->{logfh}, JSON::encode_json ([AnyEvent->time, @arg]) . "\n" + if $self->{logfh}; +} + +sub record_log { + my ($self, $path) = @_, + + require JSON; + + open $self->{logfh}, ">", $path + or Carp::croak "$path: $!"; + + $self->log (start => $VERSION); +} + =back =head1 SEE ALSO