osaf/services/saf/amf/amfd/csi.cc       |  20 ++------------------
 osaf/services/saf/amf/amfd/include/su.h |   1 +
 osaf/services/saf/amf/amfd/sgproc.cc    |  12 ++----------
 osaf/services/saf/amf/amfd/su.cc        |  19 +++++++++++++++++++
 4 files changed, 24 insertions(+), 28 deletions(-)


Add and use a method for the task of finding an unassigned component that can
provide a specified CSType. Preparing for later changing the comp_list
implementation. Removes some code duplication.

diff --git a/osaf/services/saf/amf/amfd/csi.cc 
b/osaf/services/saf/amf/amfd/csi.cc
--- a/osaf/services/saf/amf/amfd/csi.cc
+++ b/osaf/services/saf/amf/amfd/csi.cc
@@ -470,15 +470,7 @@ static SaAisErrorT csi_ccb_completed_cre
                                        compcsi = compcsi->susi_csicomp_next;
                                }
 
-                               t_comp = su->list_of_comp;
-                               while (t_comp != NULL) {
-                                       if ((t_comp->assign_flag == false) &&
-                                                       
(avd_compcstype_find_match(&cstype_name, t_comp) != NULL)) {
-                                               /* We have found the component. 
Assign csi to it. */
-                                               break;
-                                       }
-                                       t_comp = t_comp->su_comp_next;
-                               }/* while (t_comp != NULL) */
+                               t_comp = 
su->find_unassigned_comp_that_provides_cstype(&cstype_name);
 
                                /* Component not found.*/
                                if (NULL == t_comp) {
@@ -854,15 +846,7 @@ static void csi_ccb_apply_create_hdlr(st
                                compcsi = compcsi->susi_csicomp_next;
                        }
 
-                       t_comp = t_sisu->su->list_of_comp;
-                       while (t_comp != NULL) {
-                               if ((t_comp->assign_flag == false) &&
-                                               (NULL != (cst = 
avd_compcstype_find_match(&csi->saAmfCSType, t_comp)))) {
-                                       /* We have found the component. Assign 
csi to it. */
-                                       break;
-                               }
-                               t_comp = t_comp->su_comp_next;
-                       }/* while (t_comp != NULL) */
+                       t_comp = 
t_sisu->su->find_unassigned_comp_that_provides_cstype(&csi->saAmfCSType);
 
                        /* Component not found.*/
                        if (NULL == t_comp) {
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
@@ -119,6 +119,7 @@ class AVD_SU {
        avd_avnd_tag *get_node_ptr(void);
        bool is_in_service(void);
        void reset_all_comps_assign_flag();
+       AVD_COMP *find_unassigned_comp_that_provides_cstype(const SaNameT 
*cstype);
 
  private:
        void send_attribute_update(AVSV_AMF_SU_ATTR_ID attrib_id);
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
@@ -94,16 +94,8 @@ uint32_t avd_new_assgn_susi(AVD_CL_CB *c
 
        l_csi = si->list_of_csi;
        while (l_csi != NULL) {
-               /* find the component that has to be assigned this CSI */
-
-               l_comp = su->list_of_comp;
-               while (l_comp != NULL) {
-                       if ((l_comp->assign_flag == false) &&
-                           (NULL != (cst = 
avd_compcstype_find_match(&l_csi->saAmfCSType, l_comp))))
-                               break;
-
-                       l_comp = l_comp->su_comp_next;
-               }
+               /* find a component that can be assigned this CSI */
+               l_comp = 
su->find_unassigned_comp_that_provides_cstype(&l_csi->saAmfCSType);
 
                if (l_comp == NULL) {
                        /* This means either - 1. l_csi cann't be assigned to 
any comp or 2. some comp got assigned 
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
@@ -1793,3 +1793,22 @@ void AVD_SU::reset_all_comps_assign_flag
                t_comp = t_comp->su_comp_next;
        }
 }
+
+/**
+ * Finds an unassigned component that provides the specified CSType
+ * @param cstype
+ * @return
+ */
+AVD_COMP *AVD_SU::find_unassigned_comp_that_provides_cstype(const SaNameT 
*cstype) {
+       AVD_COMP *l_comp = list_of_comp;
+       while (l_comp != NULL) {
+               if (l_comp->assign_flag == false) {
+                       AVD_COMPCS_TYPE *cst = 
avd_compcstype_find_match(cstype, l_comp);
+                       if (cst != NULL)
+                               break;
+               }
+               l_comp = l_comp->su_comp_next;
+       }
+
+       return l_comp;
+}

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

Reply via email to