
# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1197367712 -3600 # Node ID 8ef14daa017090e8473e1f958bc5e5e584032398 # Parent b5847180d00719ff39f2d451d4e79d4369952ad5 [CU] Merge do_ref() and do_assoc() The two functions do_ref() and do_assoc() run through the same logic. The only difference are the returned instances. By configuring the do_assoc() function with an additional paramter (ref_rslt) to inidcate the type of the returned instance(s) - either reference(names) or associator(names) - the two functions can be merged. Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r b5847180d007 -r 8ef14daa0170 std_association.c --- a/std_association.c Fri Dec 07 17:15:07 2007 -0500 +++ b/std_association.c Tue Dec 11 11:08:32 2007 +0100 @@ -226,21 +226,23 @@ static CMPIStatus do_assoc(struct std_as struct std_assoc_info *info, const CMPIResult *results, const CMPIObjectPath *ref, + bool ref_rslt, bool names_only) { CMPIStatus s = {CMPI_RC_OK, NULL}; struct inst_list list; struct std_assoc *handler; - - inst_list_init(&list); + int i; CU_DEBUG("Getting handler..."); handler = std_assoc_get_handler(ctx, info, ref); if (handler == NULL) { CU_DEBUG("No handler found."); - goto out; + return s; } CU_DEBUG("Getting handler succeeded."); + + inst_list_init(&list); CU_DEBUG("Calling handler->handler..."); s = handler->handler(ref, info, &list); @@ -257,73 +259,48 @@ static CMPIStatus do_assoc(struct std_as goto out; } - s = filter_results(&list, - NAMESPACE(ref), - info->result_class, - ctx->brkr); - if (s.rc != CMPI_RC_OK) { - CU_DEBUG("filter_results did not return CMPI_RC_OK."); - goto out; - } - - if (list.list == NULL) { - CU_DEBUG("List is empty."); - goto out; - } else { - CU_DEBUG("Returned %u instance(s).", list.cur); - } - - if (names_only) - cu_return_instance_names(results, &list); - else - cu_return_instances(results, &list); - - out: - inst_list_free(&list); - - return s; -} - -static CMPIStatus do_ref(struct std_assoc_ctx *ctx, - struct std_assoc_info *info, - const CMPIResult *results, - const CMPIObjectPath *ref, - bool names_only) -{ - CMPIStatus s = {CMPI_RC_OK, NULL}; - struct inst_list list; - struct std_assoc *handler; - int i; - - inst_list_init(&list); - - CU_DEBUG("Getting handler..."); - handler = std_assoc_get_handler(ctx, info, ref); - if (handler == NULL) { - CU_DEBUG("No handler found."); - goto out; - } - CU_DEBUG("Getting handler succeeded."); - - CU_DEBUG("Calling handler->handler..."); - s = handler->handler(ref, info, &list); - if ((s.rc != CMPI_RC_OK) || (list.list == NULL)) - goto out; - - for (i = 0; i < list.cur; i++) { - CMPIInstance *refinst; - - refinst = handler->make_ref(ref, list.list[i], info, handler); - if (refinst == NULL) - continue; - + /* Associators and AssociatorNames */ + if (!ref_rslt) { + s = filter_results(&list, + NAMESPACE(ref), + info->result_class, + ctx->brkr); + if (s.rc != CMPI_RC_OK) { + CU_DEBUG("filter_results did not return CMPI_RC_OK."); + goto out; + } + + if (list.list == NULL) { + CU_DEBUG("List is empty."); + goto out; + } else { + CU_DEBUG("Returned %u instance(s).", list.cur); + } + } + + /* References and ReferenceNames */ + if (ref_rslt) { + for (i = 0; i < list.cur; i++) { + CMPIInstance *refinst; + + refinst = handler->make_ref(ref, list.list[i], info, handler); + if (refinst == NULL) + continue; + + if (names_only) + cu_return_instance_name(results, refinst); + else + CMReturnInstance(results, refinst); + } + } + /* Associators and AssociatorNames */ + else { if (names_only) - cu_return_instance_name(results, refinst); + cu_return_instance_names(results, &list); else - CMReturnInstance(results, refinst); - } - - CMSetStatus(&s, CMPI_RC_OK); + cu_return_instances(results, &list); + } + out: inst_list_free(&list); @@ -359,6 +336,7 @@ CMPIStatus stda_AssociatorNames(CMPIAsso &info, results, reference, + false, true); } @@ -386,6 +364,7 @@ CMPIStatus stda_Associators(CMPIAssociat &info, results, reference, + false, false); } @@ -406,7 +385,12 @@ CMPIStatus stda_ReferenceNames(CMPIAssoc self->ft->miName, }; - return do_ref(self->hdl, &info, results, reference, true); + return do_assoc(self->hdl, + &info, + results, + reference, + true, + true); } CMPIStatus stda_References(CMPIAssociationMI *self, @@ -427,7 +411,12 @@ CMPIStatus stda_References(CMPIAssociati self->ft->miName, }; - return do_ref(self->hdl, &info, results, reference, false); + return do_assoc(self->hdl, + &info, + results, + reference, + true, + false); } /*