I agree with HansF, we should use the provided iterator. /Regards HansN On 05/21/14 14:38, Hans Feldt wrote: > getnext is not needed. Maps have a built in iterator that can/should be used > directly > At least that is the pattern followed so far. > /HansF > >> -----Original Message----- >> From: nagendr...@oracle.com [mailto:nagendr...@oracle.com] >> Sent: den 21 maj 2014 12:00 >> To: Hans Feldt; Hans Nordebäck; praveen.malv...@oracle.com >> Cc: opensaf-devel@lists.sourceforge.net >> Subject: [PATCH 1 of 1] amfd: replace patricia tree with stl::maps in >> nodegroup [#713] >> >> osaf/services/saf/amf/amfd/include/db_template.h | 17 ++++++ >> osaf/services/saf/amf/amfd/include/node.h | 2 +- >> osaf/services/saf/amf/amfd/nodegroup.cc | 61 >> ++++++----------------- >> 3 files changed, 35 insertions(+), 45 deletions(-) >> >> >> diff --git a/osaf/services/saf/amf/amfd/include/db_template.h >> b/osaf/services/saf/amf/amfd/include/db_template.h >> --- a/osaf/services/saf/amf/amfd/include/db_template.h >> +++ b/osaf/services/saf/amf/amfd/include/db_template.h >> @@ -27,6 +27,7 @@ class AmfDb { >> unsigned int insert(T *obj); >> void erase(T *obj); >> T *find(const SaNameT *name); >> + T *getnext(const SaNameT *name); >> >> typedef std::map<std::string, T*> AmfDbMap; >> typedef typename AmfDbMap::const_iterator const_iterator; >> @@ -68,4 +69,20 @@ T *AmfDb<T>::find(const SaNameT *dn) { >> return it->second; >> } >> >> +template <typename T> >> +T *AmfDb<T>::getnext(const SaNameT *dn) { >> + osafassert(dn); >> + std::string name((const char*)dn->value, dn->length); >> + typename AmfDbMap::iterator it = db.find(name); >> + if (it == db.end()) >> + return NULL; >> + else { >> + it++; >> + if (it == db.end()) >> + return NULL; >> + else >> + return it->second; >> + } >> +} >> + >> #endif /* DB_TEMPLATE_H */ >> diff --git a/osaf/services/saf/amf/amfd/include/node.h >> b/osaf/services/saf/amf/amfd/include/node.h >> --- a/osaf/services/saf/amf/amfd/include/node.h >> +++ b/osaf/services/saf/amf/amfd/include/node.h >> @@ -147,7 +147,7 @@ typedef struct avd_avnd_tag { >> typedef struct avd_ng_tag { >> >> NCS_PATRICIA_NODE tree_node; /* key will be AMF node group name */ >> - SaNameT ng_name; >> + SaNameT name; >> uint32_t number_nodes; /* number of element in saAmfNGNodeList */ >> SaNameT *saAmfNGNodeList; /* array of node names in group */ >> >> diff --git a/osaf/services/saf/amf/amfd/nodegroup.cc >> b/osaf/services/saf/amf/amfd/nodegroup.cc >> --- a/osaf/services/saf/amf/amfd/nodegroup.cc >> +++ b/osaf/services/saf/amf/amfd/nodegroup.cc >> @@ -23,17 +23,7 @@ >> #include <cluster.h> >> #include <imm.h> >> >> -static NCS_PATRICIA_TREE nodegroup_db; >> - >> -/** >> - * Add a node group object to the db. >> - * @param ng >> - */ >> -static void ng_db_add(AVD_AMF_NG *ng) >> -{ >> - unsigned int rc = ncs_patricia_tree_add(&nodegroup_db, &ng->tree_node); >> - osafassert(rc == NCSCC_RC_SUCCESS); >> -} >> +AmfDb<AVD_AMF_NG> *nodegroup_db = 0; >> >> /** >> * Lookup object in db using dn >> @@ -43,12 +33,7 @@ static void ng_db_add(AVD_AMF_NG *ng) >> */ >> AVD_AMF_NG *avd_ng_get(const SaNameT *dn) >> { >> - SaNameT tmp = {0}; >> - >> - tmp.length = dn->length; >> - memcpy(tmp.value, dn->value, tmp.length); >> - >> - return (AVD_AMF_NG *)ncs_patricia_tree_get(&nodegroup_db, (uint8_t >> *)&tmp); >> + return nodegroup_db->find(dn); >> } >> >> /** >> @@ -59,12 +44,7 @@ AVD_AMF_NG *avd_ng_get(const SaNameT *dn >> */ >> static AVD_AMF_NG *ng_getnext(const SaNameT *dn) >> { >> - SaNameT tmp = {0}; >> - >> - tmp.length = dn->length; >> - memcpy(tmp.value, dn->value, tmp.length); >> - >> - return (AVD_AMF_NG *)ncs_patricia_tree_getnext(&nodegroup_db, (uint8_t >> *)&tmp); >> + return nodegroup_db->getnext(dn); >> } >> >> /** >> @@ -138,9 +118,9 @@ static AVD_AMF_NG *ng_create(SaNameT *dn >> >> ng = new AVD_AMF_NG(); >> >> - memcpy(ng->ng_name.value, dn->value, dn->length); >> - ng->ng_name.length = dn->length; >> - ng->tree_node.key_info = (uint8_t *)&(ng->ng_name); >> + memcpy(ng->name.value, dn->value, dn->length); >> + ng->name.length = dn->length; >> + ng->tree_node.key_info = (uint8_t *)&(ng->name); >> >> if >> ((immutil_getAttrValuesNumber(const_cast<SaImmAttrNameT>("saAmfNGNodeList"), >> attributes, >> &values_number) == SA_AIS_OK) && (values_number > 0)) { >> @@ -174,10 +154,7 @@ done: >> */ >> static void ng_delete(AVD_AMF_NG *ng) >> { >> - unsigned int rc = ncs_patricia_tree_del(&nodegroup_db, &ng->tree_node); >> - osafassert(rc == NCSCC_RC_SUCCESS); >> - >> - osafassert(ng); >> + nodegroup_db->erase(ng); >> free(ng->saAmfNGNodeList); >> delete ng; >> } >> @@ -228,7 +205,7 @@ SaAisErrorT avd_ng_config_get(void) >> if ((ng = ng_create(&dn, (const SaImmAttrValuesT_2 >> **)attributes)) == NULL) >> goto done2; >> >> - ng_db_add(ng); >> + nodegroup_db->insert(ng); >> } >> >> rc = SA_AIS_OK; >> @@ -249,10 +226,10 @@ done1: >> */ >> static bool su_is_mapped_to_node_via_nodegroup(const AVD_SU *su, const >> AVD_AMF_NG *ng) >> { >> - if ((memcmp(&ng->ng_name, &su->saAmfSUHostNodeOrNodeGroup, >> sizeof(SaNameT)) == 0) || >> - (memcmp(&ng->ng_name, &su->sg_of_su->saAmfSGSuHostNodeGroup, >> sizeof(SaNameT)) == 0)) { >> + if ((memcmp(&ng->name, &su->saAmfSUHostNodeOrNodeGroup, >> sizeof(SaNameT)) == 0) || >> + (memcmp(&ng->name, &su->sg_of_su->saAmfSGSuHostNodeGroup, >> sizeof(SaNameT)) == 0)) { >> >> - TRACE("SU '%s' mapped using '%s'", su->name.value, >> ng->ng_name.value); >> + TRACE("SU '%s' mapped using '%s'", su->name.value, >> ng->name.value); >> return true; >> } >> >> @@ -337,7 +314,7 @@ static SaAisErrorT ng_ccb_completed_modi >> if >> (su_is_mapped_to_node_via_nodegroup(su, ng)) { >> >> report_ccb_validation_error(opdata, "Cannot delete '%s' from '%s'." >> " An SU is >> mapped using node group", >> - >> node->name.value, ng->ng_name.value); >> + >> node->name.value, ng->name.value); >> goto done; >> >> } >> @@ -348,7 +325,7 @@ static SaAisErrorT ng_ccb_completed_modi >> if >> (su_is_mapped_to_node_via_nodegroup(su, ng)) { >> >> report_ccb_validation_error(opdata, "Cannot delete '%s' from '%s'." >> " An SU is >> mapped using node group", >> - >> node->name.value, ng->ng_name.value); >> + >> node->name.value, ng->name.value); >> goto done; >> } >> } >> @@ -444,7 +421,7 @@ static SaAisErrorT ng_ccb_completed_dele >> if (su_is_mapped_to_node_via_nodegroup(su, ng) && >> is_deleted_in_ccb(opdata->ccbId, &su->name) == >> false) { >> report_ccb_validation_error(opdata, "Cannot >> delete '%s' because '%s' is mapped using it", >> - ng->ng_name.value, su->name.value); >> + ng->name.value, su->name.value); >> goto done; >> } >> } >> @@ -453,7 +430,7 @@ static SaAisErrorT ng_ccb_completed_dele >> if (su_is_mapped_to_node_via_nodegroup(su, ng) && >> is_deleted_in_ccb(opdata->ccbId, &su->name) == >> false) { >> report_ccb_validation_error(opdata, "Cannot >> delete '%s' because '%s' is mapped using it", >> - ng->ng_name.value, su->name.value); >> + ng->name.value, su->name.value); >> goto done; >> } >> } >> @@ -571,7 +548,7 @@ static void ng_ccb_apply_cb(CcbUtilOpera >> case CCBUTIL_CREATE: >> ng = ng_create(&opdata->objectName, >> opdata->param.create.attrValues); >> osafassert(ng); >> - ng_db_add(ng); >> + nodegroup_db->insert(ng); >> break; >> case CCBUTIL_MODIFY: >> ng_ccb_apply_modify_hdlr(opdata); >> @@ -593,11 +570,7 @@ static void ng_ccb_apply_cb(CcbUtilOpera >> */ >> void avd_ng_constructor(void) >> { >> - NCS_PATRICIA_PARAMS patricia_params; >> - >> - patricia_params.key_size = sizeof(SaNameT); >> - osafassert(ncs_patricia_tree_init(&nodegroup_db, &patricia_params) == >> NCSCC_RC_SUCCESS); >> - >> + nodegroup_db = new AmfDb<AVD_AMF_NG>; >> avd_class_impl_set("SaAmfNodeGroup", NULL, NULL, ng_ccb_completed_cb, >> ng_ccb_apply_cb); >> }
------------------------------------------------------------------------------ "Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE Instantly run your Selenium tests across 300+ browser/OS combos. Get unparalleled scalability from the best Selenium testing platform available Simple to use. Nothing to install. Get started now for free." http://p.sf.net/sfu/SauceLabs _______________________________________________ Opensaf-devel mailing list Opensaf-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/opensaf-devel