summaryrefslogtreecommitdiff
path: root/src/analysis/storage/storage.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/analysis/storage/storage.c')
-rw-r--r--src/analysis/storage/storage.c75
1 files changed, 72 insertions, 3 deletions
diff --git a/src/analysis/storage/storage.c b/src/analysis/storage/storage.c
index e286641..c641a52 100644
--- a/src/analysis/storage/storage.c
+++ b/src/analysis/storage/storage.c
@@ -28,6 +28,7 @@
#include <malloc.h>
#include <string.h>
#include <unistd.h>
+#include <stdarg.h>
#include "storage-int.h"
@@ -702,6 +703,67 @@ GSerializableObject *g_object_storage_unpack_object(GObjectStorage *storage, con
/******************************************************************************
* *
+* Paramètres : storage = gestionnaire à manipuler. *
+* name = désignation d'un nouveau groupe d'objets. *
+* pbuf = zone tampon à parcourir. *
+* expected = type d'objet attendu. *
+* ... = élément restauré ou NULL en cas d'échec. [OUT] *
+* *
+* Description : Charge un objet interne à partir de données rassemblées. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_object_storage_unpack_object_2(GObjectStorage *storage, const char *name, packed_buffer_t *pbuf, GType expected, ...)
+{
+ bool result; /* Bilan d'une opération */
+ uint64_t pos; /* Localisation des données */
+ GSerializableObject *instance; /* Objet rechargé à valider */
+ va_list ap; /* Liste d'arguments variables */
+ void **object; /* Lieu d'enregistrement final */
+
+ result = extract_packed_buffer(pbuf, &pos, sizeof(uint64_t), true);
+
+ if (result)
+ {
+ if (pos == 0)
+ *object = NULL;
+
+ else
+ {
+ instance = g_object_storage_load_object(storage, name, pos);
+
+ result = G_TYPE_CHECK_INSTANCE_TYPE(instance, expected);
+
+ if (result)
+ {
+ va_start(ap, expected);
+
+ object = va_arg(ap, void **);
+
+ *object = instance;
+
+ va_end(ap);
+
+ }
+
+ else
+ g_clear_object(&instance);
+
+ }
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : storage = gestionnaire à manipuler. *
* name = désignation d'un nouveau groupe d'objets. *
* object = objet sérialisable à traiter. *
@@ -787,10 +849,17 @@ bool g_object_storage_pack_object(GObjectStorage *storage, const char *name, con
bool result; /* Bilan à retourner */
off64_t pos; /* Localisation des données */
- result = g_object_storage_store_object(storage, name, object, &pos);
+ if (object == NULL)
+ result = extend_packed_buffer(pbuf, (uint64_t []){ 0 }, sizeof(uint64_t), true);
- if (result)
- result = extend_packed_buffer(pbuf, (uint64_t []){ pos }, sizeof(uint64_t), true);
+ else
+ {
+ result = g_object_storage_store_object(storage, name, object, &pos);
+
+ if (result)
+ result = extend_packed_buffer(pbuf, (uint64_t []){ pos }, sizeof(uint64_t), true);
+
+ }
return result;