2003-08-15 Havoc Pennington <hp@redhat.com>
[platform/upstream/dbus.git] / dbus / dbus-dataslot.h
1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dbus-dataslot.h  storing data on objects
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 #ifndef DBUS_DATASLOT_H
24 #define DBUS_DATASLOT_H
25
26 #include <dbus/dbus-internals.h>
27
28 DBUS_BEGIN_DECLS;
29
30 typedef struct DBusDataSlotAllocator DBusDataSlotAllocator;
31 typedef struct DBusDataSlotList DBusDataSlotList;
32
33 /** Opaque typedef for DBusDataSlot */
34 typedef struct DBusDataSlot DBusDataSlot;
35 /** DBusDataSlot is used to store application data on the connection */
36 struct DBusDataSlot
37 {
38   void *data;                      /**< The application data */
39   DBusFreeFunction free_data_func; /**< Free the application data */
40 };
41
42 typedef struct DBusAllocatedSlot DBusAllocatedSlot;
43 struct DBusAllocatedSlot
44 {
45   dbus_int32_t slot_id;  /**< ID of this slot */
46   int          refcount; /**< Number of uses of the slot */
47 };
48
49 struct DBusDataSlotAllocator
50 {
51   DBusAllocatedSlot *allocated_slots; /**< Allocated slots */
52   int  n_allocated_slots; /**< number of slots malloc'd */
53   int  n_used_slots;      /**< number of slots used */
54   DBusMutex *lock;        /**< thread lock */
55 };
56
57 struct DBusDataSlotList
58 {
59   DBusDataSlot *slots;   /**< Data slots */
60   int           n_slots; /**< Slots we have storage for in data_slots */
61 };
62
63 dbus_bool_t _dbus_data_slot_allocator_init  (DBusDataSlotAllocator  *allocator);
64 dbus_bool_t _dbus_data_slot_allocator_alloc (DBusDataSlotAllocator  *allocator,
65                                              DBusMutex              *mutex,
66                                              int                    *slot_id_p);
67 void        _dbus_data_slot_allocator_free  (DBusDataSlotAllocator  *allocator,
68                                              int                    *slot_id_p);
69 void        _dbus_data_slot_list_init       (DBusDataSlotList       *list);
70 dbus_bool_t _dbus_data_slot_list_set        (DBusDataSlotAllocator  *allocator,
71                                              DBusDataSlotList       *list,
72                                              int                     slot,
73                                              void                   *data,
74                                              DBusFreeFunction        free_data_func,
75                                              DBusFreeFunction       *old_free_func,
76                                              void                  **old_data);
77 void*       _dbus_data_slot_list_get        (DBusDataSlotAllocator  *allocator,
78                                              DBusDataSlotList       *list,
79                                              int                     slot);
80 void        _dbus_data_slot_list_free       (DBusDataSlotList       *list);
81
82
83 DBUS_END_DECLS;
84
85 #endif /* DBUS_DATASLOT_H */