/* This file is part of GNUnet. (C) 2005 Christian Grothoff (and other contributing authors) GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNUnet; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /** * @file src/fs.c * @brief main file-sharing code of gnunet-gtk * @author Christian Grothoff */ #include "fs.h" #include "helper.h" #include "download.h" #include "search.h" #include "upload.h" #include struct FSUI_Context * ctx; static gint saveEventProcessor(SaveCall * call) { const FSUI_Event * event; event = (const FSUI_Event *) call->args; switch (event->type) { case search_result: displaySearchResult(&event->data.SearchResult.fi, event->data.SearchResult.searchURI, NULL); break; case search_error: LOG(LOG_ERROR, _("Error while searching: %s\n"), event->data.message); break; case download_progress: displayDownloadUpdate(event->data.DownloadProgress.uri, event->data.DownloadProgress.completed); /* FIXME: if directory, also update search view! */ break; case download_complete: displayDownloadComplete(event->data.DownloadProgress.uri, event->data.DownloadProgress.filename); /* FIXME: if directory, also update search view! */ break; case download_error: BREAK(); LOG(LOG_ERROR, _("Error while downloading: %s\n"), event->data.message); break; case upload_progress: displayUploadUpdate(event->data.UploadProgress.main_filename, event->data.UploadProgress.filename, event->data.UploadProgress.completed, event->data.UploadProgress.total); displayUploadUpdate(event->data.UploadProgress.main_filename, event->data.UploadProgress.main_filename, event->data.UploadProgress.main_completed, event->data.UploadProgress.main_total); break; case upload_complete: displayUploadComplete(event->data.UploadComplete.main_filename, event->data.UploadComplete.filename, event->data.UploadComplete.uri); break; case upload_error: LOG(LOG_ERROR, _("Error while uploading: %s\n"), event->data.message); break; case gnunetd_connected: LOG(LOG_MESSAGE, _("Connected to gnunetd.\n")); break; case gnunetd_disconnected: LOG(LOG_MESSAGE, _("Disconnected from gnunetd.\n")); break; default: BREAK(); LOG(LOG_ERROR, _("Unhandled (unknown) FSUI event: %u.\n"), event->type); break; } gtkSaveCallDone(call->sem); return FALSE; } /** * FSUI event handler. */ static void eventProcessor(void * cls, const FSUI_Event * event) { gtkSaveCall((GtkFunction) &saveEventProcessor, (void*) event); } void gtk_fs_init() { ctx = FSUI_start("gnunet-gtk", YES, &eventProcessor, NULL); fs_search_start(); fs_download_start(); fs_upload_start(); } static void * shutdownCode(Semaphore * sig) { fs_download_stop(); fs_search_stop(); FSUI_stop(ctx); fs_upload_stop(); SEMAPHORE_UP(sig); return NULL; } void gtk_fs_done() { PTHREAD_T doneThread; Semaphore * sig; void * unused; sig = SEMAPHORE_NEW(0); if (0 != PTHREAD_CREATE(&doneThread, (PThreadMain)&shutdownCode, sig, 8*1024)) DIE_STRERROR("pthread_create"); while (OK != SEMAPHORE_DOWN_NONBLOCKING(sig)) gtkRunSomeSaveCalls(); PTHREAD_JOIN(&doneThread, &unused); SEMAPHORE_FREE(sig); } /* end of fs.c */