root/daemons/attrd/attrd_nodes.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. attrd_get_node_xml_id
  2. attrd_set_node_xml_id
  3. attrd_forget_node_xml_id
  4. attrd_cleanup_xml_ids

   1 /*
   2  * Copyright 2024-2025 the Pacemaker project contributors
   3  *
   4  * The version control history for this file may have further details.
   5  *
   6  * This source code is licensed under the GNU General Public License version 2
   7  * or later (GPLv2+) WITHOUT ANY WARRANTY.
   8  */
   9 
  10 #include <crm_internal.h>
  11 
  12 #include <stdio.h>      // NULL
  13 #include <glib.h>       // GHashTable, etc.
  14 
  15 #include "pacemaker-attrd.h"
  16 
  17 // Track the last known node XML ID for each node name
  18 static GHashTable *node_xml_ids = NULL;
  19 
  20 /*!
  21  * \internal
  22  * \brief Get last known XML ID for a given node
  23  *
  24  * \param[in] node_name  Name of node to check
  25  *
  26  * \return Last known XML ID for node (or NULL if none known)
  27  *
  28  * \note The return value may become invalid if attrd_set_node_xml_id() or
  29  *       attrd_forget_node_xml_id() is later called for \p node_name.
  30  */
  31 const char *
  32 attrd_get_node_xml_id(const char *node_name)
     /* [previous][next][first][last][top][bottom][index][help] */
  33 {
  34     if (node_xml_ids == NULL) {
  35         return NULL;
  36     }
  37     return g_hash_table_lookup(node_xml_ids, node_name);
  38 }
  39 
  40 /*!
  41  * \internal
  42  * \brief Set last known XML ID for a given node
  43  *
  44  * \param[in] node_name    Name of node to set
  45  * \param[in] node_xml_id  New XML ID to set for node
  46  */
  47 void
  48 attrd_set_node_xml_id(const char *node_name, const char *node_xml_id)
     /* [previous][next][first][last][top][bottom][index][help] */
  49 {
  50     if (node_xml_ids == NULL) {
  51         node_xml_ids = pcmk__strikey_table(free, free);
  52     }
  53     pcmk__insert_dup(node_xml_ids, node_name, node_xml_id);
  54 }
  55 
  56 /*!
  57  * \internal
  58  * \brief Forget last known XML ID for a given node
  59  *
  60  * \param[in] node_name    Name of node to forget
  61  */
  62 void
  63 attrd_forget_node_xml_id(const char *node_name)
     /* [previous][next][first][last][top][bottom][index][help] */
  64 {
  65     if (node_xml_ids == NULL) {
  66         return;
  67     }
  68     g_hash_table_remove(node_xml_ids, node_name);
  69 }
  70 
  71 /*!
  72  * \internal
  73  * \brief Free the node XML ID cache
  74  */
  75 void
  76 attrd_cleanup_xml_ids(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  77 {
  78     if (node_xml_ids != NULL) {
  79         g_hash_table_destroy(node_xml_ids);
  80         node_xml_ids = NULL;
  81     }
  82 }

/* [previous][next][first][last][top][bottom][index][help] */