summaryrefslogtreecommitdiff
path: root/src/analysis
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2021-12-30 18:28:18 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2021-12-30 18:44:35 (GMT)
commit945e0c9ecce02155555387aad672e272f5646362 (patch)
tree3d35bdb25012a9ef710a13c9e733b5a80f6641b1 /src/analysis
parent98570719ff25a4dcde917056e55490bf2a6b1453 (diff)
Create generic functions to load and store operands.
Diffstat (limited to 'src/analysis')
-rw-r--r--src/analysis/storage/storage.c75
-rw-r--r--src/analysis/storage/storage.h3
2 files changed, 75 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;
diff --git a/src/analysis/storage/storage.h b/src/analysis/storage/storage.h
index 0d35d78..cc0caad 100644
--- a/src/analysis/storage/storage.h
+++ b/src/analysis/storage/storage.h
@@ -78,6 +78,9 @@ GSerializableObject *g_object_storage_unpack_object(GObjectStorage *, const char
/* Sauvegarde un object sous forme de données rassemblées. */
bool g_object_storage_store_object(GObjectStorage *, const char *, const GSerializableObject *, off64_t *);
+/* Charge un objet interne à partir de données rassemblées. */
+bool g_object_storage_unpack_object_2(GObjectStorage *, const char *, packed_buffer_t *, GType, ...);
+
/* Sauvegarde un object interne sous forme de données. */
bool g_object_storage_pack_object(GObjectStorage *, const char *, const GSerializableObject *, packed_buffer_t *);