sketcher rework, plugindialog selection fixes, new ffmpeg plugin.opts/plugin info...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / renderfarmfsclient.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 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 RENDERFARMFSCLIENT_H
23 #define RENDERFARMFSCLIENT_H
24
25 #include "mutex.inc"
26 #include "renderfarmclient.inc"
27 #include "renderfarmfsclient.inc"
28
29
30 // This should override the stdio commands and inderect operations on any file
31 // starting with RENDERFARM_FS_PREFIX to the network.
32
33 // The server runs on the master node.
34 // The client runs on the client.
35
36 // The traffic shares the same socket as the rest of the rendering traffic
37 // so the server and client command loops have to give control to the
38 // VFS objects when they get a VFS command.
39
40 // Only one RenderFarmClient can exist per image because the stdio operations
41 // don't allow pointers to local storage.  Fortunately only one
42 // RenderFarmClient exists per image by default.  The RenderFarmClient just needs
43 // to wait until it's forked before creating RenderFarmFSClient.
44 // The RenderFarmClient is a mutual
45 // exclusion lock and table of file descriptors.
46 // It searches through the table to see if the file descriptor is virtual.
47 // Then it translates a single stdio call at a time to and from
48 // network commands, complete with the original parameters and return values.
49
50 // The RenderFarmFSServer takes one command from the network at a time and passes
51 // it directly to the stdio call.  If call has a buffer, the buffer is
52 // created by the RenderFarmFSServer and streamed over the network.
53 // The return values are passed untouched back through the network.
54
55 // FILE* and int on RenderFarmClient are meaningless.
56 // They can't be dereferenced.
57 // Unfortunately, nothing else in Cinelerra can override stdio now.
58
59 // All the stdio functions are transferred in endian independant ways except
60 // stat, stat64.
61
62 extern RenderFarmFSClient *renderfarm_fs_global;
63
64 class RenderFarmFSClient
65 {
66 public:
67         RenderFarmFSClient(RenderFarmClientThread *client);
68         ~RenderFarmFSClient();
69
70         void initialize();
71
72 // Called by the overloaded C library functions.
73 // There may be more.
74         FILE* fopen(const char *path, const char *mode);
75         int fclose(FILE *file);
76         int remove (__const char *__filename);
77         int rename (__const char *__old, __const char *__new);
78         int fgetc (FILE *__stream);
79         int fputc (int __c, FILE *__stream);
80         size_t fread (void *__restrict __ptr, size_t __size,
81                          size_t __n, FILE *__restrict __stream);
82         size_t fwrite (__const void *__restrict __ptr, size_t __size,
83                           size_t __n, FILE *__restrict __s);
84         int fseek (FILE *__stream, int64_t __off, int __whence);
85         int64_t ftell (FILE *__stream);
86         int stat64 (__const char *__restrict __file,
87                            struct stat64 *__restrict __buf);
88         int stat (__const char *__restrict __file,
89                          struct stat *__restrict __buf);
90         char *fgets (char *__restrict __s, int __n, FILE *__restrict __stream);
91         int fileno(FILE *file);
92         int fscanf(FILE *__restrict stream, const char *__restrict format, va_list ap);
93
94 // Locking order:
95 // 1) RenderFarmFSClient
96 // 2) RenderFarmClient
97         void lock();
98         void unlock();
99         int is_open(FILE *ptr);
100 // The 64 bit argument is ignored in 64 bit architectures
101         void set_open(FILE *ptr, int64_t pointer);
102         void unset_open(FILE *ptr, int64_t pointer);
103 // Used in place of Units::ptr_to_int64 in case the pointer is only 32 bits.
104         int64_t get_64(FILE *ptr);
105
106         Mutex *mutex_lock;
107         ArrayList<FILE*> files;
108 // In 32 bit mode, this stores the 64 bit equivalents of the file handles.
109 // The 64 bit values are ignored in 64 bit architectures
110         ArrayList<int64_t> pointers;
111         RenderFarmClientThread *client;
112 };
113
114
115
116
117
118 #endif