initial commit
[goodguy/history.git] / cinelerra-5.0 / cinelerra / forkwrapper.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 FORKWRAPPER_H
23 #define FORKWRAPPER_H
24
25 // Utility functions for all the forking classes
26
27
28 #include <stdint.h>
29
30
31 class ForkWrapper
32 {
33 public:
34         ForkWrapper();
35         virtual ~ForkWrapper();
36
37 // Can't start in the constructor because it'll erase the subclass constructor.
38         void start();
39 // Called by subclass to send a command to exit the loop
40         void stop();
41 // Use the fd of another fork already in progress.
42 // Used to transfer a parent ForkWrapper from 1 process to another.
43         void start_dummy(int parent_fd, int pid);
44         void run();
45         virtual void init_child();
46         virtual int handle_command();
47 // return 1 if the child is running
48         int child_running();
49 // Return 1 if the child is dead
50         int read_timeout(unsigned char *data, int size);
51
52         int done;
53
54 // Called by parent to send commands
55         int send_command(int token, 
56                 unsigned char *data,
57                 int bytes);
58 // Called by child to get commands
59         int read_command();
60 // Called by parent to read result
61         int64_t read_result();
62 // Called by child to send result
63         int send_result(int64_t value, unsigned char *data, int data_size);
64 // Called by child to send a file descriptor
65         void send_fd(int fd);
66 // Called by parent to get a file descriptor
67         int get_fd();
68
69         int pid;
70         int parent_fd;
71         int child_fd;
72         int is_dummy;
73
74         int command_token;
75         unsigned char *command_data;
76         int command_bytes;
77         int command_allocated;
78
79
80         unsigned char *result_data;
81         int result_bytes;
82         int result_allocated;
83 };
84
85
86
87 #endif
88
89
90