aboutsummaryrefslogtreecommitdiff
path: root/src/common/helper.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/helper.c')
-rw-r--r--src/common/helper.c39
1 files changed, 21 insertions, 18 deletions
diff --git a/src/common/helper.c b/src/common/helper.c
index 504e5abe..2dcbe598 100644
--- a/src/common/helper.c
+++ b/src/common/helper.c
@@ -44,8 +44,9 @@
44typedef struct { 44typedef struct {
45 struct SEMAPHORE * sem; 45 struct SEMAPHORE * sem;
46 void * args; 46 void * args;
47 SimpleCallback func; 47 PThreadMain func;
48 int destroyed; 48 int destroyed;
49 void * rval;
49} SaveCall; 50} SaveCall;
50 51
51typedef struct Plugin { 52typedef struct Plugin {
@@ -112,8 +113,7 @@ static gboolean saveCallWrapper(gpointer data) {
112 pscCount-1); 113 pscCount-1);
113 MUTEX_UNLOCK(sclock); 114 MUTEX_UNLOCK(sclock);
114 } 115 }
115 116 call->rval = call->func(call->args);
116 call->func(call->args);
117 if (call->sem != NULL) 117 if (call->sem != NULL)
118 SEMAPHORE_UP(call->sem); 118 SEMAPHORE_UP(call->sem);
119 return FALSE; 119 return FALSE;
@@ -124,8 +124,8 @@ static gboolean saveCallWrapper(gpointer data) {
124 * Since GTK doesn't work with multi-threaded applications under Windows, 124 * Since GTK doesn't work with multi-threaded applications under Windows,
125 * all GTK operations have to be done in the main thread 125 * all GTK operations have to be done in the main thread
126 */ 126 */
127void gtkSaveCall(SimpleCallback func, 127void * gtkSaveCall(PThreadMain func,
128 void * args) { 128 void * args) {
129 SaveCall call; 129 SaveCall call;
130 130
131 MUTEX_LOCK(sclock); 131 MUTEX_LOCK(sclock);
@@ -135,6 +135,7 @@ void gtkSaveCall(SimpleCallback func,
135 call.func = func; 135 call.func = func;
136 call.sem = SEMAPHORE_CREATE(0); 136 call.sem = SEMAPHORE_CREATE(0);
137 call.destroyed = 0; 137 call.destroyed = 0;
138 call.rval = NULL;
138 GROW(psc, 139 GROW(psc,
139 pscCount, 140 pscCount,
140 pscCount+1); 141 pscCount+1);
@@ -145,9 +146,10 @@ void gtkSaveCall(SimpleCallback func,
145 PTHREAD_STOP_SLEEP(mainThread); 146 PTHREAD_STOP_SLEEP(mainThread);
146 SEMAPHORE_DOWN(call.sem, YES); 147 SEMAPHORE_DOWN(call.sem, YES);
147 SEMAPHORE_DESTROY(call.sem); 148 SEMAPHORE_DESTROY(call.sem);
149 return call.rval;
148 } else { 150 } else {
149 MUTEX_UNLOCK(sclock); 151 MUTEX_UNLOCK(sclock);
150 func(args); 152 return func(args);
151 } 153 }
152} 154}
153 155
@@ -171,7 +173,7 @@ typedef struct {
171/** 173/**
172 * Callback for infoMessage() 174 * Callback for infoMessage()
173 */ 175 */
174static void doInfoMessage(void * args) { 176static void * doInfoMessage(void * args) {
175 const InfoMessage * info = args; 177 const InfoMessage * info = args;
176 GtkTextIter iter; 178 GtkTextIter iter;
177 GtkTextBuffer * buffer; 179 GtkTextBuffer * buffer;
@@ -185,6 +187,7 @@ static void doInfoMessage(void * args) {
185 &iter, 187 &iter,
186 info->note, 188 info->note,
187 -1); 189 -1);
190 return NULL;
188} 191}
189 192
190/** 193/**
@@ -207,7 +210,7 @@ void infoMessage(int doPopup,
207 g_free(info.note); 210 g_free(info.note);
208} 211}
209 212
210static void saveAddLogEntry(void * args) { 213static void * saveAddLogEntry(void * args) {
211 static GtkWidget * s = NULL; 214 static GtkWidget * s = NULL;
212 static int once = 1; 215 static int once = 1;
213 static guint id; 216 static guint id;
@@ -224,6 +227,7 @@ static void saveAddLogEntry(void * args) {
224 gtk_statusbar_push(GTK_STATUSBAR(s), 227 gtk_statusbar_push(GTK_STATUSBAR(s),
225 id, 228 id,
226 (const char*) args); 229 (const char*) args);
230 return NULL;
227} 231}
228 232
229/** 233/**
@@ -487,10 +491,10 @@ static void * shutdownCode(void * arg) {
487 return ret; 491 return ret;
488} 492}
489 493
490void run_with_save_calls(PThreadMain cb, 494void * run_with_save_calls(PThreadMain cb,
491 void * arg) { 495 void * arg) {
492 struct PTHREAD * doneThread; 496 struct PTHREAD * doneThread;
493 void * unused; 497 void * retval;
494 struct rwsc_closure cls; 498 struct rwsc_closure cls;
495 int i; 499 int i;
496 500
@@ -525,8 +529,9 @@ void run_with_save_calls(PThreadMain cb,
525 } 529 }
526 } 530 }
527 PTHREAD_JOIN(doneThread, 531 PTHREAD_JOIN(doneThread,
528 &unused); 532 &retval);
529 SEMAPHORE_DESTROY(cls.sig); 533 SEMAPHORE_DESTROY(cls.sig);
534 return retval;
530} 535}
531 536
532/** 537/**
@@ -627,8 +632,7 @@ char * validate_utf8(char * msg) {
627*/ 632*/
628void saveMainWindowState(GtkWidget *main_window, 633void saveMainWindowState(GtkWidget *main_window,
629 GdkEventWindowState *event, 634 GdkEventWindowState *event,
630 gpointer user_data) 635 gpointer user_data) {
631{
632 main_window_state = (*event).new_window_state; 636 main_window_state = (*event).new_window_state;
633 return; 637 return;
634} 638}
@@ -636,14 +640,13 @@ void saveMainWindowState(GtkWidget *main_window,
636/** 640/**
637* Get the last main window state when restoring (tray icon use) 641* Get the last main window state when restoring (tray icon use)
638*/ 642*/
639GdkWindowState getMainWindowState() 643GdkWindowState getMainWindowState() {
640{
641 return main_window_state; 644 return main_window_state;
642} 645}
643 646
644/** 647/**
645* Start gnunet-setup, asking for a password if needed 648 * Start gnunet-setup, asking for a password if needed
646*/ 649 */
647gboolean startGNUnetSetup (gboolean run_wizard) { 650gboolean startGNUnetSetup (gboolean run_wizard) {
648 int code; 651 int code;
649 char *error_message; 652 char *error_message;