NIST Biometric Evaluation Framework
Software components for biometric technology evaluations
be_process_forkmanager.h
Go to the documentation of this file.
1/*
2 * This software was developed at the National Institute of Standards and
3 * Technology (NIST) by employees of the Federal Government in the course
4 * of their official duties. Pursuant to title 17 Section 105 of the
5 * United States Code, this software is not subject to copyright protection
6 * and is in the public domain. NIST assumes no responsibility whatsoever for
7 * its use by other parties, and makes no guarantees, expressed or implied,
8 * about its quality, reliability, or any other characteristic.
9 */
10
11#ifndef __BE_PROCESS_FORKMANAGER_H__
12#define __BE_PROCESS_FORKMANAGER_H__
13
14#include <unistd.h>
15
16#include <list>
17
18#include <be_process_manager.h>
19
20namespace BiometricEvaluation
21{
22 namespace Process
23 {
24 /* Forward declaration */
25 class ForkWorkerController;
26
32 class ForkManager : public Manager
33 {
34 public:
46 static std::list<ForkManager*> FORKMANAGERS;
47
52
63 std::shared_ptr<WorkerController>
65 std::shared_ptr<Worker> worker);
66
83 void
85 bool wait = true,
86 bool communicate = false);
87
107 void
109 std::shared_ptr<WorkerController> worker,
110 bool wait = true,
111 bool communicate = false);
112
136 void
138 std::shared_ptr<WorkerController> workerController);
139
147 void broadcastSignal(int signo);
148
161 bool
163 const pid_t pid)
164 const;
165
176 void
178 const pid_t pid);
179
185 void
187
198 bool
200 const pid_t pid)
201 const;
202
203 void
205
211
226 void
228 void (*exitCallback)
229 (std::shared_ptr<ForkWorkerController> worker,
230 int stat_loc));
231
245 static void
247 std::shared_ptr<ForkWorkerController> worker,
248 int status);
249
266 void
268 const pid_t pid,
269 const int32_t waitStatus);
270
271 private:
286 std::shared_ptr<ForkWorkerController>
287 getProcessWithPID(
288 pid_t pid);
289
294 void
295 _wait();
296
305 static void
306 reap(
307 int signal);
308
317 class Status {
318 public:
320 Status();
321
323 pid_t pid;
325 bool isWorking;
326 };
327
341 void
342 (*_exitCallback)
343 (std::shared_ptr<ForkWorkerController> wc,
344 int stat_loc);
345
347 bool _parent;
348
350 std::map<
351 std::shared_ptr<ForkWorkerController>, Status>
352 _wcStatus;
353 };
354
355
361 {
362 public:
370 bool
372 const;
373
374 bool
376 const;
377
386 void
388
401 pid_t
403 const;
404
416 static void
418 int signal);
419
425
426 protected:
427
428 private:
429
437 std::shared_ptr<Worker> worker);
438
456 void
457 start(
458 bool communicate = false);
459
469 void
470 stop();
471
473 pid_t _pid;
474
480 static std::shared_ptr<Worker> _staticWorker;
481
482 /*
483 * Friends.
484 */
485
502 friend void
504 bool wait,
505 bool communicate);
506
526 friend void
528 std::shared_ptr<WorkerController> worker,
529 bool wait,
530 bool communicate);
531
548 friend void
550 std::shared_ptr<WorkerController> workerController);
551
562 friend std::shared_ptr<WorkerController>
564 std::shared_ptr<Worker> worker);
565
582 friend void
584 const pid_t pid,
585 const int32_t waitStatus);
586 };
587 }
588}
589
590#endif /* __BE_PROCESS_FORKMANAGER_H__ */
Manager implementation that starts Workers by calling fork(2).
bool getIsWorkingStatus(const pid_t pid) const
Get Status.isWorking for PID.
void broadcastSignal(int signo)
Send a POSIX signal to all workers.
void stopWorker(std::shared_ptr< WorkerController > workerController)
Ask Worker to exit.
static void defaultExitCallback(std::shared_ptr< ForkWorkerController > worker, int status)
A default exit callback function.
static std::list< ForkManager * > FORKMANAGERS
List of all instantiated ForkManagers.
void startWorker(std::shared_ptr< WorkerController > worker, bool wait=true, bool communicate=false)
Start a worker.
bool responsibleFor(const pid_t pid) const
Obtain whether or not this ForkManager is responsbile for a particular PID.
void setExitCallback(void(*exitCallback)(std::shared_ptr< ForkWorkerController > worker, int stat_loc))
Call a function in your program when a child exits.
void setExitStatus(const pid_t pid, const int32_t waitStatus)
Set the exit status in the WorkerController for given process ID.
void setNotWorking(const pid_t pid)
Set Status.isWorking for PID to false.
void startWorkers(bool wait=true, bool communicate=false)
Begin Worker's work.
~ForkManager()
ForkManager destructor.
void waitForWorkerExit()
Block until all Workers have exited.
void markAllFinished()
Call setNotWorking() for all PIDs known to this ForkManager.
std::shared_ptr< WorkerController > addWorker(std::shared_ptr< Worker > worker)
Adds a Worker to be managed by this Manager.
ForkManager()
ForkManager constructor.
Wrapper of a Worker returned from a Process::ForkManager.
static void _stop(int signal)
Tell _staticWorker to stop.
pid_t getPID() const
Obtain the PID of this process this instance represents.
bool isWorking() const
Obtain whether or not Worker is working.
bool everWorked() const
Obtain whether or not this Worker has ever worked.
~ForkWorkerController()
ForkWorkerController destructor.
An interface for intranode process management classes.
Wrapper of a Worker returned from a Process::Manager.
This software was developed at the National Institute of Standards and Technology (NIST) by employees...