#include "register_main.h"
#include "handlers.h"


int j6_Standard(EPM_action_message_t msg) {

	return ITK_ok;
}

extern DLLAPI int ldy_register_handlers(int *decision, va_list args)
{
	int ifail = ITK_ok, n=0;
	*decision = ALL_CUSTOMIZATIONS;
	
	ITKCALL(ifail = EPM_register_rule_handler("JD_Check_StatusAndProp", "状态及属性检查", (EPM_rule_handler_t)JD_Check_StatusAndProp));
	if (ifail == ITK_ok) {
		printf("===============Registering rule handler JD_Check_StatusAndProp successful!\n");
	}
	else {
		printf("===============Registering rule handler JD_Check_StatusAndProp failed %d!\n", ifail);
	}
	ITKCALL(ifail = EPM_register_action_handler("j6_Standard", "标准化审核", (EPM_action_handler_t)j6_Standard));
	if (ifail == ITK_ok) {
		printf("================Registering action handler j6_Standard successful!\n");
	}
	else {
		printf("=================Registering action handler j6_Standard failed %d!\n", ifail);
	}	
	ITKCALL(ifail = EPM_register_action_handler("JD_ItemInfoToMediDatabase", "物料接口", (EPM_action_handler_t)JD_ItemInfoToMediDatabase));
	if (ifail == ITK_ok) {
		printf("================Registering action handler JD_ItemInfoToMediDatabase successful!\n");
	}
	else {
		printf("=================Registering action handler JD_ItemInfoToMediDatabase failed %d!\n", ifail);
	}
	ITKCALL(ifail = EPM_register_action_handler("JD_BOMInfoToMediDatabase", "BOM接口", (EPM_action_handler_t)JD_BOMInfoToMediDatabase));
	if (ifail == ITK_ok) {
		printf("================Registering action handler JD_BOMInfoToMediDatabase successful!\n");
	}
	else {
		printf("=================Registering action handler JD_BOMInfoToMediDatabase failed %d!\n", ifail);
	}
	ITKCALL(ifail = EPM_register_action_handler("JD_FileInfoToMediDatabase", "物料-文件接口", (EPM_action_handler_t)JD_FileInfoToMediDatabase));
	if (ifail == ITK_ok) {
		printf("================Registering action handler JD_FileInfoToMediDatabase successful!\n");
	}
	else {
		printf("=================Registering action handler JD_FileInfoToMediDatabase failed %d!\n", ifail);
	}

	ITKCALL(ifail = EPM_register_action_handler("SynchronizeDataSet", "启动cad同步数据集", (EPM_action_handler_t)SynchronizeDataSet));
	if (ifail == ITK_ok) {
		printf("================注册 action handler SynchronizeDataSet 成功!\n");
	}
	else {
		printf("=================注册 action handler SynchronizeDataSet 失败 %d!\n", ifail);
	}

	ITKCALL(ifail = EPM_register_action_handler("JD_BOPInfoToMediDatabase", "工艺BOM接口", (EPM_action_handler_t)JD_BOPInfoToMediDatabase));
	if (ifail == ITK_ok) {
		printf("================Registering action handler JD_BOPInfoToMediDatabase successful!\n");
	}
	else {
		printf("=================Registering action handler JD_BOPInfoToMediDatabase failed %d!\n", ifail);
	}


	ITKCALL(ifail = EPM_register_action_handler("JD_GXInfoToMediDatabase", "标准工序对象集成", (EPM_action_handler_t)JD_GXInfoToMediDatabase));
	if (ifail == ITK_ok) {
		printf("================Registering action handler JD_GXInfoToMediDatabase successful!\n");
	}
	else {
		printf("=================Registering action handler JD_GXInfoToMediDatabase failed %d!\n", ifail);
	}


	//升版二开后操
	METHOD_id_t mth_tag;
	ifail = METHOD_find_method("ItemRevision", ITEM_copy_rev_msg, &mth_tag);//参数1：类型，支持原生和客制化的；参数2：操作类型
	if (mth_tag.id != 0) {
		ifail = METHOD_add_action(mth_tag, METHOD_post_action_type, JD_RevUpgrade, NULL);//参数2：执行操作的时刻，支持前操作和后操作
		fprintf(stdout, "注册[升版二开 - JD_RevUpgrade]后操成功！ \n");
	}
	else {
		fprintf(stdout, "注册[升版二开 - JD_RevUpgrade]后操失败！ \n");
	}

	return ifail;
}

extern DLLAPI int K_register_methods()
{
	int ifail = ITK_ok;
	/*int 
		status = ITK_ok,
		numberOfArguments = 0,
		returnValueType = USERARG_STRING_TYPE,
		*argumentList = NULL;
	USER_function_t functionPtr;

	METHOD_id_t mth_tag;
	ifail=METHOD_find_method("YSR8_QuotationRevision","ITEM_deep_copy",&mth_tag);
	if(mth_tag.id!=0){
		ifail=METHOD_add_action(mth_tag,METHOD_post_action_type,(METHOD_function_t)Method,NULL);
		if(ifail==0) {
			printf("Registering method TEST_METHOD successful\n");
		} else {
			printf("Registering method TEST_METHOD failed %d\n", ifail);
		}
	}*/

	USER_function_t functionPoint;
	int argCount = 0,
		returnArgType = 0,
		* argList = NULL;
	argCount = 2;
	//处理当前服务的函数方法：USERSEVICE_getProperties（来源：cust-uservice.h中声明方法）
	functionPoint = USERSERVICE_changeUnit;
	//手动开辟一块地址
	argList = (int*)MEM_alloc(argCount * sizeof(int));
	argList[0] = USERARG_TAG_TYPE;
	argList[1] = USERARG_STRING_TYPE;

	returnArgType = USERARG_STRING_TYPE;

	ITKCALL(ifail = USERSERVICE_register_method("USERSERVICE_changeUnit", functionPoint, argCount, argList, returnArgType));
	if (ifail == ITK_ok)
	{
		TC_write_syslog("USERVICE [USERSERVICE_changeUnit] 注册成功！");
	}
	else
	{
		TC_write_syslog("USERVICE [USERSERVICE_changeUnit] 注册失败！");
	}
	MEM_free(argList);



	return ITK_ok;
}