diff options
Diffstat (limited to 'plugins/pychrysalide/analysis/storage')
-rw-r--r-- | plugins/pychrysalide/analysis/storage/storage.c | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/plugins/pychrysalide/analysis/storage/storage.c b/plugins/pychrysalide/analysis/storage/storage.c index d8739e4..1ebcc62 100644 --- a/plugins/pychrysalide/analysis/storage/storage.c +++ b/plugins/pychrysalide/analysis/storage/storage.c @@ -36,6 +36,7 @@ #include "../loaded.h" #include "../../access.h" #include "../../helpers.h" +#include "../../common/packed.h" @@ -59,9 +60,15 @@ static PyObject *py_object_storage_add_backend(PyObject *, PyObject *); /* Charge un objet à partir de données rassemblées. */ static PyObject *py_object_storage_load_object(PyObject *, PyObject *); +/* Charge un objet interne à partir de données rassemblées. */ +static PyObject *py_object_storage_unpack_object(PyObject *, PyObject *); + /* Sauvegarde un object sous forme de données rassemblées. */ static PyObject *py_object_storage_store_object(PyObject *, PyObject *); +/* Sauvegarde un object interne sous forme de données. */ +static PyObject *py_object_storage_pack_object(PyObject *, PyObject *); + /* ---------------------------------------------------------------------------------- */ @@ -302,6 +309,61 @@ static PyObject *py_object_storage_load_object(PyObject *self, PyObject *args) * Paramètres : self = classe représentant une mémorisation de types. * * args = arguments fournis à l'appel. * * * +* Description : Charge un objet interne à partir de données rassemblées. * +* * +* Retour : Objet restauré en mémoire ou None en cas d'échec. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_object_storage_unpack_object(PyObject *self, PyObject *args) +{ + PyObject *result; /* Bilan à retourner */ + const char *name; /* Désignation de groupe */ + packed_buffer *pbuf; /* Tampon de données à employer*/ + int ret; /* Bilan de lecture des args. */ + GObjectStorage *storage; /* Mécanismes natifs */ + GSerializableObject *object; /* Objet reconstruit ou NULL */ + +#define OBJECT_STORAGE_UNPACK_OBJECT_METHOD PYTHON_METHOD_DEF \ +( \ + unpack_object, "$self, name, pbuf, /", \ + METH_VARARGS, py_object_storage, \ + "Load an object from a buffer with a location pointing to data.\n" \ + "\n" \ + "The *name* is a string label for the group of target objects and" \ + " *pbuf* has to be a pychrysalide.common.PackedBuffer instance.\n" \ + "\n" \ + "The result is a pychrysalide.analysis.storage.SerializableObject" \ + " instancet in case of success, or None in case of failure." \ +) + + ret = PyArg_ParseTuple(args, "sO&", &name, convert_to_packed_buffer, &pbuf); + if (!ret) return NULL; + + storage = G_OBJECT_STORAGE(pygobject_get(self)); + + object = g_object_storage_unpack_object(storage, name, pbuf); + + if (object != NULL) + result = pygobject_new(G_OBJECT(object)); + else + { + result = Py_None; + Py_INCREF(result); + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = classe représentant une mémorisation de types. * +* args = arguments fournis à l'appel. * +* * * Description : Sauvegarde un object sous forme de données rassemblées. * * * * Retour : Bilan de l'opération. * @@ -357,6 +419,62 @@ static PyObject *py_object_storage_store_object(PyObject *self, PyObject *args) /****************************************************************************** * * +* Paramètres : self = classe représentant une mémorisation de types. * +* args = arguments fournis à l'appel. * +* * +* Description : Sauvegarde un object interne sous forme de données. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_object_storage_pack_object(PyObject *self, PyObject *args) +{ + PyObject *result; /* Emplacement à retourner */ + const char *name; /* Désignation de groupe */ + GSerializableObject *object; /* Objet à traiter */ + packed_buffer *pbuf; /* Tampon de données à employer*/ + int ret; /* Bilan de lecture des args. */ + GObjectStorage *storage; /* Mécanismes natifs */ + bool status; /* Bilan de l'opération */ + +#define OBJECT_STORAGE_PACK_OBJECT_METHOD PYTHON_METHOD_DEF \ +( \ + pack_object, "$self, name, object, pbuf/", \ + METH_VARARGS, py_object_storage, \ + "Save an object as serialized data and store the location of" \ + " the data intro a buffer.\n" \ + "\n" \ + "The *name* is a string label for the group of target objects," \ + " the processed *object* has to be a" \ + " pychrysalide.analysis.storage.SerializableObject instance" \ + " and *pbuf* is expected to be a" \ + " pychrysalide.common.PackedBuffer instance.\n" \ + "\n" \ + "The status of the operation is returned as a boolean value:" \ + " *True* for success, *False* for failure." \ +) + + ret = PyArg_ParseTuple(args, "sO&O&", &name, convert_to_serializable_object, &object, + convert_to_packed_buffer, &pbuf); + if (!ret) return NULL; + + storage = G_OBJECT_STORAGE(pygobject_get(self)); + + status = g_object_storage_pack_object(storage, name, object, pbuf); + + result = status ? Py_True : Py_False; + Py_INCREF(result); + + return result; + +} + + +/****************************************************************************** +* * * Paramètres : - * * * * Description : Fournit un accès à une définition de type à diffuser. * @@ -372,7 +490,9 @@ PyTypeObject *get_python_object_storage_type(void) static PyMethodDef py_object_storage_methods[] = { OBJECT_STORAGE_ADD_BACKEND_METHOD, OBJECT_STORAGE_LOAD_OBJECT_METHOD, + OBJECT_STORAGE_UNPACK_OBJECT_METHOD, OBJECT_STORAGE_STORE_OBJECT_METHOD, + OBJECT_STORAGE_PACK_OBJECT_METHOD, { NULL } }; |