static gboolean gplp_func_desc_load (GOPluginService *service, char const *name, GnmFuncDescriptor *res) { ServiceLoaderDataFunctionGroup *loader_data; PyObject *fn_info_obj; g_return_val_if_fail (GNM_IS_PLUGIN_SERVICE_FUNCTION_GROUP (service), FALSE); g_return_val_if_fail (name != NULL, FALSE); loader_data = g_object_get_data (G_OBJECT (service), "loader_data"); SWITCH_TO_PLUGIN (go_plugin_service_get_plugin (service)); fn_info_obj = PyDict_GetItemString (loader_data->python_fn_info_dict, (gchar *) name); if (fn_info_obj == NULL) { gnm_python_clear_error_if_needed (SERVICE_GET_LOADER (service)->py_object); return FALSE; } if (PyTuple_Check (fn_info_obj)) { PyObject *python_args; PyObject *python_fn; if (PyTuple_Size (fn_info_obj) == 3 && (python_args = PyTuple_GetItem (fn_info_obj, 0)) != NULL && PyString_Check (python_args) && (python_fn = PyTuple_GetItem (fn_info_obj, 2)) != NULL && PyCallable_Check (python_fn)) { res->arg_spec = PyString_AsString (python_args); res->help = python_function_get_gnumeric_help ( loader_data->python_fn_info_dict, python_fn, name); res->fn_args = &call_python_function_args; res->fn_nodes = NULL; res->linker = NULL; res->impl_status = GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC; res->test_status = GNM_FUNC_TEST_STATUS_UNKNOWN; return TRUE; } gnm_python_clear_error_if_needed (SERVICE_GET_LOADER (service)->py_object); return FALSE; } if (PyCallable_Check (fn_info_obj)) { res->arg_spec = ""; res->help = python_function_get_gnumeric_help ( loader_data->python_fn_info_dict, fn_info_obj, name); res->fn_args = NULL; res->fn_nodes = &call_python_function_nodes; res->linker = NULL; res->impl_status = GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC; res->test_status = GNM_FUNC_TEST_STATUS_UNKNOWN; return TRUE; } gnm_python_clear_error_if_needed (SERVICE_GET_LOADER (service)->py_object); return FALSE; }
static gboolean gplp_service_unload (GOPluginLoader *l, GOPluginService *s, GOErrorInfo **err) { if (GNM_IS_PLUGIN_SERVICE_FUNCTION_GROUP (s)) ; else return FALSE; return TRUE; }
static gboolean gplp_service_load (GOPluginLoader *l, GOPluginService *s, GOErrorInfo **err) { if (GNM_IS_PLUGIN_SERVICE_FUNCTION_GROUP (s)) gplp_load_service_function_group (l, s, err); else return FALSE; return TRUE; }
static void gplp_load_service_function_group (GOPluginLoader *loader, GOPluginService *service, GOErrorInfo **ret_error) { GnmPluginServiceFunctionGroupCallbacks *cbs; g_return_if_fail (GNM_IS_PLUGIN_SERVICE_FUNCTION_GROUP (service)); GO_INIT_RET_ERROR_INFO (ret_error); cbs = go_plugin_service_get_cbs (service); cbs->load_stub = &gplp_func_load_stub; }
static void gplp_load_service_function_group (GOPluginLoader *loader, GOPluginService *service, GOErrorInfo **ret_error) { GnmPythonPluginLoader *loader_python = GNM_PYTHON_PLUGIN_LOADER (loader); gchar *fn_info_dict_name; PyObject *python_fn_info_dict; g_return_if_fail (GNM_IS_PLUGIN_SERVICE_FUNCTION_GROUP (service)); GO_INIT_RET_ERROR_INFO (ret_error); gnm_py_interpreter_switch_to (loader_python->py_interpreter_info); fn_info_dict_name = g_strconcat ( go_plugin_service_get_id (service), "_functions", NULL); python_fn_info_dict = PyDict_GetItemString (loader_python->main_module_dict, fn_info_dict_name); gnm_python_clear_error_if_needed (loader_python->py_object); if (python_fn_info_dict != NULL && PyDict_Check (python_fn_info_dict)) { GnmPluginServiceFunctionGroupCallbacks *cbs; ServiceLoaderDataFunctionGroup *loader_data; cbs = go_plugin_service_get_cbs (service); cbs->func_desc_load = &gplp_func_desc_load; loader_data = g_new (ServiceLoaderDataFunctionGroup, 1); loader_data->python_fn_info_dict = (PyObject *) python_fn_info_dict; Py_INCREF (loader_data->python_fn_info_dict); g_object_set_data_full (G_OBJECT (service), "loader_data", loader_data, (GDestroyNotify) gplp_loader_data_fngroup_free); } else { *ret_error = go_error_info_new_printf ( _("Python file \"%s\" has invalid format."), loader_python->module_name); if (python_fn_info_dict == NULL) { go_error_info_add_details (*ret_error, go_error_info_new_printf ( _("File doesn't contain \"%s\" dictionary."), fn_info_dict_name)); } else if (!PyDict_Check (python_fn_info_dict)) { go_error_info_add_details (*ret_error, go_error_info_new_printf ( _("Object \"%s\" is not a dictionary."), fn_info_dict_name)); } } g_free (fn_info_dict_name); }
static void gplp_unload_service_function_group (GOPluginLoader *loader, GOPluginService *service, GOErrorInfo **ret_error) { ServiceLoaderDataFunctionGroup *loader_data; g_return_if_fail (GNM_IS_PYTHON_PLUGIN_LOADER (loader)); g_return_if_fail (GNM_IS_PLUGIN_SERVICE_FUNCTION_GROUP (service)); GO_INIT_RET_ERROR_INFO (ret_error); loader_data = g_object_get_data (G_OBJECT (service), "loader_data"); SWITCH_TO_PLUGIN (go_plugin_service_get_plugin (service)); Py_DECREF (loader_data->python_fn_info_dict); }