Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

renderfarmfsserver.C

Go to the documentation of this file.
00001 #include "renderfarm.h"
00002 #include "renderfarmfsserver.h"
00003 #include "units.h"
00004 
00005 
00006 #include <string.h>
00007 #include <sys/stat.h>
00008 
00009 #define DEBUG 0
00010 
00011 RenderFarmFSServer::RenderFarmFSServer(RenderFarmServerThread *server)
00012 {
00013         this->server = server;
00014 }
00015 
00016 
00017 
00018 RenderFarmFSServer::~RenderFarmFSServer()
00019 {
00020 }
00021 
00022 void RenderFarmFSServer::initialize()
00023 {
00024 }
00025 
00026 int RenderFarmFSServer::handle_request(int request_id, int request_size, unsigned char *buffer)
00027 {
00028         int result = 0;
00029 
00030 if(DEBUG)
00031 printf("RenderFarmFSServer::handle_request request_id=%d\n", request_id);
00032         switch(request_id)
00033         {
00034                 case RENDERFARM_FOPEN:
00035                 {
00036                         char *path;
00037                         char *mode;
00038                         FILE *file;
00039                         unsigned char datagram[8];
00040                         int i = 0;
00041                         int64_t file_int64;
00042 
00043 
00044                         path = (char*)buffer;
00045                         mode = (char*)buffer + strlen(path) + 1;
00046 
00047 
00048                         file = fopen64(path, mode);
00049                         file_int64 = Units::ptr_to_int64(file);
00050                         STORE_INT64(file_int64);
00051                         server->write_socket((char*)datagram, 8, RENDERFARM_TIMEOUT);
00052 if(DEBUG)
00053 printf("RenderFarmFSServer::handle_request RENDERFARM_FOPEN file=%p file_int64=%llx datagram=%02x%02x%02x%02x%02x%02x%02x%02x path=%s mode=%s\n",
00054 file, file_int64, datagram[0], datagram[1], datagram[2], datagram[3], datagram[4], datagram[5], datagram[6], datagram[7], path, mode);
00055                         result = 1;
00056                         break;
00057                 }
00058 
00059                 case RENDERFARM_FCLOSE:
00060                 {
00061                         int64_t pointer = READ_INT64((unsigned char*)buffer);
00062                         FILE *file = (FILE*)Units::int64_to_ptr(pointer);
00063 if(DEBUG)
00064 printf("RenderFarmFSServer::handle_request RENDERFARM_FCLOSE file=%p\n", file);
00065                         fclose(file);
00066                         result = 1;
00067                         break;
00068                 }
00069 
00070                 case RENDERFARM_REMOVE:
00071                 {
00072                         remove((char*)buffer);
00073 if(DEBUG)
00074 printf("RenderFarmFSServer::handle_request path=%s\n", buffer);
00075                         result = 1;
00076                         break;
00077                 }
00078 
00079                 case RENDERFARM_RENAME:
00080                 {
00081                         char *oldpath = (char*)buffer;
00082                         char *newpath = (char*)buffer + strlen(oldpath) + 1;
00083                         rename(oldpath, newpath);
00084 if(DEBUG)
00085 printf("RenderFarmFSServer::handle_request old=%s new=%s\n", oldpath, newpath);
00086                         result = 1;
00087                         break;
00088                 }
00089 
00090                 case RENDERFARM_FGETC:
00091                 {
00092                         int64_t pointer = READ_INT64((unsigned char*)buffer);
00093                         FILE *file = (FILE*)Units::int64_to_ptr(pointer);
00094                         unsigned char datagram[1];
00095                         datagram[0] = fgetc(file);
00096                         server->write_socket((char*)datagram, 1, RENDERFARM_TIMEOUT);
00097 if(DEBUG)
00098 printf("RenderFarmFSServer::handle_request file=%p\n", file);
00099                         result = 1;
00100                         break;
00101                 }
00102 
00103                 case RENDERFARM_FPUTC:
00104                 {
00105                         int64_t pointer = READ_INT64((unsigned char*)buffer);
00106                         FILE *file = (FILE*)Units::int64_to_ptr(pointer);
00107                         fputc(buffer[8], file);
00108                         result = 1;
00109 if(DEBUG)
00110 printf("RenderFarmFSServer::handle_request file=%p\n", file);
00111                         break;
00112                 }
00113 
00114                 case RENDERFARM_FREAD:
00115                 {
00116                         int64_t pointer = READ_INT64((unsigned char*)buffer);
00117                         FILE *file = (FILE*)Units::int64_to_ptr(pointer);
00118                         int size = READ_INT32((unsigned char*)buffer + 8);
00119                         int num = READ_INT32((unsigned char*)buffer + 12);
00120                         unsigned char datagram[4];
00121                         int i = 0;
00122                         int bytes;
00123 // printf("RenderFarmFSServer::handle_request RENDERFARM_FREAD %02x%02x%02x%02x%02x%02x%02x%02x %p %d %d\n", 
00124 // buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7], 
00125 // pointer,
00126 // file,
00127 // size,
00128 // num);
00129 
00130                         server->reallocate_buffer(size * num);
00131                         bytes = fread(server->buffer, size, num, file);
00132                         STORE_INT32(bytes);
00133                         server->write_socket((char*)datagram, 4, RENDERFARM_TIMEOUT);
00134                         server->write_socket((char*)server->buffer, size * bytes, RENDERFARM_TIMEOUT);
00135                         result = 1;
00136 if(DEBUG)
00137 printf("RenderFarmFSServer::handle_request file=%p size=%d num=%d bytes=%d\n", 
00138 file, size, num, bytes);
00139                         break;
00140                 }
00141 
00142                 case RENDERFARM_FGETS:
00143                 {
00144                         int64_t pointer = READ_INT64((unsigned char*)buffer);
00145                         FILE *file = (FILE*)Units::int64_to_ptr(pointer);
00146                         int size = READ_INT32((unsigned char*)buffer + 8);
00147                         unsigned char datagram[4];
00148                         int i = 0;
00149 
00150                         server->reallocate_buffer(size);
00151                         char *return_value = fgets((char*)server->buffer, size, file);
00152                         int bytes = 0;
00153                         if(return_value)
00154                         {
00155                                 bytes = strlen(return_value) + 1;
00156                         }
00157                         STORE_INT32(bytes);
00158                         server->write_socket((char*)datagram, 4, RENDERFARM_TIMEOUT);
00159                         server->write_socket((char*)server->buffer, bytes, RENDERFARM_TIMEOUT);
00160                         result = 1;
00161                         break;
00162                 }
00163 
00164                 case RENDERFARM_FILENO:
00165                 {
00166                         int64_t pointer = READ_INT64((unsigned char*)buffer);
00167                         FILE *file = (FILE*)Units::int64_to_ptr(pointer);
00168                         unsigned char datagram[4];
00169                         int i = 0;
00170 
00171                         int return_value = fileno(file);
00172                         STORE_INT32(return_value);
00173                         server->write_socket((char*)datagram, 4, RENDERFARM_TIMEOUT);
00174 if(DEBUG)
00175 printf("RenderFarmFSServer::handle_request file=%p fileno=%d\n", 
00176 file, return_value);
00177                         result = 1;
00178                         break;
00179                 }
00180 
00181                 case RENDERFARM_FWRITE:
00182                 {
00183                         int64_t pointer = READ_INT64((unsigned char*)buffer);
00184                         FILE *file = (FILE*)Units::int64_to_ptr(pointer);
00185                         int size = READ_INT32((unsigned char*)buffer + 8);
00186                         int num = READ_INT32((unsigned char*)buffer + 12);
00187                         unsigned char datagram[4];
00188                         int i = 0;
00189                         int bytes;
00190 
00191                         server->reallocate_buffer(size * num);
00192                         server->read_socket((char*)server->buffer, size * num, RENDERFARM_TIMEOUT);
00193                         bytes = fwrite(server->buffer, size, num, file);
00194                         STORE_INT32(bytes);
00195                         server->write_socket((char*)datagram, 4, RENDERFARM_TIMEOUT);
00196                         result = 1;
00197 if(DEBUG)
00198 printf("RenderFarmFSServer::handle_request RENDERFARM_FWRITE file=%p size=%d num=%d bytes=%d\n", 
00199 file, size, num, bytes);
00200                         break;
00201                 }
00202 
00203                 case RENDERFARM_FSEEK:
00204                 {
00205                         int64_t pointer = READ_INT64((unsigned char*)buffer);
00206                         FILE *file = (FILE*)Units::int64_to_ptr(pointer);
00207 // printf("RENDERFARM_FSEEK 1 buffer=%02x%02x%02x%02x%02x%02x%02x%02x %p %llx\n",
00208 // buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7],  file, pointer);
00209                         int64_t offset = READ_INT64((unsigned char*)buffer + 8);
00210                         int whence = READ_INT32((unsigned char*)buffer + 16);
00211                         int return_value;
00212                         unsigned char datagram[4];
00213                         int i = 0;
00214 
00215                         return_value = fseeko64(file, offset, whence);
00216                         STORE_INT32(return_value);
00217                         server->write_socket((char*)datagram, 4, RENDERFARM_TIMEOUT);
00218                         result = 1;
00219 if(DEBUG)
00220 printf("RenderFarmFSServer::handle_request file=%p offset=%lld whence=%d result=%d\n", 
00221 file, offset, whence, result);
00222                         break;
00223                 }
00224 
00225                 case RENDERFARM_FTELL:
00226                 {
00227                         int64_t pointer = READ_INT64((unsigned char*)buffer);
00228                         FILE *file = (FILE*)Units::int64_to_ptr(pointer);
00229                         unsigned char datagram[8];
00230                         int i = 0;
00231                         int64_t return_value = ftello64(file);
00232                         STORE_INT64(return_value);
00233                         server->write_socket((char*)datagram, 8, RENDERFARM_TIMEOUT);
00234                         result = 1;
00235 if(DEBUG)
00236 printf("RenderFarmFSServer::handle_request file=%p result=%lld\n", 
00237 file, return_value);
00238                         break;
00239                 }
00240 
00241                 case RENDERFARM_STAT:
00242                 {
00243                         struct stat stat_buf;
00244                         int return_value = stat((char*)buffer, &stat_buf);
00245                         server->write_socket((char*)&stat_buf, sizeof(struct stat), RENDERFARM_TIMEOUT);
00246                         result = 1;
00247 if(DEBUG)
00248 printf("RenderFarmFSServer::handle_request path=%s result=%d\n", 
00249 buffer, return_value);
00250                         break;
00251                 }
00252 
00253                 case RENDERFARM_STAT64:
00254                 {
00255                         struct stat64 stat_buf;
00256                         int return_value = stat64((char*)buffer, &stat_buf);
00257                         vfs_stat_t arg;
00258                         arg.dev = stat_buf.st_dev;
00259 //                      arg.ino32 = stat_buf.__st_ino;
00260                         arg.ino = stat_buf.st_ino;
00261                         arg.nlink = stat_buf.st_nlink;
00262                         arg.mode = stat_buf.st_mode;
00263                         arg.uid = stat_buf.st_uid;
00264                         arg.gid = stat_buf.st_gid;
00265                         arg.rdev = stat_buf.st_rdev;
00266                         arg.size = stat_buf.st_size;
00267                         arg.blksize = stat_buf.st_blksize;
00268                         arg.blocks = stat_buf.st_blocks;
00269                         arg.atim = stat_buf.st_atim.tv_sec;
00270                         arg.mtim = stat_buf.st_mtim.tv_sec;
00271                         arg.ctim = stat_buf.st_ctim.tv_sec;
00272                         server->write_socket((char*)&arg, sizeof(arg), RENDERFARM_TIMEOUT);
00273                         result = 1;
00274 if(DEBUG)
00275 printf("RenderFarmFSServer::handle_request path=%s result=%d\n", 
00276 buffer, return_value);
00277                         break;
00278                 }
00279         }
00280 
00281         return result;
00282 }

Generated on Sun Jan 8 13:39:00 2006 for Cinelerra-svn by  doxygen 1.4.4