summaryrefslogtreecommitdiffstats
path: root/sources/schedule.h
blob: c6657fb71b23e650315d631eb54738038543e70c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#ifndef _OG_SCHEDULE_H_
#define _OG_SCHEDULE_H_

#include <stdint.h>
#include <stdbool.h>
#include "dbi.h"
#include "list.h"
#include <ev.h>

struct og_schedule_time {
	uint32_t	years;
	uint32_t	months;
	uint32_t	weeks;
	uint32_t	week_days;
	uint32_t	days;
	uint32_t	hours;
	uint32_t	am_pm;
	uint32_t	minutes;
	bool		on_start;
};

enum og_schedule_type {
	OG_SCHEDULE_TASK,
	OG_SCHEDULE_COMMAND,
};

struct og_schedule {
	struct list_head	list;
	struct ev_timer		timer;
	time_t			seconds;
	unsigned int		task_id;
	unsigned int		schedule_id;
	enum og_schedule_type	type;
};

void og_schedule_create(unsigned int schedule_id, unsigned int task_id,
			enum og_schedule_type type,
			struct og_schedule_time *time);
void og_schedule_update(struct ev_loop *loop, unsigned int schedule_id,
			unsigned int task_id, struct og_schedule_time *time);
void og_schedule_delete(struct ev_loop *loop, uint32_t schedule_id);
void og_schedule_next(struct ev_loop *loop);
void og_schedule_refresh(struct ev_loop *loop);
void og_schedule_run(unsigned int task_id, unsigned int schedule_id,
		     enum og_schedule_type type);

#endif