数据驱动编程的实现(2)

/*

...紧接上一篇

多输入因子

*/


void func1(void *param);
void func2(void *param);
void func3(void *param);




typedef enum _sender
{
SENDER1 =0,
SENDER2,
SENDER3
}SENDER;


typedef enum _msgtype
{
MSGTYPE1=0,
MSGTYPE2,
MSGTYPE3
}MSGTYPE;


typedef enum _selfstatus
{
STATUS1=0,
STATUS2,
STATUS3
}SELFSTATUS;

typedef void (*FUNCPTR)(void *param);




typedef struct _eventdriver
{
SENDER sender;
MSGTYPE msgtype;
SELFSTATUS selfstate;
FUNCPTR funptr;
}DRI_EVENT;




DRI_EVENT event_map[]=
{
{0,0,0,func1},
{0,0,1,func2},
{0,1,0,func3}
};




FUNCPTR Driver_Event(SENDER sender,MSGTYPE msgtype,SELFSTATUS selfstate)
{
int drivercnt = sizeof(event_map)/sizeof(DRI_EVENT);
int i=0;
LOG_ERR("drivermap :%d\n",drivercnt);


for(i=0;i<drivercnt;i++)
{
if((event_map[i].sender == sender) && \
(event_map[i].msgtype == msgtype) && \
(event_map[i].selfstate == selfstate))
{
LOG_DEBUG("find %d funcptr",i);
return event_map[i].funptr;
}
}


LOG_ERR("no find funptr");
return NULL;

}




void func1(void *param)
{
LOG_INFO("func1 . %s",(char *)param);

}


void func2(void *param)
{
LOG_INFO("func2 . %s",(char *)param);
}


void func3(void *param)
{
LOG_INFO("func3 . %s",(char *)param);
}


void main()
{
funcptr = Driver_Event(0, 0, 1);
funcptr = Driver_Event(1, 0, 0);
}

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页