#define _CRT_SECURE_NO_WARNINGS
#include "epm_handler_common.h"

int connor_set_prop_value(void * returnValue) {
	int ifail = ITK_ok;
	int count = 0;
	tag_t *items = NULL;
	char * propname = NULL;
	char * propvalue = NULL;

	USERARG_get_tag_array_argument(&count, &items);
	USERARG_get_string_argument(&propname);
	USERARG_get_string_argument(&propvalue);
	POM_AM__set_application_bypass(true);
	for (int i = 0; i < count; i++)
	{

		tag_t type = NULLTAG, item_type = NULLTAG;
		logical isok = FALSE;
		char * object_type = NULL, *class_id = NULL;
		tag_t attr_id = NULLTAG, class_tag = NULLTAG, tag_instance = NULLTAG;
		ITKCALL(TCTYPE_ask_object_type(items[i], &type));
		ITKCALL(TCTYPE_find_type("Form", "", &item_type));
		ITKCALL(TCTYPE_is_type_of(type, item_type, &isok));
		if (isok)
		{

			printf("是表单类型获得存储类对象\n");
			//ITKCALL(FORM_ask_pom_instance(items[i], &tag_instance));
		}
		else
		{
			tag_instance = items[i];
		}

		ITKCALL(AOM_lock(tag_instance));
		ITKCALL(ifail = POM_class_of_instance(tag_instance, &class_tag));
		ITKCALL(ifail = POM_name_of_class(class_tag, &class_id));
		printf("对象类型：%s\n", class_id);
		ITKCALL(ifail = POM_attr_id_of_attr(propname, class_id, &attr_id));
		ITKCALL(POM_refresh_instances_any_class(1, &tag_instance, POM_modify_lock));
		ITKCALL(POM_set_attr_string(1, &tag_instance, attr_id, propvalue));
		ITKCALL(POM_save_instances(1, &tag_instance, true));
		ITKCALL(AOM_unlock(tag_instance));
		DOFREE(object_type);
		DOFREE(class_id);
	}
	POM_AM__set_application_bypass(false);

	DOFREE(propname);
	DOFREE(propvalue);


	return ITK_ok;
}