summaryrefslogtreecommitdiff
path: root/src/analysis
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2015-08-05 21:25:55 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2015-08-05 21:25:55 (GMT)
commitb5c6bcea25b1b840fd6c8e89a4a3c9fbd83ba84b (patch)
treede253301956b1cf249ae27cf1af146c3184af67f /src/analysis
parentd0a25ef16eef28d0cc355b00f5874c6c28004c78 (diff)
Run updates on collected items activity changes.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@567 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/analysis')
-rw-r--r--src/analysis/db/collection.c28
-rw-r--r--src/analysis/db/collection.h2
-rw-r--r--src/analysis/db/item-int.h4
-rw-r--r--src/analysis/db/item.c46
-rw-r--r--src/analysis/db/item.h2
5 files changed, 55 insertions, 27 deletions
diff --git a/src/analysis/db/collection.c b/src/analysis/db/collection.c
index 1afe96b..117a2d5 100644
--- a/src/analysis/db/collection.c
+++ b/src/analysis/db/collection.c
@@ -306,7 +306,7 @@ bool g_db_collection_recv(GDbCollection *collec, int fd, sqlite3 *db)
if (result)
{
- if (collec->binary != NULL)
+ if (collec->binary != NULL && g_db_item_is_active(item))
result = g_db_item_apply(item, collec->binary);
if (db != NULL)
result &= g_db_collection_store_item(collec, item, db);
@@ -337,7 +337,7 @@ bool g_db_collection_recv(GDbCollection *collec, int fd, sqlite3 *db)
if (g_db_item_is_active(G_DB_ITEM(found->data)))
{
inactive = _g_db_collection_compute_inactivity_timestamp(collec, false);
- result = _g_db_collection_update_item_activity(collec, item, inactive, false);
+ result = _g_db_collection_update_item_activity(collec, item, &inactive, false);
}
}
@@ -350,7 +350,15 @@ bool g_db_collection_recv(GDbCollection *collec, int fd, sqlite3 *db)
case DBA_CHANGE_STATE:
if (db == NULL)
- result = g_db_collection_update_item_activity(collec, item, g_db_item_get_timestamp(item) + 1);
+ {
+ if (g_db_item_is_active(item))
+ result = g_db_collection_update_item_activity(collec, item, NULL);
+ else
+ {
+ inactive = g_db_item_get_timestamp(item) + 1;
+ result = g_db_collection_update_item_activity(collec, item, &inactive);
+ }
+ }
else
result = false;
@@ -716,7 +724,7 @@ timestamp_t _g_db_collection_compute_inactivity_timestamp(GDbCollection *collec,
* *
******************************************************************************/
-bool _g_db_collection_update_item_activity(GDbCollection *collec, GDbItem *item, timestamp_t timestamp, bool lock)
+bool _g_db_collection_update_item_activity(GDbCollection *collec, GDbItem *item, timestamp_t *timestamp, bool lock)
{
bool result; /* Bilan à faire remonter */
GList *found; /* Test de présence existante */
@@ -733,7 +741,7 @@ bool _g_db_collection_update_item_activity(GDbCollection *collec, GDbItem *item,
{
internal = G_DB_ITEM(found->data);
- g_db_item_set_activity(internal, (timestamp_t []) { timestamp });
+ result = g_db_item_set_activity(internal, collec->binary, timestamp);
g_signal_emit_by_name(collec, "content-changed", DBA_CHANGE_STATE, internal);
@@ -780,7 +788,7 @@ GList *g_db_collection_set_last_active(GDbCollection *collec, timestamp_t timest
{
if (!g_db_item_is_active(item))
{
- g_db_item_set_activity(item, NULL);
+ /* ... */g_db_item_set_activity(item, collec->binary, NULL);
/* ... */g_db_collection_store_updated_item(collec, item, db);
g_signal_emit_by_name(collec, "content-changed", DBA_CHANGE_STATE, item);
}
@@ -823,16 +831,16 @@ GList *g_db_collection_set_last_active(GDbCollection *collec, timestamp_t timest
bool g_db_collection_set_inactive(GDbCollection *collec, GDbItem *item, timestamp_t *timestamp)
{
+ bool result; /* Bilan à retourner */
+
/* Si cette collection n'est pas concernée, on ne bouge pas ! */
if (G_OBJECT_TYPE(G_OBJECT(item)) != collec->type) return false;
- assert(g_db_item_is_active(item));
-
- g_db_item_set_activity(item, timestamp);
+ result = g_db_item_set_activity(item, collec->binary, timestamp);
g_signal_emit_by_name(collec, "content-changed", DBA_CHANGE_STATE, item);
- return true;
+ return result;
}
diff --git a/src/analysis/db/collection.h b/src/analysis/db/collection.h
index e9f93d2..0f7e1f0 100644
--- a/src/analysis/db/collection.h
+++ b/src/analysis/db/collection.h
@@ -109,7 +109,7 @@ bool _g_db_collection_remove_item(GDbCollection *, GDbItem *, bool);
timestamp_t _g_db_collection_compute_inactivity_timestamp(GDbCollection *, bool);
/* Met à jour le statut d'activité d'un élément de collection. */
-bool _g_db_collection_update_item_activity(GDbCollection *, GDbItem *, timestamp_t, bool);
+bool _g_db_collection_update_item_activity(GDbCollection *, GDbItem *, timestamp_t *, bool);
#define g_db_collection_add_item(c, i) _g_db_collection_add_item(c, i, true)
#define g_db_collection_remove_item(c, i) _g_db_collection_remove_item(c, i, true)
diff --git a/src/analysis/db/item-int.h b/src/analysis/db/item-int.h
index fb33c72..c2c8b31 100644
--- a/src/analysis/db/item-int.h
+++ b/src/analysis/db/item-int.h
@@ -73,10 +73,6 @@ struct _GDbItem
bool is_volatile; /* Pas besoin de sauvegarde ? */
-#ifdef DEBUG
- bool applied; /* L'élément a été appliqué */
-#endif
-
};
/* Base d'un élément pour collection générique (classe) */
diff --git a/src/analysis/db/item.c b/src/analysis/db/item.c
index 3fc6f6f..013703d 100644
--- a/src/analysis/db/item.c
+++ b/src/analysis/db/item.c
@@ -403,11 +403,9 @@ bool g_db_item_apply(GDbItem *item, GLoadedBinary *binary)
{
bool result; /* Bilan à faire remonter */
- result = G_DB_ITEM_GET_CLASS(item)->apply(item, binary);
+ assert(g_db_item_is_active(item));
-#ifdef DEBUG
- item->applied = true;
-#endif
+ result = G_DB_ITEM_GET_CLASS(item)->apply(item, binary);
return result;
@@ -431,9 +429,7 @@ bool g_db_item_cancel(GDbItem *item, GLoadedBinary *binary)
{
bool result; /* Bilan à faire remonter */
-#ifdef DEBUG
- assert(item->applied);
-#endif
+ assert(!g_db_item_is_active(item));
result = G_DB_ITEM_GET_CLASS(item)->cancel(item, binary);
@@ -482,23 +478,51 @@ timestamp_t g_db_item_get_timestamp(const GDbItem *item)
/******************************************************************************
* *
-* Paramètres : item = élément de collection à mettre à jour. *
-* first = horodatage du premier élément désactivé ou NULL. *
+* Paramètres : item = élément de collection à mettre à jour. *
+* binary = binaire chargé en mémoire à modifier. *
+* first = horodatage du premier élément désactivé ou NULL. *
* *
* Description : Active ou désactive un élément de collection en place. *
* *
-* Retour : - *
+* Retour : Bilan de la mise à jour de l'élément. *
* *
* Remarques : - *
* *
******************************************************************************/
-void g_db_item_set_activity(GDbItem *item, timestamp_t *first)
+bool g_db_item_set_activity(GDbItem *item, GLoadedBinary *binary, timestamp_t *first)
{
+ bool result; /* Bilan à faire remonter */
+ bool active; /* Etat avant changement */
+
+ active = g_db_item_is_active(item);
+
+ /* Archivage de l'état */
+
if (first == NULL)
+ {
+ assert(!active);
item->timestamp = item->created;
+ }
else
+ {
+ assert(active);
item->timestamp = --(*first);
+ }
+
+ /* Application de l'état */
+
+ if (binary != NULL)
+ {
+ if (active)
+ result = g_db_item_cancel(item, binary);
+ else
+ result = g_db_item_apply(item, binary);
+ }
+ else
+ result = true;
+
+ return result;
}
diff --git a/src/analysis/db/item.h b/src/analysis/db/item.h
index 7d3392c..2edf594 100644
--- a/src/analysis/db/item.h
+++ b/src/analysis/db/item.h
@@ -87,7 +87,7 @@ const char *g_db_item_get_label(const GDbItem *);
timestamp_t g_db_item_get_timestamp(const GDbItem *);
/* Active ou désactive un élément de collection en place. */
-void g_db_item_set_activity(GDbItem *, timestamp_t *);
+bool g_db_item_set_activity(GDbItem *, GLoadedBinary *, timestamp_t *);
/* Indique si l'élément est activé ou désactivé. */
bool g_db_item_is_active(const GDbItem *);