1*be89757eSLionel Sambuc /* $NetBSD: prop_array.h,v 1.13 2011/09/30 22:08:18 jym Exp $ */ 2*be89757eSLionel Sambuc 3*be89757eSLionel Sambuc /*- 4*be89757eSLionel Sambuc * Copyright (c) 2006, 2009 The NetBSD Foundation, Inc. 5*be89757eSLionel Sambuc * All rights reserved. 6*be89757eSLionel Sambuc * 7*be89757eSLionel Sambuc * This code is derived from software contributed to The NetBSD Foundation 8*be89757eSLionel Sambuc * by Jason R. Thorpe. 9*be89757eSLionel Sambuc * 10*be89757eSLionel Sambuc * Redistribution and use in source and binary forms, with or without 11*be89757eSLionel Sambuc * modification, are permitted provided that the following conditions 12*be89757eSLionel Sambuc * are met: 13*be89757eSLionel Sambuc * 1. Redistributions of source code must retain the above copyright 14*be89757eSLionel Sambuc * notice, this list of conditions and the following disclaimer. 15*be89757eSLionel Sambuc * 2. Redistributions in binary form must reproduce the above copyright 16*be89757eSLionel Sambuc * notice, this list of conditions and the following disclaimer in the 17*be89757eSLionel Sambuc * documentation and/or other materials provided with the distribution. 18*be89757eSLionel Sambuc * 19*be89757eSLionel Sambuc * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20*be89757eSLionel Sambuc * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21*be89757eSLionel Sambuc * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22*be89757eSLionel Sambuc * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23*be89757eSLionel Sambuc * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24*be89757eSLionel Sambuc * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25*be89757eSLionel Sambuc * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26*be89757eSLionel Sambuc * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27*be89757eSLionel Sambuc * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28*be89757eSLionel Sambuc * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29*be89757eSLionel Sambuc * POSSIBILITY OF SUCH DAMAGE. 30*be89757eSLionel Sambuc */ 31*be89757eSLionel Sambuc 32*be89757eSLionel Sambuc #ifndef _PROPLIB_PROP_ARRAY_H_ 33*be89757eSLionel Sambuc #define _PROPLIB_PROP_ARRAY_H_ 34*be89757eSLionel Sambuc 35*be89757eSLionel Sambuc #include <prop/prop_object.h> 36*be89757eSLionel Sambuc 37*be89757eSLionel Sambuc typedef struct _prop_array *prop_array_t; 38*be89757eSLionel Sambuc 39*be89757eSLionel Sambuc __BEGIN_DECLS 40*be89757eSLionel Sambuc prop_array_t prop_array_create(void); 41*be89757eSLionel Sambuc prop_array_t prop_array_create_with_capacity(unsigned int); 42*be89757eSLionel Sambuc 43*be89757eSLionel Sambuc prop_array_t prop_array_copy(prop_array_t); 44*be89757eSLionel Sambuc prop_array_t prop_array_copy_mutable(prop_array_t); 45*be89757eSLionel Sambuc 46*be89757eSLionel Sambuc unsigned int prop_array_capacity(prop_array_t); 47*be89757eSLionel Sambuc unsigned int prop_array_count(prop_array_t); 48*be89757eSLionel Sambuc bool prop_array_ensure_capacity(prop_array_t, unsigned int); 49*be89757eSLionel Sambuc 50*be89757eSLionel Sambuc void prop_array_make_immutable(prop_array_t); 51*be89757eSLionel Sambuc bool prop_array_mutable(prop_array_t); 52*be89757eSLionel Sambuc 53*be89757eSLionel Sambuc prop_object_iterator_t prop_array_iterator(prop_array_t); 54*be89757eSLionel Sambuc 55*be89757eSLionel Sambuc prop_object_t prop_array_get(prop_array_t, unsigned int); 56*be89757eSLionel Sambuc bool prop_array_set(prop_array_t, unsigned int, prop_object_t); 57*be89757eSLionel Sambuc bool prop_array_add(prop_array_t, prop_object_t); 58*be89757eSLionel Sambuc void prop_array_remove(prop_array_t, unsigned int); 59*be89757eSLionel Sambuc 60*be89757eSLionel Sambuc bool prop_array_equals(prop_array_t, prop_array_t); 61*be89757eSLionel Sambuc 62*be89757eSLionel Sambuc char * prop_array_externalize(prop_array_t); 63*be89757eSLionel Sambuc prop_array_t prop_array_internalize(const char *); 64*be89757eSLionel Sambuc 65*be89757eSLionel Sambuc bool prop_array_externalize_to_file(prop_array_t, const char *); 66*be89757eSLionel Sambuc prop_array_t prop_array_internalize_from_file(const char *); 67*be89757eSLionel Sambuc 68*be89757eSLionel Sambuc #if defined(__NetBSD__) 69*be89757eSLionel Sambuc struct plistref; 70*be89757eSLionel Sambuc 71*be89757eSLionel Sambuc #if !defined(_KERNEL) && !defined(_STANDALONE) 72*be89757eSLionel Sambuc bool prop_array_externalize_to_pref(prop_array_t, struct plistref *); 73*be89757eSLionel Sambuc bool prop_array_internalize_from_pref(const struct plistref *, 74*be89757eSLionel Sambuc prop_array_t *); 75*be89757eSLionel Sambuc int prop_array_send_ioctl(prop_array_t, int, unsigned long); 76*be89757eSLionel Sambuc int prop_array_recv_ioctl(int, unsigned long, prop_array_t *); 77*be89757eSLionel Sambuc int prop_array_send_syscall(prop_array_t, struct plistref *); 78*be89757eSLionel Sambuc int prop_array_recv_syscall(const struct plistref *, 79*be89757eSLionel Sambuc prop_array_t *); 80*be89757eSLionel Sambuc #elif defined(_KERNEL) 81*be89757eSLionel Sambuc int prop_array_copyin(const struct plistref *, prop_array_t *); 82*be89757eSLionel Sambuc int prop_array_copyout(struct plistref *, prop_array_t); 83*be89757eSLionel Sambuc int prop_array_copyin_ioctl(const struct plistref *, const u_long, 84*be89757eSLionel Sambuc prop_array_t *); 85*be89757eSLionel Sambuc int prop_array_copyout_ioctl(struct plistref *, const u_long, 86*be89757eSLionel Sambuc prop_array_t); 87*be89757eSLionel Sambuc #endif 88*be89757eSLionel Sambuc #endif /* __NetBSD__ */ 89*be89757eSLionel Sambuc 90*be89757eSLionel Sambuc /* 91*be89757eSLionel Sambuc * Utility routines to make it more convenient to work with values 92*be89757eSLionel Sambuc * stored in dictionaries. 93*be89757eSLionel Sambuc */ 94*be89757eSLionel Sambuc bool prop_array_get_bool(prop_array_t, unsigned int, 95*be89757eSLionel Sambuc bool *); 96*be89757eSLionel Sambuc bool prop_array_set_bool(prop_array_t, unsigned int, 97*be89757eSLionel Sambuc bool); 98*be89757eSLionel Sambuc 99*be89757eSLionel Sambuc bool prop_array_get_int8(prop_array_t, unsigned int, 100*be89757eSLionel Sambuc int8_t *); 101*be89757eSLionel Sambuc bool prop_array_get_uint8(prop_array_t, unsigned int, 102*be89757eSLionel Sambuc uint8_t *); 103*be89757eSLionel Sambuc bool prop_array_set_int8(prop_array_t, unsigned int, 104*be89757eSLionel Sambuc int8_t); 105*be89757eSLionel Sambuc bool prop_array_set_uint8(prop_array_t, unsigned int, 106*be89757eSLionel Sambuc uint8_t); 107*be89757eSLionel Sambuc 108*be89757eSLionel Sambuc bool prop_array_get_int16(prop_array_t, unsigned int, 109*be89757eSLionel Sambuc int16_t *); 110*be89757eSLionel Sambuc bool prop_array_get_uint16(prop_array_t, unsigned int, 111*be89757eSLionel Sambuc uint16_t *); 112*be89757eSLionel Sambuc bool prop_array_set_int16(prop_array_t, unsigned int, 113*be89757eSLionel Sambuc int16_t); 114*be89757eSLionel Sambuc bool prop_array_set_uint16(prop_array_t, unsigned int, 115*be89757eSLionel Sambuc uint16_t); 116*be89757eSLionel Sambuc 117*be89757eSLionel Sambuc bool prop_array_get_int32(prop_array_t, unsigned int, 118*be89757eSLionel Sambuc int32_t *); 119*be89757eSLionel Sambuc bool prop_array_get_uint32(prop_array_t, unsigned int, 120*be89757eSLionel Sambuc uint32_t *); 121*be89757eSLionel Sambuc bool prop_array_set_int32(prop_array_t, unsigned int, 122*be89757eSLionel Sambuc int32_t); 123*be89757eSLionel Sambuc bool prop_array_set_uint32(prop_array_t, unsigned int, 124*be89757eSLionel Sambuc uint32_t); 125*be89757eSLionel Sambuc 126*be89757eSLionel Sambuc bool prop_array_get_int64(prop_array_t, unsigned int, 127*be89757eSLionel Sambuc int64_t *); 128*be89757eSLionel Sambuc bool prop_array_get_uint64(prop_array_t, unsigned int, 129*be89757eSLionel Sambuc uint64_t *); 130*be89757eSLionel Sambuc bool prop_array_set_int64(prop_array_t, unsigned int, 131*be89757eSLionel Sambuc int64_t); 132*be89757eSLionel Sambuc bool prop_array_set_uint64(prop_array_t, unsigned int, 133*be89757eSLionel Sambuc uint64_t); 134*be89757eSLionel Sambuc 135*be89757eSLionel Sambuc bool prop_array_add_int8(prop_array_t, int8_t); 136*be89757eSLionel Sambuc bool prop_array_add_uint8(prop_array_t, uint8_t); 137*be89757eSLionel Sambuc 138*be89757eSLionel Sambuc bool prop_array_add_int16(prop_array_t, int16_t); 139*be89757eSLionel Sambuc bool prop_array_add_uint16(prop_array_t, uint16_t); 140*be89757eSLionel Sambuc 141*be89757eSLionel Sambuc bool prop_array_add_int32(prop_array_t, int32_t); 142*be89757eSLionel Sambuc bool prop_array_add_uint32(prop_array_t, uint32_t); 143*be89757eSLionel Sambuc 144*be89757eSLionel Sambuc bool prop_array_add_int64(prop_array_t, int64_t); 145*be89757eSLionel Sambuc bool prop_array_add_uint64(prop_array_t, uint64_t); 146*be89757eSLionel Sambuc 147*be89757eSLionel Sambuc bool prop_array_get_cstring(prop_array_t, unsigned int, 148*be89757eSLionel Sambuc char **); 149*be89757eSLionel Sambuc bool prop_array_set_cstring(prop_array_t, unsigned int, 150*be89757eSLionel Sambuc const char *); 151*be89757eSLionel Sambuc 152*be89757eSLionel Sambuc bool prop_array_get_cstring_nocopy(prop_array_t, 153*be89757eSLionel Sambuc unsigned int, 154*be89757eSLionel Sambuc const char **); 155*be89757eSLionel Sambuc bool prop_array_set_cstring_nocopy(prop_array_t, 156*be89757eSLionel Sambuc unsigned int, 157*be89757eSLionel Sambuc const char *); 158*be89757eSLionel Sambuc 159*be89757eSLionel Sambuc bool prop_array_add_and_rel(prop_array_t, prop_object_t); 160*be89757eSLionel Sambuc 161*be89757eSLionel Sambuc __END_DECLS 162*be89757eSLionel Sambuc 163*be89757eSLionel Sambuc #endif /* _PROPLIB_PROP_ARRAY_H_ */ 164