PageRenderTime 353ms CodeModel.GetById 201ms app.highlight 4ms RepoModel.GetById 147ms app.codeStats 0ms

/src/test/primary_source_test.c

http://ftk.googlecode.com/
C | 46 lines | 41 code | 5 blank | 0 comment | 0 complexity | 0bb4b7ec2dd270e6251b2f3440b1b044 MD5 | raw file
 1#include "ftk.h"
 2#include "ftk_source_primary.h"
 3
 4Ret my_action(void* user_data)
 5{
 6	printf("%s:%p\n", __func__, user_data);
 7
 8	return RET_REMOVE;
 9}
10
11Ret on_event(void* user_data, FtkEvent* event)
12{
13	printf("event->type=%d\n", event->type);
14
15	return RET_OK;
16}
17
18int main(int argc, char* argv[])
19{
20	int fd = 0;
21	int ret =  0;
22	fd_set fdset;
23	struct timeval tv = {0};
24	ftk_set_allocator(ftk_allocator_default_create());
25	FtkSource* thiz = ftk_source_primary_create(on_event, NULL);
26	fd = ftk_source_get_fd(thiz);
27	assert(fd >= 0);
28	FD_ZERO(&fdset);
29	FD_SET(fd, &fdset);
30	tv.tv_sec = 1000;
31	tv.tv_usec =0;
32	FtkEvent event = {.type = 1};
33	ftk_source_queue_event(thiz, &event);
34	event.type = 2;
35	ftk_source_queue_event(thiz, &event);
36	event.type = 3;
37	ftk_source_queue_event(thiz, &event);
38	event.type = 4;
39	ftk_source_queue_event(thiz, &event);
40	while((ret = select(fd+1, &fdset, NULL, NULL, &tv)) > 0)
41	{
42		ftk_source_dispatch(thiz);
43	}
44	ftk_source_unref(thiz);
45	return 0;
46}