summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/analysis/db
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2019-09-12 21:44:24 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2019-09-12 21:44:38 (GMT)
commit682159e73cfbf8ec61d2f2aba765be1016a30ded (patch)
tree9477af8765263667b20a48c53835aa9b3be73a2a /plugins/pychrysalide/analysis/db
parent57f6179e22f880bbcff031714e8576cf9bd488ac (diff)
Extended the Python API for update databases.
Diffstat (limited to 'plugins/pychrysalide/analysis/db')
-rw-r--r--plugins/pychrysalide/analysis/db/collection.c63
-rw-r--r--plugins/pychrysalide/analysis/db/constants.c39
-rw-r--r--plugins/pychrysalide/analysis/db/item.c3
-rw-r--r--plugins/pychrysalide/analysis/db/items/bookmark.c223
-rw-r--r--plugins/pychrysalide/analysis/db/items/bookmark.h17
-rw-r--r--plugins/pychrysalide/analysis/db/items/module.c1
6 files changed, 343 insertions, 3 deletions
diff --git a/plugins/pychrysalide/analysis/db/collection.c b/plugins/pychrysalide/analysis/db/collection.c
index b7e3e0b..e62c17e 100644
--- a/plugins/pychrysalide/analysis/db/collection.c
+++ b/plugins/pychrysalide/analysis/db/collection.c
@@ -37,6 +37,66 @@
+/* Renvoie la liste des éléments rassemblés. */
+static PyObject *py_db_collection_get_items(PyObject *, void *);
+
+
+
+/******************************************************************************
+* *
+* Paramètres : self = objet Python concerné par l'appel. *
+* closure = non utilisé ici. *
+* *
+* Description : Renvoie la liste des éléments rassemblés. *
+* *
+* Retour : Liste d'éléments à parcourir. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_db_collection_get_items(PyObject *self, void *closure)
+{
+ PyObject *result; /* Trouvailles à retourner */
+ GDbCollection *collec; /* Version native */
+ size_t counter; /* Décompte des éléments */
+ GList *items; /* Eléments déjà en place */
+ GList *iter; /* Boucle de parcours */
+ int ret; /* Bilan d'une extension */
+
+#define DB_COLLECTION_ITEMS_ATTRIB PYTHON_GET_DEF_FULL \
+( \
+ items, py_db_collection, \
+ "List of all items contained in the collection." \
+ "\n" \
+ "These items can currently be applied or not." \
+)
+
+ collec = G_DB_COLLECTION(pygobject_get(self));
+
+ counter = 0;
+ result = PyTuple_New(counter);
+
+ g_db_collection_rlock(collec);
+
+ items = g_db_collection_get_items(G_DB_COLLECTION(collec));
+
+ for (iter = g_list_first(items); iter != NULL; iter = g_list_next(iter))
+ {
+ ret = _PyTuple_Resize(&result, ++counter);
+ if (ret == -1) break;
+
+ PyTuple_SetItem(result, counter - 1, pygobject_new(G_OBJECT(iter->data)));
+
+ }
+
+ g_db_collection_runlock(collec);
+
+ return result;
+
+}
+
+
/******************************************************************************
* *
* Paramètres : - *
@@ -56,9 +116,8 @@ PyTypeObject *get_python_db_collection_type(void)
};
static PyGetSetDef py_db_collection_getseters[] = {
-
+ DB_COLLECTION_ITEMS_ATTRIB,
{ NULL }
-
};
static PyTypeObject py_db_collection_type = {
diff --git a/plugins/pychrysalide/analysis/db/constants.c b/plugins/pychrysalide/analysis/db/constants.c
index 0c03cfc..9c628f9 100644
--- a/plugins/pychrysalide/analysis/db/constants.c
+++ b/plugins/pychrysalide/analysis/db/constants.c
@@ -37,6 +37,45 @@
* *
* Paramètres : type = type dont le dictionnaire est à compléter. *
* *
+* Description : Définit les constantes relatives au protocole. *
+* *
+* Retour : true en cas de succès de l'opération, false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool define_db_protocol_constants(PyTypeObject *type)
+{
+ bool result; /* Bilan à retourner */
+ PyObject *values; /* Groupe de valeurs à établir */
+
+ values = PyDict_New();
+
+ result = add_const_to_group(values, "BOOKMARKS", DBF_BOOKMARKS);
+ if (result) result = add_const_to_group(values, "COMMENTS", DBF_COMMENTS);
+ if (result) result = add_const_to_group(values, "MOVES", DBF_MOVES);
+ if (result) result = add_const_to_group(values, "DISPLAY_SWITCHERS", DBF_DISPLAY_SWITCHERS);
+
+ if (!result)
+ {
+ Py_DECREF(values);
+ goto exit;
+ }
+
+ result = attach_constants_group(type, false, "DBFeatures", values, "Features provided by database items.");
+
+ exit:
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : type = type dont le dictionnaire est à compléter. *
+* *
* Description : Définit les constantes pour les éléments de base de données. *
* *
* Retour : true en cas de succès de l'opération, false sinon. *
diff --git a/plugins/pychrysalide/analysis/db/item.c b/plugins/pychrysalide/analysis/db/item.c
index 9505838..0923268 100644
--- a/plugins/pychrysalide/analysis/db/item.c
+++ b/plugins/pychrysalide/analysis/db/item.c
@@ -286,6 +286,9 @@ bool ensure_python_db_item_is_registered(void)
if (!register_class_for_pygobject(dict, G_TYPE_DB_ITEM, type, &PyGObject_Type))
return false;
+ if (!define_db_protocol_constants(type))
+ return false;
+
if (!define_db_item_constants(type))
return false;
diff --git a/plugins/pychrysalide/analysis/db/items/bookmark.c b/plugins/pychrysalide/analysis/db/items/bookmark.c
index 783efa6..468f38c 100644
--- a/plugins/pychrysalide/analysis/db/items/bookmark.c
+++ b/plugins/pychrysalide/analysis/db/items/bookmark.c
@@ -33,6 +33,7 @@
#include <plugins/dt.h>
+#include "../collection.h"
#include "../item.h"
#include "../../../access.h"
#include "../../../helpers.h"
@@ -40,6 +41,9 @@
+/* --------------------- ELABORATION D'UN ELEMENT DE COLLECTION --------------------- */
+
+
/* Crée un nouvel objet Python de type 'DbBookmark'. */
static PyObject *py_db_bookmark_new(PyTypeObject *, PyObject *, PyObject *);
@@ -54,6 +58,19 @@ static PyObject *py_db_bookmark_get_comment(PyObject *, void *);
+/* ---------------------- DEFINITION DE LA COLLECTION ASSOCIEE ---------------------- */
+
+
+/* Crée un nouvel objet Python de type 'BookmarkCollection'. */
+static PyObject *py_bookmark_collection_new(PyTypeObject *, PyObject *, PyObject *);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* ELABORATION D'UN ELEMENT DE COLLECTION */
+/* ---------------------------------------------------------------------------------- */
+
+
/******************************************************************************
* *
* Paramètres : type = type de l'objet à instancier. *
@@ -144,7 +161,7 @@ static int py_db_bookmark_init(PyObject *self, PyObject *args, PyObject *kwds)
"\n" \
"Instances can be created using the following constructor:\n" \
"\n" \
- " DbBookmark(addr, comment=None)" \
+ " DbBookmark(addr, comment=None)\n" \
"\n" \
"Where addr is a location of type pychrysalide.arch.vmpa and" \
" comment is a string or None.\n" \
@@ -400,3 +417,207 @@ int convert_to_db_bookmark(PyObject *arg, void *dst)
return result;
}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* DEFINITION DE LA COLLECTION ASSOCIEE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : type = type de l'objet à instancier. *
+* args = arguments fournis à l'appel. *
+* kwds = arguments de type key=val fournis. *
+* *
+* Description : Crée un nouvel objet Python de type 'BookmarkCollection'. *
+* *
+* Retour : Instance Python mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_bookmark_collection_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+ PyObject *result; /* Objet à retourner */
+ PyTypeObject *base; /* Type de base à dériver */
+ bool first_time; /* Evite les multiples passages*/
+ GType gtype; /* Nouveau type de processeur */
+ bool status; /* Bilan d'un enregistrement */
+
+#define BOOKMARK_COLLECTION_DOC \
+ "BookmarkCollection remembers all bookmark definitions.\n" \
+ "\n" \
+ "Instances can be created using the following constructor:\n" \
+ "\n" \
+ " DbBookmark()\n" \
+ "\n" \
+ "There should be no need for creating such instances manually."
+
+ /* Validations diverses */
+
+ base = get_python_db_bookmark_type();
+
+ if (type == base)
+ goto simple_way;
+
+ /* Mise en place d'un type dédié */
+
+ first_time = (g_type_from_name(type->tp_name) == 0);
+
+ gtype = build_dynamic_type(G_TYPE_DB_BOOKMARK, type->tp_name, NULL, NULL, NULL);
+
+ if (first_time)
+ {
+ status = register_class_for_dynamic_pygobject(gtype, type, base);
+
+ if (!status)
+ {
+ result = NULL;
+ goto exit;
+ }
+
+ }
+
+ /* On crée, et on laisse ensuite la main à PyGObject_Type.tp_init() */
+
+ simple_way:
+
+ result = PyType_GenericNew(type, args, kwds);
+
+ exit:
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Fournit un accès à une définition de type à diffuser. *
+* *
+* Retour : Définition d'objet pour Python. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+PyTypeObject *get_python_bookmark_collection_type(void)
+{
+ static PyMethodDef py_bookmark_collection_methods[] = {
+ { NULL }
+ };
+
+ static PyGetSetDef py_bookmark_collection_getseters[] = {
+ { NULL }
+ };
+
+ static PyTypeObject py_bookmark_collection_type = {
+
+ PyVarObject_HEAD_INIT(NULL, 0)
+
+ .tp_name = "pychrysalide.analysis.db.items.BookmarkCollection",
+ .tp_basicsize = sizeof(PyGObject),
+
+ .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+
+ .tp_doc = BOOKMARK_COLLECTION_DOC,
+
+ .tp_methods = py_bookmark_collection_methods,
+ .tp_getset = py_bookmark_collection_getseters,
+
+ .tp_new = py_bookmark_collection_new,
+
+ };
+
+ return &py_bookmark_collection_type;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Prend en charge l'objet 'pychrysalide....BookmarkCollection'.*
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool ensure_python_bookmark_collection_is_registered(void)
+{
+ PyTypeObject *type; /* Type Python 'DbBookmark' */
+ PyObject *module; /* Module à recompléter */
+ PyObject *dict; /* Dictionnaire du module */
+
+ type = get_python_bookmark_collection_type();
+
+ if (!PyType_HasFeature(type, Py_TPFLAGS_READY))
+ {
+ module = get_access_to_python_module("pychrysalide.analysis.db.items");
+
+ dict = PyModule_GetDict(module);
+
+ if (!ensure_python_db_item_is_registered())
+ return false;
+
+ if (!register_class_for_pygobject(dict, G_TYPE_BM_COLLECTION, type, get_python_db_collection_type()))
+ return false;
+
+ }
+
+ return true;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : arg = argument quelconque à tenter de convertir. *
+* dst = destination des valeurs récupérées en cas de succès. *
+* *
+* Description : Tente de convertir en collection de signets. *
+* *
+* Retour : Bilan de l'opération, voire indications supplémentaires. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+int convert_to_bookmark_collection(PyObject *arg, void *dst)
+{
+ int result; /* Bilan à retourner */
+
+ result = PyObject_IsInstance(arg, (PyObject *)get_python_bookmark_collection_type());
+
+ switch (result)
+ {
+ case -1:
+ /* L'exception est déjà fixée par Python */
+ result = 0;
+ break;
+
+ case 0:
+ PyErr_SetString(PyExc_TypeError, "unable to convert the provided argument to bookmark collection");
+ break;
+
+ case 1:
+ *((GBookmarkCollection **)dst) = G_BM_COLLECTION(pygobject_get(arg));
+ break;
+
+ default:
+ assert(false);
+ break;
+
+ }
+
+ return result;
+
+}
diff --git a/plugins/pychrysalide/analysis/db/items/bookmark.h b/plugins/pychrysalide/analysis/db/items/bookmark.h
index bcf1c11..504795f 100644
--- a/plugins/pychrysalide/analysis/db/items/bookmark.h
+++ b/plugins/pychrysalide/analysis/db/items/bookmark.h
@@ -31,6 +31,9 @@
+/* --------------------- ELABORATION D'UN ELEMENT DE COLLECTION --------------------- */
+
+
/* Fournit un accès à une définition de type à diffuser. */
PyTypeObject *get_python_db_bookmark_type(void);
@@ -42,4 +45,18 @@ int convert_to_db_bookmark(PyObject *, void *);
+/* ---------------------- DEFINITION DE LA COLLECTION ASSOCIEE ---------------------- */
+
+
+/* Fournit un accès à une définition de type à diffuser. */
+PyTypeObject *get_python_bookmark_collection_type(void);
+
+/* Prend en charge l'objet 'pychrysalide.analysis.db.items.BookmarkCollection'. */
+bool ensure_python_bookmark_collection_is_registered(void);
+
+/* Tente de convertir en collection de signets. */
+int convert_to_bookmark_collection(PyObject *, void *);
+
+
+
#endif /* _PLUGINS_PYCHRYSALIDE_ANALYSIS_DB_ITEMS_BOOKMARK_H */
diff --git a/plugins/pychrysalide/analysis/db/items/module.c b/plugins/pychrysalide/analysis/db/items/module.c
index fcf636f..04349b5 100644
--- a/plugins/pychrysalide/analysis/db/items/module.c
+++ b/plugins/pychrysalide/analysis/db/items/module.c
@@ -89,6 +89,7 @@ bool populate_analysis_db_items_module(void)
result = true;
+ if (result) result = ensure_python_bookmark_collection_is_registered();
if (result) result = ensure_python_db_bookmark_is_registered();
if (result) result = ensure_python_db_comment_is_registered();