KDK_TIMER_INIT(3)

NAME
kdk_timer_init - 初始化定时器核心组件

SYNOPSIS

#include <libkytimer.h>

  Functions

  int kdk_timer_init ()

初始化定时器核心组件

Returns
    int 成功返回0，失败返回错误码

Link with -lkytimer.

Detailed Description

接口的主要功能是初始化定时器核心组件

EXAMPLES
    #include <libkytimer.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <assert.h>
    #include <unistd.h>
    #include <time.h>
    #include <string.h>
    void func(char* comment)
    {
    	char date[32]	= {0};
    	time_t now;
    	time(&now);
    	if (ctime_r(&now , date))
    		date[strlen(date) - 1]	= ' ';
    	printf("[%s]这是%s , date , comment);
    }
    void stop(size_t* fdpoll)
    {
    	printf("开始停止定时器);
    	for (int i = 0 ; i < 10 ; i ++)
    	{
    		kdk_timer_stop(fdpoll[i]);
    	}
    }
    int main()
    {
    	assert(kdk_timer_init() == 0);
    	//测试1 -- 基本功能
    	size_t fdpoll[10]	= {0};
    	// for (int i = 1 ; i <= 10 ; i ++)
    	// {
    	// 	char* data	= (char*)malloc(10);
    	// 	assert(data);
    	// 	sprintf(data , "%d号" , i);
    	// 	fdpoll[i - 1]	= kdk_timer_start(i * 1000 , (time_handler)func , KTIMER_PERIODIC , KTIMER_ABSOLUTE, (void*)data , 1);
    	// 	assert(fdpoll[i - 1]);
    	// }
    	kdk_timer_start(10000 , (time_handler)stop , KTIMER_SINGLESHOT , KTIMER_ABSOLUTE, (void*)fdpoll , 0);
    	sleep(11);
    	//测试3 -- 单次触发
    	printf("单次触发测试：);
    	kdk_timer_start(2000 , (time_handler)func , KTIMER_SINGLESHOT , KTIMER_ABSOLUTE, "2号" , 0);
    	sleep(5);
    	//测试2 -- 重置定时器时间
    	printf("修改时间测试：);
    	int persec	= kdk_timer_start(1000 , (time_handler)func , KTIMER_PERIODIC , KTIMER_ABSOLUTE, "1号" , 0);
    	int sec3	= kdk_timer_start(3000 , (time_handler)func , KTIMER_SINGLESHOT , KTIMER_ABSOLUTE, "3号" , 0);
    	sleep(2);
    	kdk_timer_reset(sec3 , 4000);
    	printf("sec3 时钟已被重置为4000ms);
    	sleep(10);
    	printf("正在销毁定时器核心...);
    	kdk_timer_destroy();
    	return 0;
    }

CONFORMING TO
These functions are as per the withdrawn POSIX.1e draft specification. The following functions are Linux extensions: kdk_timer_start(), kdk_timer_stop(), kdk_timer_reset() and kdk_timer_destroy().

SEE ALSO
kdk_timer_start(3), kdk_timer_stop(3), kdk_timer_reset(3) and kdk_timer_destroy(3).

Author

Generated automatically by Doxygen for libkytimer.h from the source code.