App-Chart

 view release on metacpan or  search on metacpan

lib/App/Chart/Gtk2/Subprocess.pm  view on Meta::CPAN

# 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

=head1 NAME

App::Chart::Gtk2::Subprocess -- child process to run jobs

=head1 SYNOPSIS

 use App::Chart::Gtk2::Subprocess;
 my $subprocess = App::Chart::Gtk2::Subprocess->new;

=head1 DESCRIPTION

A C<App::Chart::Gtk2::Subprocess> is a child sub-process running C<chart
--subprocess>.  That subprocess reads tasks from its standard input (in a
length-delimited "Storable" format) and prints messages and
C<PerlIO::via::EscStatus> status strings to its stdout.  The
C<App::Chart::Gtk2::Subprocess> sends a C<App::Chart::Gtk2::Job> task to the subprocess
then reads its output.

C<App::Chart::Gtk2::Subprocess> notices if the child dies because the output pipe
closes.  It then waits that child with C<waitpid>.
C<< Glib::Child->watch_add >> is not used because in single thread mode it's
implemented with a non-restart C<sigaction> to stop the main loop poll, and
it's a bit worrying to think how much third-party library code might not
cope gracefully with EINTR.

=head1 FUNCTIONS

=over 4

=item C<< App::Chart::Gtk2::Subprocess->new (key=>value,...) >>

Create and return a new subprocess.  The process is running, but idle.

=item C<< $subprocess->start_job ($job) >>

Start a C<App::Chart::Gtk2::Job> on C<$subprocess>.  C<$subprocess> must be idle.
This is meant for use by C<App::Chart::Gtk2::JobQueue>.

=item C<< $subprocess->pid() >>

Return the process ID of C<$subprocess>, or undef if no longer running.

=item C<< $subprocess->stop() >>

Forcibly stop the process and any job running in it.

=back

=head1 SEE ALSO

L<App::Chart::Gtk2::Job>

=cut



( run in 3.690 seconds using v1.01-cache-2.11-cpan-524268b4103 )