summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pychrysalide')
-rw-r--r--plugins/pychrysalide/core.c93
1 files changed, 93 insertions, 0 deletions
diff --git a/plugins/pychrysalide/core.c b/plugins/pychrysalide/core.c
index 30d4259..f1191fb 100644
--- a/plugins/pychrysalide/core.c
+++ b/plugins/pychrysalide/core.c
@@ -107,6 +107,9 @@ static void extend_python_path(const char *);
/* Charge autant de greffons composés en Python que possible. */
static void load_python_plugins(GPluginModule *);
+/* Efface un type Python pour greffon de la mémoire. */
+static void free_native_plugin_type(PyTypeObject *);
+
/******************************************************************************
@@ -839,6 +842,28 @@ G_MODULE_EXPORT void chrysalide_plugin_exit(GPluginModule *plugin)
/******************************************************************************
* *
+* Paramètres : type = informations à libérer de la mémoire. *
+* *
+* Description : Efface un type Python pour greffon de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void free_native_plugin_type(PyTypeObject *type)
+{
+ free((char *)type->tp_name);
+ free((char *)type->tp_doc);
+
+ free(type);
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : plugin = greffon à manipuler. *
* action = type d'action attendue. *
* *
@@ -852,9 +877,77 @@ G_MODULE_EXPORT void chrysalide_plugin_exit(GPluginModule *plugin)
G_MODULE_EXPORT void chrysalide_plugin_on_plugins_loaded(GPluginModule *plugin, PluginAction action)
{
+ size_t count; /* Quantité de greffons chargés*/
+ PyTypeObject *parent; /* Type Python pour greffon */
+ PyObject *module; /* Module à recompléter */
+ PyObject *dict; /* Dictionnaire du module */
+ GPluginModule **list; /* Ensemble de ces greffons */
+ size_t i; /* Boucle de parcours */
+ char *name; /* Désignation complète */
+ char *doc; /* Description adaptée */
+ int ret; /* Bilan d'un appel */
+ PyTypeObject *type; /* Nouveau type dynamique */
+
if (action == PGA_NATIVE_PLUGINS_LOADED)
+ {
+ /* Intégration des greffons natifs en Python */
+
+ if (ensure_python_plugin_module_is_registered())
+ {
+ parent = get_python_plugin_module_type();
+
+ module = get_access_to_python_module("pychrysalide.plugins");
+ assert(module != NULL);
+
+ dict = PyModule_GetDict(module);
+
+ list = get_all_plugins(&count);
+
+ for (i = 0; i < count; i++)
+ {
+ ret = asprintf(&name, "pychrysalide.plugins.%s", G_OBJECT_TYPE_NAME(list[i]) + 1);
+ if (ret == -1)
+ {
+ LOG_ERROR_N("asprintf");
+ continue;
+ }
+
+ ret = asprintf(&doc, "Place holder for the native plugin %s documentation",
+ G_OBJECT_TYPE_NAME(list[i]) + 1);
+ if (ret == -1)
+ {
+ LOG_ERROR_N("asprintf");
+ free(name);
+ continue;
+ }
+
+ type = calloc(1, sizeof(PyTypeObject));
+
+ type->tp_name = name;
+ type->tp_doc = doc;
+ type->tp_flags = Py_TPFLAGS_DEFAULT;
+ type->tp_new = no_python_constructor_allowed;
+
+ if (register_class_for_pygobject(dict, G_OBJECT_TYPE(list[i]), type, parent))
+ g_object_set_data_full(G_OBJECT(list[i]), "python_type", type,
+ (GDestroyNotify)free_native_plugin_type);
+
+ else
+ free_native_plugin_type(type);
+
+ }
+
+ }
+
+ if (list != NULL)
+ free(list);
+
+ /* Chargement des extensions purement Python */
+
load_python_plugins(plugin);
+ }
+
}