OK fixed before push but since this will become a pattern in about 20 places I think it would be better to have db->insert return void and internally do this check. What do you think?
As a side note, db->insert should not return NCSCC_RC_SUCCESS/FAILURE but a bool. Thanks, Hans On 18 April 2014 15:12, Nagendra Kumar <[email protected]> wrote: > Ack with comment: > > We need to check for assert as done in avd_su_db_add when it fails to add. > When insert returns NCSCC_RC_FAILURE, we need to assert or log error at all > the places. > > - avd_su_db_add(su); > + su_db->insert(su); > > Thanks > -Nagu > >> -----Original Message----- >> From: Hans Feldt [mailto:[email protected]] >> Sent: 17 April 2014 15:45 >> To: [email protected]; Praveen Malviya; Nagendra Kumar >> Cc: [email protected] >> Subject: [PATCH 1 of 1] amfd: use db_template for the SU db [#713] >> >> osaf/services/saf/amf/amfd/ckpt_dec.cc | 20 +- >> osaf/services/saf/amf/amfd/ckpt_enc.cc | 13 +- >> osaf/services/saf/amf/amfd/ckpt_updt.cc | 12 +- >> osaf/services/saf/amf/amfd/comp.cc | 2 +- >> osaf/services/saf/amf/amfd/imm.cc | 8 +- >> osaf/services/saf/amf/amfd/include/su.h | 36 +------ >> osaf/services/saf/amf/amfd/include/susi.h | 1 - >> osaf/services/saf/amf/amfd/ndproc.cc | 2 +- >> osaf/services/saf/amf/amfd/sg_nway_fsm.cc | 2 +- >> osaf/services/saf/amf/amfd/sgproc.cc | 6 +- >> osaf/services/saf/amf/amfd/siass.cc | 78 +-------------- >> osaf/services/saf/amf/amfd/sirankedsu.cc | 2 +- >> osaf/services/saf/amf/amfd/su.cc | 78 +++----------- >> osaf/services/saf/amf/amfd/util.cc | 157 >> +++++++---------------------- >> 14 files changed, 96 insertions(+), 321 deletions(-) >> >> >> diff --git a/osaf/services/saf/amf/amfd/ckpt_dec.cc >> b/osaf/services/saf/amf/amfd/ckpt_dec.cc >> --- a/osaf/services/saf/amf/amfd/ckpt_dec.cc >> +++ b/osaf/services/saf/amf/amfd/ckpt_dec.cc >> @@ -1452,7 +1452,7 @@ static uint32_t dec_su_preinstan(AVD_CL_ >> >> osafassert(status == NCSCC_RC_SUCCESS); >> >> - if (NULL == (su_struct = avd_su_get(&su_ptr->name))) >> + if (NULL == (su_struct = su_db->find(&su_ptr->name))) >> osafassert(0); >> >> /* Update the fields received in this checkpoint message */ >> @@ -1544,7 +1544,7 @@ static uint32_t dec_su_admin_state(AVD_C >> >> osafassert(status == NCSCC_RC_SUCCESS); >> >> - if (NULL == (su_struct = avd_su_get(&su_ptr->name))) >> + if (NULL == (su_struct = su_db->find(&su_ptr->name))) >> osafassert(0); >> >> /* Update the fields received in this checkpoint message */ >> @@ -1590,7 +1590,7 @@ static uint32_t dec_su_readiness_state(A >> >> osafassert(status == NCSCC_RC_SUCCESS); >> >> - if (NULL == (su_struct = avd_su_get(&su_ptr->name))) >> + if (NULL == (su_struct = su_db->find(&su_ptr->name))) >> osafassert(0); >> >> /* Update the fields received in this checkpoint message */ >> @@ -1636,7 +1636,7 @@ static uint32_t dec_su_pres_state(AVD_CL >> >> osafassert(status == NCSCC_RC_SUCCESS); >> >> - if (NULL == (su_struct = avd_su_get(&su_ptr->name))) >> + if (NULL == (su_struct = su_db->find(&su_ptr->name))) >> osafassert(0); >> >> /* Update the fields received in this checkpoint message */ >> @@ -1682,7 +1682,7 @@ static uint32_t dec_su_si_curr_active(AV >> >> osafassert(status == NCSCC_RC_SUCCESS); >> >> - if (NULL == (su_struct = avd_su_get(&su_ptr->name))) >> + if (NULL == (su_struct = su_db->find(&su_ptr->name))) >> osafassert(0); >> >> /* Update the fields received in this checkpoint message */ >> @@ -1727,7 +1727,7 @@ static uint32_t dec_su_si_curr_stby(AVD_ >> >> osafassert(status == NCSCC_RC_SUCCESS); >> >> - if (NULL == (su_struct = avd_su_get(&su_ptr->name))) >> + if (NULL == (su_struct = su_db->find(&su_ptr->name))) >> osafassert(0); >> >> /* Update the fields received in this checkpoint message */ >> @@ -1773,7 +1773,7 @@ static uint32_t dec_su_term_state(AVD_CL >> >> osafassert(status == NCSCC_RC_SUCCESS); >> >> - if (NULL == (su_struct = avd_su_get(&su_ptr->name))) >> + if (NULL == (su_struct = su_db->find(&su_ptr->name))) >> osafassert(0); >> >> /* Update the fields received in this checkpoint message */ >> @@ -1818,7 +1818,7 @@ static uint32_t dec_su_switch(AVD_CL_CB >> >> osafassert(status == NCSCC_RC_SUCCESS); >> >> - if (NULL == (su_struct = avd_su_get(&su_ptr->name))) >> + if (NULL == (su_struct = su_db->find(&su_ptr->name))) >> osafassert(0); >> >> /* Update the fields received in this checkpoint message */ >> @@ -1864,7 +1864,7 @@ static uint32_t dec_su_act_state(AVD_CL_ >> >> osafassert(status == NCSCC_RC_SUCCESS); >> >> - if (NULL == (su_struct = avd_su_get(&su_ptr->name))) >> + if (NULL == (su_struct = su_db->find(&su_ptr->name))) >> osafassert(0); >> >> /* Update the fields received in this checkpoint message */ >> @@ -1910,7 +1910,7 @@ static uint32_t dec_su_restart_count(AVD >> >> osafassert(status == NCSCC_RC_SUCCESS); >> >> - if (NULL == (su_struct = avd_su_get(&su_ptr->name))) >> + if (NULL == (su_struct = su_db->find(&su_ptr->name))) >> osafassert(0); >> >> /* Update the fields received in this checkpoint message */ >> diff --git a/osaf/services/saf/amf/amfd/ckpt_enc.cc >> b/osaf/services/saf/amf/amfd/ckpt_enc.cc >> --- a/osaf/services/saf/amf/amfd/ckpt_enc.cc >> +++ b/osaf/services/saf/amf/amfd/ckpt_enc.cc >> @@ -2334,8 +2334,9 @@ static uint32_t enc_cs_su_config(AVD_CL_ >> /* >> * Walk through the entire list and send the entire list data. >> */ >> - for (su = avd_su_getnext(&su_name); su != NULL; >> - su = avd_su_getnext(&su_name)) { >> + for (std::map<std::string, AVD_SU*>::const_iterator it = su_db- >> >begin(); >> + it != su_db->end(); it++) { >> + su = it->second; >> status = m_NCS_EDU_VER_EXEC(&cb->edu_hdl, >> avsv_edp_ckpt_msg_su, &enc->io_uba, >> EDP_OP_TYPE_ENC, su, &ederror, >> enc->i_peer_version); >> >> @@ -2546,7 +2547,6 @@ static uint32_t enc_cs_siass(AVD_CL_CB * >> { >> uint32_t status = NCSCC_RC_SUCCESS; >> AVD_SU *su; >> - SaNameT su_name = {0}; >> AVSV_SU_SI_REL_CKPT_MSG su_si_ckpt; >> AVD_SU_SI_REL *rel; >> EDU_ERR ederror = static_cast<EDU_ERR>(0); >> @@ -2558,10 +2558,10 @@ static uint32_t enc_cs_siass(AVD_CL_CB * >> * are sent.We will send the corresponding COMP_CSI relationship for >> that SU_SI >> * in the same update. >> */ >> - su_name.length = 0; >> memset(&su_si_ckpt, 0, sizeof(su_si_ckpt)); >> - for (su = avd_su_getnext(&su_name); su != NULL; >> - su = avd_su_getnext(&su_name)) { >> + for (std::map<std::string, AVD_SU*>::const_iterator it = su_db- >> >begin(); >> + it != su_db->end(); it++) { >> + su = it->second; >> su_si_ckpt.su_name = su->name; >> >> for (rel = su->list_of_susi; rel != NULL; rel = rel->su_next) { >> @@ -2580,7 +2580,6 @@ static uint32_t enc_cs_siass(AVD_CL_CB * >> >> (*num_of_obj)++; >> } >> - su_name = su->name; >> } >> TRACE_LEAVE2("status '%u'", status); >> return status; >> diff --git a/osaf/services/saf/amf/amfd/ckpt_updt.cc >> b/osaf/services/saf/amf/amfd/ckpt_updt.cc >> --- a/osaf/services/saf/amf/amfd/ckpt_updt.cc >> +++ b/osaf/services/saf/amf/amfd/ckpt_updt.cc >> @@ -184,8 +184,8 @@ uint32_t avd_ckpt_su(AVD_CL_CB *cb, AVD_ >> >> osafassert (action == NCS_MBCSV_ACT_UPDATE); >> >> - if (NULL == (su = avd_su_get(&ckpt_su->name))) { >> - LOG_ER("avd_su_get FAILED for '%s'", ckpt_su->name.value); >> + if (NULL == (su = su_db->find(&ckpt_su->name))) { >> + LOG_ER("su_db->find FAILED for '%s'", ckpt_su->name.value); >> rc = NCSCC_RC_FAILURE; >> goto done; >> } >> @@ -272,7 +272,7 @@ uint32_t avd_ckpt_su_oper_list(AVD_CL_CB >> >> TRACE_ENTER2("'%s'", ckpt_su->name.value); >> >> - su = avd_su_get(&ckpt_su->name); >> + su = su_db->find(&ckpt_su->name); >> osafassert(su); >> >> if (NCS_MBCSV_ACT_ADD == action) >> @@ -359,8 +359,8 @@ uint32_t avd_ckpt_si_trans(AVD_CL_CB *cb >> switch (action) { >> case NCS_MBCSV_ACT_ADD: >> sg_ptr->si_tobe_redistributed = avd_si_get(&si_trans_ckpt- >> >si_name); >> - sg_ptr->min_assigned_su = avd_su_get(&si_trans_ckpt- >> >min_su_name); >> - sg_ptr->max_assigned_su = avd_su_get(&si_trans_ckpt- >> >max_su_name); >> + sg_ptr->min_assigned_su = su_db->find(&si_trans_ckpt- >> >min_su_name); >> + sg_ptr->max_assigned_su = su_db->find(&si_trans_ckpt- >> >max_su_name); >> break; >> >> case NCS_MBCSV_ACT_RMV: >> @@ -408,7 +408,7 @@ uint32_t avd_ckpt_siass(AVD_CL_CB *cb, A >> >> su_si_rel_ptr = avd_susi_find(cb, &su_si_ckpt->su_name, &su_si_ckpt- >> >si_name); >> >> - su_ptr = avd_su_get(&su_si_ckpt->su_name); >> + su_ptr = su_db->find(&su_si_ckpt->su_name); >> osafassert(su_ptr); >> si_ptr_up = avd_si_get(&su_si_ckpt->si_name); >> osafassert(si_ptr_up); >> diff --git a/osaf/services/saf/amf/amfd/comp.cc >> b/osaf/services/saf/amf/amfd/comp.cc >> --- a/osaf/services/saf/amf/amfd/comp.cc >> +++ b/osaf/services/saf/amf/amfd/comp.cc >> @@ -213,7 +213,7 @@ static void comp_add_to_model(AVD_COMP * >> } >> >> avsv_sanamet_init(&comp->comp_info.name, &dn, "safSu"); >> - su = comp->su = avd_su_get(&dn); >> + su = comp->su = su_db->find(&dn); >> >> avd_comp_db_add(comp); >> comp->comp_type = avd_comptype_get(&comp->saAmfCompType); >> diff --git a/osaf/services/saf/amf/amfd/imm.cc >> b/osaf/services/saf/amf/amfd/imm.cc >> --- a/osaf/services/saf/amf/amfd/imm.cc >> +++ b/osaf/services/saf/amf/amfd/imm.cc >> @@ -1553,8 +1553,6 @@ void avd_saImmOiRtObjectDelete(const SaN >> */ >> void avd_imm_update_runtime_attrs(void) >> { >> - SaNameT su_name = {0}; >> - AVD_SU *su; >> SaNameT comp_name ={0}; >> AVD_COMP *comp; >> SaNameT node_name = {0}; >> @@ -1563,8 +1561,9 @@ void avd_imm_update_runtime_attrs(void) >> AVD_SI *si; >> >> /* Update SU Class runtime cached attributes. */ >> - su = avd_su_getnext(&su_name); >> - while (su != NULL) { >> + for (std::map<std::string, AVD_SU*>::const_iterator it = su_db- >> >begin(); >> + it != su_db->end(); it++) { >> + AVD_SU *su = it->second; >> avd_saImmOiRtObjectUpdate(&su->name, >> "saAmfSUPreInstantiable", >> SA_IMM_ATTR_SAUINT32T, &su- >> >saAmfSUPreInstantiable); >> >> @@ -1580,7 +1579,6 @@ void avd_imm_update_runtime_attrs(void) >> avd_saImmOiRtObjectUpdate(&su->name, >> "saAmfSUReadinessState", >> SA_IMM_ATTR_SAUINT32T, &su- >> >saAmfSuReadinessState); >> >> - su = avd_su_getnext(&su->name); >> } >> >> /* Update Component Class runtime cached attributes. */ >> diff --git a/osaf/services/saf/amf/amfd/include/su.h >> b/osaf/services/saf/amf/amfd/include/su.h >> --- a/osaf/services/saf/amf/amfd/include/su.h >> +++ b/osaf/services/saf/amf/amfd/include/su.h >> @@ -35,7 +35,6 @@ >> #define AVD_SU_H >> >> #include <saAmf.h> >> -#include <ncspatricia.h> >> #include <def.h> >> #include <cb.h> >> #include <node.h> >> @@ -43,6 +42,7 @@ >> #include <amf_defs.h> >> #include <msg.h> >> #include <comp.h> >> +#include "include/db_template.h" >> >> /* The semantics the SU is undergoing. */ >> typedef enum { >> @@ -57,8 +57,6 @@ typedef enum { >> */ >> class AVD_SU { >> public: >> - NCS_PATRICIA_NODE tree_node; /* key will be the SU name */ >> - >> SaNameT name; >> SaNameT saAmfSUType; >> uint32_t saAmfSURank; >> @@ -120,6 +118,8 @@ class AVD_SU { >> void set_all_susis_assigned(void); >> }; >> >> +extern AmfDb<AVD_SU> *su_db; >> + >> typedef struct { >> NCS_PATRICIA_NODE tree_node; /* key is name */ >> SaNameT name; >> @@ -166,36 +166,6 @@ extern AVD_SU *avd_su_new(const SaNameT >> */ >> extern void avd_su_delete(AVD_SU *su); >> >> -/** >> - * Add SU to SU DB. >> - * @param su >> - */ >> -extern void avd_su_db_add(AVD_SU *su); >> - >> -/** >> - * Remove SU from SU DB >> - * @param su >> - */ >> -extern void avd_su_db_remove(AVD_SU *su); >> - >> -/** >> - * Get SU object from DB using given key >> - * >> - * @param dn >> - * >> - * @return struct AVD_SU* >> - */ >> -extern AVD_SU *avd_su_get(const SaNameT *dn); >> - >> -/** >> - * Get next SU object from DB using given key >> - * >> - * @param dn >> - * >> - * @return struct AVD_SU* >> - */ >> -extern AVD_SU *avd_su_getnext(const SaNameT *dn); >> - >> extern void avd_su_remove_comp(struct avd_comp_tag *comp); >> extern void avd_su_add_comp(struct avd_comp_tag *comp); >> >> diff --git a/osaf/services/saf/amf/amfd/include/susi.h >> b/osaf/services/saf/amf/amfd/include/susi.h >> --- a/osaf/services/saf/amf/amfd/include/susi.h >> +++ b/osaf/services/saf/amf/amfd/include/susi.h >> @@ -142,7 +142,6 @@ AVD_SU_SI_REL *avd_susi_find(AVD_CL_CB * >> extern void avd_susi_update(AVD_SU_SI_REL *susi, SaAmfHAStateT ha_state); >> >> AVD_SU_SI_REL *avd_su_susi_find(AVD_CL_CB *cb, AVD_SU *su, const >> SaNameT *si_name); >> -AVD_SU_SI_REL *avd_susi_find_next(AVD_CL_CB *cb, SaNameT su_name, >> SaNameT si_name); >> uint32_t avd_susi_delete(AVD_CL_CB *cb, AVD_SU_SI_REL *susi, bool ckpt); >> extern AVD_SUS_PER_SI_RANK *avd_sirankedsu_getnext_valid(AVD_CL_CB >> *cb, >> AVD_SUS_PER_SI_RANK_INDX indx, AVD_SU **o_su); >> diff --git a/osaf/services/saf/amf/amfd/ndproc.cc >> b/osaf/services/saf/amf/amfd/ndproc.cc >> --- a/osaf/services/saf/amf/amfd/ndproc.cc >> +++ b/osaf/services/saf/amf/amfd/ndproc.cc >> @@ -715,7 +715,7 @@ void avd_data_update_req_evh(AVD_CL_CB * >> } >> case AVSV_SA_AMF_SU:{ >> /* Find the component record in the database, >> specified in the message. */ >> - if ((su = avd_su_get(&n2d_msg- >> >msg_info.n2d_data_req.param_info.name)) == NULL) { >> + if ((su = su_db->find(&n2d_msg- >> >msg_info.n2d_data_req.param_info.name)) == NULL) { >> LOG_ER("%s: Invalid SU '%s' (%u)", >> __FUNCTION__, >> n2d_msg- >> >msg_info.n2d_data_req.param_info.name.value, >> n2d_msg- >> >msg_info.n2d_data_req.param_info.name.length); >> diff --git a/osaf/services/saf/amf/amfd/sg_nway_fsm.cc >> b/osaf/services/saf/amf/amfd/sg_nway_fsm.cc >> --- a/osaf/services/saf/amf/amfd/sg_nway_fsm.cc >> +++ b/osaf/services/saf/amf/amfd/sg_nway_fsm.cc >> @@ -1389,7 +1389,7 @@ AVD_SU *avd_sg_nway_si_find_highest_sira >> /* Iterate through the si->rankedsu_list_head to find the highest >> sirankedsu */ >> sirankedsu = si->rankedsu_list_head; >> for (; sirankedsu ; sirankedsu = sirankedsu->next) { >> - if ((ranked_su = avd_su_get(&sirankedsu->suname)) != NULL) { >> + if ((ranked_su = su_db->find(&sirankedsu->suname)) != NULL) >> { >> if (ranked_su == *assigned_su) { >> TRACE("SI is assigned to highest SIRankedSU >> for this SI"); >> break; >> diff --git a/osaf/services/saf/amf/amfd/sgproc.cc >> b/osaf/services/saf/amf/amfd/sgproc.cc >> --- a/osaf/services/saf/amf/amfd/sgproc.cc >> +++ b/osaf/services/saf/amf/amfd/sgproc.cc >> @@ -429,7 +429,7 @@ void avd_su_oper_state_evh(AVD_CL_CB *cb >> >> /* get the SU from the tree */ >> >> - if ((su = avd_su_get(&n2d_msg->msg_info.n2d_opr_state.su_name)) >> == NULL) { >> + if ((su = su_db->find(&n2d_msg->msg_info.n2d_opr_state.su_name)) >> == NULL) { >> LOG_ER("%s: %s not found", __FUNCTION__, n2d_msg- >> >msg_info.n2d_opr_state.su_name.value); >> goto done; >> } >> @@ -794,7 +794,7 @@ void avd_su_si_assign_evh(AVD_CL_CB *cb, >> * SU operation. >> */ >> >> - if ((su = avd_su_get(&n2d_msg- >> >msg_info.n2d_su_si_assign.su_name)) == NULL) { >> + if ((su = su_db->find(&n2d_msg- >> >msg_info.n2d_su_si_assign.su_name)) == NULL) { >> LOG_ER("%s:%d %s", __FUNCTION__, __LINE__, >> n2d_msg->msg_info.n2d_su_si_assign.su_name.value); >> goto done; >> } >> @@ -1108,7 +1108,7 @@ void avd_su_si_assign_evh(AVD_CL_CB *cb, >> SI could be assigned to SU successfully if there was any. The >> operation >> failed if >> AvND encountered error while assigning/unassigning SI to the SU. */ >> >> - su = avd_su_get(&n2d_msg->msg_info.n2d_su_si_assign.su_name); >> + su = su_db->find(&n2d_msg->msg_info.n2d_su_si_assign.su_name); >> >> if (su != NULL) { >> if (su->pend_cbk.invocation != 0) { >> 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 >> @@ -178,7 +178,7 @@ AVD_SU_SI_REL *avd_susi_create(AVD_CL_CB >> for (su_rank_rec = avd_sirankedsu_getnext(cb, i_idx); >> su_rank_rec && (m_CMP_HORDER_SANAMET(su_rank_rec- >> >indx.si_name, si->name) == 0); >> su_rank_rec = avd_sirankedsu_getnext(cb, su_rank_rec->indx)) { >> - curr_su = avd_su_get(&su_rank_rec->su_name); >> + curr_su = su_db->find(&su_rank_rec->su_name); >> if (curr_su == su) >> break; >> } >> @@ -201,7 +201,7 @@ AVD_SU_SI_REL *avd_susi_create(AVD_CL_CB >> i_su_rank_rec >> && (m_CMP_HORDER_SANAMET(i_su_rank_rec- >> >indx.si_name, si->name) == 0); >> i_su_rank_rec = avd_sirankedsu_getnext(cb, >> i_su_rank_rec->indx)) { >> - curr_su = avd_su_get(&i_su_rank_rec- >> >su_name); >> + curr_su = su_db->find(&i_su_rank_rec- >> >su_name); >> if (curr_su == i_su_si->su) >> break; >> } >> @@ -324,85 +324,13 @@ AVD_SU_SI_REL *avd_susi_find(AVD_CL_CB * >> { >> AVD_SU *su; >> >> - if ((su = avd_su_get(su_name)) == NULL) >> + if ((su = su_db->find(su_name)) == NULL) >> return NULL; >> >> return avd_su_susi_find(cb, su, si_name); >> } >> >> >> /************************************************************ >> ***************** >> - * Function: avd_susi_find_next >> - * >> - * Purpose: This function will find the next AVD_SU_SI_REL structure from >> the >> - * list of susis in a su. If NULL, it will find the first SUSI for the next >> - * SU in the tree. >> - * >> - * Input: cb - the AVD control block >> - * su_name - The SU name of the SU SI relation. >> - * si_name - The SI name of the SU SI relation. >> - * >> - * Returns: The AVD_SU_SI_REL structure that was found. >> - * >> - * NOTES: >> - * >> - * >> - >> ************************************************************* >> *************/ >> - >> -AVD_SU_SI_REL *avd_susi_find_next(AVD_CL_CB *cb, SaNameT su_name, >> SaNameT si_name) >> -{ >> - AVD_SU *su; >> - AVD_SU_SI_REL *su_si = NULL; >> - SaNameT lsu_name, lsi_name; >> - >> - /* check if exact match of SU is found so that the next SU SI >> - * in the list of SU can be found. If not select the next SUs >> - * first SU SI relation >> - */ >> - if (su_name.length != 0) { >> - su = avd_su_get(&su_name); >> - if (su == NULL) >> - su_si = NULL; >> - else >> - su_si = su->list_of_susi; >> - } >> - >> - memset((char *)&lsi_name, '\0', sizeof(SaNameT)); >> - memcpy(lsi_name.value, si_name.value, si_name.length); >> - lsi_name.length = si_name.length; >> - >> - while ((su_si != NULL) && (m_CMP_HORDER_SANAMET(su_si->si- >> >name, lsi_name) <= 0)) { >> - su_si = su_si->su_next; >> - } >> - >> - if (su_si != NULL) { >> - return su_si; >> - } >> - >> - /* Find the the first SU SI relation in the next SU with >> - * a SU SI relation. >> - */ >> - lsu_name = su_name; >> - >> - while ((su = avd_su_getnext(&lsu_name)) != NULL) { >> - if (su->list_of_susi != NULL) >> - break; >> - >> - lsu_name = su->name; >> - } >> - >> - /* The given element didn't have a exact match but an element with >> - * a greater SI name was found in the list >> - */ >> - >> - if (su == NULL) >> - return NULL; >> - else >> - return su->list_of_susi; >> - >> - return su_si; >> -} >> - >> - >> /************************************************************ >> ***************** >> * Function: avd_susi_delete >> * >> * Purpose: This function will delete and free AVD_SU_SI_REL structure both >> diff --git a/osaf/services/saf/amf/amfd/sirankedsu.cc >> b/osaf/services/saf/amf/amfd/sirankedsu.cc >> --- a/osaf/services/saf/amf/amfd/sirankedsu.cc >> +++ b/osaf/services/saf/amf/amfd/sirankedsu.cc >> @@ -194,7 +194,7 @@ AVD_SUS_PER_SI_RANK *avd_sirankedsu_getn >> } >> >> /* get the su & si */ >> - su = avd_su_get(&ranked_su_per_si->su_name); >> + su = su_db->find(&ranked_su_per_si->su_name); >> si = avd_si_get(&indx.si_name); >> >> /* validate this entry */ >> diff --git a/osaf/services/saf/amf/amfd/su.cc >> b/osaf/services/saf/amf/amfd/su.cc >> --- a/osaf/services/saf/amf/amfd/su.cc >> +++ b/osaf/services/saf/amf/amfd/su.cc >> @@ -29,23 +29,7 @@ >> #include <proc.h> >> #include <csi.h> >> >> -static NCS_PATRICIA_TREE su_db; >> - >> -void avd_su_db_add(AVD_SU *su) >> -{ >> - unsigned int rc; >> - >> - if (avd_su_get(&su->name) == NULL) { >> - rc = ncs_patricia_tree_add(&su_db, &su->tree_node); >> - osafassert(rc == NCSCC_RC_SUCCESS); >> - } >> -} >> - >> -void avd_su_db_remove(AVD_SU *su) >> -{ >> - unsigned int rc = ncs_patricia_tree_del(&su_db, &su->tree_node); >> - osafassert(rc == NCSCC_RC_SUCCESS); >> -} >> +AmfDb<AVD_SU> *su_db = NULL; >> >> AVD_SU *avd_su_new(const SaNameT *dn) >> { >> @@ -56,7 +40,6 @@ AVD_SU *avd_su_new(const SaNameT *dn) >> >> memcpy(su->name.value, dn->value, dn->length); >> su->name.length = dn->length; >> - su->tree_node.key_info = (uint8_t *)&(su->name); >> avsv_sanamet_init(dn, &sg_name, "safSg"); >> su->saAmfSUFailover = false; >> su->term_state = false; >> @@ -91,23 +74,13 @@ void avd_su_delete(AVD_SU *su) >> m_AVSV_SEND_CKPT_UPDT_ASYNC_RMV(avd_cb, su, >> AVSV_CKPT_AVD_SU_CONFIG); >> avd_node_remove_su(su); >> avd_sutype_remove_su(su); >> - avd_su_db_remove(su); >> + su_db->erase(su); >> avd_sg_remove_su(su); >> delete su; >> >> TRACE_LEAVE(); >> } >> >> -AVD_SU *avd_su_get(const SaNameT *dn) >> -{ >> - SaNameT tmp = {0}; >> - >> - tmp.length = dn->length; >> - memcpy(tmp.value, dn->value, tmp.length); >> - >> - return (AVD_SU *)ncs_patricia_tree_get(&su_db, (uint8_t *)&tmp); >> -} >> - >> /** >> * Return an SU object if it exist, otherwise create it and >> * return a reference to the new object. >> @@ -117,27 +90,18 @@ AVD_SU *avd_su_get(const SaNameT *dn) >> */ >> AVD_SU *avd_su_get_or_create(const SaNameT *dn) >> { >> - AVD_SU *su = avd_su_get(dn); >> + AVD_SU *su = su_db->find(dn); >> >> - if (!su) { >> + if (su == NULL) { >> TRACE("'%s' does not exist, creating it", dn->value); >> su = avd_su_new(dn); >> osafassert(su != NULL); >> - avd_su_db_add(su); >> + su_db->insert(su); >> } >> >> return su; >> } >> >> -AVD_SU *avd_su_getnext(const SaNameT *dn) >> -{ >> - SaNameT tmp = {0}; >> - >> - tmp.length = dn->length; >> - memcpy(tmp.value, dn->value, tmp.length); >> - >> - return (AVD_SU *)ncs_patricia_tree_getnext(&su_db, (uint8_t >> *)&tmp); >> -} >> /** >> * @brief gets the current no of assignmnents on a SU for a particular >> state >> * >> @@ -459,7 +423,7 @@ static AVD_SU *su_create(const SaNameT * >> ** If called at new active at failover, the object is found in the DB >> ** but needs to get configuration attributes initialized. >> */ >> - if ((su = avd_su_get(dn)) == NULL) { >> + if ((su = su_db->find(dn)) == NULL) { >> if ((su = avd_su_new(dn)) == NULL) >> goto done; >> } else >> @@ -583,7 +547,7 @@ static void su_add_to_model(AVD_SU *su) >> { >> SaNameT dn; >> AVD_AVND *node; >> - int new_su = 0; >> + bool new_su = false; >> >> TRACE_ENTER2("%s", su->name.value); >> >> @@ -594,8 +558,8 @@ static void su_add_to_model(AVD_SU *su) >> } >> >> /* Determine of the SU is added now, if so msg to amfnd needs to be >> sent */ >> - if (avd_su_get(&su->name) == NULL) >> - new_su = 1; >> + if (su_db->find(&su->name) == NULL) >> + new_su = true; >> >> avsv_sanamet_init(&su->name, &dn, "safSg"); >> >> @@ -607,7 +571,7 @@ static void su_add_to_model(AVD_SU *su) >> su->sg_of_su = avd_sg_get(&dn); >> osafassert(su->sg_of_su); >> >> - avd_su_db_add(su); >> + su_db->insert(su); >> su->su_type = avd_sutype_get(&su->saAmfSUType); >> osafassert(su->su_type); >> avd_sutype_add_su(su); >> @@ -647,7 +611,7 @@ static void su_add_to_model(AVD_SU *su) >> if (avd_cb->avail_state_avd != SA_AMF_HA_ACTIVE) >> goto done; >> >> - if (new_su) { >> + if (new_su == true) { >> if ((node->node_state == AVD_AVND_STATE_PRESENT) || >> (node->node_state == AVD_AVND_STATE_NO_CONFIG) || >> (node->node_state == AVD_AVND_STATE_NCS_INIT)) { >> @@ -896,7 +860,7 @@ static void su_admin_op_cb(SaImmOiHandle >> goto done; >> } >> >> - if (NULL == (su = avd_su_get(su_name))) { >> + if (NULL == (su = su_db->find(su_name))) { >> LOG_CR("SU '%s' not found", su_name->value); >> /* internal error? osafassert instead? */ >> goto done; >> @@ -1213,7 +1177,7 @@ done: >> static SaAisErrorT su_rt_attr_cb(SaImmOiHandleT immOiHandle, >> const SaNameT *objectName, const SaImmAttrNameT >> *attributeNames) >> { >> - AVD_SU *su = avd_su_get(objectName); >> + AVD_SU *su = su_db->find(objectName); >> SaImmAttrNameT attributeName; >> int i = 0; >> >> @@ -1270,7 +1234,7 @@ static SaAisErrorT su_ccb_completed_modi >> continue; >> >> if (!strcmp(attr_mod->modAttr.attrName, "saAmfSUFailover")) >> { >> - AVD_SU *su = avd_su_get(&opdata->objectName); >> + AVD_SU *su = su_db->find(&opdata->objectName); >> uint32_t su_failover = *((SaUint32T *)attr_mod- >> >modAttr.attrValues[0]); >> >> /* If SG is not in stable state and amfnd is already >> busy >> in the handling of some fault, >> @@ -1290,7 +1254,7 @@ static SaAisErrorT su_ccb_completed_modi >> goto done; >> } >> } else if (!strcmp(attr_mod->modAttr.attrName, >> "saAmfSUMaintenanceCampaign")) { >> - AVD_SU *su = avd_su_get(&opdata->objectName); >> + AVD_SU *su = su_db->find(&opdata->objectName); >> >> if (su->saAmfSUMaintenanceCampaign.length > 0) { >> report_ccb_validation_error(opdata, >> "saAmfSUMaintenanceCampaign already set for %s", >> @@ -1301,7 +1265,7 @@ static SaAisErrorT su_ccb_completed_modi >> } else if (!strcmp(attr_mod->modAttr.attrName, >> "saAmfSUType")) { >> AVD_SU *su; >> SaNameT sutype_name = *(SaNameT*) attr_mod- >> >modAttr.attrValues[0]; >> - su = avd_su_get(&opdata->objectName); >> + su = su_db->find(&opdata->objectName); >> if(SA_AMF_ADMIN_LOCKED_INSTANTIATION != su- >> >saAmfSUAdminState) { >> report_ccb_validation_error(opdata, "SU is >> not in locked-inst, present state '%d'", >> su->saAmfSUAdminState); >> @@ -1351,7 +1315,7 @@ static SaAisErrorT su_ccb_completed_dele >> if (strstr((char *)opdata->objectName.value, "safApp=OpenSAF") != >> NULL) >> is_app_su = 0; >> >> - su = avd_su_get(&opdata->objectName); >> + su = su_db->find(&opdata->objectName); >> osafassert(su != NULL); >> >> if (is_app_su && (su->saAmfSUAdminState != >> SA_AMF_ADMIN_LOCKED_INSTANTIATION)) { >> @@ -1455,7 +1419,7 @@ static void su_ccb_apply_modify_hdlr(str >> >> TRACE_ENTER2("CCB ID %llu, '%s'", opdata->ccbId, opdata- >> >objectName.value); >> >> - su = avd_su_get(&opdata->objectName); >> + su = su_db->find(&opdata->objectName); >> >> while ((attr_mod = opdata->param.modify.attrMods[i++]) != NULL) { >> /* Attribute value removed */ >> @@ -1630,11 +1594,7 @@ void avd_su_dec_curr_stdby_si(AVD_SU *su >> >> void avd_su_constructor(void) >> { >> - NCS_PATRICIA_PARAMS patricia_params; >> - >> - patricia_params.key_size = sizeof(SaNameT); >> - osafassert(ncs_patricia_tree_init(&su_db, &patricia_params) == >> NCSCC_RC_SUCCESS); >> - >> + su_db = new AmfDb<AVD_SU>; >> avd_class_impl_set("SaAmfSU", su_rt_attr_cb, su_admin_op_cb, >> su_ccb_completed_cb, su_ccb_apply_cb); >> } >> diff --git a/osaf/services/saf/amf/amfd/util.cc >> b/osaf/services/saf/amf/amfd/util.cc >> --- a/osaf/services/saf/amf/amfd/util.cc >> +++ b/osaf/services/saf/amf/amfd/util.cc >> @@ -24,6 +24,7 @@ >> >> ************************************************************* >> ***************** >> */ >> >> +#include <vector> >> #include <string.h> >> >> #include <saImmOm.h> >> @@ -445,34 +446,15 @@ done: >> return rc; >> } >> >> - >> /************************************************************ >> ***************** >> - * Function: avd_prep_su_info >> - * >> - * Purpose: This function prepares the SU >> - * information for the given SU and adds it to the message. >> - * >> - * Input: cb - Pointer to the AVD control block >> - * su - Pointer to the SU related to which the messages need to be >> sent. >> - * su_msg - Pointer to the SU message being prepared. >> - * >> - * Returns: NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE >> - * >> - * NOTES: none. >> - * >> - * >> - >> ************************************************************* >> *************/ >> +/** >> + * Creates and initializes the su_info part of the REG_SU message >> + * @param su >> + * @param su_msg >> + */ >> +static void reg_su_msg_init_su_info(AVD_DND_MSG *su_msg, const AVD_SU >> *su) >> +{ >> + AVSV_SU_INFO_MSG *su_info = new AVSV_SU_INFO_MSG(); >> >> -static uint32_t avd_prep_su_info(AVD_CL_CB *cb, AVD_SU *su, >> AVD_DND_MSG *su_msg) >> -{ >> - AVSV_SU_INFO_MSG *su_info; >> - >> - TRACE_ENTER(); >> - >> - su_info = new AVSV_SU_INFO_MSG(); >> - >> - /* fill and add the SU into >> - * the SU message at the top of the list >> - */ >> su_info->name = su->name; >> su_info->comp_restart_max = su->sg_of_su- >> >saAmfSGCompRestartMax; >> su_info->comp_restart_prob = su->sg_of_su- >> >saAmfSGCompRestartProb; >> @@ -485,9 +467,6 @@ static uint32_t avd_prep_su_info(AVD_CL_ >> su_info->next = su_msg->msg_info.d2n_reg_su.su_list; >> su_msg->msg_info.d2n_reg_su.su_list = su_info; >> su_msg->msg_info.d2n_reg_su.num_su++; >> - >> - return NCSCC_RC_SUCCESS; >> - >> } >> >> >> /************************************************************ >> ***************** >> @@ -508,71 +487,40 @@ static uint32_t avd_prep_su_info(AVD_CL_ >> >> uint32_t avd_snd_su_reg_msg(AVD_CL_CB *cb, AVD_AVND *avnd, bool >> fail_over) >> { >> - AVD_SU *i_su = NULL; >> - AVD_DND_MSG *su_msg; >> - uint32_t i, count = 0; >> - SaNameT temp_su_name = {0}; >> + AVD_SU *su = NULL; >> uint32_t rc = NCSCC_RC_SUCCESS; >> >> TRACE_ENTER2("%s", avnd->node_name); >> >> - su_msg = new AVSV_DND_MSG(); >> - >> - /* prepare the SU message. */ >> + AVD_DND_MSG *su_msg = new AVSV_DND_MSG(); >> su_msg->msg_type = AVSV_D2N_REG_SU_MSG; >> su_msg->msg_info.d2n_reg_su.nodeid = avnd->node_info.nodeId; >> su_msg->msg_info.d2n_reg_su.msg_on_fover = fail_over; >> >> - /* build the SU message for both the NCS and application SUs. */ >> + // Add osaf SUs >> + for (su = avnd->list_of_ncs_su; su != NULL; su = su->avnd_list_su_next) >> + reg_su_msg_init_su_info(su_msg, su); >> >> - /* Check whether the AvND belongs to ACT controller. If yes, then send >> all >> - the external SUs/Components to it, otherwise send only cluster >> - components. */ >> + // Add app SUs >> + for (su = avnd->list_of_su; su != NULL; su = su->avnd_list_su_next) >> + reg_su_msg_init_su_info(su_msg, su); >> + >> + // Add external SUs but only if node belongs to ACT controller >> if (avnd->node_info.nodeId == cb->node_id_avd) { >> - count = 2; >> - } else >> - count = 1; >> - >> - for (i = 0; i <= count; ++i) { >> - if (i == 0) >> - i_su = avnd->list_of_ncs_su; >> - else if (i == 1) >> - i_su = avnd->list_of_su; >> - else { >> - /* For external component, we don't have any node >> attached to it. >> - So, get the first external SU. */ >> - temp_su_name.length = 0; >> - while (NULL != (i_su = >> avd_su_getnext(&temp_su_name))) { >> - if (true == i_su->su_is_external) >> - break; >> - >> - temp_su_name = i_su->name; >> - } >> + // filter out external SUs from all SUs >> + std::vector<AVD_SU*> ext_su_vec; >> + for (std::map<std::string, AVD_SU*>::const_iterator it = su_db- >> >begin(); >> + it != su_db->end(); it++) { >> + su = it->second; >> + if (su->su_is_external == true) >> + ext_su_vec.push_back(su); >> } >> >> - while (i_su != NULL) { >> - /* Add information about this SU to the message */ >> - if (avd_prep_su_info(cb, i_su, su_msg) == >> NCSCC_RC_FAILURE) { >> - /* Free all the messages and return error */ >> - d2n_msg_free(su_msg); >> - LOG_EM("%s:%u: %u", __FILE__, __LINE__, >> avnd->node_info.nodeId); >> - rc = NCSCC_RC_FAILURE; >> - goto done; >> - } >> - >> - /* get the next SU in the node */ >> - if ((0 == i) || (1 == i)) >> - i_su = i_su->avnd_list_su_next; >> - else { >> - /* Get the next external SU. */ >> - temp_su_name = i_su->name; >> - while (NULL != (i_su = >> avd_su_getnext(&temp_su_name))) { >> - if (true == i_su->su_is_external) >> - break; >> - >> - temp_su_name = i_su->name; >> - } >> - } >> + // And add them >> + for (std::vector<AVD_SU*>::iterator it = ext_su_vec.begin(); >> + it != ext_su_vec.end(); it++) { >> + su = *it; >> + reg_su_msg_init_su_info(su_msg, su); >> } >> } >> >> @@ -627,45 +575,18 @@ done: >> >> uint32_t avd_snd_su_msg(AVD_CL_CB *cb, AVD_SU *su) >> { >> - AVD_DND_MSG *su_msg; >> AVD_AVND *node = NULL; >> >> TRACE_ENTER(); >> >> - if (su == NULL) { >> - /* This is a invalid situation as the SU >> - * needs to be mentioned. >> - */ >> - >> - /* Log a fatal error that su can't be null */ >> - LOG_EM("%s:%u: %u", __FILE__, __LINE__, 0); >> - return NCSCC_RC_FAILURE; >> - } >> - >> m_AVD_GET_SU_NODE_PTR(cb, su, node); >> >> - su_msg = new AVSV_DND_MSG(); >> - >> - /* prepare the SU message. */ >> - >> + AVD_DND_MSG *su_msg = new AVSV_DND_MSG(); >> su_msg->msg_type = AVSV_D2N_REG_SU_MSG; >> - >> su_msg->msg_info.d2n_reg_su.nodeid = node->node_info.nodeId; >> - >> - /* Add information about this SU to the message */ >> - if (avd_prep_su_info(cb, su, su_msg) == NCSCC_RC_FAILURE) { >> - /* Free the messages and return error */ >> - LOG_EM("%s:%u: %u", __FILE__, __LINE__, node- >> >node_info.nodeId); >> - delete su_msg; >> - return NCSCC_RC_FAILURE; >> - } >> - >> + reg_su_msg_init_su_info(su_msg, su); >> su_msg->msg_info.d2n_reg_su.msg_id = ++(node->snd_msg_id); >> >> - /* send the SU message to the node if return value is failure >> - * free messages and return error. >> - */ >> - >> TRACE("Sending %u to %x", AVSV_D2N_REG_SU_MSG, node- >> >node_info.nodeId); >> >> if (avd_d2n_msg_snd(cb, node, su_msg) == NCSCC_RC_FAILURE) { >> @@ -1468,9 +1389,9 @@ void amfd_file_dump(const char *path) >> dn = sg->name; >> } >> >> - AVD_SU *su; >> - dn.length = 0; >> - for (su = avd_su_getnext(&dn); su != NULL; su = avd_su_getnext(&dn)) >> { >> + for (std::map<std::string, AVD_SU*>::const_iterator it = su_db- >> >begin(); >> + it != su_db->end(); it++) { >> + const AVD_SU *su = it->second; >> fprintf(f, "%s\n", su->name.value); >> fprintf(f, "\tsaAmfSUPreInstantiable=%u\n", su- >> >saAmfSUPreInstantiable); >> fprintf(f, "\tsaAmfSUOperState=%u\n", su- >> >saAmfSUOperState); >> @@ -1512,14 +1433,14 @@ void amfd_file_dump(const char *path) >> } >> >> AVD_SU_SI_REL *rel; >> - dn.length = 0; >> - for (su = avd_su_getnext(&dn); su != NULL; su = avd_su_getnext(&dn)) >> { >> + for (std::map<std::string, AVD_SU*>::const_iterator it = su_db- >> >begin(); >> + it != su_db->end(); it++) { >> + const AVD_SU *su = it->second; >> for (rel = su->list_of_susi; rel != NULL; rel = rel->su_next) { >> fprintf(f, "%s,%s\n", rel->su->name.value, rel->si- >> >name.value); >> fprintf(f, "\thastate=%u\n", rel->state); >> fprintf(f, "\tfsm=%u\n", rel->fsm); >> } >> - dn = su->name; >> } >> >> dn.length = 0; ------------------------------------------------------------------------------ Start Your Social Network Today - Download eXo Platform Build your Enterprise Intranet with eXo Platform Software Java Based Open Source Intranet - Social, Extensible, Cloud Ready Get Started Now And Turn Your Intranet Into A Collaboration Platform http://p.sf.net/sfu/ExoPlatform _______________________________________________ Opensaf-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/opensaf-devel
