Ejemplo n.º 1
0
ret_code_t domain_proc(void)
{
	SaHpiDomainInfoT	info;
	SaHpiEntryIdT		entryid, nextentryid;
	SaHpiDrtEntryT		drtentry;
	SaErrorT		rv;
	SaHpiDomainIdT		id;
	SaHpiSessionIdT		sessionId;
	int			i, n, first;
	gpointer		ptr;
	Domain_t		*domain = (Domain_t *)NULL;
	Domain_t		*new_domain;
	term_def_t		*term;

	term = get_next_term();
	if (term == NULL) {
		printf("Domain list:\n");
		printf("    ID: %d   SessionId: %d", Domain->domainId,
			Domain->sessionId);
		rv = saHpiDomainInfoGet(Domain->sessionId, &info);
		if (rv == SA_OK) {
			print_text_buffer_text("    Tag: ",
				&(info.DomainTag), NULL, ui_print);
		};
		printf("\n");
		entryid = SAHPI_FIRST_ENTRY;
		first = 1;
		while (entryid != SAHPI_LAST_ENTRY) {
			rv = saHpiDrtEntryGet(Domain->sessionId, entryid,
				&nextentryid, &drtentry);
			if (rv != SA_OK) break;
			if (first) {
				first = 0;
				printf("        Domain Reference Table:\n");
			};
			printf("            ID: %d", drtentry.DomainId);
			entryid = nextentryid;
			rv = saHpiSessionOpen(drtentry.DomainId,
						&sessionId, NULL);
			if (rv != SA_OK) {
				printf("\n");
				continue;
			};
			rv = saHpiDomainInfoGet(sessionId, &info);
			if (rv == SA_OK) {
				print_text_buffer_text("    Tag: ",  &(info.DomainTag), NULL, ui_print);
			};
			saHpiSessionClose(sessionId);
			printf("\n");
		}
		return(HPI_SHELL_OK);
	};

	if (isdigit(term->term[0]))
		id = (int)atoi(term->term);
	else
		return HPI_SHELL_PARM_ERROR;
	n = g_slist_length(domainlist);
	for (i = 0; i < n; i++) {
		ptr = g_slist_nth_data(domainlist, i);
		if (ptr == (gpointer)NULL) break;
		domain = (Domain_t *)ptr;
		if (domain->domainId == id) break;
	};
	if (i >= n) {
		new_domain = (Domain_t *)malloc(sizeof(Domain_t));
		memset(new_domain, 0, sizeof(Domain_t));
		new_domain->domainId = id;
		if (add_domain(new_domain) < 0) {
			free(new_domain);
			printf("Can not open domain: %d\n", id);
			return HPI_SHELL_PARM_ERROR;
		};
		domain = new_domain;
	};
	Domain = domain;
	set_Subscribe(Domain, prt_flag);
	add_domain(Domain);
	return(HPI_SHELL_OK);
}
Ejemplo n.º 2
0
/**********************************************************
*   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;
}