#pragma warning (disable: 4996) 
#pragma warning (disable: 4819) 
#pragma warning (disable: 4995) 

#include <tc/tc.h>
#include "epm_handler_common.h"

#include <ict/ict_userservice.h>
#include <tccore/custom.h>
#include <epm/epm_toolkit_tc_utils.h>
#include <tccore/aom.h>
#include <tccore/aom_prop.h>
#include <tccore/item.h>
#include <bom/bom.h>
#include "ps/ps.h";
#include "ps/vrule.h"
#include "sstream"
#include <tccore/grm.h>
#include "epm/epm.h"
#include "sa/sa.h"
#include "libxl.h"
#include <map>
#include "epm/signoff.h"
#include <ctime>
#include <vector>
#include <locale>
#include <codecvt>
#include "ae/dataset.h"
#include <iostream>
extern "C" int POM_AM__set_application_bypass(logical bypass);
#define ITKCALL( argument )                                             \
{                                                                       \
	int retcode = argument;                                             \
	if ( retcode != ITK_ok ) {                                          \
	char* s;                                                        \
	printf( " "#argument "\n" );                                    \
	printf( "  returns [%d]\n", retcode );                          \
	EMH_ask_error_text (retcode, &s);                               \
	TC_printf( "  Teamcenter ERROR: [%s]\n", s);           \
	printf( "  in file ["__FILE__"], line [%d]\n\n", __LINE__ );    \
	if (s != 0) MEM_free (s);                                       \
	}                                                                   \
}
int AddReleaseStatus(EPM_action_message_t msg)
{
	cout<<"添加发布状态"<<endl;

	int ifail = ITK_ok, arg_cnt = 0, i = 0, att_cnt = 0;
	tag_t task_tag = NULLTAG, rootTask_tag = NULLTAG, *attachments = NULL;
	tag_t *release_status=NULL;int rs_num=0;
	char *value=NULL;

		tag_t release_stat = NULLTAG;
	ITKCALL(ifail=RELSTAT_create_release_status("TCM Released", &release_stat));
	task_tag = msg.task;
	//获取根流程节点

	ITKCALL(	ifail = EPM_ask_root_task(task_tag, &rootTask_tag));
	//获取目标引用对象
	ITKCALL(	ifail = EPM_ask_attachments(rootTask_tag, EPM_target_attachment, &att_cnt, &attachments));
	//循环目标对象	
	for (int i=0;i<att_cnt;i++)
	{
		//			ifail = AOM_ask_value_tags(attachments[i],"release_status_list",&rs_num,&release_status);
		ITKCALL(ifail =AOM_ask_value_string(attachments[i],"object_string",&value));

		cout<<value<<endl;
		ITKCALL(ifail=RELSTAT_add_release_status(release_stat, 1, &attachments[i], true));
	}
	if (value != NULL)
	{
		MEM_free(value);
		value = NULL;
	}
	if (attachments != NULL)
	{
		MEM_free(attachments);
		attachments = NULL;
	}
	if (release_status != NULL)
	{
		MEM_free(release_status);
		release_status = NULL;
	}
	return ifail;
}
