diff options
Diffstat (limited to 'src/common/helper.c')
-rw-r--r-- | src/common/helper.c | 86 |
1 files changed, 46 insertions, 40 deletions
diff --git a/src/common/helper.c b/src/common/helper.c index e454fe06..d3c1ef64 100644 --- a/src/common/helper.c +++ b/src/common/helper.c | |||
@@ -26,6 +26,7 @@ | |||
26 | 26 | ||
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "gnunetgtk_common.h" | 28 | #include "gnunetgtk_common.h" |
29 | #include <GNUnet/gnunet_util_crypto.h> | ||
29 | #include <glib.h> | 30 | #include <glib.h> |
30 | 31 | ||
31 | #define HELPER_DEBUG NO | 32 | #define HELPER_DEBUG NO |
@@ -68,7 +69,7 @@ static GdkWindowState main_window_state; | |||
68 | /** | 69 | /** |
69 | * the main thread | 70 | * the main thread |
70 | */ | 71 | */ |
71 | static struct PTHREAD_T * mainThread; | 72 | static struct PTHREAD * mainThread; |
72 | 73 | ||
73 | static SaveCall ** psc; | 74 | static SaveCall ** psc; |
74 | 75 | ||
@@ -82,6 +83,8 @@ static Plugin * plugin; | |||
82 | 83 | ||
83 | static void * shutdown_function; | 84 | static void * shutdown_function; |
84 | 85 | ||
86 | static struct GE_Context * ectx; | ||
87 | |||
85 | #ifdef WINDOWS | 88 | #ifdef WINDOWS |
86 | static void CALLBACK sigalrmHandler(DWORD sig) { | 89 | static void CALLBACK sigalrmHandler(DWORD sig) { |
87 | } | 90 | } |
@@ -101,7 +104,7 @@ static gboolean saveCallWrapper(gpointer data) { | |||
101 | break; | 104 | break; |
102 | } | 105 | } |
103 | } | 106 | } |
104 | GNUNET_ASSERT(i != pscCount); | 107 | GE_ASSERT(NULL, i != pscCount); |
105 | GROW(psc, | 108 | GROW(psc, |
106 | pscCount, | 109 | pscCount, |
107 | pscCount-1); | 110 | pscCount-1); |
@@ -125,10 +128,10 @@ void gtkSaveCall(SimpleCallback func, | |||
125 | 128 | ||
126 | MUTEX_LOCK(sclock); | 129 | MUTEX_LOCK(sclock); |
127 | if ( (saveCallsUp == NO) || | 130 | if ( (saveCallsUp == NO) || |
128 | (! PTHREAD_SELF_TEST(mainThread)) ) { | 131 | (! PTHREAD_TEST_SELF(mainThread)) ) { |
129 | call.args = args; | 132 | call.args = args; |
130 | call.func = func; | 133 | call.func = func; |
131 | call.sem = SEMAPHORE_NEW(0); | 134 | call.sem = SEMAPHORE_CREATE(0); |
132 | call.destroyed = 0; | 135 | call.destroyed = 0; |
133 | GROW(psc, | 136 | GROW(psc, |
134 | pscCount, | 137 | pscCount, |
@@ -139,7 +142,7 @@ void gtkSaveCall(SimpleCallback func, | |||
139 | MUTEX_UNLOCK(sclock); | 142 | MUTEX_UNLOCK(sclock); |
140 | PTHREAD_STOP_SLEEP(mainThread); | 143 | PTHREAD_STOP_SLEEP(mainThread); |
141 | SEMAPHORE_DOWN(call.sem, YES); | 144 | SEMAPHORE_DOWN(call.sem, YES); |
142 | SEMAPHORE_FREE(call.sem, YES); | 145 | SEMAPHORE_DESTROY(call.sem); |
143 | } else { | 146 | } else { |
144 | MUTEX_UNLOCK(sclock); | 147 | MUTEX_UNLOCK(sclock); |
145 | func(args); | 148 | func(args); |
@@ -269,9 +272,9 @@ static void connector(const gchar *handler_name, | |||
269 | plug = plugin; | 272 | plug = plugin; |
270 | method = NULL; | 273 | method = NULL; |
271 | while (plug != NULL) { | 274 | while (plug != NULL) { |
272 | method = trybindDynamicMethod(plug->library, | 275 | method = os_plugin_resolve_function(plug->library, |
273 | "", | 276 | handler_name, |
274 | handler_name); | 277 | NO); |
275 | if (method != NULL) | 278 | if (method != NULL) |
276 | break; | 279 | break; |
277 | plug = plug->next; | 280 | plug = plug->next; |
@@ -301,26 +304,22 @@ typedef void (*PlainCall)(void); | |||
301 | 304 | ||
302 | static void loadPlugin(const char * name) { | 305 | static void loadPlugin(const char * name) { |
303 | Plugin * p; | 306 | Plugin * p; |
304 | void * lib; | 307 | struct PluginHandle * lib; |
305 | PlainCall init; | 308 | PlainCall init; |
306 | 309 | ||
307 | lib = loadDynamicLibrary("libgnunetgtkmodule_", | 310 | lib = os_plugin_load(ectx, |
308 | name); | 311 | "libgnunetgtkmodule_", |
309 | if (lib == NULL) { | 312 | name); |
310 | GE_LOG(ectx, | 313 | if (lib == NULL) |
311 | GE_WARNING | GE_ADMIN | GE_IMMEDIATE, | 314 | return; |
312 | _("Failed to load plugin `%s'\n"), | ||
313 | name); | ||
314 | return; | ||
315 | } | ||
316 | p = MALLOC(sizeof(Plugin)); | 315 | p = MALLOC(sizeof(Plugin)); |
317 | p->name = STRDUP(name); | 316 | p->name = STRDUP(name); |
318 | p->next = plugin; | 317 | p->next = plugin; |
319 | p->library = lib; | 318 | p->library = lib; |
320 | plugin = p; | 319 | plugin = p; |
321 | init = trybindDynamicMethod(lib, | 320 | init = os_plugin_resolve_function(lib, |
322 | "init_", | 321 | "init_", |
323 | name); | 322 | NO); |
324 | if (init != NULL) | 323 | if (init != NULL) |
325 | init(); | 324 | init(); |
326 | } | 325 | } |
@@ -357,22 +356,25 @@ static void loadPlugins(const char * names) { | |||
357 | static void unloadPlugin(Plugin * plug) { | 356 | static void unloadPlugin(Plugin * plug) { |
358 | PlainCall done; | 357 | PlainCall done; |
359 | 358 | ||
360 | done = trybindDynamicMethod(plug->library, | 359 | done = os_plugin_resolve_function(plug->library, |
361 | "done_", | 360 | "done_", |
362 | plug->name); | 361 | NO); |
363 | if (done != NULL) | 362 | if (done != NULL) |
364 | done(); | 363 | done(); |
365 | unloadDynamicLibrary(plug->library); | 364 | os_plugin_unload(plug->library); |
366 | FREE(plug->name); | 365 | FREE(plug->name); |
367 | FREE(plug); | 366 | FREE(plug); |
368 | } | 367 | } |
369 | 368 | ||
370 | void initGNUnetGTKCommon(void * callback) { | 369 | void initGNUnetGTKCommon(struct GE_Context * e, |
370 | struct GC_Configuration * cfg, | ||
371 | void * callback) { | ||
371 | char * load; | 372 | char * load; |
372 | 373 | ||
374 | ectx = e; | ||
373 | shutdown_function = callback; | 375 | shutdown_function = callback; |
374 | sclock = MUTEX_CREATE(YES); | 376 | sclock = MUTEX_CREATE(YES); |
375 | PTHREAD_GET_SELF(&mainThread); | 377 | mainThread = PTHREAD_GET_SELF(); |
376 | saveCallsUp = YES; | 378 | saveCallsUp = YES; |
377 | 379 | ||
378 | /* load the interface */ | 380 | /* load the interface */ |
@@ -388,8 +390,10 @@ void initGNUnetGTKCommon(void * callback) { | |||
388 | "mainWindow", | 390 | "mainWindow", |
389 | PACKAGE_NAME); | 391 | PACKAGE_NAME); |
390 | if (mainXML == NULL) | 392 | if (mainXML == NULL) |
391 | errexit(_("Failed to open `%s'.\n"), | 393 | GE_DIE_STRERROR_FILE(ectx, |
392 | gladeFile); | 394 | GE_FATAL | GE_USER | GE_IMMEDIATE, |
395 | "glade_xml_new", | ||
396 | gladeFile); | ||
393 | statusXML | 397 | statusXML |
394 | = glade_xml_new(getGladeFileName(), | 398 | = glade_xml_new(getGladeFileName(), |
395 | "statusWindow", | 399 | "statusWindow", |
@@ -401,10 +405,11 @@ void initGNUnetGTKCommon(void * callback) { | |||
401 | = glade_xml_get_widget(statusXML, | 405 | = glade_xml_get_widget(statusXML, |
402 | "messageWindowTextView"); | 406 | "messageWindowTextView"); |
403 | /* load the plugins */ | 407 | /* load the plugins */ |
404 | load = getConfigurationString("GNUNET-GTK", | 408 | GC_get_configuration_value_string(cfg, |
405 | "PLUGINS"); | 409 | "GNUNET-GTK", |
406 | if (load == NULL) | 410 | "PLUGINS", |
407 | load = STRDUP("about daemon fs"); | 411 | "about daemon fs", |
412 | &load); | ||
408 | loadPlugins(load); | 413 | loadPlugins(load); |
409 | FREE(load); | 414 | FREE(load); |
410 | connectGladeWithPlugins(mainXML); | 415 | connectGladeWithPlugins(mainXML); |
@@ -440,7 +445,7 @@ void shutdownPlugins() { | |||
440 | the gtkSaveCall method before destroying | 445 | the gtkSaveCall method before destroying |
441 | the mutex! */ | 446 | the mutex! */ |
442 | while (i != 0) { | 447 | while (i != 0) { |
443 | gnunet_util_sleep(50 * cronMILLIS); | 448 | PTHREAD_SLEEP(50 * cronMILLIS); |
444 | MUTEX_LOCK(sclock); | 449 | MUTEX_LOCK(sclock); |
445 | i = pscCount; | 450 | i = pscCount; |
446 | MUTEX_UNLOCK(sclock); | 451 | MUTEX_UNLOCK(sclock); |
@@ -448,7 +453,7 @@ void shutdownPlugins() { | |||
448 | } | 453 | } |
449 | 454 | ||
450 | void doneGNUnetGTKCommon() { | 455 | void doneGNUnetGTKCommon() { |
451 | PTHREAD_REL_SELF(&mainThread); | 456 | PTHREAD_REL_SELF(mainThread); |
452 | MUTEX_DESTROY(sclock); | 457 | MUTEX_DESTROY(sclock); |
453 | } | 458 | } |
454 | 459 | ||
@@ -470,12 +475,12 @@ static void * shutdownCode(void * arg) { | |||
470 | 475 | ||
471 | void run_with_save_calls(PThreadMain cb, | 476 | void run_with_save_calls(PThreadMain cb, |
472 | void * arg) { | 477 | void * arg) { |
473 | struct PTHREAD_T * doneThread; | 478 | struct PTHREAD * doneThread; |
474 | void * unused; | 479 | void * unused; |
475 | struct rwsc_closure cls; | 480 | struct rwsc_closure cls; |
476 | int i; | 481 | int i; |
477 | 482 | ||
478 | cls.sig = SEMAPHORE_NEW(0); | 483 | cls.sig = SEMAPHORE_CREATE(0); |
479 | cls.realMain = cb; | 484 | cls.realMain = cb; |
480 | cls.arg = arg; | 485 | cls.arg = arg; |
481 | doneThread = PTHREAD_CREATE(&shutdownCode, | 486 | doneThread = PTHREAD_CREATE(&shutdownCode, |
@@ -483,8 +488,9 @@ void run_with_save_calls(PThreadMain cb, | |||
483 | 64*1024); | 488 | 64*1024); |
484 | if (doneThread == NULL) | 489 | if (doneThread == NULL) |
485 | GE_DIE_STRERROR(ectx, | 490 | GE_DIE_STRERROR(ectx, |
491 | GE_FATAL | GE_ADMIN | GE_BULK, | ||
486 | "pthread_create"); | 492 | "pthread_create"); |
487 | if (! PTHREAD_SELF_TEST(mainThread)) { | 493 | if (! PTHREAD_TEST_SELF(mainThread)) { |
488 | /* another thread will run the save calls */ | 494 | /* another thread will run the save calls */ |
489 | SEMAPHORE_DOWN(cls.sig, YES); | 495 | SEMAPHORE_DOWN(cls.sig, YES); |
490 | } else { | 496 | } else { |
@@ -500,13 +506,13 @@ void run_with_save_calls(PThreadMain cb, | |||
500 | MUTEX_UNLOCK(sclock); | 506 | MUTEX_UNLOCK(sclock); |
501 | if ( (i == -1) && | 507 | if ( (i == -1) && |
502 | (OK != SEMAPHORE_DOWN(cls.sig, NO)) ) { | 508 | (OK != SEMAPHORE_DOWN(cls.sig, NO)) ) { |
503 | gnunet_util_sleep(50 * cronMILLIS); | 509 | PTHREAD_SLEEP(50 * cronMILLIS); |
504 | } | 510 | } |
505 | } | 511 | } |
506 | } | 512 | } |
507 | PTHREAD_JOIN(doneThread, | 513 | PTHREAD_JOIN(doneThread, |
508 | &unused); | 514 | &unused); |
509 | SEMAPHORE_FREE(cls.sig); | 515 | SEMAPHORE_DESTROY(cls.sig); |
510 | } | 516 | } |
511 | 517 | ||
512 | /** | 518 | /** |