4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
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.
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.
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
22 #ifndef RENDERFARMFSCLIENT_H
23 #define RENDERFARMFSCLIENT_H
26 #include "renderfarmclient.inc"
27 #include "renderfarmfsclient.inc"
30 // This should override the stdio commands and inderect operations on any file
31 // starting with RENDERFARM_FS_PREFIX to the network.
33 // The server runs on the master node.
34 // The client runs on the client.
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.
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.
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.
55 // FILE* and int on RenderFarmClient are meaningless.
56 // They can't be dereferenced.
57 // Unfortunately, nothing else in Cinelerra can override stdio now.
59 // All the stdio functions are transferred in endian independant ways except
62 extern RenderFarmFSClient *renderfarm_fs_global;
64 class RenderFarmFSClient
67 RenderFarmFSClient(RenderFarmClientThread *client);
68 ~RenderFarmFSClient();
72 // Called by the overloaded C library functions.
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);
95 // 1) RenderFarmFSClient
96 // 2) RenderFarmClient
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);
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;