• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
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 
39 /* embed this in a child expire item struct */
40 struct 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 
46 BusExpireList* bus_expire_list_new                 (DBusLoop      *loop,
47                                                     int            expire_after,
48                                                     BusExpireFunc  expire_func,
49                                                     void          *data);
50 void           bus_expire_list_free                (BusExpireList *list);
51 void           bus_expire_list_recheck_immediately (BusExpireList *list);
52 void           bus_expire_list_remove_link         (BusExpireList *list,
53                                                     DBusList      *link);
54 dbus_bool_t    bus_expire_list_remove              (BusExpireList *list,
55                                                     BusExpireItem *item);
56 DBusList*      bus_expire_list_get_first_link      (BusExpireList *list);
57 DBusList*      bus_expire_list_get_next_link       (BusExpireList *list,
58                                                     DBusList      *link);
59 dbus_bool_t    bus_expire_list_add                 (BusExpireList *list,
60                                                     BusExpireItem *item);
61 void           bus_expire_list_add_link            (BusExpireList *list,
62                                                     DBusList      *link);
63 dbus_bool_t    bus_expire_list_contains_item       (BusExpireList *list,
64                                                     BusExpireItem *item);
65 void           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 
77 void bus_expire_timeout_set_interval (DBusTimeout   *timeout,
78                                       int            next_interval);
79 
80 #endif /* BUS_EXPIRE_LIST_H */
81