D-Bus  1.12.16
dbus-hash.h
1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /* dbus-hash.h Generic hash table utility (internal to D-Bus implementation)
3  *
4  * Copyright (C) 2002 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 DBUS_HASH_H
25 #define DBUS_HASH_H
26 
27 #ifdef HAVE_STDINT_H
28 #include <stdint.h>
29 #endif
30 
31 #ifdef HAVE_INTTYPES_H
32 #include <inttypes.h>
33 #endif
34 
35 #include <dbus/dbus-memory.h>
36 #include <dbus/dbus-types.h>
37 #include <dbus/dbus-sysdeps.h>
38 
40 
50 {
51  void *dummy1;
52  void *dummy2;
53  void *dummy3;
54  void *dummy4;
55  int dummy5;
56  int dummy6;
57 };
58 
60 typedef struct DBusHashIter DBusHashIter;
61 
62 /* Allowing an arbitrary function as with GLib
63  * would be nicer for a public API, but for
64  * an internal API this saves typing, we can add
65  * more whenever we feel like it.
66  */
67 typedef enum
68 {
72 } DBusHashType;
73 
74 DBUS_PRIVATE_EXPORT
76  DBusFreeFunction key_free_function,
77  DBusFreeFunction value_free_function);
79 DBUS_PRIVATE_EXPORT
82 DBUS_PRIVATE_EXPORT
84  DBusHashIter *iter);
85 DBUS_PRIVATE_EXPORT
87 DBUS_PRIVATE_EXPORT
89 DBUS_PRIVATE_EXPORT
92  void *value);
93 DBUS_PRIVATE_EXPORT
95 DBUS_PRIVATE_EXPORT
97 DBUS_PRIVATE_EXPORT
100  void *key,
101  dbus_bool_t create_if_not_found,
102  DBusHashIter *iter);
103 DBUS_PRIVATE_EXPORT
105  const char *key);
106 DBUS_PRIVATE_EXPORT
108  int key);
109 DBUS_PRIVATE_EXPORT
111  uintptr_t key);
112 DBUS_PRIVATE_EXPORT
114  const char *key);
115 DBUS_PRIVATE_EXPORT
117  int key);
118 DBUS_PRIVATE_EXPORT
120  uintptr_t key);
121 DBUS_PRIVATE_EXPORT
123  char *key,
124  void *value);
125 DBUS_PRIVATE_EXPORT
127  int key,
128  void *value);
129 DBUS_PRIVATE_EXPORT
131  uintptr_t key,
132  void *value);
133 DBUS_PRIVATE_EXPORT
135 
136 DBUS_PRIVATE_EXPORT
138  char delimiter);
139 DBUS_PRIVATE_EXPORT
141  char **array,
142  char delimiter);
143 
144 /* Preallocation */
145 
148 
149 DBUS_PRIVATE_EXPORT
151 DBUS_PRIVATE_EXPORT
153  DBusPreallocatedHash *preallocated);
154 DBUS_PRIVATE_EXPORT
156  DBusPreallocatedHash *preallocated,
157  char *key,
158  void *value);
159 
160 #ifdef DBUS_WIN
161 # define DBUS_HASH_POLLABLE DBUS_HASH_UINTPTR
162 #else
163 # define DBUS_HASH_POLLABLE DBUS_HASH_INT
164 #endif
165 
166 static inline DBusPollable
167 _dbus_hash_iter_get_pollable_key (DBusHashIter *iter)
168 {
169 #ifdef DBUS_WIN
170  DBusSocket s;
171 
172  s.sock = _dbus_hash_iter_get_uintptr_key (iter);
173  return s;
174 #else
175  return _dbus_hash_iter_get_int_key (iter);
176 #endif
177 }
178 
179 static inline void *
180 _dbus_hash_table_lookup_pollable (DBusHashTable *table,
181  DBusPollable key)
182 {
183 #ifdef DBUS_WIN
184  return _dbus_hash_table_lookup_uintptr (table, key.sock);
185 #else
186  return _dbus_hash_table_lookup_int (table, key);
187 #endif
188 }
189 
190 static inline dbus_bool_t
191 _dbus_hash_table_remove_pollable (DBusHashTable *table,
192  DBusPollable key)
193 {
194 #ifdef DBUS_WIN
195  return _dbus_hash_table_remove_uintptr (table, key.sock);
196 #else
197  return _dbus_hash_table_remove_int (table, key);
198 #endif
199 }
200 
201 static inline dbus_bool_t
202 _dbus_hash_table_insert_pollable (DBusHashTable *table,
203  DBusPollable key,
204  void *value)
205 {
206 #ifdef DBUS_WIN
207  return _dbus_hash_table_insert_uintptr (table, key.sock, value);
208 #else
209  return _dbus_hash_table_insert_int (table, key, value);
210 #endif
211 }
212 
213 static inline void
214 _dbus_clear_hash_table (DBusHashTable **table_p)
215 {
216  _dbus_clear_pointer_impl (DBusHashTable, table_p, _dbus_hash_table_unref);
217 }
218 
222 
223 #endif /* DBUS_HASH_H */