1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
/*
* Copyright (C) 2011 Red Hat, Inc.
*
* Author: Angus Salkeld <asalkeld@redhat.com>
*
* This file is part of libqb.
*
* libqb is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
*
* libqb is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with libqb. If not, see <http://www.gnu.org/licenses/>.
*/
#include "os_base.h"
#include <qb/qbmap.h>
#include "map_int.h"
void
qb_map_put(struct qb_map *map, const char *key, const void *value)
{
map->put(map, key, value);
}
void *
qb_map_get(struct qb_map *map, const char *key)
{
return map->get(map, key);
}
int32_t
qb_map_rm(struct qb_map * map, const char *key)
{
return map->rm(map, key);
}
size_t
qb_map_count_get(struct qb_map * map)
{
return map->count_get(map);
}
void
qb_map_foreach(struct qb_map *map, qb_map_transverse_fn func, void *user_data)
{
const char *key;
void *value;
qb_map_iter_t *i = qb_map_iter_create(map);
for (key = qb_map_iter_next(i, &value);
key; key = qb_map_iter_next(i, &value)) {
if (func(key, value, user_data)) {
goto clean_up;
}
}
clean_up:
qb_map_iter_free(i);
}
qb_map_iter_t *
qb_map_iter_create(struct qb_map *map)
{
return map->iter_create(map, NULL);
}
qb_map_iter_t *
qb_map_pref_iter_create(qb_map_t * map, const char *prefix)
{
return map->iter_create(map, prefix);
}
const char *
qb_map_iter_next(struct qb_map_iter *i, void **value)
{
return i->m->iter_next(i, value);
}
void
qb_map_iter_free(qb_map_iter_t * i)
{
i->m->iter_free(i);
}
int32_t
qb_map_notify_add(qb_map_t * m, const char *key, qb_map_notify_fn fn,
int32_t events, void *user_data)
{
if (key != NULL && events & QB_MAP_NOTIFY_FREE) {
return -EINVAL;
}
if (m->notify_add) {
return m->notify_add(m, key, fn, events, user_data);
} else {
return -ENOSYS;
}
}
int32_t
qb_map_notify_del(qb_map_t * m, const char *key, qb_map_notify_fn fn,
int32_t events)
{
if (m->notify_del) {
return m->notify_del(m, key, fn, events, QB_FALSE, NULL);
} else {
return -ENOSYS;
}
}
int32_t
qb_map_notify_del_2(qb_map_t * m, const char *key, qb_map_notify_fn fn,
int32_t events, void *user_data)
{
if (m->notify_del) {
return m->notify_del(m, key, fn, events, QB_TRUE, user_data);
} else {
return -ENOSYS;
}
}
void
qb_map_destroy(struct qb_map *map)
{
map->destroy(map);
}
|