diff options
author | Dmitri Pal <dpal@redhat.com> | 2009-12-23 15:14:51 -0500 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2010-01-21 15:02:16 -0500 |
commit | 743d22b5f0592d0dba1d4d9040d998c9d711603e (patch) | |
tree | 60dc14c74dac91764bf5a462b3a5ef96418f491f /common/refarray/ref_array.h | |
parent | 526dd14cdc1461859a5dd1cdd83ee9b1268175fe (diff) | |
download | sssd-743d22b5f0592d0dba1d4d9040d998c9d711603e.tar.gz sssd-743d22b5f0592d0dba1d4d9040d998c9d711603e.tar.bz2 sssd-743d22b5f0592d0dba1d4d9040d998c9d711603e.zip |
REFARRAY: New referenced array object
This object allows creation the arrays
with the reference count. Usefull when
there are many instances of some object
have to reference dynamically allocated array
which is common for all these instances.
In case of ELAPI the event object
keeps a referecne to the common array
of the sinks in the fail over order.
We decided that it will be a common object
not specific only to ELAPI.
All the review concerns related to this
object have been addressed in this patch.
It also has been moved to the common area.
Diffstat (limited to 'common/refarray/ref_array.h')
-rw-r--r-- | common/refarray/ref_array.h | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/common/refarray/ref_array.h b/common/refarray/ref_array.h new file mode 100644 index 00000000..42112907 --- /dev/null +++ b/common/refarray/ref_array.h @@ -0,0 +1,84 @@ +/* + REF ARRAY + + Header file for of the dynamic array with reference count. + + Copyright (C) Dmitri Pal <dpal@redhat.com> 2009 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + This program 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 General Public License for more details. + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef REF_ARRAY_H +#define REF_ARRAY_H + +#include <stdint.h> +#include <stdlib.h> + +struct ref_array; + +#ifndef EOK +#define EOK 0 +#endif + +/*************************************/ +/* Interface to the referenced array */ +/*************************************/ + +typedef enum +{ + REF_ARRAY_DESTROY, + REF_ARRAY_DELETE, +} ref_array_del_enum; + +/* Callback that can be provided by caller + * to free data when the storage is actually destroyed + */ +typedef void (*ref_array_fn)(void *elem, + ref_array_del_enum type, + void *data); + + +/* Create referenced array */ +int ref_array_create(struct ref_array **ra, + size_t elem, + uint32_t grow_by, + ref_array_fn cb, + void *data); + +/* Get new reference to an array */ +struct ref_array *ref_array_getref(struct ref_array *ra); + +/* Delete the array */ +void ref_array_destroy(struct ref_array *ra); + +/* Add new element to the array */ +int ref_array_append(struct ref_array *ra, void *element); + +/* Get element */ +void *ref_array_get(struct ref_array *ra, uint32_t idx, void *acptr); + +/* Get array length */ +int ref_array_getlen(struct ref_array *ra, uint32_t *len); + +/* Alternative function to get length. + * Returns 0 if the array is invalid + */ +uint32_t ref_array_len(struct ref_array *ra); + + +/* In future in might make sense to add entry points + * to insert and delete elements from the array. + * Current use cases do not require this kind of + * functionality so it is left out of the implementation + */ + +#endif |