osaf/services/saf/amf/amfd/include/node.h |   2 +-
 osaf/services/saf/amf/amfd/nodegroup.cc   |  76 ++++++++----------------------
 2 files changed, 22 insertions(+), 56 deletions(-)


diff --git a/osaf/services/saf/amf/amfd/include/node.h 
b/osaf/services/saf/amf/amfd/include/node.h
--- a/osaf/services/saf/amf/amfd/include/node.h
+++ b/osaf/services/saf/amf/amfd/include/node.h
@@ -147,7 +147,7 @@ typedef struct avd_avnd_tag {
 typedef struct avd_ng_tag {
 
        NCS_PATRICIA_NODE tree_node;    /* key will be AMF  node group name */
-       SaNameT ng_name;
+       SaNameT name;
        uint32_t number_nodes;  /* number of element in saAmfNGNodeList */
        SaNameT *saAmfNGNodeList;       /* array of node names in group */
 
diff --git a/osaf/services/saf/amf/amfd/nodegroup.cc 
b/osaf/services/saf/amf/amfd/nodegroup.cc
--- a/osaf/services/saf/amf/amfd/nodegroup.cc
+++ b/osaf/services/saf/amf/amfd/nodegroup.cc
@@ -23,17 +23,7 @@
 #include <cluster.h>
 #include <imm.h>
 
-static NCS_PATRICIA_TREE nodegroup_db;
-
-/**
- * Add a node group object to the db.
- * @param ng
- */
-static void ng_db_add(AVD_AMF_NG *ng)
-{
-       unsigned int rc = ncs_patricia_tree_add(&nodegroup_db, &ng->tree_node);
-       osafassert(rc == NCSCC_RC_SUCCESS);
-}
+AmfDb<AVD_AMF_NG> *nodegroup_db = 0;
 
 /**
  * Lookup object in db using dn
@@ -43,28 +33,7 @@ static void ng_db_add(AVD_AMF_NG *ng)
  */
 AVD_AMF_NG *avd_ng_get(const SaNameT *dn)
 {
-       SaNameT tmp = {0};
-
-       tmp.length = dn->length;
-       memcpy(tmp.value, dn->value, tmp.length);
-
-       return (AVD_AMF_NG *)ncs_patricia_tree_get(&nodegroup_db, (uint8_t 
*)&tmp);
-}
-
-/**
- * Get next object from db using dn
- * @param dn
- * 
- * @return AVD_AMF_NG*
- */
-static AVD_AMF_NG *ng_getnext(const SaNameT *dn)
-{
-       SaNameT tmp = {0};
-
-       tmp.length = dn->length;
-       memcpy(tmp.value, dn->value, tmp.length);
-
-       return (AVD_AMF_NG *)ncs_patricia_tree_getnext(&nodegroup_db, (uint8_t 
*)&tmp);
+       return nodegroup_db->find(dn);
 }
 
 /**
@@ -138,9 +107,9 @@ static AVD_AMF_NG *ng_create(SaNameT *dn
 
        ng = new AVD_AMF_NG();
 
-       memcpy(ng->ng_name.value, dn->value, dn->length);
-       ng->ng_name.length = dn->length;
-       ng->tree_node.key_info = (uint8_t *)&(ng->ng_name);
+       memcpy(ng->name.value, dn->value, dn->length);
+       ng->name.length = dn->length;
+       ng->tree_node.key_info = (uint8_t *)&(ng->name);
 
        if 
((immutil_getAttrValuesNumber(const_cast<SaImmAttrNameT>("saAmfNGNodeList"), 
attributes,
                &values_number) == SA_AIS_OK) && (values_number > 0)) {
@@ -174,10 +143,7 @@ done:
  */
 static void ng_delete(AVD_AMF_NG *ng)
 {
-       unsigned int rc = ncs_patricia_tree_del(&nodegroup_db, &ng->tree_node);
-       osafassert(rc == NCSCC_RC_SUCCESS);
-
-       osafassert(ng);
+       nodegroup_db->erase(ng);
        free(ng->saAmfNGNodeList);
        delete ng;
 }
@@ -203,8 +169,12 @@ SaAisErrorT avd_ng_config_get(void)
        /* Could be here as a consequence of a fail/switch-over. Delete the DB
        ** since it is anyway not synced and needs to be rebuilt. */
        dn.length = 0;
-       for (ng = ng_getnext(&dn); ng != NULL; ng = ng_getnext(&dn))
+       for (std::map<std::string, AVD_AMF_NG*>::const_iterator it = 
nodegroup_db->begin();
+                       it != nodegroup_db->end(); ) {
+               AVD_AMF_NG *ng = it->second;
+               it++;
                ng_delete(ng);
+       }
 
        searchParam.searchOneAttr.attrName = 
const_cast<SaImmAttrNameT>("SaImmAttrClassName");
        searchParam.searchOneAttr.attrValueType = SA_IMM_ATTR_SASTRINGT;
@@ -228,7 +198,7 @@ SaAisErrorT avd_ng_config_get(void)
                if ((ng = ng_create(&dn, (const SaImmAttrValuesT_2 
**)attributes)) == NULL)
                        goto done2;
 
-               ng_db_add(ng);
+               nodegroup_db->insert(ng);
        }
 
        rc = SA_AIS_OK;
@@ -249,10 +219,10 @@ done1:
  */
 static bool su_is_mapped_to_node_via_nodegroup(const AVD_SU *su, const 
AVD_AMF_NG *ng)
 {
-       if ((memcmp(&ng->ng_name, &su->saAmfSUHostNodeOrNodeGroup, 
sizeof(SaNameT)) == 0) ||
-           (memcmp(&ng->ng_name, &su->sg_of_su->saAmfSGSuHostNodeGroup, 
sizeof(SaNameT)) == 0)) {
+       if ((memcmp(&ng->name, &su->saAmfSUHostNodeOrNodeGroup, 
sizeof(SaNameT)) == 0) ||
+           (memcmp(&ng->name, &su->sg_of_su->saAmfSGSuHostNodeGroup, 
sizeof(SaNameT)) == 0)) {
                
-               TRACE("SU '%s' mapped using '%s'", su->name.value, 
ng->ng_name.value);
+               TRACE("SU '%s' mapped using '%s'", su->name.value, 
ng->name.value);
                return true;
        }
 
@@ -337,7 +307,7 @@ static SaAisErrorT ng_ccb_completed_modi
                                        if 
(su_is_mapped_to_node_via_nodegroup(su, ng)) {
                                                
report_ccb_validation_error(opdata, "Cannot delete '%s' from '%s'."
                                                                " An SU is 
mapped using node group",
-                                                               
node->name.value, ng->ng_name.value);
+                                                               
node->name.value, ng->name.value);
                                                goto done;
                                                
                                        }
@@ -348,7 +318,7 @@ static SaAisErrorT ng_ccb_completed_modi
                                        if 
(su_is_mapped_to_node_via_nodegroup(su, ng)) {
                                                
report_ccb_validation_error(opdata, "Cannot delete '%s' from '%s'."
                                                                " An SU is 
mapped using node group",
-                                                               
node->name.value, ng->ng_name.value);
+                                                               
node->name.value, ng->name.value);
                                                goto done;
                                        }
                                }
@@ -444,7 +414,7 @@ static SaAisErrorT ng_ccb_completed_dele
                        if (su_is_mapped_to_node_via_nodegroup(su, ng) &&
                            is_deleted_in_ccb(opdata->ccbId, &su->name) == 
false) {
                                report_ccb_validation_error(opdata, "Cannot 
delete '%s' because '%s' is mapped using it",
-                                       ng->ng_name.value, su->name.value);
+                                       ng->name.value, su->name.value);
                                goto done;
                        }
                }
@@ -453,7 +423,7 @@ static SaAisErrorT ng_ccb_completed_dele
                        if (su_is_mapped_to_node_via_nodegroup(su, ng) &&
                            is_deleted_in_ccb(opdata->ccbId, &su->name) == 
false) {
                                report_ccb_validation_error(opdata, "Cannot 
delete '%s' because '%s' is mapped using it",
-                                       ng->ng_name.value, su->name.value);
+                                       ng->name.value, su->name.value);
                                goto done;
                        }
                }
@@ -571,7 +541,7 @@ static void ng_ccb_apply_cb(CcbUtilOpera
        case CCBUTIL_CREATE:
                ng = ng_create(&opdata->objectName, 
opdata->param.create.attrValues);
                osafassert(ng);
-               ng_db_add(ng);
+               nodegroup_db->insert(ng);
                break;
        case CCBUTIL_MODIFY:
                ng_ccb_apply_modify_hdlr(opdata);
@@ -593,11 +563,7 @@ static void ng_ccb_apply_cb(CcbUtilOpera
  */
 void avd_ng_constructor(void)
 {
-       NCS_PATRICIA_PARAMS patricia_params;
-
-       patricia_params.key_size = sizeof(SaNameT);
-       osafassert(ncs_patricia_tree_init(&nodegroup_db, &patricia_params) == 
NCSCC_RC_SUCCESS);
-
+       nodegroup_db = new AmfDb<AVD_AMF_NG>;
        avd_class_impl_set("SaAmfNodeGroup", NULL, NULL, ng_ccb_completed_cb,
                        ng_ccb_apply_cb);
 }

------------------------------------------------------------------------------
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.
Get unparalleled scalability from the best Selenium testing platform available
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
_______________________________________________
Opensaf-devel mailing list
Opensaf-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to