快速业务通道

linux精确定时服务

作者 佚名技术 来源 Linux系统 浏览 发布时间 2012-04-18
eek;
}DATE_REC; typedef struct _entry
{
int flags;
unsigned char bit_decl(minute, MINUTE_COUNT);
unsigned char bit_decl(hour, HOUR_COUNT);
unsigned char bit_decl(day_of_mon, DAYOFMON_COUNT);
unsigned char bit_decl(mon_of_year, MONTH_COUNT);
unsigned char bit_decl(day_of_week, DAYOFWEEK_COUNT);
char command[MAX_BUF];
struct _entry *next;
}ENTRY; #endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h> #include <sys/time.h>
#include <time.h> //#include <sqlite3.h>
#include "dbcron_comm.h" static ENTRY *head = NULL;
static ENTRY *tail = NULL; int set_bit(unsigned char *bits, int low, int high, int number)
{
if (number < low || number > high)
return -1; bit_set(bits, (number - low));
return 0;
} int set_element(unsigned char *bits, ELEMENT element, int low, int high)
{
int i;
int num1;
int num2;
int num3;

bit_nclear(bits, 0, (high - low 1)); if (E_EVERY == element.flag)
{
num1 = low;
num2 = high;
}
else if (E_NORMAL == element.flag)
{
num1 = element.low;
set_bit(bits, low, high, num1);
return 0;
}
else if (E_AREA == element.flag)
{
num1 = element.low;
num2 = element.high;
}
num3 = element.step;
if (num3 <= 0)
return -1;

for (i = num1; i <= num2; i = num3)
{
set_bit(bits, low, high, i);
}

return 0;
} int load_entry(ENTRY *pEntry, DATE_REC *pDate)
{
if (E_EVERY == pDate->minute.flag)
pEntry->flags |= MINUTE_EVERY;
set_element(pEntry->minute, pDate->minute, FIRST_MINUTE, LAST_MINUTE); if (E_EVERY == pDate->hour.flag)
pEntry->flags |= HOUR_EVERY;
set_element(pEntry->hour, pDate->hour, FIRST_HOUR, LAST_HOUR); if (E_EVERY == pDate->day_of_mon.flag)
pEntry->flags |= DAY_MON_EVERY;
set_element(pEntry->day_of_mon, pDate->day_of_mon, FIRST_DAYOFMON, LAST_DAYOFMON); if (E_EVERY == pDate->mon_of_year.flag)
pEntry->flags |= MON_YEAR_EVERY;
set_element(pEntry->mon_of_year, pDate->mon_of_year, FIRST_MONTH, LAST_MONTH); if (E_EVERY == pDate->day_of_week.flag)
pEntry->flags |= DAY_WEEK_EVERY;
set_element(pEntry->day_of_week, pDate->day_of_week, FIRST_DAYOFWEEK, LAST_DAYOFWEEK); if (bit_test(pEntry->day_of_week, 0) || bit_test(pEntry->day_of_week, 7))
{
bit_set(pEntry->day_of_week, 0);
bit_set(pEntry->day_of_week, 7);
} return 0;

} ENTRY *add_entry(void)
{
ENTRY *pEntry; pEntry = (ENTRY *)malloc(sizeof(ENTRY));
if (NULL == pEntry)
{
return NULL;
} memset(pEntry, 0, sizeof(ENTRY));
pEntry->next = NULL; if (NULL == head)
head = pEntry;
else
tail->next = pEntry; tail = pEntry; return pEntry;

} void del_entry()
{
ENTRY *pEntry; if (NULL == head)
return;

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号