App-Chart
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/App/Chart/Gtk2/Subprocess.pm view on Meta::CPAN
delete $self->{'io_watch'};
delete $self->{'sock'};
delete $self->{'pidobj'};
_unset_job ($self, undef, __('Stopped'));
}
sub _do_read {
my ($fd, $conditions, $ref_weak_self) = @_;
my $self = $$ref_weak_self || return Glib::SOURCE_REMOVE;
#### Subprocess read: "$self"
my $sock = $self->{'sock'};
my $status = undef;
for (;;) {
my $buf;
my $len = $sock->sysread ($buf, 8192);
#### got: $len
### $!
if (! $len) {
if (! defined $len) {
if ($! == EWOULDBLOCK) { last; } # no more data for now
my $errmsg = Glib::strerror ($!);
$self->message ("Subprocess read error: $errmsg\n");
$status = __('Read error');
} else {
# end of file, child closed pipe
$status = __('Died');
}
delete $self->{'io_watch'};
delete $self->{'sock'};
delete $self->{'pidobj'};
_unset_job ($self, $status, $status);
return Glib::SOURCE_REMOVE;
}
my ($new_status, $message) = $self->{'status_parser'}->parse($buf);
$self->message ($message);
if (defined $new_status) { $status = $new_status; }
}
if (defined $status) {
if ($status eq 'Idle') {
_unset_job ($self, __('Done'), __('Idle'));
App::Chart::Gtk2::JobQueue->consider_run;
} else {
if (my $job = $self->{'job'}) {
$job->set (status => $status);
}
}
}
return Glib::SOURCE_CONTINUE;
}
sub _update_idle_timer {
my ($self) = @_;
my $want_timer = ($self->pid && ! $self->{'job'});
if ($want_timer) {
$self->{'timer_ids'} ||= Glib::Ex::SourceIds->new
(Glib::Timeout->add (IDLE_TIMEOUT_SECONDS * 1000,
\&_do_idle_timeout,
App::Chart::Glib::Ex::MoreUtils::ref_weak($self)));
} else {
$self->{'timer_ids'} = undef;
}
}
sub _do_idle_timeout {
my ($ref_weak_self) = @_;
my $self = $$ref_weak_self || return Glib::SOURCE_REMOVE;
$self->stop;
Gtk2::Ex::TreeModelBits::remove_matching_rows
($store, sub { my ($store, $iter) = @_;
$store->get_value($iter,0) == $self });
$self->{'timer_ids'} = undef;
return Glib::SOURCE_REMOVE;
}
# send out a 'row-changed' on the global $store for subprocesses $self
sub _emit_row_changed {
my ($self) = @_;
$store->foreach (sub {
my ($store, $path, $iter) = @_;
my $this = $store->get_value ($iter, 0);
if ($this && $this == $self) {
$store->row_changed ($path, $iter);
}
});
}
sub all_subprocesses {
my ($class) = @_;
return Gtk2::Ex::TreeModelBits::column_contents ($store, 0);
}
sub remove_done {
my ($class) = @_;
Gtk2::Ex::TreeModelBits::remove_matching_rows
($store, sub { my ($store, $iter) = @_;
my $proc = $store->get_value ($iter, 0);
return ! $proc->pid;
});
}
#------------------------------------------------------------------------------
# generic helpers
sub liststore_append_with_values {
my $store = shift;
$store->insert_with_values ($store->iter_n_children(undef), @_);
}
1;
__END__
=for stopwords subprocess Storable stdout EINTR undef
view all matches for this distributionview release on metacpan - search on metacpan
( run in 0.563 second using v1.00-cache-2.02-grep-82fe00e-cpan-2c419f77a38b )