2004-08-09 Havoc Pennington <hp@redhat.com>
[platform/upstream/dbus.git] / bus / expirelist.h
1 /* -*- mode: C; c-file-style: "gnu" -*- */
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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
31 typedef struct BusExpireList BusExpireList;
32 typedef struct BusExpireItem BusExpireItem;
33
34 typedef dbus_bool_t (* BusExpireFunc) (BusExpireList *list,
35                                        DBusList      *link,
36                                        void          *data);
37
38 struct BusExpireList
39 {
40   DBusList      *items; /**< List of BusExpireItem */
41   DBusTimeout   *timeout;
42   DBusLoop      *loop;
43   BusExpireFunc  expire_func;
44   void          *data;
45   int            expire_after; /**< Expire after milliseconds (thousandths) */
46 };
47
48 /* embed this in a child expire item struct */
49 struct BusExpireItem
50 {
51   long added_tv_sec;  /**< Time we were added (seconds component) */
52   long added_tv_usec; /**< Time we were added (microsec component) */
53 };
54
55 BusExpireList* bus_expire_list_new    (DBusLoop      *loop,
56                                        int            expire_after,
57                                        BusExpireFunc  expire_func,
58                                        void          *data);
59 void           bus_expire_list_free   (BusExpireList *list);
60
61 #define ELAPSED_MILLISECONDS_SINCE(orig_tv_sec, orig_tv_usec,   \
62                                    now_tv_sec, now_tv_usec)     \
63  (((double) (now_tv_sec) - (double) (orig_tv_sec)) * 1000.0 +   \
64  ((double) (now_tv_usec) - (double) (orig_tv_usec)) / 1000.0)
65
66 void bus_expire_timeout_set_interval (DBusTimeout *timeout,
67                                       int          next_interval);
68
69 #endif /* BUS_EXPIRE_LIST_H */