1/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2/* expirelist.h  List of stuff that expires
3 *
4 * Copyright (C) 2003  Red Hat, Inc.
5 *
6 * Licensed under the Academic Free License version 2.1
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21 *
22 */
23
24#ifndef BUS_EXPIRE_LIST_H
25#define BUS_EXPIRE_LIST_H
26
27#include <dbus/dbus.h>
28#include <dbus/dbus-list.h>
29#include <dbus/dbus-mainloop.h>
30
31typedef struct BusExpireList BusExpireList;
32typedef struct BusExpireItem BusExpireItem;
33
34typedef dbus_bool_t (* BusExpireFunc) (BusExpireList *list,
35                                       DBusList      *link,
36                                       void          *data);
37
38
39/* embed this in a child expire item struct */
40struct BusExpireItem
41{
42  long added_tv_sec;  /**< Time we were added (seconds component) */
43  long added_tv_usec; /**< Time we were added (microsec component) */
44};
45
46BusExpireList* bus_expire_list_new                 (DBusLoop      *loop,
47                                                    int            expire_after,
48                                                    BusExpireFunc  expire_func,
49                                                    void          *data);
50void           bus_expire_list_free                (BusExpireList *list);
51void           bus_expire_list_recheck_immediately (BusExpireList *list);
52void           bus_expire_list_remove_link         (BusExpireList *list,
53                                                    DBusList      *link);
54dbus_bool_t    bus_expire_list_remove              (BusExpireList *list,
55                                                    BusExpireItem *item);
56DBusList*      bus_expire_list_get_first_link      (BusExpireList *list);
57DBusList*      bus_expire_list_get_next_link       (BusExpireList *list,
58                                                    DBusList      *link);
59dbus_bool_t    bus_expire_list_add                 (BusExpireList *list,
60                                                    BusExpireItem *item);
61void           bus_expire_list_add_link            (BusExpireList *list,
62                                                    DBusList      *link);
63dbus_bool_t    bus_expire_list_contains_item       (BusExpireList *list,
64                                                    BusExpireItem *item);
65void           bus_expire_list_unlink              (BusExpireList *list,
66                                                    DBusList      *link);
67
68/* this macro and function are semi-related utility functions, not really part of the
69 * BusExpireList API
70 */
71
72#define ELAPSED_MILLISECONDS_SINCE(orig_tv_sec, orig_tv_usec,   \
73                                   now_tv_sec, now_tv_usec)     \
74 (((double) (now_tv_sec) - (double) (orig_tv_sec)) * 1000.0 +   \
75 ((double) (now_tv_usec) - (double) (orig_tv_usec)) / 1000.0)
76
77void bus_expire_timeout_set_interval (DBusTimeout   *timeout,
78                                      int            next_interval);
79
80#endif /* BUS_EXPIRE_LIST_H */
81