Chinaunix首页 | 论坛 | 博客
  • 博客访问: 367869
  • 博文数量: 53
  • 博客积分: 2000
  • 博客等级: 大尉
  • 技术积分: 1143
  • 用 户 组: 普通用户
  • 注册时间: 2007-11-14 11:53
文章分类

全部博文(53)

文章存档

2011年(1)

2008年(52)

我的朋友

分类:

2008-09-22 20:04:25

/* includes */
#include "vxWorks.h"
#include "taskLib.h"
#include "taskHookLib.h"    /* taskHook所对应的库 */
 
/* task function */
void myFunc(void)
{
    int i;
    printf("Hello, I am task %d\n", taskIdSelf()); /* Print task Id */
}
 
/* taskCreatHook */
void myTaskHook(void)
{
    printf("task hook function called\n");
}
 
/* user entry */
void user_start()
{
    taskCreateHookAdd( (FUNCPTR) myTaskHook);
    taskSpawn("myTask", 90, 0x100, 2000, (FUNCPTR) myFunc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
}

运行输出:
task hook function called
Hello, I am task 14868640
 
  有过Windows钩子(Hook)编程经验的读者应该对其概念并不陌生,Hook作为回调函数,当被挂接后。操作系统发生特定的事情时,将触发这个Hook回调函数的执行。VxWorks也有钩子的概念,不过比Windows要简单许多,主要有taskCreateHook、taskDeleteHook、taskSwitchHookAdd,可以通过如下6个API来添加和删除这三种Hook:
STATUS taskCreateHookAdd (FUNCPTR createHook /* routine to be called when a task is created */ );
STATUS taskCreateHookDelete (FUNCPTR createHook /* routine to be deleted from list */);
STATUS taskSwitchHookAdd (FUNCPTR switchHook /* routine to be called at every task switch */);
STATUS taskSwitchHookDelete (FUNCPTR switchHook /* routine to be deleted from list */);
STATUS taskDeleteHookAdd (FUNCPTR deleteHook /* routine to be called when a task is deleted */);
STATUS taskDeleteHookDelete (FUNCPTR deleteHook /* routine to be deleted from list */);

 
阅读(4548) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~