/*===================================================================================================
					Copyright(c) 2011 Siemens PLM Software Corp. All rights reserved.
							 Unpublished - All rights reserved
====================================================================================================
File description:

	Filename : epm_register_handler.c

	This file registers functions which are called when Teamcenter is being initialized

====================================================================================================
Date               Name                  Description of Change
2011-8-21			Ray wei              creation

$HISTORY$
==================================================================================================*/

#pragma warning (disable: 4819) 

/**
* @headerfile			tcua ͷ�ļ�
*/
#include <server_exits/user_server_exits.h>
#include <tccore/custom.h>
#include <epm/epm.h>

/**
* @headerfile			standard c & cpp header files
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <time.h>


/**
* @headerfile			user's header files
*/
#include "epm_register_handler.h"
#include "epm_handler_common.h"



// Method and Workflow Handler
extern DLLAPI int CUST_init_module(int *decision, va_list args)
{
	int ifail = ITK_ok, n = 0;
	char date_buf[80], *expire_date;
	time_t now;
	struct   tm   *p;

	*decision = ALL_CUSTOMIZATIONS;

	printf("register start\n");
	ifail = EPM_register_action_handler("bs_file_transfer", "bs_file_transfer",
		(EPM_action_handler_t)bs_file_transfer);
	if (ifail)
	{
		printf("register bs_file_transfer failed\n");
	}
	else
	{
		printf("register bs_file_transfer successfully\n");

	}
	ifail = EPM_register_action_handler("bs_sap_material", "bs_sap_material",
		(EPM_action_handler_t)bs_sap_material);
	if (ifail)
	{
		printf("register  bs_sap_material failed\n");
	}
	else
	{
		printf("register bs_sap_material successfully\n");

	}
	ifail = EPM_register_action_handler("bs_sap_bom", "bs_sap_bom",
		(EPM_action_handler_t)bs_sap_bom);
	if (ifail)
	{
		printf("register bs_sap_bom failed\n");
	}
	else
	{
		printf("register bs_sap_bom successfully\n");

	}
	ifail = EPM_register_rule_handler("bs_bom_check", "bs_bom_check", (EPM_rule_handler_t)bs_bom_check);
	if (ifail)
	{
		printf("register bs_bom_check failed\n");
	}
	else
	{
		printf("register bs_bom_check successfully\n");

	}
	ifail = EPM_register_rule_handler("bs_wl_check", "bs_wl_check", (EPM_rule_handler_t)bs_wl_check);
	if (ifail)
	{
		printf("register bs_wl_check failed\n");
	}
	else
	{
		printf("register bs_wl_check successfully\n");

	}
	ifail = EPM_register_action_handler("bs_sign_cad", "bs_sign_cad",
		(EPM_action_handler_t)bs_sign_cad);
	if (ifail)
	{
		printf("register bs_sign_cad failed\n");
	}
	else
	{
		printf("register bs_sign_cad successfully\n");

	}
	ifail = EPM_register_rule_handler("bs_test_release_check", "bs_test_release_check",
		(EPM_rule_handler_t)bs_test_release_check);
	if (ifail)
	{
		printf("register bs_test_release_check failed\n");
	}
	else
	{
		printf("register bs_test_release_check successfully\n");

	}

	ifail = EPM_register_action_handler("jd_signoff", "jd_signoff",
		(EPM_action_handler_t)jd_signoff);
	if (ifail) {
		printf("register jd_signoff failed\n");
	}
	else {
		printf("register jd_signoff successfully\n");

	}
	//if(ifail == ITK_ok) 
	//{ 
	//	fprintf(stdout,"Registering action handler qtmc-sign-ir completed!\n"); 
	//} 
	//else
	//{
	//	fprintf(stdout , "Registering action handler qtmc-sign-ir failed %d!\n",ifail);
	//}


	return ifail;
}
//
////register service method
extern DLLAPI int USERSERVICE_custom_register_methods()
{
	int status = 0;

	METHOD_id_t mth_tag;
	METHOD_find_method("BOMWindow", "BOMWindow_save", &mth_tag);
	printf("register service\n");
	if (mth_tag.id)
	{
		printf("register bomwindow_save\n");
		status = METHOD_add_action(mth_tag, METHOD_pre_action_type, (METHOD_function_t)bs_bom_save_check, NULL);
		if (status == ITK_ok)
		{
			printf("register bomwindow_save success\n");

		}
		else
		{
			printf("register bomwindow_save failed\n");

		}

		int numberOfArguments = 1,
			returnValueType = USERARG_STRING_TYPE,
			*argumentList = (int*)MEM_alloc(numberOfArguments * sizeof(int));
		argumentList[0] = USERARG_LOGICAL_TYPE;;
		USER_function_t functionPtr;
		functionPtr = bs_bypass;
		status = USERSERVICE_register_method("bs_bypass", functionPtr, numberOfArguments, argumentList, returnValueType);
		if (status == ITK_ok) {
			printf("register bs_bypass success\n");
		} else {
			printf("register bs_bypass failed\n");

		}
	}

	return 0;
}

