Ack, code review only./Regards HansN

-----Original Message-----
From: praveen.malv...@oracle.com [mailto:praveen.malv...@oracle.com] 
Sent: den 16 juni 2014 07:08
To: Hans Feldt; Hans Nordebäck; nagendr...@oracle.com
Cc: opensaf-devel@lists.sourceforge.net
Subject: [PATCH 1 of 1] amfd : use of db_template in si_dep.cc [#713]

 osaf/services/saf/amf/amfd/include/cb.h     |    7 -
 osaf/services/saf/amf/amfd/include/si_dep.h |   53 +-
 osaf/services/saf/amf/amfd/include/timer.h  |    4 +-
 osaf/services/saf/amf/amfd/si_dep.cc        |  709 ++++++++-------------------
 osaf/services/saf/amf/amfd/siass.cc         |   32 +-
 5 files changed, 233 insertions(+), 572 deletions(-)


Following changes have been done:
1)Replaced patricia tree using db_template.
2)Instead of  AVD_SI_SI_DEP_INDX and AVD_SI_SI_DEP, now there is
  a class AVD_SI_DEP.
3)Earlier there were two separate databases, one had sponsor as primary
  key and dependent as secondary key and other database had vice versa.
  This has been replaced by a single database of AVD_SI_DEP.

TODO:Use of methods and other proposed changes as per #713.

diff --git a/osaf/services/saf/amf/amfd/include/cb.h 
b/osaf/services/saf/amf/amfd/include/cb.h
--- a/osaf/services/saf/amf/amfd/include/cb.h
+++ b/osaf/services/saf/amf/amfd/include/cb.h
@@ -103,13 +103,6 @@ typedef struct avd_evt_queue_list {
        AVD_EVT_QUEUE *tail;
 } AVD_EVT_QUEUE_LIST;
 
-/* SI-SI dependency database */
-typedef struct avd_si_dep {
-       NCS_PATRICIA_TREE spons_anchor; /* Tree of SI-SI dep, sponsor SI acts
-                                          as a primary key */
-       NCS_PATRICIA_TREE dep_anchor;   /* Tree of SI-SI dep, dependent SI 
-                                          acts as a primary key */
-} AVD_SI_DEP;
 
 /* AVD IMM Admin Operation Callback */
 typedef struct admin_oper_cbk {
diff --git a/osaf/services/saf/amf/amfd/include/si_dep.h 
b/osaf/services/saf/amf/amfd/include/si_dep.h
--- a/osaf/services/saf/amf/amfd/include/si_dep.h
+++ b/osaf/services/saf/amf/amfd/include/si_dep.h
@@ -45,52 +45,31 @@ typedef struct avd_si_dep_name_list {
        struct avd_si_dep_name_list *next;
 } AVD_SI_DEP_NAME_LIST;
 
-/*
- * Index data to retrieve a specific SI-SI dep. data record from its
- * database (si_dep: dep_anchor, spons_anchor) defined AvD CB .
- */
-typedef struct avd_si_si_dep_indx_tag {
-       /* primary-key: sponsor SI name */
-       SaNameT si_name_prim;
+class AVD_SI_DEP {
+public:
+        SaNameT name;
+        AVD_SI *spons_si;
+        SaNameT spons_name;
+        AVD_SI *dep_si;
+        SaNameT dep_name;
+        SaTimeT saAmfToleranceTime;
+        AVD_TMR si_dep_timer;
 
-       /* secondary-key: dependant SI name */
-       SaNameT si_name_sec;
-} AVD_SI_SI_DEP_INDX;
-
-/*
- * Data structure that holds SI-SI dependency data, same record is updated
- * in two SI_SI dep anch tree's. One of the tree hold sponsor SI name as the
- * primary indx & dependent SI name as secondary indx (as per SI_SI dep cfg).
- * The other one has vis-versa.
- */
-typedef struct avd_si_si_dep {
-       NCS_PATRICIA_NODE tree_node_imm;
-       NCS_PATRICIA_NODE tree_node;
-
-       /* Index info to retrieve the record */
-       AVD_SI_SI_DEP_INDX indx_imm;
-       AVD_SI_SI_DEP_INDX indx;
-
-       uint32_t si_dep_hdl;
-       SaTimeT saAmfToleranceTime;
-       AVD_TMR si_dep_timer;   /* SI-SI dep. tol timer */
-       bool unassign_event;
-} AVD_SI_SI_DEP;
+};
 
 /* Spons-SI node of the spons-list in SI struct */
 typedef struct avd_spons_si_tag {
        struct avd_si_tag *si;
-       AVD_SI_SI_DEP *sidep_rec;
+       AVD_SI_DEP *sidep_rec;
        struct avd_spons_si_tag *next;
 } AVD_SPONS_SI_NODE;
 
-#define AVD_SI_SI_DEP_NULL ((AVD_SI_SI_DEP *)0)
+extern AmfDb<std::pair<std::string, std::string>, AVD_SI_DEP> *sidep_db;
 
-void sidep_spons_list_del(AVD_CL_CB *cb, AVD_SI_SI_DEP *si_dep_rec);
-AVD_SI_SI_DEP *sidep_struc_crt(AVD_CL_CB *cb, AVD_SI_SI_DEP_INDX *indx);
-AVD_SI_SI_DEP *avd_sidep_find(AVD_CL_CB *cb, AVD_SI_SI_DEP_INDX *indx, bool 
isImmIdx);
-AVD_SI_SI_DEP *avd_sidep_find_next(AVD_CL_CB *cb, AVD_SI_SI_DEP_INDX *indx, 
bool isImmIdx);
-uint32_t sidep_del_row(AVD_CL_CB *cb, AVD_SI_SI_DEP *rec);
+#define AVD_SI_DEP_NULL ((AVD_SI_DEP *)0)
+
+void sidep_spons_list_del(AVD_CL_CB *cb, AVD_SI_DEP *si_dep_rec);
+AVD_SI_DEP *avd_sidep_find(AVD_SI *spons_si, AVD_SI *dep_si);
 void avd_sidep_tol_tmr_evh(AVD_CL_CB *cb, struct avd_evt_tag *evt);
 void avd_sidep_assign_evh(AVD_CL_CB *cb, struct avd_evt_tag *evt);
 void avd_sidep_unassign_evh(AVD_CL_CB *cb, struct avd_evt_tag *evt);
diff --git a/osaf/services/saf/amf/amfd/include/timer.h 
b/osaf/services/saf/amf/amfd/include/timer.h
--- a/osaf/services/saf/amf/amfd/include/timer.h
+++ b/osaf/services/saf/amf/amfd/include/timer.h
@@ -72,8 +72,8 @@ typedef struct avd_tmr_tag {
 {\
    si_dep_rec->si_dep_timer.is_active = false; \
    si_dep_rec->si_dep_timer.type = AVD_TMR_SI_DEP_TOL; \
-   si_dep_rec->si_dep_timer.spons_si_name = si_dep_rec->indx_imm.si_name_prim; 
\
-   si_dep_rec->si_dep_timer.dep_si_name = si_dep_rec->indx_imm.si_name_sec; \
+   si_dep_rec->si_dep_timer.spons_si_name = si_dep_rec->spons_name; \
+   si_dep_rec->si_dep_timer.dep_si_name = si_dep_rec->dep_name; \
    avd_start_tmr(cb, &si_dep_rec->si_dep_timer, 
si_dep_rec->saAmfToleranceTime); \
 }
 
diff --git a/osaf/services/saf/amf/amfd/si_dep.cc 
b/osaf/services/saf/amf/amfd/si_dep.cc
--- a/osaf/services/saf/amf/amfd/si_dep.cc
+++ b/osaf/services/saf/amf/amfd/si_dep.cc
@@ -157,19 +157,19 @@
 #include <susi.h>
 #include <proc.h>
 
+AmfDb<std::pair<std::string, std::string>, AVD_SI_DEP> *sidep_db = NULL;
+
 /* static function prototypes */
 static bool avd_sidep_all_sponsors_active(AVD_SI *si);
-static void sidep_update_si_dep_state_for_spons_unassign(AVD_CL_CB *cb, AVD_SI 
*dep_si, AVD_SI_SI_DEP *si_dep_rec);
+static void sidep_update_si_dep_state_for_spons_unassign(AVD_CL_CB *cb, AVD_SI 
*dep_si, AVD_SI_DEP *si_dep_rec);
 static uint32_t sidep_unassign_dependent(AVD_CL_CB *cb, AVD_SI *si);
 static bool sidep_is_si_active(AVD_SI *si);
 static uint32_t sidep_sg_red_si_process_assignment(AVD_CL_CB *cb, AVD_SI *si);
 static uint32_t sidep_si_dep_state_evt_send(AVD_CL_CB *cb, AVD_SI *si, 
AVD_EVT_TYPE evt_type);
-static uint32_t sidep_cyclic_dep_find(AVD_CL_CB *cb, AVD_SI_SI_DEP_INDX *indx);
+static uint32_t sidep_cyclic_dep_find(AVD_SI_DEP *sidep);
 static void sidep_si_dep_start_unassign(AVD_CL_CB *cb, AVD_EVT *evt);
 static void sidep_dependentsi_role_failover(AVD_SI *si);
 
-static AVD_SI_DEP si_dep; /* SI-SI dependency data */
-
 static const char *depstatename[] = {
        "",
        "NO_DEPENDENCY",
@@ -263,14 +263,14 @@ bool sidep_is_si_active(AVD_SI *si)
  *           dependent-SI.
  *
  * Input:  cb - ptr to AVD control block
- *         si_dep_rec - ptr to AVD_SI_SI_DEP struct 
+ *         si_dep_rec - ptr to AVD_SI_DEP struct 
  *
  * Returns:
  *
  * NOTES:
  * 
  **************************************************************************/
-void sidep_spons_list_del(AVD_CL_CB *cb, AVD_SI_SI_DEP *si_dep_rec)
+void sidep_spons_list_del(AVD_SI_DEP *si_dep_rec)
 {
        AVD_SI *dep_si = NULL;
        AVD_SPONS_SI_NODE *spons_si_node = NULL;
@@ -279,8 +279,8 @@ void sidep_spons_list_del(AVD_CL_CB *cb,
        TRACE_ENTER();
 
        /* Dependent SI should be active, if not return error */
-       dep_si = avd_si_get(&si_dep_rec->indx_imm.si_name_sec);
-       osafassert(dep_si);
+       dep_si = avd_si_get(&si_dep_rec->dep_name);
+       osafassert(dep_si != NULL); 
 
        /* SI doesn't depend on any other SIs */
        osafassert (dep_si->spons_si_list != NULL);
@@ -288,7 +288,7 @@ void sidep_spons_list_del(AVD_CL_CB *cb,
        spons_si_node = dep_si->spons_si_list;
 
        /* Check if the sponsor is the first node of the list */
-       if (m_CMP_HORDER_SANAMET(dep_si->spons_si_list->si->name, 
si_dep_rec->indx_imm.si_name_prim) == 0) {
+       if (m_CMP_HORDER_SANAMET(dep_si->spons_si_list->si->name, 
si_dep_rec->spons_si->name) == 0) {
                dep_si->spons_si_list = spons_si_node->next;
                /* decrement the dependent SI count in sponsor SI */
                spons_si_node->si->num_dependents --;
@@ -296,7 +296,7 @@ void sidep_spons_list_del(AVD_CL_CB *cb,
        } else {
                while (spons_si_node->next != NULL) {
                        if (m_CMP_HORDER_SANAMET(spons_si_node->next->si->name,
-                                                
si_dep_rec->indx_imm.si_name_prim) != 0) {
+                                                si_dep_rec->spons_si->name) != 
0) {
                                spons_si_node = spons_si_node->next;
                                continue;
                        }
@@ -313,7 +313,7 @@ void sidep_spons_list_del(AVD_CL_CB *cb,
        TRACE_LEAVE();
 }
 
-static bool rec_already_in_sponsor_list(const AVD_SI *si, const AVD_SI_SI_DEP 
*rec)
+static bool rec_already_in_sponsor_list(const AVD_SI *si, const AVD_SI_DEP 
*rec)
 {
        AVD_SPONS_SI_NODE *node;
 
@@ -335,7 +335,7 @@ static bool rec_already_in_sponsor_list(
  *         rec
  * 
  **************************************************************************/
-void avd_si_dep_spons_list_add(AVD_SI *dep_si, AVD_SI *spons_si, AVD_SI_SI_DEP 
*rec)
+void avd_si_dep_spons_list_add(AVD_SI *dep_si, AVD_SI *spons_si, AVD_SI_DEP 
*rec)
 {
        AVD_SPONS_SI_NODE *spons_si_node;
 
@@ -354,6 +354,12 @@ void avd_si_dep_spons_list_add(AVD_SI *d
        dep_si->spons_si_list = spons_si_node;
 }
 
+static AVD_SI_DEP *sidep_db_find(SaNameT *sponsor, SaNameT *dependent)
+{
+       return  sidep_db->find(make_pair(Amf::to_string(sponsor), 
Amf::to_string(dependent)));
+}
+
+
 /*****************************************************************************
  * Function: sidep_stop_tol_timer
  *
@@ -369,29 +375,19 @@ void avd_si_dep_spons_list_add(AVD_SI *d
  * NOTES: 
  * 
  **************************************************************************/
-void sidep_stop_tol_timer(AVD_CL_CB *cb, AVD_SI *si)
+void sidep_stop_tol_timer(AVD_CL_CB *cb, AVD_SI *dep_si)
 {
-       AVD_SI_SI_DEP_INDX indx;
-       AVD_SI_SI_DEP *rec = NULL;
-       AVD_SPONS_SI_NODE *spons_si_node = si->spons_si_list;
-
-       memset((char *)&indx, '\0', sizeof(AVD_SI_SI_DEP_INDX));
-       indx.si_name_sec.length = si->name.length;
-       memcpy(indx.si_name_sec.value, si->name.value, si->name.length);
+       AVD_SI_DEP *rec;
+       AVD_SPONS_SI_NODE *spons_si_node = dep_si->spons_si_list;
 
        while (spons_si_node) {
-               /* Need to stop the tolerance timer */
-               indx.si_name_prim.length = spons_si_node->si->name.length;
-               memcpy(indx.si_name_prim.value, spons_si_node->si->name.value,
-                      spons_si_node->si->name.length);
-
-               if ((rec = avd_sidep_find(cb, &indx, true)) != NULL) {
+               if ((rec = sidep_db_find(&spons_si_node->si->name, 
&dep_si->name)) != NULL) {
                        if (rec->si_dep_timer.is_active == true) {
                                avd_stop_tmr(cb, &rec->si_dep_timer);
-                               TRACE("Tolerance timer stopped for '%s'", 
si->name.value);
+                               TRACE("Tolerance timer stopped for '%s'", 
dep_si->name.value);
 
-                               if (si->tol_timer_count > 0) {
-                                       si->tol_timer_count--;
+                               if (dep_si->tol_timer_count > 0) {
+                                       dep_si->tol_timer_count--;
                                }
                        }
                }
@@ -845,20 +841,20 @@ done:
  *
  * Input:  cb - ptr to AVD control block
  *         dep_si - ptr to AVD_SI struct (dependent SI).
- *         si_dep_rec - ptr to AVD_SI_SI_DEP struct 
+ *         si_dep_rec - ptr to AVD_SI_DEP struct 
  *
  * Returns: 
  *
  * NOTES:
  * 
  **************************************************************************/
-void sidep_update_si_dep_state_for_spons_unassign(AVD_CL_CB *cb, AVD_SI 
*dep_si, AVD_SI_SI_DEP *si_dep_rec)
+void sidep_update_si_dep_state_for_spons_unassign(AVD_CL_CB *cb, AVD_SI 
*dep_si, AVD_SI_DEP *si_dep_rec)
 {
        AVD_SI *spons_si = NULL;
 
        TRACE_ENTER2("si:'%s', 
si_dep_state:'%s'",dep_si->name.value,depstatename[dep_si->si_dep_state]);
 
-       spons_si = avd_si_get(&si_dep_rec->indx_imm.si_name_prim);
+       spons_si = avd_si_get(&si_dep_rec->spons_name);
        osafassert(spons_si != NULL);
 
        /* Take action only when both sponsor and dependent belongs to same sg 
@@ -914,29 +910,16 @@ done:
  **************************************************************************/
 void sidep_take_action_on_dependents(AVD_SI *si)
 {
-       AVD_SI *dep_si = NULL;
-       AVD_SI_SI_DEP_INDX si_indx;
-       AVD_SI_SI_DEP *si_dep_rec = NULL;
-
        TRACE_ENTER();
 
-       memset((char *)&si_indx, '\0', sizeof(AVD_SI_SI_DEP_INDX));
-       si_indx.si_name_prim.length = si->name.length;
-       memcpy(si_indx.si_name_prim.value, si->name.value, 
si_indx.si_name_prim.length);
+       for (std::map<std::pair<std::string,std::string>, 
AVD_SI_DEP*>::const_iterator it = sidep_db->begin();
+                       it != sidep_db->end(); it++) {
+               const AVD_SI_DEP *sidep = it->second;
 
-       /* If si_dep is NULL, means adjust the SI dep states for all depended 
-        * SIs of the sponsor SI.
-        */
-       si_dep_rec = avd_sidep_find_next(avd_cb, &si_indx, true);
-       while (si_dep_rec != NULL) {
-               if (m_CMP_HORDER_SANAMET(si_dep_rec->indx_imm.si_name_prim, 
si_indx.si_name_prim) != 0) {
-                       /* Seems no more node exists in spons_anchor tree with 
-                        * "si_indx.si_name_prim" as primary key 
-                        */
-                       break;
-               }
+               if (sidep->spons_si != si)
+                       continue;
 
-               dep_si = avd_si_get(&si_dep_rec->indx_imm.si_name_sec);
+               AVD_SI *dep_si = avd_si_get(&sidep->dep_name);
                osafassert(dep_si != NULL);
 
                /* Take action only when both sponsor and dependent belongs to 
same sg 
@@ -950,9 +933,9 @@ void sidep_take_action_on_dependents(AVD
                                avd_sidep_si_dep_state_set(dep_si, 
AVD_SI_READY_TO_ASSIGN);
                                sidep_dependentsi_role_failover(dep_si);
                        }
-                       si_dep_rec = avd_sidep_find_next(avd_cb, 
&si_dep_rec->indx_imm, true);
                        continue;
                }
+
                if (dep_si->si_dep_state == AVD_SI_FAILOVER_UNDER_PROGRESS) {
                        /* If the dependent SI is under 
AVD_SI_FAILOVER_UNDER_PROGRESS state
                         * update its dep_state to AVD_SI_READY_TO_UNASSIGN
@@ -967,202 +950,22 @@ void sidep_take_action_on_dependents(AVD
                        sidep_si_dep_state_evt_send(avd_cb, dep_si, 
AVD_EVT_ASSIGN_SI_DEP_STATE);
                }
 
-               si_dep_rec = avd_sidep_find_next(avd_cb, &si_dep_rec->indx_imm, 
true);
        }
 
        TRACE_LEAVE();
 }
 
-/*****************************************************************************
- * Function: sidep_struc_crt
- *
- * Purpose: This function will create and add a AVD_SI_SI_DEP structure to the
- *          trees if an element with the same key value doesn't exist in the
- *          tree.
- *
- * Input: cb - the AVD control block
- *        indx - Index for the row to be added. 
- *
- * Returns: The pointer to AVD_SI_SI_DEP structure allocated and added.
- *
- * NOTES:
- *
- **************************************************************************/
-AVD_SI_SI_DEP *sidep_struc_crt(AVD_CL_CB *cb, AVD_SI_SI_DEP_INDX *indx)
+AVD_SI_DEP *get_sidep_with_same_dep(AVD_SI_DEP *sidep) 
 {
-       AVD_SI_SI_DEP *rec;
-       uint32_t si_prim_len = indx->si_name_prim.length;
-       uint32_t si_sec_len = indx->si_name_sec.length;
-
-       TRACE_ENTER();
-
-       if ((rec = avd_sidep_find(cb, indx, true)) != NULL)
-               goto done;
-
-       /* Allocate a new block structure for imm rec now */
-       rec = new AVD_SI_SI_DEP();
-
-       rec->indx_imm.si_name_prim.length = indx->si_name_prim.length;
-       memcpy(rec->indx_imm.si_name_prim.value, indx->si_name_prim.value, 
si_prim_len);
-
-       rec->indx_imm.si_name_sec.length = indx->si_name_sec.length;
-       memcpy(rec->indx_imm.si_name_sec.value, indx->si_name_sec.value, 
si_sec_len);
-
-       rec->indx.si_name_prim.length = indx->si_name_sec.length;
-       memcpy(rec->indx.si_name_prim.value, indx->si_name_sec.value, 
si_sec_len);
-
-       rec->indx.si_name_sec.length = indx->si_name_prim.length;
-       memcpy(rec->indx.si_name_sec.value, indx->si_name_prim.value, 
si_prim_len);
-
-       rec->tree_node_imm.key_info = (uint8_t *)&(rec->indx_imm);
-       rec->tree_node_imm.bit = 0;
-       rec->tree_node_imm.left = NCS_PATRICIA_NODE_NULL;
-       rec->tree_node_imm.right = NCS_PATRICIA_NODE_NULL;
-
-       rec->tree_node.key_info = (uint8_t *)&(rec->indx);
-       rec->tree_node.bit = 0;
-       rec->tree_node.left = NCS_PATRICIA_NODE_NULL;
-       rec->tree_node.right = NCS_PATRICIA_NODE_NULL;
-
-       if (ncs_patricia_tree_add(&si_dep.spons_anchor, &rec->tree_node_imm) != 
NCSCC_RC_SUCCESS) {
-               LOG_ER("%s: spons ncs_patricia_tree_add failed", __FUNCTION__);
-               delete rec;
-               rec = NULL;
-               goto done;
+       for (std::map<std::pair<std::string,std::string>, 
AVD_SI_DEP*>::const_iterator it = sidep_db->begin();
+                       it != sidep_db->end(); it++) {
+               AVD_SI_DEP *tmp_sidep = it->second;
+               if (sidep == tmp_sidep)
+                       continue;
+               if (m_CMP_HORDER_SANAMET(tmp_sidep->dep_name, sidep->dep_name) 
== 0)
+                       return tmp_sidep;
        }
-
-       if (ncs_patricia_tree_add(&si_dep.dep_anchor, &rec->tree_node) != 
NCSCC_RC_SUCCESS) {
-               LOG_ER("%s: dep ncs_patricia_tree_add failed", __FUNCTION__);
-               ncs_patricia_tree_del(&si_dep.spons_anchor, 
&rec->tree_node_imm);
-               delete rec;
-               rec = NULL;
-               goto done;
-       }
-
-done:
-       TRACE_LEAVE();
-       return rec;
-}
-
-/*****************************************************************************
- * Function: avd_sidep_find 
- *
- * Purpose:  This function will find a AVD_SI_SI_DEP structure in the tree 
- *           with indx value as key. Indices can be provided as per the order
- *           mention in the imm or in the reverse of that. 
- *
- * Input: cb - The AVD control block
- *        indx - The key.
- *
- * Returns: The pointer to AVD_SG_SI_RANK structure found in the tree.
- *
- * NOTES: Set the isImmIdx flag value to 1 if indices are as defined by imm 
and 0
- *        if it is in reverse order
- * 
- **************************************************************************/
-AVD_SI_SI_DEP *avd_sidep_find(AVD_CL_CB *cb, AVD_SI_SI_DEP_INDX *indx, bool 
isImmIdx)
-{
-       AVD_SI_SI_DEP *rec = NULL;
-
-       if (isImmIdx) {
-               rec = (AVD_SI_SI_DEP 
*)ncs_patricia_tree_get(&si_dep.spons_anchor, (uint8_t *)indx);
-       } else {
-               rec = (AVD_SI_SI_DEP 
*)ncs_patricia_tree_get(&si_dep.dep_anchor, (uint8_t *)indx);
-               if (rec != NULL) {
-                       /* Adjust the pointer */
-                       rec = (AVD_SI_SI_DEP *)(((char *)rec)
-                                               - (((char 
*)&(AVD_SI_SI_DEP_NULL->tree_node))
-                                                  - ((char 
*)AVD_SI_SI_DEP_NULL)));
-               }
-       }
-
-       return rec;
-}
-
-/*****************************************************************************
- * Function: avd_sidep_find_next 
- *
- * Purpose:  This function will find next AVD_SI_SI_DEP structure in the tree
- *           with indx value as key. Indices can be provided as per the order
- *           mention in the imm or in the reverse of that. 
- *
- * Input: cb - the AVD control block
- *        indx - The key.
- *
- * Returns: The next pointer to AVD_SG_SI_RANK structure found in the tree.
- *
- * NOTES: Set the isImmIdx flag value to 1 if indices are as defined by imm 
and 0
- *        if it is in reverse order
- * 
- **************************************************************************/
-AVD_SI_SI_DEP *avd_sidep_find_next(AVD_CL_CB *cb, AVD_SI_SI_DEP_INDX *indx, 
bool isImmIdx)
-{
-       AVD_SI_SI_DEP *rec = NULL;
-
-       if (isImmIdx) {
-               rec = (AVD_SI_SI_DEP 
*)ncs_patricia_tree_getnext(&si_dep.spons_anchor, (uint8_t *)indx);
-       } else {
-               rec = (AVD_SI_SI_DEP 
*)ncs_patricia_tree_getnext(&si_dep.dep_anchor, (uint8_t *)indx);
-               if (rec != NULL) {
-                       /* Adjust the pointer */
-                       rec = (AVD_SI_SI_DEP *)(((char *)rec)
-                                               - (((char 
*)&(AVD_SI_SI_DEP_NULL->tree_node))
-                                                  - ((char 
*)AVD_SI_SI_DEP_NULL)));
-               }
-       }
-
-       return rec;
-}
-
-/*****************************************************************************
- * Function: sidep_del_row 
- *
- * Purpose:  This function will delete and free AVD_SI_SI_DEP structure from 
- *           the tree. It will delete the record from both patricia trees
- *
- * Input: cb - The AVD control block
- *        si - Pointer to service instance row 
- *
- * Returns: NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE  
- *
- * NOTES:
- * 
- **************************************************************************/
-uint32_t sidep_del_row(AVD_CL_CB *cb, AVD_SI_SI_DEP *rec)
-{
-       AVD_SI_SI_DEP *si_dep_rec = NULL;
-       uint32_t rc = NCSCC_RC_FAILURE;
-
-       TRACE_ENTER();
-
-       if (rec == NULL)
-               goto done;
-
-       if ((si_dep_rec = avd_sidep_find(cb, &rec->indx, false)) != NULL) {
-               if (ncs_patricia_tree_del(&si_dep.dep_anchor, 
&si_dep_rec->tree_node)
-                   != NCSCC_RC_SUCCESS) {
-                       LOG_ER("Failed deleting SI Dep from Dependent Anchor");
-                       goto done;
-               }
-       }
-
-       si_dep_rec = NULL;
-
-       if ((si_dep_rec = avd_sidep_find(cb, &rec->indx_imm, true)) != NULL) {
-               if (ncs_patricia_tree_del(&si_dep.spons_anchor, 
&si_dep_rec->tree_node_imm)
-                   != NCSCC_RC_SUCCESS) {
-                       LOG_ER("Failed deleting SI Dep from Sponsor Anchor");
-                       goto done;
-               }
-       }
-
-       if (si_dep_rec)
-               delete si_dep_rec;
-
-       rc = NCSCC_RC_SUCCESS;
-done:
-       TRACE_LEAVE();
-       return rc;
+       return NULL;
 }
 
 /*****************************************************************************
@@ -1180,18 +983,17 @@ done:
  *        buffer is not sufficient to process this request.
  *
  **************************************************************************/
-uint32_t sidep_cyclic_dep_find(AVD_CL_CB *cb, AVD_SI_SI_DEP_INDX *indx)
+uint32_t sidep_cyclic_dep_find(AVD_SI_DEP *sidep)
 {
-       AVD_SI_SI_DEP *rec = NULL;
        AVD_SI_DEP_NAME_LIST *start = NULL;
        AVD_SI_DEP_NAME_LIST *temp = NULL;
        AVD_SI_DEP_NAME_LIST *last = NULL;
        uint32_t rc = NCSCC_RC_FAILURE;
-       AVD_SI_SI_DEP_INDX idx;
+       AVD_SI_DEP *tmp_sidep = NULL;
 
        TRACE_ENTER();
 
-       if (m_CMP_HORDER_SANAMET(indx->si_name_prim, indx->si_name_sec) == 0) {
+       if (m_CMP_HORDER_SANAMET(sidep->spons_name, sidep->dep_name) == 0) {
                /* dependent SI and Sponsor SI can not be same 
                   Cyclic dependency found return sucess
                 */
@@ -1200,21 +1002,22 @@ uint32_t sidep_cyclic_dep_find(AVD_CL_CB
        }
 
        start = new AVD_SI_DEP_NAME_LIST;
-       start->si_name = indx->si_name_prim;
+       start->si_name = sidep->spons_name;
        start->next = NULL;
        last = start;
+       LOG_NO("got si :%s",start->si_name.value);
        
 
        while (last) {
-               memset((char *)&idx, '\0', sizeof(AVD_SI_SI_DEP_INDX));
+               for (std::map<std::pair<std::string,std::string>, 
AVD_SI_DEP*>::const_iterator it = sidep_db->begin();
+                               it != sidep_db->end(); it++) {
+                       tmp_sidep = it->second;
+                       if (m_CMP_HORDER_SANAMET(tmp_sidep->dep_name, 
last->si_name) == 0)
+                               break;
+               }
 
-               idx.si_name_prim.length = last->si_name.length;
-               memcpy(idx.si_name_prim.value, last->si_name.value, 
last->si_name.length);
-
-               rec = avd_sidep_find_next(cb, &idx, false);
-
-               while ((rec != NULL) && 
(m_CMP_HORDER_SANAMET(rec->indx.si_name_prim, idx.si_name_prim) == 0)) {
-                       if (m_CMP_HORDER_SANAMET(indx->si_name_sec, 
rec->indx.si_name_sec) == 0) {
+               while ((tmp_sidep != NULL) && 
(m_CMP_HORDER_SANAMET(tmp_sidep->dep_name, last->si_name) == 0)) { 
+                       if (m_CMP_HORDER_SANAMET(sidep->dep_name, 
tmp_sidep->spons_name) == 0) {
                                /* Cyclic dependency found */
                                rc = NCSCC_RC_SUCCESS;
                                break;
@@ -1222,21 +1025,20 @@ uint32_t sidep_cyclic_dep_find(AVD_CL_CB
 
                        /* Search if this SI name already exist in the list */
                        temp = start;
-                       if (m_CMP_HORDER_SANAMET(temp->si_name, 
rec->indx.si_name_sec) != 0) {
+                       if (m_CMP_HORDER_SANAMET(temp->si_name, 
tmp_sidep->spons_name) != 0) {
                                while ((temp->next != NULL) &&
-                                      
(m_CMP_HORDER_SANAMET(temp->next->si_name, rec->indx.si_name_sec) != 0)) {
+                                               
(m_CMP_HORDER_SANAMET(temp->next->si_name, tmp_sidep->spons_name) != 0)) {
                                        temp = temp->next;
                                }
 
                                /* SI Name not found in the list, add it */
                                if (temp->next == NULL) {
                                        temp->next = new AVD_SI_DEP_NAME_LIST;
-                                       temp->next->si_name = 
rec->indx.si_name_sec;
+                                       temp->next->si_name = 
tmp_sidep->spons_name;
                                        temp->next->next = NULL;
                                }
                        }
-
-                       rec = avd_sidep_find_next(cb, &rec->indx, false);
+                       tmp_sidep = get_sidep_with_same_dep(tmp_sidep);
                }
 
                if (rc == NCSCC_RC_SUCCESS) {
@@ -1246,6 +1048,7 @@ uint32_t sidep_cyclic_dep_find(AVD_CL_CB
                }
        }
 
+
        /* Free the allocated SI name list */
        while (start) {
                temp = start->next;
@@ -1258,53 +1061,59 @@ done:
        return rc;
 }
 
-static int avd_sidep_indx_init(const SaNameT *sidep_name, AVD_SI_SI_DEP_INDX 
*indx)
+static int avd_sidep_indx_init(const SaNameT *sidep_name, AVD_SI_DEP 
*sidep_obj)
 {
-       char *p;
-       SaNameT tmp;
-       uint32_t i = 0;
+        char *p;
+        SaNameT tmp;
+        int i = 0;
 
-       memset(&tmp, 0, sizeof(SaNameT));
-       tmp.length = sidep_name->length;
-       memcpy(&tmp.value, &sidep_name->value, tmp.length);
-               
-       memset(indx, 0, sizeof(AVD_SI_SI_DEP_INDX));
+        memset(&tmp, 0, sizeof(SaNameT));
+        tmp.length = sidep_name->length;
+        memcpy(&tmp.value, &sidep_name->value, tmp.length);
 
-       /* find first occurence and step past it */
-       p = strstr((char *)tmp.value, "safSi=") + 1;
-       if (p == NULL) return false;
+        memset(sidep_obj, 0, sizeof(AVD_SI_DEP));
+       memcpy(sidep_obj->name.value, &sidep_name->value, sidep_name->length);
 
-       /* find second occurence, an error if not found */
-       p = strstr(p, "safSi=");
-       if (p == NULL) return false;
+        /* find first occurence and step past it */
+        p = strstr((char *)tmp.value, "safSi=") + 1;
+        if (p == NULL) return false;
 
-       *(p - 1) = '\0';        /* null terminate at comma before SI */
+        /* find second occurence, an error if not found */
+        p = strstr(p, "safSi=");
+        if (p == NULL) return false;
 
-       indx->si_name_sec.length = snprintf((char *)indx->si_name_sec.value, 
SA_MAX_NAME_LENGTH, "%s", p);
+        *(p - 1) = '\0';        /* null terminate at comma before SI */
 
-       /* Skip past the RDN tag */
-       p = strchr((char *)tmp.value, '=') + 1;
-       if (p == NULL) return false;
+       sidep_obj->dep_name.length = snprintf((char 
*)sidep_obj->dep_name.value, SA_MAX_NAME_LENGTH, "%s", p);
 
-       /*
-        ** Example DN, need to copy to get rid of back slash escaped commas.
-        ** 
'safDepend=safSi=SC2-NoRed\,safApp=OpenSAF,safSi=SC-2N,safApp=OpenSAF'
-        */
+        /* Skip past the RDN tag */
+        p = strchr((char *)tmp.value, '=') + 1;
+        if (p == NULL) return false;
 
-       /* Copy the RDN value which is a DN with escaped commas */
-       while (*p) {
-               if (*p != '\\')
-                       indx->si_name_prim.value[i++] = *p;
-               p++;
-       }
-       indx->si_name_prim.length = strlen((char *)indx->si_name_prim.value);
+        /*
+         ** Example DN, need to copy to get rid of back slash escaped commas.
+         ** 
'safDepend=safSi=SC2-NoRed\,safApp=OpenSAF,safSi=SC-2N,safApp=OpenSAF'
+         */
 
-       return true;
+        /* Copy the RDN value which is a DN with escaped commas */
+       i = 0;
+        while (*p) {
+                if (*p != '\\')
+                        sidep_obj->spons_name.value[i++] = *p;
+                p++;
+        }
+       sidep_obj->spons_name.length = strlen((char 
*)sidep_obj->spons_name.value);
+       
+       /* Set SI pointers */
+        sidep_obj->spons_si =  
si_db->find(Amf::to_string(&sidep_obj->spons_name));
+        sidep_obj->dep_si =  si_db->find(Amf::to_string(&sidep_obj->dep_name));
+
+        return true;
 }
 
 static uint32_t is_config_valid(SaNameT *sidep_name, CcbUtilOperationData_t 
*opdata)
 {
-       AVD_SI_SI_DEP_INDX indx;
+       AVD_SI_DEP sidep;
        AVD_SI *spons_si, *dep_si;
        CcbUtilOperationData_t *tmp;
        uint32_t dep_saAmfSIRank, spons_saAmfSIRank;
@@ -1313,25 +1122,25 @@ static uint32_t is_config_valid(SaNameT 
 
        TRACE_ENTER();
        
-       if( !avd_sidep_indx_init(sidep_name, &indx)) {
+       if( !avd_sidep_indx_init(sidep_name, &sidep)) {
                report_ccb_validation_error(opdata, "SI dep validation: Bad DN 
for SI Dependency");
                goto done;
        }
 
        /* Sponsor SI need to exist */
-       if ((spons_si = avd_si_get(&indx.si_name_prim)) == NULL) {
+       if ((spons_si = avd_si_get(&sidep.spons_name)) == NULL) {
                if (opdata == NULL) {
                        report_ccb_validation_error(opdata, "SI dep validation: 
'%s' does not exist in model and '%s'"
                                        " depends on it",
-                                       indx.si_name_prim.value, 
indx.si_name_sec.value);
+                                       sidep.spons_name.value, 
sidep.dep_name.value);
                        goto done;
                }
 
                /* SI does not exist in current model, check CCB */
-               if ((tmp = ccbutil_getCcbOpDataByDN(opdata->ccbId, 
&indx.si_name_prim)) == NULL) {
+               if ((tmp = ccbutil_getCcbOpDataByDN(opdata->ccbId, 
&sidep.spons_name)) == NULL) {
                        report_ccb_validation_error(opdata, "SI dep validation: 
'%s' does not exist in existing model or"
                                        " in CCB and '%s' depends on it",
-                                       indx.si_name_prim.value, 
indx.si_name_sec.value);
+                                        sidep.spons_name.value, 
sidep.dep_name.value);
                        goto done;
                }
 
@@ -1346,17 +1155,17 @@ static uint32_t is_config_valid(SaNameT 
        if (spons_saAmfSIRank == 0)
                spons_saAmfSIRank = ~0U; /* zero means lowest possible rank */
 
-       if ((dep_si = avd_si_get(&indx.si_name_sec)) == NULL) {
+       if ((dep_si = avd_si_get(&sidep.dep_name)) == NULL) {
                if (opdata == NULL) {
                        report_ccb_validation_error(opdata, "SI dep validation: 
'%s' does not exist in model",
-                                       indx.si_name_sec.value);
+                                       sidep.dep_name.value);
                        goto done;
                }
 
                /* SI does not exist in current model, check CCB */
-               if ((tmp = ccbutil_getCcbOpDataByDN(opdata->ccbId, 
&indx.si_name_sec)) == NULL) {
+               if ((tmp = ccbutil_getCcbOpDataByDN(opdata->ccbId, 
&sidep.dep_name)) == NULL) {
                        report_ccb_validation_error(opdata, "SI dep validation: 
'%s' does not exist in existing"
-                                       " model or in CCB", 
indx.si_name_sec.value);
+                                       " model or in CCB", 
sidep.dep_name.value);
                        goto done;
                }
 
@@ -1374,7 +1183,7 @@ static uint32_t is_config_valid(SaNameT 
        if ((opdata != NULL) && dependent_si_is_assigned) {
                report_ccb_validation_error(opdata, "SI dep validation: adding 
dependency from existing SI '%s'"
                                " to SI '%s' is not allowed",
-                               indx.si_name_prim.value, 
indx.si_name_sec.value);
+                               sidep.spons_name.value, sidep.dep_name.value);
                goto done;
        }
 
@@ -1384,13 +1193,13 @@ static uint32_t is_config_valid(SaNameT 
        /* higher number => lower rank, see 3.8.1.1 */
        if (spons_saAmfSIRank > dep_saAmfSIRank) {
                report_ccb_validation_error(opdata, "SI dep validation: Sponsor 
SI '%s' has lower rank than"
-                               " dependent SI '%s'", indx.si_name_prim.value, 
indx.si_name_sec.value);
+                               " dependent SI '%s'", sidep.spons_name.value, 
sidep.dep_name.value);
                goto done;
        }
 
-       if (sidep_cyclic_dep_find(avd_cb, &indx) == NCSCC_RC_SUCCESS) {
+       if (sidep_cyclic_dep_find(&sidep) == NCSCC_RC_SUCCESS) {
                /* Return value that record cannot be added due to cyclic 
dependency */
-               report_ccb_validation_error(opdata, "SI dep validation: cyclic 
dependency for '%s'", indx.si_name_sec.value);
+               report_ccb_validation_error(opdata, "SI dep validation: cyclic 
dependency for '%s'", sidep.dep_name.value);
                goto done;
        }
 
@@ -1401,43 +1210,43 @@ done:
        return rc;
 } 
  
-static AVD_SI_SI_DEP *sidep_new(SaNameT *sidep_name, const SaImmAttrValuesT_2 
**attributes)
+static AVD_SI_DEP *sidep_new(SaNameT *sidep_name, const SaImmAttrValuesT_2 
**attributes)
 {
-       AVD_SI_SI_DEP *sidep = NULL;
-       AVD_SI_SI_DEP_INDX indx;
-       AVD_SI *dep_si = NULL;
-       AVD_SI *spons_si = NULL;
+       AVD_SI_DEP tmp_sidep, *sidep = NULL;
 
        TRACE_ENTER2("%s", sidep_name->value);
 
-       avd_sidep_indx_init(sidep_name, &indx);
+       avd_sidep_indx_init(sidep_name, &tmp_sidep);
+       if ((sidep = sidep_db_find(&tmp_sidep.spons_name,&tmp_sidep.dep_name)) 
!= NULL) {
+               TRACE("SI dependency already exists");
+       }
 
-       if ((sidep = sidep_struc_crt(avd_cb, &indx)) == NULL) {
-               LOG_ER("Unable create SI-SI dependency record");
-               goto done;
-       }
-       
+       sidep = new AVD_SI_DEP();
+       avd_sidep_indx_init(sidep_name, sidep);
+       osafassert(sidep->dep_si != NULL);
+       osafassert(sidep->spons_si != NULL);
+       sidep_db->insert(make_pair(Amf::to_string(&sidep->spons_name), 
Amf::to_string(&sidep->dep_name)), sidep);
+
+        /* Allocate a new block structure for imm rec now */
+
        if (immutil_getAttr(const_cast<SaImmAttrNameT>("saAmfToleranceTime"), 
attributes, 0, &sidep->saAmfToleranceTime) != SA_AIS_OK) {
                /* Empty, assign default value */
                sidep->saAmfToleranceTime = 0;
        }
 
        /* Add to dependent's sponsors list */
-       osafassert(spons_si = avd_si_get(&indx.si_name_prim));
-       osafassert(dep_si = avd_si_get(&indx.si_name_sec));
-       avd_si_dep_spons_list_add(dep_si, spons_si, sidep);
+       avd_si_dep_spons_list_add(sidep->dep_si, sidep->spons_si, sidep);
 
        if (avd_cb->avail_state_avd == SA_AMF_HA_ACTIVE)  {
                /* While configuring the dependencies, set the dependent dep 
state considering 
                  all its sponsors assignment status. Possibly a call to 
*_chosen_asgn() after this 
                  may be made and thus it will help in avoiding re-screening in 
*_chosen_asgn(). 
                 */
-               if (avd_sidep_all_sponsors_active(dep_si))
-                       avd_sidep_si_dep_state_set(dep_si, 
AVD_SI_READY_TO_ASSIGN);
+               if (avd_sidep_all_sponsors_active(sidep->dep_si))
+                       avd_sidep_si_dep_state_set(sidep->dep_si, 
AVD_SI_READY_TO_ASSIGN);
                else 
-                       avd_sidep_si_dep_state_set(dep_si, 
AVD_SI_SPONSOR_UNASSIGNED);
+                       avd_sidep_si_dep_state_set(sidep->dep_si, 
AVD_SI_SPONSOR_UNASSIGNED);
        }
-done:
        TRACE_LEAVE();
        return sidep;
 }
@@ -1498,7 +1307,6 @@ SaAisErrorT avd_sidep_config_get(void)
 static SaAisErrorT sidep_ccb_completed_cb(CcbUtilOperationData_t *opdata)
 {
        SaAisErrorT rc = SA_AIS_OK;
-       AVD_SI_SI_DEP_INDX indx;
 
        TRACE_ENTER2("CCB ID %llu, '%s'", opdata->ccbId, 
opdata->objectName.value);
 
@@ -1509,8 +1317,9 @@ static SaAisErrorT sidep_ccb_completed_c
                break;
        case CCBUTIL_DELETE:
        case CCBUTIL_MODIFY:
-               avd_sidep_indx_init(&opdata->objectName, &indx);
-               if (NULL == avd_sidep_find(avd_cb, &indx, true))
+               AVD_SI_DEP sidep;
+               avd_sidep_indx_init(&opdata->objectName, &sidep);
+               if (sidep_db_find(&sidep.spons_name, &sidep.dep_name) == NULL)
                        rc = SA_AIS_ERR_BAD_OPERATION;
                break;
        default:
@@ -1524,10 +1333,8 @@ static SaAisErrorT sidep_ccb_completed_c
 
 static void sidep_ccb_apply_cb(CcbUtilOperationData_t *opdata)
 {
-       AVD_SI_SI_DEP *sidep;
-       AVD_SI_SI_DEP_INDX indx;
+       AVD_SI_DEP *sidep, tmp_sidep;
        AVD_SI *dep_si = NULL;
-
        const SaImmAttrModificationT_2 *attr_mod;
        int i = 0;
 
@@ -1539,9 +1346,10 @@ static void sidep_ccb_apply_cb(CcbUtilOp
                break;
 
        case CCBUTIL_DELETE:
-               avd_sidep_indx_init(&opdata->objectName, &indx);
-               sidep = avd_sidep_find(avd_cb, &indx, true);
-               osafassert(dep_si = avd_si_get(&indx.si_name_sec));
+               avd_sidep_indx_init(&opdata->objectName, &tmp_sidep);
+               sidep = sidep_db_find(&tmp_sidep.spons_name, 
&tmp_sidep.dep_name);
+               dep_si = avd_si_get(&sidep->dep_name);
+               osafassert(dep_si != NULL);
                /* If SI is in tolerance timer running state because of this
                 * SI-SI dep cfg, then stop the tolerance timer.
                 */
@@ -1552,8 +1360,9 @@ static void sidep_ccb_apply_cb(CcbUtilOp
                        if(dep_si->tol_timer_count > 0)
                                dep_si->tol_timer_count--;
                }
-               sidep_spons_list_del(avd_cb, sidep);
-               sidep_del_row(avd_cb, sidep);
+               sidep_spons_list_del(sidep);
+               sidep_db->erase(make_pair(Amf::to_string(&sidep->spons_name), 
Amf::to_string(&sidep->dep_name)));
+               delete sidep;
                if (avd_cb->avail_state_avd == SA_AMF_HA_ACTIVE)  {
                        /* Update the SI according to its existing sponsors 
state */
                        sidep_si_screen_si_dependencies(dep_si);
@@ -1562,8 +1371,8 @@ static void sidep_ccb_apply_cb(CcbUtilOp
                break;
 
        case CCBUTIL_MODIFY:
-               avd_sidep_indx_init(&opdata->objectName, &indx);
-               sidep = avd_sidep_find(avd_cb, &indx, true);
+               avd_sidep_indx_init(&opdata->objectName, &tmp_sidep);
+               sidep = sidep_db_find(&tmp_sidep.spons_name, 
&tmp_sidep.dep_name);
                while ((attr_mod = opdata->param.modify.attrMods[i++]) != NULL) 
{
                        if (!strcmp(attr_mod->modAttr.attrName, 
"saAmfToleranceTime")) {
                                TRACE("saAmfToleranceTime modified from '%llu' 
to '%llu'", sidep->saAmfToleranceTime,
@@ -1583,33 +1392,18 @@ static void sidep_ccb_apply_cb(CcbUtilOp
 
 void avd_sidep_constructor(void)
 {
-       unsigned int rc;
-       NCS_PATRICIA_PARAMS patricia_params = {0};
-
-       patricia_params.key_size = sizeof(AVD_SI_SI_DEP_INDX);
-       rc = ncs_patricia_tree_init(&si_dep.spons_anchor, &patricia_params);
-       osafassert(rc == NCSCC_RC_SUCCESS);
-       rc = ncs_patricia_tree_init(&si_dep.dep_anchor, &patricia_params);
-       osafassert(rc == NCSCC_RC_SUCCESS);
-
+       sidep_db = new AmfDb<std::pair<std::string, std::string>, AVD_SI_DEP>;
        avd_class_impl_set("SaAmfSIDependency", NULL, NULL, 
sidep_ccb_completed_cb,
                sidep_ccb_apply_cb);
 }
+
 void avd_sidep_start_tolerance_timer_for_dependant(AVD_SI *dep_si, AVD_SI 
*spons_si)
 {
-       AVD_SI_SI_DEP_INDX si_indx;
-       AVD_SI_SI_DEP *si_dep_rec;
+       AVD_SI_DEP *si_dep_rec;
 
        TRACE("dep_si:%s spons_si:%s",dep_si->name.value,spons_si->name.value);
 
-       /* Frame the index completely to the associated si_dep_rec */
-       memset((char *)&si_indx, '\0', sizeof(AVD_SI_SI_DEP_INDX));
-       si_indx.si_name_prim.length = spons_si->name.length;
-       memcpy(si_indx.si_name_prim.value, spons_si->name.value, 
si_indx.si_name_prim.length);
-       si_indx.si_name_sec.length = dep_si->name.length;
-       memcpy(si_indx.si_name_sec.value, dep_si->name.value, 
dep_si->name.length);
-
-       si_dep_rec = avd_sidep_find(avd_cb, &si_indx, true);
+       si_dep_rec = sidep_db_find(&spons_si->name, &dep_si->name);
        if (si_dep_rec != NULL) {
                sidep_update_si_dep_state_for_spons_unassign(avd_cb, dep_si, 
si_dep_rec);
        } else {
@@ -1641,31 +1435,20 @@ void avd_si_unassign(AVD_SI *si)
  **/
 void avd_sidep_unassign_dependents(AVD_SI *si, AVD_SU *su)
 {
-       AVD_SI_SI_DEP_INDX si_indx;
-       AVD_SI_SI_DEP *si_dep_rec;
        AVD_SI *dep_si;
        AVD_SU_SI_REL *sisu;
 
        TRACE_ENTER2(": '%s'",si->name.value);
 
-       memset(&si_indx, '\0', sizeof(si_indx));
-       si_indx.si_name_prim.length = si->name.length;
-       memcpy(si_indx.si_name_prim.value, si->name.value, 
si_indx.si_name_prim.length);
-       si_dep_rec = avd_sidep_find_next(avd_cb, &si_indx, true);
+       for (std::map<std::pair<std::string,std::string>, 
AVD_SI_DEP*>::const_iterator it = sidep_db->begin();
+                       it != sidep_db->end(); it++) {
+               const AVD_SI_DEP *sidep = it->second;
+               if (m_CMP_HORDER_SANAMET(sidep->spons_si->name, si->name) != 0)
+                       continue;
 
-       while (si_dep_rec != NULL) {
-               if (m_CMP_HORDER_SANAMET(si_dep_rec->indx_imm.si_name_prim, 
si_indx.si_name_prim) != 0) {
-                       /* Seems no more node exists in spons_anchor tree with
-                        * "si_indx.si_name_prim" as primary key
-                        */
-                       break;
-               }
-               dep_si = avd_si_get(&si_dep_rec->indx_imm.si_name_sec);
-               if (dep_si == NULL) {
-                       /* No corresponding SI node?? some thing wrong */
-                       si_dep_rec = avd_sidep_find_next(avd_cb, 
&si_dep_rec->indx_imm, true);
-                       continue;
-               }
+               dep_si = si_db->find(Amf::to_string(&sidep->dep_name));
+               osafassert(dep_si != NULL); 
+
                /* Get the Active susi */
                for (sisu = dep_si->list_of_sisu;sisu;sisu = sisu->si_next) {
                        if (((sisu->state == SA_AMF_HA_ACTIVE) || (sisu->state 
== SA_AMF_HA_QUIESCING)) &&
@@ -1673,10 +1456,9 @@ void avd_sidep_unassign_dependents(AVD_S
                                break;
                        }
                }
-               if (sisu == NULL) {
-                       si_dep_rec = avd_sidep_find_next(avd_cb, 
&si_dep_rec->indx_imm, true);
+
+               if (sisu == NULL) 
                        continue;
-               }
 
                /* if dependant SI has Active assignment on the node which went 
down, remove the assignments 
                 * else start Tolerance timer
@@ -1694,7 +1476,6 @@ void avd_sidep_unassign_dependents(AVD_S
                if (dep_si->num_dependents > 0)
                         avd_sidep_unassign_dependents(dep_si, su);
 
-               si_dep_rec = avd_sidep_find_next(avd_cb, &si_dep_rec->indx_imm, 
true);
        }
        TRACE_LEAVE();
 }
@@ -1984,34 +1765,20 @@ bool valid_standby_susi(AVD_SU_SI_REL *s
  **/
 void avd_sidep_update_depstate_si_failover(AVD_SI *si, AVD_SU *su)
 {
-       AVD_SI_SI_DEP_INDX si_indx;
-       AVD_SI_SI_DEP *si_dep_rec;
-       AVD_SI *dep_si;
-       AVD_SU_SI_REL *sisu;
        AVD_SPONS_SI_NODE *spons_si_node;
 
        TRACE_ENTER2("si:%s",si->name.value);
 
-       memset((char *)&si_indx, '\0', sizeof(si_indx));
-       si_indx.si_name_prim.length = si->name.length;
-       memcpy(si_indx.si_name_prim.value, si->name.value, 
si_indx.si_name_prim.length);
+       for (std::map<std::pair<std::string,std::string>, 
AVD_SI_DEP*>::const_iterator it = sidep_db->begin();
+                       it != sidep_db->end(); it++) {
+               const AVD_SI_DEP *sidep = it->second;
+               if (m_CMP_HORDER_SANAMET(sidep->spons_si->name, si->name) != 0) 
+                       continue;
 
-       si_dep_rec = avd_sidep_find_next(avd_cb, &si_indx, true);
+               AVD_SI *dep_si = avd_si_get(&sidep->dep_name);
+               osafassert(dep_si != NULL); 
 
-       while (si_dep_rec != NULL) {
-               if (m_CMP_HORDER_SANAMET(si_dep_rec->indx_imm.si_name_prim, 
si_indx.si_name_prim) != 0) {
-                       /* Seems no more node exists in spons_anchor tree with
-                        * "si_indx.si_name_prim" as primary key
-                        */
-                       break;
-               }
-               dep_si = avd_si_get(&si_dep_rec->indx_imm.si_name_sec);
-               if (dep_si == NULL) {
-                       TRACE("No corresponding SI node?? some thing wrong");
-                       si_dep_rec = avd_sidep_find_next(avd_cb, 
&si_dep_rec->indx_imm, true);
-                       continue;
-               }
-               for (sisu = dep_si->list_of_sisu;sisu;sisu = sisu->si_next) {
+               for (AVD_SU_SI_REL *sisu = dep_si->list_of_sisu;sisu;sisu = 
sisu->si_next) {
                        TRACE("sisu si:%s su:%s state:%d 
fsm_state:%d",sisu->si->name.value,sisu->su->name.value,sisu->state,sisu->fsm);
                        if (((sisu->state == SA_AMF_HA_ACTIVE) || (sisu->state 
== SA_AMF_HA_QUIESCING)
                                                || (sisu->state == 
SA_AMF_HA_QUIESCED))
@@ -2087,7 +1854,6 @@ void avd_sidep_update_depstate_si_failov
                                }
                        }
                }
-               si_dep_rec = avd_sidep_find_next(avd_cb, &si_dep_rec->indx_imm, 
true);
        }
        TRACE_LEAVE();
 }
@@ -2236,34 +2002,20 @@ done:
  **/
 void avd_sidep_reset_dependents_depstate_in_sufault(AVD_SI *si)
 {
-       AVD_SI_SI_DEP_INDX si_indx;
-       AVD_SI_SI_DEP *si_dep_rec;
-       AVD_SI *dep_si;
-
        TRACE_ENTER2(" SI: '%s'",si->name.value);
 
-       memset((char *)&si_indx, '\0', sizeof(si_indx));
-       si_indx.si_name_prim.length = si->name.length;
-       memcpy(si_indx.si_name_prim.value, si->name.value, 
si_indx.si_name_prim.length);
-       si_dep_rec = avd_sidep_find_next(avd_cb, &si_indx, true);
+       for (std::map<std::pair<std::string,std::string>, 
AVD_SI_DEP*>::const_iterator it = sidep_db->begin();
+                       it != sidep_db->end(); it++) {
+               const AVD_SI_DEP *sidep = it->second;
 
-       while (si_dep_rec != NULL) {
-               if (m_CMP_HORDER_SANAMET(si_dep_rec->indx_imm.si_name_prim, 
si_indx.si_name_prim) != 0) {
-                       /* Seems no more node exists in spons_anchor tree with
-                        * "si_indx.si_name_prim" as primary key
-                        */
-                       break;
-               }
-               dep_si = avd_si_get(&si_dep_rec->indx_imm.si_name_sec);
-               if (dep_si == NULL) {
-                       /* No corresponding SI node?? some thing wrong */
-                       si_dep_rec = avd_sidep_find_next(avd_cb, 
&si_dep_rec->indx_imm, true);
+               if (m_CMP_HORDER_SANAMET(sidep->spons_si->name, si->name) != 0) 
                        continue;
-               }
-               if(dep_si->si_dep_state == AVD_SI_FAILOVER_UNDER_PROGRESS) {
+
+               AVD_SI *dep_si = avd_si_get(&sidep->dep_name);
+               osafassert(dep_si != NULL); 
+
+               if (dep_si->si_dep_state == AVD_SI_FAILOVER_UNDER_PROGRESS)
                        avd_sidep_si_dep_state_set(dep_si, 
AVD_SI_SPONSOR_UNASSIGNED);
-               }
-               si_dep_rec = avd_sidep_find_next(avd_cb, &si_dep_rec->indx_imm, 
true);
        }
 
        TRACE_LEAVE();
@@ -2310,10 +2062,7 @@ bool avd_sidep_si_dependency_exists_with
  **/
 void avd_sidep_send_active_to_dependents(const AVD_SI *si)
 {
-       AVD_SI_SI_DEP_INDX si_indx;
-       AVD_SI_SI_DEP *si_dep_rec;
        AVD_SU_SI_REL *sisu;
-       AVD_SI *dep_si;
        AVD_SU *active_su  = NULL;
 
        TRACE_ENTER2(": '%s'",si->name.value);
@@ -2327,31 +2076,20 @@ void avd_sidep_send_active_to_dependents
                }       
        }   
 
-       memset(&si_indx, '\0', sizeof(si_indx));
-       si_indx.si_name_prim.length = si->name.length;
-       memcpy(si_indx.si_name_prim.value, si->name.value, 
si_indx.si_name_prim.length);
-       si_dep_rec = avd_sidep_find_next(avd_cb, &si_indx, true);
+       for (std::map<std::pair<std::string,std::string>, 
AVD_SI_DEP*>::const_iterator it = sidep_db->begin();
+                       it != sidep_db->end(); it++) {
+               const AVD_SI_DEP *sidep = it->second;
+               if (m_CMP_HORDER_SANAMET(sidep->spons_si->name, si->name) != 0) 
+                       continue;
 
-       while (si_dep_rec != NULL) {
-               if (m_CMP_HORDER_SANAMET(si_dep_rec->indx_imm.si_name_prim, 
si_indx.si_name_prim) != 0) {
-                       /* Seems no more node exists in spons_anchor tree with
-                        * "si_indx.si_name_prim" as primary key
-                       */
-                       break;
-               }
-               dep_si = avd_si_get(&si_dep_rec->indx_imm.si_name_sec);
-               if (dep_si == NULL) {
-                       /* No corresponding SI node?? some thing wrong */
-                       si_dep_rec = avd_sidep_find_next(avd_cb, 
&si_dep_rec->indx_imm, true);
-                       continue;
-               }
+               AVD_SI *dep_si = avd_si_get(&sidep->dep_name);
+               osafassert(dep_si != NULL); 
+
                TRACE("dependent si:%s 
dep_si->si_dep_state:%d",dep_si->name.value,dep_si->si_dep_state);
                if(dep_si->si_dep_state == AVD_SI_FAILOVER_UNDER_PROGRESS) {
-                       if (!avd_sidep_all_sponsors_active(dep_si)) {
+                       if (!avd_sidep_all_sponsors_active(dep_si)) 
                                /* Some of the sponsors are not yet in Active 
state */
-                               si_dep_rec = avd_sidep_find_next(avd_cb, 
&si_dep_rec->indx_imm, true);
                                continue;
-                       }
                        AVD_SU_SI_REL *sisu;
                        switch (si->sg_of_si->sg_redundancy_model) {
                        case SA_AMF_NPM_REDUNDANCY_MODEL:
@@ -2386,7 +2124,6 @@ void avd_sidep_send_active_to_dependents
                        }
                        avd_sidep_si_dep_state_set(dep_si, AVD_SI_ASSIGNED);
                }
-               si_dep_rec = avd_sidep_find_next(avd_cb, &si_dep_rec->indx_imm, 
true);
        }
        TRACE_LEAVE();
 }
@@ -2399,33 +2136,20 @@ void avd_sidep_send_active_to_dependents
  **/
 bool avd_sidep_quiesced_done_for_all_dependents(const AVD_SI *si, const AVD_SU 
*su)
 {
-       AVD_SI_SI_DEP_INDX si_indx;
-       AVD_SI_SI_DEP *si_dep_rec;
-       AVD_SI *dep_si;
-       AVD_SU_SI_REL *sisu = NULL;
        bool quiesced = true; 
 
        TRACE_ENTER2(": '%s'",si->name.value);
 
-       memset(&si_indx, '\0', sizeof(si_indx));
-       si_indx.si_name_prim.length = si->name.length;
-       memcpy(si_indx.si_name_prim.value, si->name.value, 
si_indx.si_name_prim.length);
-       si_dep_rec = avd_sidep_find_next(avd_cb, &si_indx, true);
+       for (std::map<std::pair<std::string,std::string>, 
AVD_SI_DEP*>::const_iterator it = sidep_db->begin();
+                       it != sidep_db->end(); it++) {
+               const AVD_SI_DEP *sidep = it->second;
+               if (m_CMP_HORDER_SANAMET(sidep->spons_si->name, si->name) != 0) 
+                       continue;
 
-       while (si_dep_rec != NULL) {
-               if (m_CMP_HORDER_SANAMET(si_dep_rec->indx_imm.si_name_prim, 
si_indx.si_name_prim) != 0) {
-                       /* Seems no more node exists in spons_anchor tree with
-                        * "si_indx.si_name_prim" as primary key
-                        */
-                       break;
-               }
-               dep_si = avd_si_get(&si_dep_rec->indx_imm.si_name_sec);
-               if (dep_si == NULL) {
-                       /* No corresponding SI node?? some thing wrong */
-                       si_dep_rec = avd_sidep_find_next(avd_cb, 
&si_dep_rec->indx_imm, true);
-                       continue;
-               }
-               for (sisu = dep_si->list_of_sisu; sisu ; sisu = sisu->si_next) {
+               AVD_SI *dep_si = avd_si_get(&sidep->dep_name);
+               osafassert(dep_si != NULL); 
+
+               for (AVD_SU_SI_REL *sisu = dep_si->list_of_sisu; sisu ; sisu = 
sisu->si_next) {
                        if ((sisu->su == su) && 
                                (((sisu->state != SA_AMF_HA_STANDBY) && 
(sisu->state != SA_AMF_HA_QUIESCED)) || 
                                                (sisu->fsm != 
AVD_SU_SI_STATE_ASGND))) {
@@ -2433,7 +2157,6 @@ bool avd_sidep_quiesced_done_for_all_dep
                                goto done;
                        }
                }
-               si_dep_rec = avd_sidep_find_next(avd_cb, &si_dep_rec->indx_imm, 
true);
        }
 
 done:
@@ -2485,33 +2208,22 @@ done:
  **/
 void sidep_update_dependents_states(AVD_SI *si)
 {
-       AVD_SI *dep_si = NULL;
-       AVD_SI_SI_DEP_INDX si_indx;
-       AVD_SI_SI_DEP *si_dep_rec = NULL;
-
        if (si->num_dependents == 0) 
                return;
 
-       TRACE("sponsor si:'%s', dep state:'%s'", si->name.value, 
depstatename[si->si_dep_state]);
-
-       memset((char *)&si_indx, 0, sizeof(AVD_SI_SI_DEP_INDX));
-       si_indx.si_name_prim.length = si->name.length;
-       memcpy(si_indx.si_name_prim.value, si->name.value, 
si_indx.si_name_prim.length);
-
        /* Update the si_dep_state for all dependents  
         * SIs of the sponsor SI.
         */
-       si_dep_rec = avd_sidep_find_next(avd_cb, &si_indx, true);
-       while (si_dep_rec != NULL) {
-               if (m_CMP_HORDER_SANAMET(si_dep_rec->indx_imm.si_name_prim, 
si_indx.si_name_prim) != 0) {
-                       /* Seems no more node exists in spons_anchor tree with 
-                        * "si_indx.si_name_prim" as primary key 
-                        */
-                       break;
-               }
+       TRACE("sponsor si:'%s', dep state:'%s'", si->name.value, 
depstatename[si->si_dep_state]);
 
-               dep_si = avd_si_get(&si_dep_rec->indx_imm.si_name_sec);
-               osafassert(dep_si); 
+       for (std::map<std::pair<std::string,std::string>, 
AVD_SI_DEP*>::const_iterator it = sidep_db->begin();
+                       it != sidep_db->end(); it++) {
+               const AVD_SI_DEP *sidep = it->second;
+               if (m_CMP_HORDER_SANAMET(sidep->spons_si->name, si->name) != 0) 
+                       continue;
+
+               AVD_SI *dep_si = avd_si_get(&sidep->dep_name);
+               osafassert(dep_si != NULL); 
 
                /* update si_dep_state of dependent if its SG fsm is 
                   stable or if both sponsor and dependent belongs to same SG.  
 
@@ -2520,7 +2232,6 @@ void sidep_update_dependents_states(AVD_
                                (dep_si->sg_of_si == si->sg_of_si)) 
                        sidep_update_si_self_dep_state(dep_si);
 
-               si_dep_rec = avd_sidep_find_next(avd_cb, &si_dep_rec->indx_imm, 
true);
        }
 }
 
@@ -2700,8 +2411,7 @@ void avd_sidep_sg_take_action(AVD_SG *sg
 void sidep_process_ready_to_unassign_depstate(AVD_SI *dep_si) 
 {
        AVD_SI *spons_si = NULL;
-       AVD_SI_SI_DEP_INDX si_indx;
-       AVD_SI_SI_DEP *si_dep_rec = NULL;
+       AVD_SI_DEP *si_dep_rec;
        AVD_SPONS_SI_NODE *temp_spons_list = NULL;
 
        TRACE_ENTER2("dep si:'%s'", dep_si->name.value);
@@ -2711,14 +2421,7 @@ void sidep_process_ready_to_unassign_dep
                spons_si = temp_spons_list->si;
                TRACE("spons si:'%s'",spons_si->name.value);
 
-               /* Frame the index completely to the associated si_dep_rec */
-               memset((char *)&si_indx, 0, sizeof(AVD_SI_SI_DEP_INDX));
-               si_indx.si_name_prim.length = spons_si->name.length;
-               memcpy(si_indx.si_name_prim.value, spons_si->name.value, 
si_indx.si_name_prim.length);
-               si_indx.si_name_sec.length = dep_si->name.length;
-               memcpy(si_indx.si_name_sec.value, dep_si->name.value, 
dep_si->name.length);
-
-               si_dep_rec = avd_sidep_find(avd_cb, &si_indx, true);
+               si_dep_rec = sidep_db_find(&spons_si->name, &dep_si->name);
                if (si_dep_rec == NULL)
                        goto done;
 
@@ -2772,7 +2475,7 @@ void avd_sidep_unassign_evh(AVD_CL_CB *c
        osafassert(evt->rcv_evt == AVD_EVT_UNASSIGN_SI_DEP_STATE);
 
        dep_si = avd_si_get(&evt->info.tmr.dep_si_name);
-       osafassert(dep_si);
+       osafassert(dep_si != NULL); 
 
        avd_sidep_si_dep_state_set(dep_si, AVD_SI_UNASSIGNING_DUE_TO_DEP);
 
diff --git a/osaf/services/saf/amf/amfd/siass.cc 
b/osaf/services/saf/amf/amfd/siass.cc
--- a/osaf/services/saf/amf/amfd/siass.cc
+++ b/osaf/services/saf/amf/amfd/siass.cc
@@ -749,10 +749,6 @@ done:
  **/
 bool avd_susi_quiesced_canbe_given(const AVD_SU_SI_REL *susi)
 {
-       AVD_SI_SI_DEP *si_dep_rec;
-       AVD_SI *dep_si;
-       AVD_SI_SI_DEP_INDX si_indx;
-       AVD_SU_SI_REL *sisu;
        bool quiesc_role = true;
 
        TRACE_ENTER2("%s %s", susi->su->name.value, susi->si->name.value);
@@ -762,25 +758,16 @@ bool avd_susi_quiesced_canbe_given(const
                return quiesc_role;
        } else {
                /* Check if any of its dependents assigned to same SU for which 
quiesced role is not yet given */
-               memset(&si_indx, '\0', sizeof(si_indx));
-               si_indx.si_name_prim.length = susi->si->name.length;
-               memcpy(si_indx.si_name_prim.value, susi->si->name.value, 
si_indx.si_name_prim.length);
-               si_dep_rec = avd_sidep_find_next(avd_cb, &si_indx, true);
+               for (std::map<std::pair<std::string,std::string>, 
AVD_SI_DEP*>::const_iterator it = sidep_db->begin();
+                       it != sidep_db->end(); it++) {
+                       const AVD_SI_DEP *sidep = it->second;
+                       if (m_CMP_HORDER_SANAMET(sidep->spons_si->name, 
susi->si->name) != 0) 
+                               continue;
 
-               while (si_dep_rec != NULL) {
-                       if 
(m_CMP_HORDER_SANAMET(si_dep_rec->indx_imm.si_name_prim, si_indx.si_name_prim) 
!= 0) {
-                               /* Seems no more node exists in spons_anchor 
tree with
-                                * "si_indx.si_name_prim" as primary key
-                                */
-                               break;
-                       }
-                       dep_si = avd_si_get(&si_dep_rec->indx_imm.si_name_sec);
-                       if (dep_si == NULL) {
-                               /* No corresponding SI node?? some thing wrong 
*/
-                               si_dep_rec = avd_sidep_find_next(avd_cb, 
&si_dep_rec->indx_imm, true);
-                               continue;
-                       }
-                       for (sisu = dep_si->list_of_sisu; sisu ; sisu = 
sisu->si_next) {
+                       AVD_SI *dep_si = avd_si_get(&sidep->dep_name);
+                       osafassert(dep_si != NULL); 
+
+                       for (AVD_SU_SI_REL *sisu = dep_si->list_of_sisu; sisu ; 
sisu = sisu->si_next) {
                                if (sisu->su == susi->su) {
                                        if ((sisu->state == SA_AMF_HA_ACTIVE) ||
                                                ((sisu->state == 
SA_AMF_HA_QUIESCED) && (sisu->fsm == AVD_SU_SI_STATE_MODIFY))) {
@@ -790,7 +777,6 @@ bool avd_susi_quiesced_canbe_given(const
                                }       
 
                        }
-                       si_dep_rec = avd_sidep_find_next(avd_cb, 
&si_dep_rec->indx_imm, true);
                }
        }
 done:

------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
Opensaf-devel mailing list
Opensaf-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to