WvStreams
wvsubprocqueue.h
1 /* -*- Mode: C++ -*-
2  * Worldvisions Weaver Software:
3  * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4  *
5  * A class for running a series or set of processes, one at a time.
6  */
7 #ifndef __WVSUBPROCQUEUE_H
8 #define __WVSUBPROCQUEUE_H
9 
10 #include "wvsubproc.h"
11 
59 {
60 public:
65  WvSubProcQueue(unsigned _maxrunning);
66 
67  virtual ~WvSubProcQueue();
68 
78  void add(void *cookie, WvSubProc *proc);
79 
84  void add(void *cookie, const char *cmd, const char * const *argv);
85 
95  int go();
96 
103  void finish();
104 
106  unsigned running() const;
107 
109  unsigned remaining() const;
110 
112  bool isempty() const;
113 
114 private:
115  struct Ent
116  {
117  Ent(void *_cookie, WvSubProc *_proc)
118  {
119  cookie = _cookie;
120  proc = _proc;
121  redo = false;
122  }
123 
124  ~Ent()
125  {
126  if (proc) delete proc;
127  }
128 
129  void *cookie;
130  WvSubProc *proc;
131  bool redo;
132  };
133  DeclareWvList(Ent);
134 
135  unsigned maxrunning;
136  EntList runq, waitq;
137 
138  bool cookie_running();
139 };
140 
141 
142 #endif // __WVSUBPROCQUEUE_H
143 
unsigned running() const
Return the number of currently running processes.
unsigned remaining() const
Return the number of unfinished (ie. running or waiting) processes.
int go()
Clean up after any running processes in the queue, and start running additional processes if any are ...
void add(void *cookie, WvSubProc *proc)
Enqueue a process.
WvSubProcQueue(unsigned _maxrunning)
Create a WvSubProcQueue.
bool isempty() const
True if there are no unfinished (ie. running or waiting) processes.
void finish()
Wait synchronously for all processes in the entire queue to finish.
An ordered queue of WvSubProc instances.