D-Bus
1.10.12
|
00001 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ 00002 /* dbus-hash.h Generic hash table utility (internal to D-Bus implementation) 00003 * 00004 * Copyright (C) 2002 Red Hat, Inc. 00005 * 00006 * Licensed under the Academic Free License version 2.1 00007 * 00008 * This program is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation; either version 2 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * This program is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with this program; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00021 * 00022 */ 00023 00024 #ifndef DBUS_HASH_H 00025 #define DBUS_HASH_H 00026 00027 #ifdef HAVE_STDINT_H 00028 #include <stdint.h> 00029 #endif 00030 00031 #ifdef HAVE_INTTYPES_H 00032 #include <inttypes.h> 00033 #endif 00034 00035 #include <dbus/dbus-memory.h> 00036 #include <dbus/dbus-types.h> 00037 #include <dbus/dbus-sysdeps.h> 00038 00039 DBUS_BEGIN_DECLS 00040 00049 struct DBusHashIter 00050 { 00051 void *dummy1; 00052 void *dummy2; 00053 void *dummy3; 00054 void *dummy4; 00055 int dummy5; 00056 int dummy6; 00057 }; 00058 00059 typedef struct DBusHashTable DBusHashTable; 00060 typedef struct DBusHashIter DBusHashIter; 00061 00062 /* Allowing an arbitrary function as with GLib 00063 * would be nicer for a public API, but for 00064 * an internal API this saves typing, we can add 00065 * more whenever we feel like it. 00066 */ 00067 typedef enum 00068 { 00069 DBUS_HASH_STRING, 00070 DBUS_HASH_INT, 00071 DBUS_HASH_UINTPTR 00072 } DBusHashType; 00073 00074 DBUS_PRIVATE_EXPORT 00075 DBusHashTable* _dbus_hash_table_new (DBusHashType type, 00076 DBusFreeFunction key_free_function, 00077 DBusFreeFunction value_free_function); 00078 DBusHashTable* _dbus_hash_table_ref (DBusHashTable *table); 00079 DBUS_PRIVATE_EXPORT 00080 void _dbus_hash_table_unref (DBusHashTable *table); 00081 void _dbus_hash_table_remove_all (DBusHashTable *table); 00082 DBUS_PRIVATE_EXPORT 00083 void _dbus_hash_iter_init (DBusHashTable *table, 00084 DBusHashIter *iter); 00085 DBUS_PRIVATE_EXPORT 00086 dbus_bool_t _dbus_hash_iter_next (DBusHashIter *iter); 00087 DBUS_PRIVATE_EXPORT 00088 void _dbus_hash_iter_remove_entry (DBusHashIter *iter); 00089 DBUS_PRIVATE_EXPORT 00090 void* _dbus_hash_iter_get_value (DBusHashIter *iter); 00091 void _dbus_hash_iter_set_value (DBusHashIter *iter, 00092 void *value); 00093 DBUS_PRIVATE_EXPORT 00094 int _dbus_hash_iter_get_int_key (DBusHashIter *iter); 00095 DBUS_PRIVATE_EXPORT 00096 const char* _dbus_hash_iter_get_string_key (DBusHashIter *iter); 00097 DBUS_PRIVATE_EXPORT 00098 uintptr_t _dbus_hash_iter_get_uintptr_key (DBusHashIter *iter); 00099 dbus_bool_t _dbus_hash_iter_lookup (DBusHashTable *table, 00100 void *key, 00101 dbus_bool_t create_if_not_found, 00102 DBusHashIter *iter); 00103 DBUS_PRIVATE_EXPORT 00104 void* _dbus_hash_table_lookup_string (DBusHashTable *table, 00105 const char *key); 00106 DBUS_PRIVATE_EXPORT 00107 void* _dbus_hash_table_lookup_int (DBusHashTable *table, 00108 int key); 00109 DBUS_PRIVATE_EXPORT 00110 void* _dbus_hash_table_lookup_uintptr (DBusHashTable *table, 00111 uintptr_t key); 00112 DBUS_PRIVATE_EXPORT 00113 dbus_bool_t _dbus_hash_table_remove_string (DBusHashTable *table, 00114 const char *key); 00115 DBUS_PRIVATE_EXPORT 00116 dbus_bool_t _dbus_hash_table_remove_int (DBusHashTable *table, 00117 int key); 00118 DBUS_PRIVATE_EXPORT 00119 dbus_bool_t _dbus_hash_table_remove_uintptr (DBusHashTable *table, 00120 uintptr_t key); 00121 DBUS_PRIVATE_EXPORT 00122 dbus_bool_t _dbus_hash_table_insert_string (DBusHashTable *table, 00123 char *key, 00124 void *value); 00125 DBUS_PRIVATE_EXPORT 00126 dbus_bool_t _dbus_hash_table_insert_int (DBusHashTable *table, 00127 int key, 00128 void *value); 00129 DBUS_PRIVATE_EXPORT 00130 dbus_bool_t _dbus_hash_table_insert_uintptr (DBusHashTable *table, 00131 uintptr_t key, 00132 void *value); 00133 DBUS_PRIVATE_EXPORT 00134 int _dbus_hash_table_get_n_entries (DBusHashTable *table); 00135 00136 /* Preallocation */ 00137 00139 typedef struct DBusPreallocatedHash DBusPreallocatedHash; 00140 00141 DBUS_PRIVATE_EXPORT 00142 DBusPreallocatedHash *_dbus_hash_table_preallocate_entry (DBusHashTable *table); 00143 DBUS_PRIVATE_EXPORT 00144 void _dbus_hash_table_free_preallocated_entry (DBusHashTable *table, 00145 DBusPreallocatedHash *preallocated); 00146 DBUS_PRIVATE_EXPORT 00147 void _dbus_hash_table_insert_string_preallocated (DBusHashTable *table, 00148 DBusPreallocatedHash *preallocated, 00149 char *key, 00150 void *value); 00151 00152 #ifdef DBUS_WIN 00153 # define DBUS_HASH_POLLABLE DBUS_HASH_UINTPTR 00154 #else 00155 # define DBUS_HASH_POLLABLE DBUS_HASH_INT 00156 #endif 00157 00158 static inline DBusPollable 00159 _dbus_hash_iter_get_pollable_key (DBusHashIter *iter) 00160 { 00161 #ifdef DBUS_WIN 00162 DBusSocket s; 00163 00164 s.sock = _dbus_hash_iter_get_uintptr_key (iter); 00165 return s; 00166 #else 00167 return _dbus_hash_iter_get_int_key (iter); 00168 #endif 00169 } 00170 00171 static inline void * 00172 _dbus_hash_table_lookup_pollable (DBusHashTable *table, 00173 DBusPollable key) 00174 { 00175 #ifdef DBUS_WIN 00176 return _dbus_hash_table_lookup_uintptr (table, key.sock); 00177 #else 00178 return _dbus_hash_table_lookup_int (table, key); 00179 #endif 00180 } 00181 00182 static inline dbus_bool_t 00183 _dbus_hash_table_remove_pollable (DBusHashTable *table, 00184 DBusPollable key) 00185 { 00186 #ifdef DBUS_WIN 00187 return _dbus_hash_table_remove_uintptr (table, key.sock); 00188 #else 00189 return _dbus_hash_table_remove_int (table, key); 00190 #endif 00191 } 00192 00193 static inline dbus_bool_t 00194 _dbus_hash_table_insert_pollable (DBusHashTable *table, 00195 DBusPollable key, 00196 void *value) 00197 { 00198 #ifdef DBUS_WIN 00199 return _dbus_hash_table_insert_uintptr (table, key.sock, value); 00200 #else 00201 return _dbus_hash_table_insert_int (table, key, value); 00202 #endif 00203 } 00204 00207 DBUS_END_DECLS 00208 00209 #endif /* DBUS_HASH_H */