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

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/dy22511825/article/details/79829848

/*

...紧接上一篇

多输入因子

*/


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);
}

展开阅读全文

没有更多推荐了,返回首页