GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
child-list.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1993-2017 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 the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 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 <http://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
37  OCTAVE_API
38  child
39  {
40  public:
41 
42  // Do whatever to handle event for child with PID (might not
43  // actually be dead, could just be stopped). Return true if
44  // the list element corresponding to PID should be removed from
45  // list. This function should not call any functions that modify
46  // the child_list.
47 
48  typedef bool (*child_event_handler) (pid_t, int);
49 
50  child (pid_t id = -1, child_event_handler f = 0)
51  : pid (id), handler (f), have_status (0), status (0) { }
52 
53  child (const child& oc)
54  : pid (oc.pid), handler (oc.handler),
55  have_status (oc.have_status), status (oc.status) { }
56 
57  child& operator = (const child& oc)
58  {
59  if (&oc != this)
60  {
61  pid = oc.pid;
62  handler = oc.handler;
63  have_status = oc.have_status;
64  status = oc.status;
65  }
66  return *this;
67  }
68 
69  ~child (void) { }
70 
71  // The process id of this child.
72  pid_t pid;
73 
74  // The function we call if an event happens for this child.
75  child_event_handler handler;
76 
77  // Nonzero if this child has stopped or terminated.
78  sig_atomic_t have_status;
79 
80  // The status of this child; 0 if running, otherwise a status value
81  // from waitpid.
82  int status;
83  };
84 
85  class
86  OCTAVE_API
88  {
89  protected:
90 
91  child_list (void) { }
92 
93  class child_list_rep : public base_list<child>
94  {
95  public:
96 
97  void insert (pid_t pid, child::child_event_handler f);
98 
99  void reap (void);
100 
101  bool wait (void);
102  };
103 
104  public:
105 
106  ~child_list (void) { }
107 
108  static void insert (pid_t pid, child::child_event_handler f);
109 
110  static void reap (void);
111 
112  static bool wait (void);
113 
114  static void remove (pid_t pid);
115 
116  private:
117 
118  static bool instance_ok (void);
119 
121 
122  static void cleanup_instance (void) { delete instance; instance = 0; }
123  };
124 }
125 
126 #if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS)
127 
128 OCTAVE_DEPRECATED ("use 'octave::child' instead")
129 typedef octave::child octave_child;
130 
131 OCTAVE_DEPRECATED ("use 'octave::child_list' instead")
132 typedef octave::child_list octave_child_list;
133 
134 #endif
135 
136 #endif
uint32_t id
Definition: graphics.cc:11587
~child(void)
Definition: child-list.h:69
child(pid_t id=-1, child_event_handler f=0)
Definition: child-list.h:50
Octave interface to the compression and uncompression libraries.
Definition: aepbalance.cc:47
child_event_handler handler
Definition: child-list.h:75
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &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 F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE * f
static child_list_rep * instance
Definition: child-list.h:120
sig_atomic_t have_status
Definition: child-list.h:78
child(const child &oc)
Definition: child-list.h:53
bool(* child_event_handler)(pid_t, int)
Definition: child-list.h:48
static void cleanup_instance(void)
Definition: child-list.h:122