static const struct dol_tag *find_tag(const struct dol_tag *tags, unsigned int num_tags, const uint8_t *idb, size_t tag_len) { while ( num_tags ) { unsigned int i; int cmp; i = num_tags / 2U; cmp = tag_cmp(tags + i, idb, tag_len); if ( cmp < 0 ) { num_tags = i; }else if ( cmp > 0 ) { tags = tags + (i + 1U); num_tags = num_tags - (i + 1U); }else return tags + i; } return NULL; }
/********************************************************** * Main Function * takes no arguments * * returns: SAF_TEST_PASS when successfull * SAF_TEST_FAIL when an unexpected error occurs *************************************************************/ int main(int argc, char **argv) { SaHpiSessionIdT session, new_session; SaErrorT status; SaHpiDomainInfoT domain_info; SaHpiEntryIdT entry_id, next_entry_id, entry_id_domain2; SaHpiDrtEntryT domain_table_entry; int retval = SAF_TEST_UNKNOWN; SaHpiTextBufferT new_tag, old_tag, old_tag_domain2; SaHpiEntityPathT old_entity_path; SaHpiRptEntryT Report; SaHpiBoolT old_session_open = SAHPI_FALSE; SaHpiBoolT new_session_open = SAHPI_FALSE; SaHpiBoolT found_res = SAHPI_FALSE; SaHpiResourceIdT res_id_domain1; // // Open the session // status = saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID, &session, NULL); if (status != SA_OK) { e_print(saHpiSessionOpen, SA_OK, status); retval = SAF_TEST_UNRESOLVED; } else { // // Discover Resources // old_session_open = SAHPI_TRUE; // // Get the DRT info // status = saHpiDomainInfoGet(session, &domain_info); if (status != SA_OK) { //Unable to discover e_print(saHpiDomainInfoGet, SA_OK, status); retval = SAF_TEST_UNRESOLVED; } else { if (!domain_info.IsPeer) retval = SAF_TEST_NOTSUPPORT; else { status = saHpiDrtEntryGet(session, SAHPI_FIRST_ENTRY, &next_entry_id, &domain_table_entry); if (status != SA_OK) { e_print(saHpiDrtEntryGet, SA_OK, status); retval = SAF_TEST_UNRESOLVED; } } } } //Get the information of another domain if (retval == SAF_TEST_UNKNOWN) { status = saHpiSessionOpen(domain_table_entry.DomainId, &new_session, NULL); if (status != SA_OK) { e_print(saHpiSessionOpen, SA_OK, status); retval = SAF_TEST_UNRESOLVED; } else { // // Discover Resources // new_session_open = SAHPI_TRUE; } } //update the resource tag in the first domain if (retval == SAF_TEST_UNKNOWN) { status = saHpiRptEntryGet(session, SAHPI_FIRST_ENTRY, &next_entry_id, &Report); if (status != SA_OK) { e_print(saHpiRptEntryGet, SA_OK, status); retval = SAF_TEST_UNRESOLVED; } else { old_entity_path = Report.ResourceEntity; old_tag.DataType = Report.ResourceTag.DataType; old_tag.Language = Report.ResourceTag.Language; old_tag.DataLength = Report.ResourceTag.DataLength; memcpy(old_tag.Data, Report.ResourceTag.Data, sizeof(Report.ResourceTag.Data)); res_id_domain1 = Report.ResourceId; //find the exist tag for resource in the 2nd domain while (next_entry_id != SAHPI_LAST_ENTRY) { entry_id = next_entry_id; status = saHpiRptEntryGet(new_session, entry_id, &next_entry_id, &Report); if (status != SA_OK) { e_print(saHpiRptEntryGet, SA_OK, status); retval = SAF_TEST_UNRESOLVED; break; } else { if (is_entitypath_equal (&Report.ResourceEntity, &old_entity_path)) { found_res = SAHPI_TRUE; entry_id_domain2 = Report.EntryId; old_tag_domain2.DataType = Report.ResourceTag.DataType; old_tag_domain2.Language = Report.ResourceTag.Language; old_tag_domain2.DataLength = Report.ResourceTag. DataLength; memcpy(old_tag_domain2.Data, Report.ResourceTag.Data, sizeof(Report. ResourceTag. Data)); break; } } } if (!found_res) retval = SAF_TEST_FAIL; if (retval == SAF_TEST_UNKNOWN) { memset(&new_tag, 0, sizeof(new_tag)); new_tag.DataType = SAHPI_TL_TYPE_BINARY; new_tag.Language = SAHPI_LANG_ENGLISH; new_tag.DataLength = sizeof(TEST_STR); memcpy(new_tag.Data, TEST_STR, new_tag.DataLength); status = saHpiResourceTagSet(session, res_id_domain1, &new_tag); if (status != SA_OK) { e_print(saHpiResourceTagSet, SA_OK, status); retval = SAF_TEST_UNRESOLVED; } } } } //find the resource in the second domain and check whether the resource tag has been changed if (retval == SAF_TEST_UNKNOWN) { status = saHpiRptEntryGet(new_session, entry_id_domain2, &next_entry_id, &Report); if (status != SA_OK) { e_print(saHpiRptEntryGet, SA_OK, status); retval = SAF_TEST_UNRESOLVED; } else { if (!tag_cmp(&Report.ResourceTag, &old_tag_domain2)) retval = SAF_TEST_PASS; else { m_print ("The resource tag for the resource in the second domain "); m_print ("is different than the resource tag for the resource "); m_print ("in the first domain. They should have been the same!"); retval = SAF_TEST_FAIL; } } } // // Close all the session // if (old_session_open) { status = saHpiSessionClose(session); if (status != SA_OK) { m_print("The old session failed to close properly!"); e_print(saHpiSessionClose, SA_OK, status); } } if (new_session_open) { status = saHpiSessionClose(new_session); if (status != SA_OK) { m_print("The new session failed to close properly!"); e_print(saHpiSessionClose, SA_OK, status); } } return retval; }
/** Check for non-empty selection. */ static bool selection_active(void) { return (tag_cmp(&pane.caret_pos, &pane.sel_start) != 0); }