Blame lib/map.c

Packit Service f88c7f
/*
Packit Service f88c7f
 * Copyright (C) 2011 Red Hat, Inc.
Packit Service f88c7f
 *
Packit Service f88c7f
 * Author: Angus Salkeld <asalkeld@redhat.com>
Packit Service f88c7f
 *
Packit Service f88c7f
 * This file is part of libqb.
Packit Service f88c7f
 *
Packit Service f88c7f
 * libqb is free software: you can redistribute it and/or modify
Packit Service f88c7f
 * it under the terms of the GNU Lesser General Public License as published by
Packit Service f88c7f
 * the Free Software Foundation, either version 2.1 of the License, or
Packit Service f88c7f
 * (at your option) any later version.
Packit Service f88c7f
 *
Packit Service f88c7f
 * libqb is distributed in the hope that it will be useful,
Packit Service f88c7f
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service f88c7f
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service f88c7f
 * GNU Lesser General Public License for more details.
Packit Service f88c7f
 *
Packit Service f88c7f
 * You should have received a copy of the GNU Lesser General Public License
Packit Service f88c7f
 * along with libqb.  If not, see <http://www.gnu.org/licenses/>.
Packit Service f88c7f
 */
Packit Service f88c7f
Packit Service f88c7f
#include "os_base.h"
Packit Service f88c7f
#include <qb/qbmap.h>
Packit Service f88c7f
#include "map_int.h"
Packit Service f88c7f
Packit Service f88c7f
void
Packit Service f88c7f
qb_map_put(struct qb_map *map, const char *key, const void *value)
Packit Service f88c7f
{
Packit Service f88c7f
	map->put(map, key, value);
Packit Service f88c7f
}
Packit Service f88c7f
Packit Service f88c7f
void *
Packit Service f88c7f
qb_map_get(struct qb_map *map, const char *key)
Packit Service f88c7f
{
Packit Service f88c7f
	return map->get(map, key);
Packit Service f88c7f
}
Packit Service f88c7f
Packit Service f88c7f
int32_t
Packit Service f88c7f
qb_map_rm(struct qb_map * map, const char *key)
Packit Service f88c7f
{
Packit Service f88c7f
	return map->rm(map, key);
Packit Service f88c7f
}
Packit Service f88c7f
Packit Service f88c7f
size_t
Packit Service f88c7f
qb_map_count_get(struct qb_map * map)
Packit Service f88c7f
{
Packit Service f88c7f
	return map->count_get(map);
Packit Service f88c7f
}
Packit Service f88c7f
Packit Service f88c7f
void
Packit Service f88c7f
qb_map_foreach(struct qb_map *map, qb_map_transverse_fn func, void *user_data)
Packit Service f88c7f
{
Packit Service f88c7f
	const char *key;
Packit Service f88c7f
	void *value;
Packit Service f88c7f
	qb_map_iter_t *i = qb_map_iter_create(map);
Packit Service f88c7f
Packit Service f88c7f
	for (key = qb_map_iter_next(i, &value);
Packit Service f88c7f
	     key; key = qb_map_iter_next(i, &value)) {
Packit Service f88c7f
		if (func(key, value, user_data)) {
Packit Service f88c7f
			goto clean_up;
Packit Service f88c7f
		}
Packit Service f88c7f
	}
Packit Service f88c7f
clean_up:
Packit Service f88c7f
	qb_map_iter_free(i);
Packit Service f88c7f
}
Packit Service f88c7f
Packit Service f88c7f
qb_map_iter_t *
Packit Service f88c7f
qb_map_iter_create(struct qb_map *map)
Packit Service f88c7f
{
Packit Service f88c7f
	return map->iter_create(map, NULL);
Packit Service f88c7f
}
Packit Service f88c7f
Packit Service f88c7f
qb_map_iter_t *
Packit Service f88c7f
qb_map_pref_iter_create(qb_map_t * map, const char *prefix)
Packit Service f88c7f
{
Packit Service f88c7f
	return map->iter_create(map, prefix);
Packit Service f88c7f
}
Packit Service f88c7f
Packit Service f88c7f
const char *
Packit Service f88c7f
qb_map_iter_next(struct qb_map_iter *i, void **value)
Packit Service f88c7f
{
Packit Service f88c7f
	return i->m->iter_next(i, value);
Packit Service f88c7f
}
Packit Service f88c7f
Packit Service f88c7f
void
Packit Service f88c7f
qb_map_iter_free(qb_map_iter_t * i)
Packit Service f88c7f
{
Packit Service f88c7f
	i->m->iter_free(i);
Packit Service f88c7f
}
Packit Service f88c7f
Packit Service f88c7f
int32_t
Packit Service f88c7f
qb_map_notify_add(qb_map_t * m, const char *key, qb_map_notify_fn fn,
Packit Service f88c7f
		  int32_t events, void *user_data)
Packit Service f88c7f
{
Packit Service f88c7f
	if (key != NULL && events & QB_MAP_NOTIFY_FREE) {
Packit Service f88c7f
		return -EINVAL;
Packit Service f88c7f
	}
Packit Service f88c7f
	if (m->notify_add) {
Packit Service f88c7f
		return m->notify_add(m, key, fn, events, user_data);
Packit Service f88c7f
	} else {
Packit Service f88c7f
		return -ENOSYS;
Packit Service f88c7f
	}
Packit Service f88c7f
}
Packit Service f88c7f
Packit Service f88c7f
int32_t
Packit Service f88c7f
qb_map_notify_del(qb_map_t * m, const char *key, qb_map_notify_fn fn,
Packit Service f88c7f
		  int32_t events)
Packit Service f88c7f
{
Packit Service f88c7f
	if (m->notify_del) {
Packit Service f88c7f
		return m->notify_del(m, key, fn, events, QB_FALSE, NULL);
Packit Service f88c7f
	} else {
Packit Service f88c7f
		return -ENOSYS;
Packit Service f88c7f
	}
Packit Service f88c7f
}
Packit Service f88c7f
Packit Service f88c7f
int32_t
Packit Service f88c7f
qb_map_notify_del_2(qb_map_t * m, const char *key, qb_map_notify_fn fn,
Packit Service f88c7f
		    int32_t events, void *user_data)
Packit Service f88c7f
{
Packit Service f88c7f
	if (m->notify_del) {
Packit Service f88c7f
		return m->notify_del(m, key, fn, events, QB_TRUE, user_data);
Packit Service f88c7f
	} else {
Packit Service f88c7f
		return -ENOSYS;
Packit Service f88c7f
	}
Packit Service f88c7f
}
Packit Service f88c7f
Packit Service f88c7f
void
Packit Service f88c7f
qb_map_destroy(struct qb_map *map)
Packit Service f88c7f
{
Packit Service f88c7f
	map->destroy(map);
Packit Service f88c7f
}