| 1 | /* |
| 2 | * Copyright 2011 Red Hat Inc., Durham, North Carolina. |
| 3 | * All Rights Reserved. |
| 4 | * |
| 5 | * This library is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Lesser General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2.1 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Lesser General Public |
| 16 | * License along with this library; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | * |
| 19 | * Authors: |
| 20 | * Daniel Kopecek <[email protected]> |
| 21 | */ |
| 22 | #ifndef RCACHE_H |
| 23 | #define RCACHE_H |
| 24 | |
| 25 | #include <stddef.h> |
| 26 | #include <sexp.h> |
| 27 | #include "../SEAP/generic/rbt/rbt.h" |
| 28 | |
| 29 | /** |
| 30 | * Probe cache structure. |
| 31 | */ |
| 32 | typedef struct { |
| 33 | rbt_t *tree; /**< red-black tree used to store the items */ |
| 34 | } probe_rcache_t; |
| 35 | |
| 36 | /** |
| 37 | * Create a new probe cache. |
| 38 | * @return probe cache pointer or NULL on failure |
| 39 | */ |
| 40 | probe_rcache_t *probe_rcache_new(void); |
| 41 | |
| 42 | /** |
| 43 | * Free the probe cache. This function frees the memory used to store |
| 44 | * the probe cache items and also the items themselves. |
| 45 | * @param cache the cache to be freed |
| 46 | */ |
| 47 | void probe_rcache_free(probe_rcache_t *cache); |
| 48 | |
| 49 | /** |
| 50 | * Add a new S-exp to the cache identified by an S-exp string. |
| 51 | * @param cache probe cache |
| 52 | * @param id S-exp string object containing the id |
| 53 | * @param item the S-exp (item) to be stored in the cache |
| 54 | * @retval 0 on success |
| 55 | * @retval -1 on failure |
| 56 | */ |
| 57 | int probe_rcache_sexp_add(probe_rcache_t *cache, const SEXP_t *id, SEXP_t *item); |
| 58 | |
| 59 | /** |
| 60 | * Add a new S-exp to the cache identified by a C string. |
| 61 | * @param cache probe cache |
| 62 | * @param id C string containing the id |
| 63 | * @param item the S-exp (item) to be stored in the cache |
| 64 | * @retval 0 on success |
| 65 | * @retval -1 on failure |
| 66 | */ |
| 67 | int probe_rcache_cstr_add(probe_rcache_t *cache, const char *id, SEXP_t *item); |
| 68 | |
| 69 | /** |
| 70 | * Delete an S-exp from the cache identified by an S-exp string. |
| 71 | * @param cache probe cache |
| 72 | * @param id S-exp string object containing the id |
| 73 | * @param item the S-exp (item) to be stored in the cache |
| 74 | * @retval 0 on success |
| 75 | * @retval -1 on failure |
| 76 | */ |
| 77 | int probe_rcache_sexp_del(probe_rcache_t *cache, const SEXP_t *id); |
| 78 | |
| 79 | |
| 80 | /** |
| 81 | * Delete an S-exp from the cache identified by a C string. |
| 82 | * @param cache probe cache |
| 83 | * @param id C string containing the id |
| 84 | * @param item the S-exp (item) to be stored in the cache |
| 85 | * @retval 0 on success |
| 86 | * @retval -1 on failure |
| 87 | */ |
| 88 | int probe_rcache_cstr_del(probe_rcache_t *cache, const char *id); |
| 89 | |
| 90 | /** |
| 91 | * Get a reference to an cached S-exp identified by an S-exp string. |
| 92 | * @param cache probe cache |
| 93 | * @param id S-exp string object containing the id |
| 94 | * @param item the S-exp (item) to be stored in the cache |
| 95 | * @retval S-exp reference to the requested item |
| 96 | */ |
| 97 | SEXP_t *probe_rcache_sexp_get(probe_rcache_t *cache, const SEXP_t *id); |
| 98 | |
| 99 | /** |
| 100 | * Get a reference to an cached S-exp identified by a C string. |
| 101 | * @param cache probe cache |
| 102 | * @param id C string containing the id |
| 103 | * @param item the S-exp (item) to be stored in the cache |
| 104 | * @retval S-exp reference to the requested item |
| 105 | */ |
| 106 | SEXP_t *probe_rcache_cstr_get(probe_rcache_t *cache, const char *id); |
| 107 | |
| 108 | #endif /* PROBE_RCACHE_H */ |