diff options
Diffstat (limited to 'src/analysis/db/items/switcher.c')
-rw-r--r-- | src/analysis/db/items/switcher.c | 74 |
1 files changed, 35 insertions, 39 deletions
diff --git a/src/analysis/db/items/switcher.c b/src/analysis/db/items/switcher.c index 5a03e8e..01c1910 100644 --- a/src/analysis/db/items/switcher.c +++ b/src/analysis/db/items/switcher.c @@ -34,9 +34,6 @@ #include "../collection-int.h" #include "../item-int.h" -#include "../../../common/io.h" - - @@ -81,10 +78,10 @@ static void g_db_switcher_finalize(GDbSwitcher *); static gint g_db_switcher_cmp(GDbSwitcher *, GDbSwitcher *, bool); /* Importe la définition d'un signet depuis un flux réseau. */ -static bool g_db_switcher_recv_from_fd(GDbSwitcher *, int, int); +static bool g_db_switcher_unpack(GDbSwitcher *, packed_buffer *); /* Exporte la définition d'un signet dans un flux réseau. */ -static bool g_db_switcher_send_to_fd(const GDbSwitcher *, int, int); +static bool g_db_switcher_pack(const GDbSwitcher *, packed_buffer *); /* Construit la description humaine d'un signet sur un tampon. */ static void g_db_switcher_build_label(GDbSwitcher *); @@ -185,8 +182,8 @@ static void g_db_switcher_class_init(GDbSwitcherClass *klass) item->cmp = (cmp_db_item_fc)g_db_switcher_cmp; - item->recv = (recv_db_item_fc)g_db_switcher_recv_from_fd; - item->send = (send_db_item_fc)g_db_switcher_send_to_fd; + item->unpack = (unpack_db_item_fc)g_db_switcher_unpack; + item->pack = (pack_db_item_fc)g_db_switcher_pack; item->build_label = (build_item_label_fc)g_db_switcher_build_label; item->apply = (run_item_fc)g_db_switcher_apply; @@ -358,8 +355,7 @@ static gint g_db_switcher_cmp(GDbSwitcher *a, GDbSwitcher *b, bool with) /****************************************************************************** * * * Paramètres : switcher = bascule d'affichage aux infos à charger. [OUT] * -* fd = flux ouvert en lecture pour l'importation. * -* flags = éventuelles options d'envoi supplémentaires. * +* pbuf = paquet de données où venir inscrire les infos. * * * * Description : Importe la définition d'un signet depuis un flux réseau. * * * @@ -369,31 +365,33 @@ static gint g_db_switcher_cmp(GDbSwitcher *a, GDbSwitcher *b, bool with) * * ******************************************************************************/ -static bool g_db_switcher_recv_from_fd(GDbSwitcher *switcher, int fd, int flags) +static bool g_db_switcher_unpack(GDbSwitcher *switcher, packed_buffer *pbuf) { - bool status; /* Bilan d'opération initiale */ - uint32_t val32; /* Valeur sur 32 bits */ + bool result; /* Bilan à retourner */ + uint32_t tmp32; /* Valeur sur 32 bits */ - status = G_DB_ITEM_CLASS(g_db_switcher_parent_class)->recv(G_DB_ITEM(switcher), fd, flags); - if (!status) return false; + result = G_DB_ITEM_CLASS(g_db_switcher_parent_class)->unpack(G_DB_ITEM(switcher), pbuf); - if (!recv_vmpa(&switcher->addr, fd, flags)) - return false; - - status = safe_recv(fd, &val32, sizeof(uint32_t), MSG_WAITALL | flags); - if (!status) return false; + if (result) + result = unpack_vmpa(&switcher->addr, pbuf); - switcher->index = be32toh(val32); + if (result) + { + result = extract_packed_buffer(pbuf, &tmp32, sizeof(uint32_t), true); + switcher->index = tmp32; + } - status = safe_recv(fd, &val32, sizeof(uint32_t), MSG_WAITALL | flags); - if (!status) return false; + if (result) + { + result = extract_packed_buffer(pbuf, &tmp32, sizeof(uint32_t), true); + switcher->display = tmp32; - switcher->display = be32toh(val32); + if (switcher->display > IOD_COUNT) + result = false; - if (switcher->display > IOD_COUNT) - return false; + } - return true; + return result; } @@ -401,8 +399,7 @@ static bool g_db_switcher_recv_from_fd(GDbSwitcher *switcher, int fd, int flags) /****************************************************************************** * * * Paramètres : switcher = bascule d'affichage aux infos à sauvegarder. * -* fd = flux ouvert en écriture pour l'exportation. * -* flags = éventuelles options d'envoi supplémentaires. * +* pbuf = paquet de données où venir inscrire les infos. * * * * Description : Exporte la définition d'une bascule d'affichage d'opérande. * * * @@ -412,23 +409,22 @@ static bool g_db_switcher_recv_from_fd(GDbSwitcher *switcher, int fd, int flags) * * ******************************************************************************/ -static bool g_db_switcher_send_to_fd(const GDbSwitcher *switcher, int fd, int flags) +static bool g_db_switcher_pack(const GDbSwitcher *switcher, packed_buffer *pbuf) { - bool status; /* Bilan d'opération initiale */ + bool result; /* Bilan à retourner */ - status = G_DB_ITEM_CLASS(g_db_switcher_parent_class)->send(G_DB_ITEM(switcher), fd, MSG_MORE | flags); - if (!status) return false; + result = G_DB_ITEM_CLASS(g_db_switcher_parent_class)->pack(G_DB_ITEM(switcher), pbuf); - if (!send_vmpa(&switcher->addr, fd, MSG_MORE | flags)) - return false; + if (result) + result = pack_vmpa(&switcher->addr, pbuf); - status = safe_send(fd, (uint32_t []) { htobe32(switcher->index) }, sizeof(uint32_t), MSG_MORE | flags); - if (!status) return false; + if (result) + result = extend_packed_buffer(pbuf, (uint32_t []) { switcher->index }, sizeof(uint32_t), true); - status = safe_send(fd, (uint32_t []) { htobe32(switcher->display) }, sizeof(uint32_t), flags); - if (!status) return false; + if (result) + result = extend_packed_buffer(pbuf, (uint32_t []) { switcher->display }, sizeof(uint32_t), true); - return true; + return result; } |