This file is indexed.

/usr/include/nih/timer.h is in libnih-dev 1.0.3-4ubuntu9.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/* libnih
 *
 * Copyright © 2009 Scott James Remnant <scott@netsplit.com>.
 * Copyright © 2009 Canonical Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2, as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#ifndef NIH_TIMER_H
#define NIH_TIMER_H

#include <nih/macros.h>
#include <nih/list.h>

#include <time.h>


/**
 * NihTimerCb:
 * @data: pointer given with callback,
 * @timer: timer that triggered the call.
 *
 * The timer callback is called whenever the timer has been triggered.
 * For periodic and scheduled timers, the timer may be removed by calling
 * nih_list_remove() or similar; this happens automatically for timeouts.
 **/
typedef struct nih_timer NihTimer;
typedef void (*NihTimerCb) (void *data, NihTimer *timer);


/**
 * NihTimerType:
 *
 * Used to identify the different types of timers that can be registered;
 * note that scheduled timers are not yet implemented.
 **/
typedef enum {
	NIH_TIMER_TIMEOUT,
	NIH_TIMER_PERIODIC,
	NIH_TIMER_SCHEDULED
} NihTimerType;

/**
 * NihTimerSchedule:
 * @minutes: minutes past the hour (0-59),
 * @hours: hours (0-23),
 * @mdays: days of month (1-31),
 * @months: months (1-12),
 * @wdays: days of week (0-7).
 *
 * Indidcates when scheduled timers should be run, each member is a bit
 * field where the bit is 1 if the timer should be run for that value and
 * 0 if not.
 **/
typedef struct nih_timer_schedule {
	uint64_t minutes;
	uint32_t hours;
	uint32_t mdays;
	uint16_t months;
	uint8_t  wdays;
} NihTimerSchedule;

/**
 * NihTimer:
 * @entry: list header,
 * @due: time next due,
 * @type: type of timer,
 * @timeout: seconds after registration timer should be triggered (timeout),
 * @period: seconds between triggerings of timer (periodic),
 * @schedule: detail of when to call the timer (scheduled),
 * @callback: function called when timer triggered,
 * @data: pointer passed to callback.
 *
 * Timers may be used whenever a function needs to be called later in
 * the process.  They are divided into three types, identified by @type.
 *
 * Timeouts are called once, @timeout seconds after they were registered.
 * Periodic timers are called every @period seconds after they were registered.
 * Scheduled timers are called based on the information in @schedule.
 *
 * In all cases, a timer may be cancelled by calling nih_list_remove() on
 * it as they are held in a list internally.
 **/
struct nih_timer {
	NihList       entry;
	time_t        due;

	NihTimerType  type;
	union {
		time_t           timeout;
		time_t           period;
		NihTimerSchedule schedule;
	};

	NihTimerCb    callback;
	void         *data;
};


NIH_BEGIN_EXTERN

extern NihList *nih_timers;


void      nih_timer_init          (void);

NihTimer *nih_timer_add_timeout   (const void *parent, time_t timeout,
				   NihTimerCb callback, void *data)
	__attribute__ ((warn_unused_result, malloc));
NihTimer *nih_timer_add_periodic  (const void *parent, time_t period,
				   NihTimerCb callback, void *data)
	__attribute__ ((warn_unused_result, malloc));
NihTimer *nih_timer_add_scheduled (const void *parent,
				   NihTimerSchedule *schedule,
				   NihTimerCb callback, void *data)
	__attribute__ ((warn_unused_result, malloc));

NihTimer *nih_timer_next_due       (void);
void      nih_timer_poll           (void);

NIH_END_EXTERN

#endif /* NIH_TIMER_H */