d4357325202d63f13f491a6d737e64b818d2978d
[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 struct DBusDataSlotAllocator
43 {
44   int *allocated_slots;   /**< Allocated slots */
45   int  n_allocated_slots; /**< number of slots malloc'd */
46   int  n_used_slots;      /**< number of slots used */
47   DBusMutex *lock;        /**< thread lock */
48 };
49
50 struct DBusDataSlotList
51 {
52   DBusDataSlot *slots;   /**< Data slots */
53   int           n_slots; /**< Slots we have storage for in data_slots */
54 };
55
56 dbus_bool_t _dbus_data_slot_allocator_init  (DBusDataSlotAllocator  *allocator);
57 int         _dbus_data_slot_allocator_alloc (DBusDataSlotAllocator  *allocator,
58                                              DBusMutex              *mutex);
59 void        _dbus_data_slot_allocator_free  (DBusDataSlotAllocator  *allocator,
60                                              int                     slot_id);
61 void        _dbus_data_slot_list_init       (DBusDataSlotList       *list);
62 dbus_bool_t _dbus_data_slot_list_set        (DBusDataSlotAllocator  *allocator,
63                                              DBusDataSlotList       *list,
64                                              int                     slot,
65                                              void                   *data,
66                                              DBusFreeFunction        free_data_func,
67                                              DBusFreeFunction       *old_free_func,
68                                              void                  **old_data);
69 void*       _dbus_data_slot_list_get        (DBusDataSlotAllocator  *allocator,
70                                              DBusDataSlotList       *list,
71                                              int                     slot);
72 void        _dbus_data_slot_list_free       (DBusDataSlotList       *list);
73
74
75 DBUS_END_DECLS;
76
77 #endif /* DBUS_DATASLOT_H */