2013-02-25 23:36:09 +00:00
|
|
|
/*
|
|
|
|
* cache.c
|
|
|
|
* package object cache
|
|
|
|
*
|
|
|
|
* Copyright (c) 2013 pkgconf authors (see AUTHORS).
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* This software is provided 'as is' and without any warranty, express or
|
|
|
|
* implied. In no event shall the authors be liable for any damages arising
|
|
|
|
* from the use of this software.
|
|
|
|
*/
|
|
|
|
|
2015-09-06 14:35:08 +00:00
|
|
|
#include <libpkgconf/libpkgconf.h>
|
2013-02-25 23:36:09 +00:00
|
|
|
|
2015-09-06 15:31:21 +00:00
|
|
|
static pkgconf_list_t pkg_cache = PKGCONF_LIST_INITIALIZER;
|
2013-02-25 23:36:09 +00:00
|
|
|
|
|
|
|
/*
|
2015-09-06 15:50:23 +00:00
|
|
|
* pkgconf_cache_lookup(id)
|
2013-02-25 23:36:09 +00:00
|
|
|
*
|
|
|
|
* looks up a package in the cache given an 'id' atom,
|
|
|
|
* such as 'gtk+-3.0' and returns the already loaded version
|
|
|
|
* if present.
|
|
|
|
*/
|
2015-09-06 16:20:48 +00:00
|
|
|
pkgconf_pkg_t *
|
2015-09-06 15:50:23 +00:00
|
|
|
pkgconf_cache_lookup(const char *id)
|
2013-02-25 23:36:09 +00:00
|
|
|
{
|
2015-09-06 15:31:21 +00:00
|
|
|
pkgconf_node_t *node;
|
2013-02-25 23:36:09 +00:00
|
|
|
|
2015-09-06 15:31:21 +00:00
|
|
|
PKGCONF_FOREACH_LIST_ENTRY(pkg_cache.head, node)
|
2013-02-25 23:36:09 +00:00
|
|
|
{
|
2015-09-06 16:20:48 +00:00
|
|
|
pkgconf_pkg_t *pkg = node->data;
|
2013-03-01 16:14:20 +00:00
|
|
|
|
2013-02-25 23:36:09 +00:00
|
|
|
if (!strcmp(pkg->id, id))
|
2015-09-06 16:20:48 +00:00
|
|
|
return pkgconf_pkg_ref(pkg);
|
2013-02-25 23:36:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2015-09-06 15:50:23 +00:00
|
|
|
* pkgconf_cache_add(pkg)
|
2013-02-25 23:36:09 +00:00
|
|
|
*
|
|
|
|
* adds an entry for the package to the package cache.
|
|
|
|
* the cache entry must be removed if the package is freed.
|
|
|
|
*/
|
|
|
|
void
|
2015-09-06 16:20:48 +00:00
|
|
|
pkgconf_cache_add(pkgconf_pkg_t *pkg)
|
2013-02-25 23:36:09 +00:00
|
|
|
{
|
2013-03-15 21:50:30 +00:00
|
|
|
if (pkg == NULL)
|
|
|
|
return;
|
|
|
|
|
2015-09-06 16:20:48 +00:00
|
|
|
pkgconf_pkg_ref(pkg);
|
2015-09-06 15:31:21 +00:00
|
|
|
pkgconf_node_insert(&pkg->cache_iter, pkg, &pkg_cache);
|
2013-02-25 23:36:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2015-09-06 15:50:23 +00:00
|
|
|
* pkgconf_cache_remove(pkg)
|
2013-02-25 23:36:09 +00:00
|
|
|
*
|
|
|
|
* deletes a package from the cache entry.
|
|
|
|
*/
|
|
|
|
void
|
2015-09-06 16:20:48 +00:00
|
|
|
pkgconf_cache_remove(pkgconf_pkg_t *pkg)
|
2013-02-25 23:36:09 +00:00
|
|
|
{
|
2013-03-15 21:50:30 +00:00
|
|
|
if (pkg == NULL)
|
|
|
|
return;
|
|
|
|
|
2015-09-06 15:31:21 +00:00
|
|
|
pkgconf_node_delete(&pkg->cache_iter, &pkg_cache);
|
2013-02-25 23:36:09 +00:00
|
|
|
}
|
2013-02-26 05:29:57 +00:00
|
|
|
|
|
|
|
void
|
2015-09-06 15:50:23 +00:00
|
|
|
pkgconf_cache_free(void)
|
2013-02-26 05:29:57 +00:00
|
|
|
{
|
2015-09-06 15:31:21 +00:00
|
|
|
pkgconf_node_t *iter, *iter2;
|
2013-02-26 05:29:57 +00:00
|
|
|
|
2015-09-06 15:31:21 +00:00
|
|
|
PKGCONF_FOREACH_LIST_ENTRY_SAFE(pkg_cache.head, iter2, iter)
|
2013-02-26 05:29:57 +00:00
|
|
|
{
|
2015-09-06 16:20:48 +00:00
|
|
|
pkgconf_pkg_t *pkg = iter->data;
|
|
|
|
pkgconf_pkg_free(pkg);
|
2013-02-26 05:29:57 +00:00
|
|
|
}
|
|
|
|
}
|