bool PluginManager::unloadAllPlugins() { if (!initialized) { std::cerr << "PluginManager: Manager not initialized" << std::endl; return false; } if (!shutdownAllPlugins()) return false; for (DynLibMap::iterator di = dynlibs.begin(); di != dynlibs.end(); ++di) { SNL_DLL_STOP_PLUGIN stop_func = (SNL_DLL_STOP_PLUGIN)di->second->getSymbol("dllStopPlugin"); stop_func(); // this must call uninstall(), which removes the plugin from the installed list if (!DynLibManager::unload(di->second)) return false; } dynlibs.clear(); // There should be only static libs left now for (PluginList::iterator pi = plugins.begin(); pi != plugins.end(); ++pi) { std::cout << "PluginManager: Uninstalling plugin '" << (*pi)->getName() << '\'' << std::endl; if (!(*pi)->uninstall()) return false; } plugins.clear(); return false; }
static void RdkHandle_dealloc(PyObject *self, PyObject *(*stop_func) (RdkHandle *)) { PyObject *stop_result = stop_func((RdkHandle *)self); if (!stop_result) { /* We'll swallow the exception, so let's try to log info first */ PyObject *res = PyObject_CallMethod( logger, "exception", "s", "In dealloc: stop() failed."); PyErr_Clear(); Py_XDECREF(res); } else { Py_DECREF(stop_result); } pthread_rwlock_destroy(&((RdkHandle *)self)->rwlock); self->ob_type->tp_free(self); }
/* Cleanup helper for *_start(), returns NULL to allow shorthand in use. * NB: assumes self->rwlock is held and releases it. */ static PyObject * RdkHandle_start_fail(RdkHandle *self, PyObject *(*stop_func) (RdkHandle *)) { /* Something went wrong so we expect an exception has been set */ PyObject *err_type, *err_value, *err_traceback; PyErr_Fetch(&err_type, &err_value, &err_traceback); RdkHandle_unlock(self); PyObject *stop_result = stop_func(self); /* stop_func is likely to raise exceptions, as start was incomplete */ if (! stop_result) PyErr_Clear(); else Py_DECREF(stop_result); PyErr_Restore(err_type, err_value, err_traceback); return NULL; }
void join_thread(pthread_t* thread, void* data, void (*stop_func)(void*)) { int result; void* status; if (*thread != 0) { if (stop_func != NULL) { stop_func(data); } if ((result = pthread_join(*thread, (void **)&status)) != 0) { ml_log_warn("Failed to join thread: %s\n", strerror(result)); } *thread = 0; } }
bool PluginManager::unload(std::string const & path) { if (!initialized) { std::cerr << "PluginManager: Manager not initialized" << std::endl; return false; } DynLibMap::iterator dyn_loaded = dynlibs.find(path); if (dyn_loaded != dynlibs.end()) { SNL_DLL_STOP_PLUGIN stop_func = (SNL_DLL_STOP_PLUGIN)dyn_loaded->second->getSymbol("dllStopPlugin"); stop_func(); // this must call uninstall(), which removes the plugin from the installed list if (!DynLibManager::unload(dyn_loaded->second)) return false; dynlibs.erase(dyn_loaded); } return true; }
static void _eventd_protocol_evp_parse_line(EventdProtocol *self, const gchar *line, GError **error) { #ifdef EVENTD_DEBUG g_debug("[%s] Parse line: %.255s%s", _eventd_protocol_evp_states[self->state], line, ( strlen(line) > 255 ) ? " […]" : ""); #endif /* EVENTD_DEBUG */ const EventdProtocolTokens *message; /* * Handle the end of a dot message */ if ( g_strcmp0(line, ".") == 0 ) { for ( message = _eventd_protocol_evp_dot_messages ; message->message != NULL ; ++message ) { if ( self->state == message->continue_state ) return message->stop_func(self, error); } return g_set_error(error, EVENTD_PROTOCOL_PARSE_ERROR, EVENTD_PROTOCOL_PARSE_ERROR_UNEXPECTED_TOKEN, "Got '.' in an invalid state '%s'", _eventd_protocol_evp_states[self->state]); } /* * Handle dot message line */ for ( message = _eventd_protocol_evp_dot_messages ; message->message != NULL ; ++message ) { if ( self->state == message->continue_state ) { if ( message->continue_func(self, line, error) ) return; } } /* * Either we got a brand new message * or the dot message did not eat the line */ const EventdProtocolState *state; if ( g_str_has_prefix(line, ".") ) { message = _eventd_protocol_evp_dot_messages; ++line; } else message = _eventd_protocol_evp_messages; for ( ; message->message != NULL ; ++message ) { if ( ! g_str_has_prefix(line, message->message) ) continue; const gchar *args = line + strlen(message->message); gchar **argv = NULL; if ( g_str_has_prefix(args, " ") ) { ++args; if ( message->max_args < 1 ) return g_set_error(error, EVENTD_PROTOCOL_PARSE_ERROR, EVENTD_PROTOCOL_PARSE_ERROR_MALFORMED, "Message '%s' does not take arguments, but got '%s'", message->message, args); gsize argc; argv = g_strsplit(args, " ", message->max_args); argc = g_strv_length(argv); if ( argc < message->min_args ) { g_strfreev(argv); return g_set_error(error, EVENTD_PROTOCOL_PARSE_ERROR, EVENTD_PROTOCOL_PARSE_ERROR_MALFORMED, "Message '%s' does take at least %" G_GSIZE_FORMAT " arguments, but got %" G_GSIZE_FORMAT, message->message, message->min_args, argc); } } else if ( message->min_args > 0 ) return g_set_error(error, EVENTD_PROTOCOL_PARSE_ERROR, EVENTD_PROTOCOL_PARSE_ERROR_MALFORMED, "Message '%s' does take at least %" G_GSIZE_FORMAT " arguments, but got none", message->message, message->min_args); gboolean valid = FALSE; for ( state = message->start_states ; *state != _EVENTD_PROTOCOL_EVP_STATE_SIZE ; ++state ) { if ( self->state == *state ) valid = TRUE; } if ( valid ) message->start_func(self, (const gchar * const *) argv, error); else g_set_error(error, EVENTD_PROTOCOL_PARSE_ERROR, EVENTD_PROTOCOL_PARSE_ERROR_UNEXPECTED_TOKEN, "Message '%s' in an invalid state '%s'", message->message, _eventd_protocol_evp_states[self->state]); return; } }