2ca84b71d4c6c56ffc71db925e0840de2ac642ff
[goodguy/history.git] / cinelerra-5.1 / cinelerra / forkbase.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2009 Adam Williams <broadcast at earthling dot net>
5  * 
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * 
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  * 
20  */
21
22 #ifndef __FORKBASE_H__
23 #define __FORKBASE_H__
24
25 #include "forkbase.inc"
26 #include "mutex.h"
27 #include "thread.h"
28
29 // Utility functions for all the forking classes
30
31 #include <stdint.h>
32
33 class ForkBase : public Mutex
34 {
35 public:
36         enum { EXIT_CODE=0x7fff };
37         typedef struct { int64_t token; int bytes; } token_bfr_t;
38
39         ForkBase();
40         virtual ~ForkBase();
41
42         virtual int is_running() = 0;
43         void send_bfr(int fd, const void *bfr, int len);
44         int read_timeout(int ms, int fd, void *data, int bytes);
45         int read_parent(int ms);
46         int send_parent(int64_t value, const void *data, int bytes);
47         int read_child(int ms);
48         int send_child(int64_t value, const void *data, int bytes);
49
50         int done, ppid, pid;
51         ForkChild *child;
52
53         int child_fd;
54         int64_t child_token;
55         int child_bytes;
56         int child_allocated;
57         uint8_t *child_data;
58
59         int parent_fd;
60         int64_t parent_token;
61         int parent_bytes;
62         int parent_allocated;
63         uint8_t *parent_data;
64 };
65
66 class ForkChild : public ForkBase
67 {
68 public:
69         ForkChild();
70         virtual ~ForkChild();
71         virtual int handle_child();
72         int child_iteration();
73         int is_running();
74         virtual void run() {}
75 };
76
77 class ForkParent : public Thread, public ForkBase
78 {
79 public:
80         ForkParent();
81         virtual ~ForkParent();
82         virtual int handle_parent();
83         virtual ForkChild *new_fork() = 0;
84         int is_running();
85
86         void start_child();
87         void start();
88         void stop();
89         void run();
90         int parent_iteration();
91 };
92
93 #endif