2e7752fc4838b3da650642b8e9343f4e199a2946
[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 1.2
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 void (* BusExpireFunc) (BusExpireList *list,
35                                 BusExpireItem *item,
36                                 void          *data);
37
38 struct BusExpireList
39 {
40   DBusList      *items; /**< List of BusExpireItem */
41   int            n_items;
42   DBusTimeout   *timeout;
43   DBusLoop      *loop;
44   BusExpireFunc  expire_func;
45   void          *data;
46   int            expire_after; /**< Expire after milliseconds (thousandths) */
47 };
48
49 /* embed this in a child expire item struct */
50 struct BusExpireItem
51 {
52   long added_tv_sec;  /**< Time we were added (seconds component) */
53   long added_tv_usec; /**< Time we were added (microsec component) */
54 };
55
56 BusExpireList* bus_expire_list_new    (DBusLoop      *loop,
57                                        int            expire_after,
58                                        BusExpireFunc  expire_func,
59                                        void          *data);
60 void           bus_expire_list_free   (BusExpireList *list);
61
62 #define ELAPSED_MILLISECONDS_SINCE(orig_tv_sec, orig_tv_usec,   \
63                                    now_tv_sec, now_tv_usec)     \
64  (((double) (now_tv_sec) - (double) (orig_tv_sec)) * 1000.0 +   \
65  ((double) (now_tv_usec) - (double) (orig_tv_usec)) / 1000.0)
66
67 void bus_expire_timeout_set_interval (DBusTimeout *timeout,
68                                       int          next_interval);
69
70 #endif /* BUS_EXPIRE_LIST_H */