int s52ais_initAIS(void) { g_print("s52ais_initAIS() .. start\n"); // so all occurence of _ais_list are mutex'ed // (but this one is useless - but what if android restart main()!) GMUTEXLOCK(&_ais_list_mutex); if (NULL == _ais_list) { _ais_list = g_array_new(FALSE, TRUE, sizeof(_ais_t)); } else { g_print("s52ais:s52ais_initAIS(): bizzard case where we are restarting a running process!!\n"); GMUTEXUNLOCK(&_ais_list_mutex); return TRUE; } GMUTEXUNLOCK(&_ais_list_mutex); #if 0 // NOTE: on Ubuntu, GPSD is started at boot-time if (TRUE != _startGPSD()) return FALSE; #endif #ifdef WIN32 WSADATA wsaData; WSAStartup(MAKEWORD(2, 2), &wsaData); #endif #ifdef S52_USE_DBUS _initDBus(); #endif #ifdef S52_USE_SOCK _s52_connection = _s52_init_sock(_localhost, S52_PORT); if (NULL == _s52_connection) { g_print("s52ais_initAIS() .. _s52_init_sock() failed \n"); return FALSE; } #endif // no thread needed in standalone #if !defined(S52AIS_STANDALONE) // not joinable - gps done will not wait #ifdef S52_USE_ANDROID _gpsClientThread = g_thread_create_full(_gpsdClientStart, NULL, 0, FALSE, TRUE, G_THREAD_PRIORITY_NORMAL, NULL); #else _gpsClientThread = g_thread_new("threadName", _gpsdClientStart, NULL); #endif #endif // setup timer g_get_current_time(&_timeTick); return TRUE; }
static void _trapSIG(int sig, siginfo_t *info, void *secret) { switch(sig) { // 2 case SIGINT: g_print("s52ais:_trapSIG(): Signal 'Interrupt' cought - SIGINT(%i)\n", sig); s52ais_doneAIS(); // continue with normal sig handling if (NULL != _old_signal_handler_SIGINT.sa_sigaction) _old_signal_handler_SIGINT.sa_sigaction(sig, info, secret); break; // 11 case SIGSEGV: g_print("s52ais:_trapSIG(): Signal 'Segmentation violation' cought - SIGSEGV(%i)\n", sig); s52ais_doneAIS(); // continue with normal sig handling if (NULL != _old_signal_handler_SIGSEGV.sa_sigaction) _old_signal_handler_SIGSEGV.sa_sigaction(sig, info, secret); break; // 15 case SIGTERM: g_print("s52ais:_trapSIG(): Signal 'Termination (ANSI)' cought - SIGTERM(%i)\n", sig); s52ais_doneAIS(); // continue with normal sig handling if (NULL != _old_signal_handler_SIGTERM.sa_sigaction) _old_signal_handler_SIGTERM.sa_sigaction(sig, info, secret); break; // 10 case SIGUSR1: g_print("s52ais:_trapSIG(): Signal 'User-defined 1' cought - SIGUSR1(%i)\n", sig); // continue with normal sig handling //_old_signal_handler.sa_sigaction(sig, info, secret); break; // 12 case SIGUSR2: g_print("s52ais:_trapSIG(): Signal 'User-defined 2' cought - SIGUSR2(%i)\n", sig); // continue with normal sig handling //_old_signal_handler.sa_sigaction(sig, info, secret); // re-connect to libS52 if (NULL == _s52_connection) { _flushAIS(FALSE); _s52_connection = _s52_init_sock(_localhost, S52_PORT); g_print("s52ais:_trapSIG(): re-connect to libS52\n"); } break; default: g_print("s52ais:_trapSIG():handler not found [%i]\n", sig); break; } return; }