GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
child-list.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1993-2018 John W. Eaton
4 
5 This file is part of Octave.
6 
7 Octave is free software: you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if ! defined (octave_child_list_h)
24 #define octave_child_list_h 1
25 
26 #include "octave-config.h"
27 
28 #include <csignal>
29 
30 #include <sys/types.h>
31 
32 #include "base-list.h"
33 
34 namespace octave
35 {
36  class OCTAVE_API child
37  {
38  public:
39 
40  // Do whatever to handle event for child with PID (might not
41  // actually be dead, could just be stopped). Return true if
42  // the list element corresponding to PID should be removed from
43  // list. This function should not call any functions that modify
44  // the child_list.
45 
46  typedef bool (*child_event_handler) (pid_t, int);
47 
48  child (pid_t id = -1, child_event_handler f = nullptr)
49  : pid (id), handler (f), have_status (0), status (0)
50  { }
51 
52  child (const child&) = default;
53 
54  child& operator = (const child&) = default;
55 
56  ~child (void) = default;
57 
58  // The process id of this child.
59  pid_t pid;
60 
61  // The function we call if an event happens for this child.
62  child_event_handler handler;
63 
64  // Nonzero if this child has stopped or terminated.
65  sig_atomic_t have_status;
66 
67  // The status of this child; 0 if running, otherwise a status value
68  // from waitpid.
69  int status;
70  };
71 
72  class OCTAVE_API child_list
73  {
74  public:
75 
76  child_list (void) { }
77 
78  void insert (pid_t pid, child::child_event_handler f);
79 
80  void remove (pid_t pid);
81 
82  void reap (void);
83 
84  bool wait (void);
85 
86  private:
87 
89  };
90 }
91 
92 #endif
uint32_t id
Definition: graphics.cc:12193
base_list< child > m_list
Definition: child-list.h:88
child_event_handler handler
Definition: child-list.h:62
bool(* child_event_handler)(pid_t, int)
Definition: child-list.h:46
F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE * f
sig_atomic_t have_status
Definition: child-list.h:65
child(pid_t id=-1, child_event_handler f=nullptr)
Definition: child-list.h:48