1 /* 2 * Copyright © 2004-2010 Jens Oknelid, paskharen@gmail.com 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 * 18 * In addition, as a special exception, compiling, linking, and/or 19 * using OpenSSL with this program is allowed. 20 */ 21 22 #pragma once 23 24 #include <gtk/gtk.h> 25 #include <glib.h> 26 #include <string> 27 #include "dialogentry.hh" 28 #include "func.hh" 29 #include "mainwindow.hh" 30 31 class WulforManager 32 { 33 public: 34 static void start(int argc, char **argv); 35 static void stop(); 36 static WulforManager *get(); 37 38 WulforManager(); 39 ~WulforManager(); 40 41 std::string getURL(); 42 std::string getPath(); 43 MainWindow *getMainWindow(); 44 void deleteMainWindow(); 45 void dispatchGuiFunc(FuncBase *func); 46 void dispatchClientFunc(FuncBase *func); 47 48 void insertEntry_gui(Entry *entry); 49 void deleteEntry_gui(Entry *entry); 50 bool isEntry_gui(Entry *entry); 51 52 // DialogEntry functions 53 gint openHashDialog_gui(); 54 gint openSettingsDialog_gui(); 55 DialogEntry *getHashDialog_gui(); 56 DialogEntry *getSettingsDialog_gui(); 57 58 void onReceived_gui(const std::string &link); 59 60 private: 61 // argv[1] from main 62 static std::string argv1; 63 64 // MainWindow-related functions 65 void createMainWindow(); 66 67 // Entry functions 68 DialogEntry *getDialogEntry_gui(const std::string &id); 69 70 // Thread-related functions 71 static gpointer threadFunc_gui(gpointer data); 72 static gpointer threadFunc_client(gpointer data); 73 void processGuiQueue(); 74 void processClientQueue(); 75 76 static WulforManager *manager; 77 MainWindow *mainWin; 78 std::string path; 79 std::deque<FuncBase *> guiFuncs; 80 std::deque<FuncBase *> clientFuncs; 81 std::unordered_map<std::string, Entry *> entries; 82 gint guiCondValue; 83 gint clientCondValue; 84 GCond *guiCond; 85 GCond *clientCond; 86 GMutex *guiCondMutex; 87 GMutex *clientCondMutex; 88 GMutex *clientCallMutex; 89 GMutex *guiQueueMutex; 90 GMutex *clientQueueMutex; 91 #if !GLIB_CHECK_VERSION(2,32,0) 92 GStaticRWLock entryMutex; 93 #else 94 GRWLock entryMutex; 95 #endif 96 GThread *guiThread; 97 GThread *clientThread; 98 bool abort; 99 }; 100