4 * Copyright (C) 2009 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
26 #include "bcresources.h"
27 #include "bcsignals.h"
29 #include "fileserver.h"
36 FileServer::FileServer(Preferences *preferences) : ForkWrapper()
38 this->preferences = preferences;
39 lock = new Mutex("FileServer::lock");
42 FileServer::~FileServer()
48 void FileServer::init_child()
50 BC_WindowBase::get_resources()->vframe_shm = 1;
51 //printf("FileServer::init_child %d %d\n", __LINE__, getpid());
54 int FileServer::handle_command()
61 FileFork *file_fork = new FileFork(this);
63 unsigned char buffer[sizeof(FileFork*) + sizeof(int)];
64 FileFork **ffbfr = (FileFork **)buffer;
66 int *ibfr = (int *)&ffbfr[1];
67 *ibfr = file_fork->pid;
69 if(debug) printf("FileServer::handle_command NEW_FILEFORK %d parent_fd=%d file_fork=%p\n",
73 send_fd(file_fork->parent_fd);
74 send_result(0, buffer, sizeof(FileFork*) + sizeof(int));
80 FileFork **ffbfr = (FileFork **)command_data;
81 FileFork *file_fork = *ffbfr;
82 if(debug) printf("FileServer::handle_command DELETE_FILEFORK %d file_fork=%p\n",
93 FileFork* FileServer::new_filefork()
95 lock->lock("FileServer::open_file");
96 FileFork *dummy_fork = new FileFork(this);
97 // Create real file fork on the server
98 send_command(FileServer::NEW_FILEFORK, 0, 0);
100 int parent_fd = get_fd();
103 // Transfer fd to dummy file fork
104 dummy_fork->start_dummy(parent_fd, *(int*)(result_data + sizeof(FileFork*)));
105 dummy_fork->real_fork = *(FileFork**)result_data;
106 // printf("FileServer::new_filefork %d parent_fd=%d real_fork=%p\n",
109 // dummy_fork->real_fork);
114 void FileServer::delete_filefork(FileFork *file_fork)
116 lock->lock("FileServer::close_file");
117 // Delete filefork on server
118 unsigned char buffer[sizeof(FileFork*)];
119 FileFork **ffbfr = (FileFork **)buffer;
121 send_command(FileServer::DELETE_FILEFORK, buffer, sizeof(FileFork*));
125 #endif // USE_FILEFORK