Handler是用于控制流程的系统行为,分为rule handler(规则处理程序)与action handler(操作处理程序)。
action handler可以在流程节点不同的状态中做需要的操作。在流程中的节点有很多的状态,比如开始、执行、完成等。
- 在这里使用action handler实现一个修改目标对象名称的小例子,如何创建一个项目并引用tc的头文件和链接库配置可以参考下面这一篇文章。
- VS2015搭建ITK开发环境
- 创建完后的项目结构如下图:
- handlerstudy.h文件内容如下,声明需要使用的方法
#pragma once
#include <ict/ict_userservice.h>
#include <tc/iman.h>
#include <tccore/custom.h>
#include <epm/epm_toolkit_tc_utils.h>
#ifdef __cplusplus
extern "C"
{
#endif
extern DLLAPI int CUST_init_module(int *, va_list);
extern DLLAPI int handlerstudy_register_callbacks();
extern DLLAPI int cust_actionhandler(EPM_action_message_t msg);
#ifdef __cplusplus
}
#endif
- handlerstudy.cpp文件内容如下,在cust_actionhandler方法中修改目标对象的名称
#include <pie/sample_err.h>
#include <ict/ict_userservice.h>
#include<tc/tc.h>
#include <bom/bom.h>
#include <tccore/aom_prop.h>
#include <tccore/custom.h>
#include "handlerstudy_cust.h"
extern DLLAPI int handlerstudy_register_callbacks()
{
int stat = ITK_ok;
CUSTOM_register_exit("handlerstudy", "USER_gs_shell_init_module", (CUSTOM_EXIT_ftn_t)CUST_init_module);
return stat;
}
extern DLLAPI int CUST_init_module(int *decision, va_list args)
{
printf("CUST_init_module\n");
int stat = ITK_ok;
*decision = ALL_CUSTOMIZATIONS;
// register action handlers
//使用EPM_register_action_handler() 注册action handler
EPM_register_action_handler("cust_actionhandler", "Sample Action Handler", (EPM_action_handler_t)cust_actionhandler);
return stat;
}
int cust_actionhandler(EPM_action_message_t msg) {
tag_t
obj = NULLTAG,
*attachments = NULL;
int
att_count = 0;
EPM_ask_root_task(msg.task, &obj);
EPM_ask_attachments(obj, EPM_target_attachment, &att_count, &attachments);
char *str_object_name = NULL;
char *object_name = "修改的名称";
for (int i = 0; i < att_count; i++) {
//获取对象的属性值
AOM_ask_value_string(attachments[i], "object_name", &str_object_name);
printf(str_object_name);//修改前名称
AOM_set_value_string(attachments[i], "object_name", object_name);
printf(object_name);//需要修改成的名称
AOM_ask_value_string(attachments[i], "object_name", &str_object_name);
printf(str_object_name);//修改后的名称
}
return ITK_ok;
}
- 生成解决方案,将生成的handlerstudy.dll文件放到%TC_ROOT%\bin下
- 在首选项TC_customization_libraries中添加生成的dll文件名称
- 启动TC胖客户端查看TAO窗口,可以看到注册的handler信息
- 在流程中的完成节点中添加注册的cust_actionhandler
到这里一个简单的actionhandler的开发流程就完成了