xref: /netbsd/common/include/prop/prop_array.h (revision 9b09c481)
1*9b09c481Shaad /*     $NetBSD: prop_array.h,v 1.7 2008/06/03 20:18:24 haad Exp $    */
2774eb1a3Sthorpej 
3774eb1a3Sthorpej /*-
4774eb1a3Sthorpej  * Copyright (c) 2006 The NetBSD Foundation, Inc.
5774eb1a3Sthorpej  * All rights reserved.
6774eb1a3Sthorpej  *
7774eb1a3Sthorpej  * This code is derived from software contributed to The NetBSD Foundation
8774eb1a3Sthorpej  * by Jason R. Thorpe.
9774eb1a3Sthorpej  *
10774eb1a3Sthorpej  * Redistribution and use in source and binary forms, with or without
11774eb1a3Sthorpej  * modification, are permitted provided that the following conditions
12774eb1a3Sthorpej  * are met:
13774eb1a3Sthorpej  * 1. Redistributions of source code must retain the above copyright
14774eb1a3Sthorpej  *    notice, this list of conditions and the following disclaimer.
15774eb1a3Sthorpej  * 2. Redistributions in binary form must reproduce the above copyright
16774eb1a3Sthorpej  *    notice, this list of conditions and the following disclaimer in the
17774eb1a3Sthorpej  *    documentation and/or other materials provided with the distribution.
18774eb1a3Sthorpej  *
19774eb1a3Sthorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20774eb1a3Sthorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21774eb1a3Sthorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22774eb1a3Sthorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23774eb1a3Sthorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24774eb1a3Sthorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25774eb1a3Sthorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26774eb1a3Sthorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27774eb1a3Sthorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28774eb1a3Sthorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29774eb1a3Sthorpej  * POSSIBILITY OF SUCH DAMAGE.
30774eb1a3Sthorpej  */
31774eb1a3Sthorpej 
32774eb1a3Sthorpej #ifndef _PROPLIB_PROP_ARRAY_H_
33774eb1a3Sthorpej #define	_PROPLIB_PROP_ARRAY_H_
34774eb1a3Sthorpej 
35774eb1a3Sthorpej #include <prop/prop_object.h>
36774eb1a3Sthorpej 
37774eb1a3Sthorpej typedef struct _prop_array *prop_array_t;
38774eb1a3Sthorpej 
39774eb1a3Sthorpej __BEGIN_DECLS
40774eb1a3Sthorpej prop_array_t	prop_array_create(void);
41774eb1a3Sthorpej prop_array_t	prop_array_create_with_capacity(unsigned int);
42774eb1a3Sthorpej 
43774eb1a3Sthorpej prop_array_t	prop_array_copy(prop_array_t);
44774eb1a3Sthorpej prop_array_t	prop_array_copy_mutable(prop_array_t);
45774eb1a3Sthorpej 
46774eb1a3Sthorpej unsigned int	prop_array_capacity(prop_array_t);
47774eb1a3Sthorpej unsigned int	prop_array_count(prop_array_t);
4804377267Sthorpej bool		prop_array_ensure_capacity(prop_array_t, unsigned int);
49774eb1a3Sthorpej 
50774eb1a3Sthorpej void		prop_array_make_immutable(prop_array_t);
5104377267Sthorpej bool		prop_array_mutable(prop_array_t);
52774eb1a3Sthorpej 
53774eb1a3Sthorpej prop_object_iterator_t prop_array_iterator(prop_array_t);
54774eb1a3Sthorpej 
55774eb1a3Sthorpej prop_object_t	prop_array_get(prop_array_t, unsigned int);
5604377267Sthorpej bool		prop_array_set(prop_array_t, unsigned int, prop_object_t);
5704377267Sthorpej bool		prop_array_add(prop_array_t, prop_object_t);
58774eb1a3Sthorpej void		prop_array_remove(prop_array_t, unsigned int);
593e69f1b2Sthorpej 
6004377267Sthorpej bool		prop_array_equals(prop_array_t, prop_array_t);
61d21620b2Sthorpej 
62d21620b2Sthorpej char *		prop_array_externalize(prop_array_t);
63d21620b2Sthorpej prop_array_t	prop_array_internalize(const char *);
64d21620b2Sthorpej 
6504377267Sthorpej bool		prop_array_externalize_to_file(prop_array_t, const char *);
66d21620b2Sthorpej prop_array_t	prop_array_internalize_from_file(const char *);
671aea07a3Sthorpej 
681aea07a3Sthorpej #if defined(__NetBSD__)
691aea07a3Sthorpej #if !defined(_KERNEL) && !defined(_STANDALONE)
701aea07a3Sthorpej int		prop_array_send_ioctl(prop_array_t, int, unsigned long);
711aea07a3Sthorpej int		prop_array_recv_ioctl(int, unsigned long, prop_array_t *);
721aea07a3Sthorpej #elif defined(_KERNEL)
731aea07a3Sthorpej struct plistref;
741aea07a3Sthorpej 
751aea07a3Sthorpej int		prop_array_copyin_ioctl(const struct plistref *, const u_long,
761aea07a3Sthorpej 					prop_array_t *);
771aea07a3Sthorpej int		prop_array_copyout_ioctl(struct plistref *, const u_long,
781aea07a3Sthorpej 					 prop_array_t);
791aea07a3Sthorpej #endif
801aea07a3Sthorpej #endif /* __NetBSD__ */
811aea07a3Sthorpej 
82*9b09c481Shaad /*
83*9b09c481Shaad  * Utility routines to make it more convenient to work with values
84*9b09c481Shaad  * stored in dictionaries.
85*9b09c481Shaad  */
86*9b09c481Shaad bool		prop_array_get_bool(prop_array_t, unsigned int,
87*9b09c481Shaad 					 bool *);
88*9b09c481Shaad bool		prop_array_set_bool(prop_array_t, unsigned int,
89*9b09c481Shaad 					 bool);
90*9b09c481Shaad 
91*9b09c481Shaad bool		prop_array_get_int8(prop_array_t, unsigned int,
92*9b09c481Shaad 					 int8_t *);
93*9b09c481Shaad bool		prop_array_get_uint8(prop_array_t, unsigned int,
94*9b09c481Shaad 					  uint8_t *);
95*9b09c481Shaad bool		prop_array_set_int8(prop_array_t, unsigned int,
96*9b09c481Shaad 					 int8_t);
97*9b09c481Shaad bool		prop_array_set_uint8(prop_array_t, unsigned int,
98*9b09c481Shaad 					  uint8_t);
99*9b09c481Shaad 
100*9b09c481Shaad bool		prop_array_get_int16(prop_array_t, unsigned int,
101*9b09c481Shaad 					  int16_t *);
102*9b09c481Shaad bool		prop_array_get_uint16(prop_array_t, unsigned int,
103*9b09c481Shaad 					   uint16_t *);
104*9b09c481Shaad bool		prop_array_set_int16(prop_array_t, unsigned int,
105*9b09c481Shaad 					  int16_t);
106*9b09c481Shaad bool		prop_array_set_uint16(prop_array_t, unsigned int,
107*9b09c481Shaad 					   uint16_t);
108*9b09c481Shaad 
109*9b09c481Shaad bool		prop_array_get_int32(prop_array_t, unsigned int,
110*9b09c481Shaad 					  int32_t *);
111*9b09c481Shaad bool		prop_array_get_uint32(prop_array_t, unsigned int,
112*9b09c481Shaad 					   uint32_t *);
113*9b09c481Shaad bool		prop_array_set_int32(prop_array_t, unsigned int,
114*9b09c481Shaad 					  int32_t);
115*9b09c481Shaad bool		prop_array_set_uint32(prop_array_t, unsigned int,
116*9b09c481Shaad 					   uint32_t);
117*9b09c481Shaad 
118*9b09c481Shaad bool		prop_array_get_int64(prop_array_t, unsigned int,
119*9b09c481Shaad 					  int64_t *);
120*9b09c481Shaad bool		prop_array_get_uint64(prop_array_t, unsigned int,
121*9b09c481Shaad 					   uint64_t *);
122*9b09c481Shaad bool		prop_array_set_int64(prop_array_t, unsigned int,
123*9b09c481Shaad 					  int64_t);
124*9b09c481Shaad bool		prop_array_set_uint64(prop_array_t, unsigned int,
125*9b09c481Shaad 					   uint64_t);
126*9b09c481Shaad 
127*9b09c481Shaad bool		prop_array_get_cstring(prop_array_t, unsigned int,
128*9b09c481Shaad 					     char **);
129*9b09c481Shaad bool		prop_array_set_cstring(prop_array_t, unsigned int,
130*9b09c481Shaad 					    const char *);
131*9b09c481Shaad 
132*9b09c481Shaad bool		prop_array_get_cstring_nocopy(prop_array_t,
133*9b09c481Shaad                                                    unsigned int,
134*9b09c481Shaad 						   const char **);
135*9b09c481Shaad bool		prop_array_set_cstring_nocopy(prop_array_t,
136*9b09c481Shaad 						   unsigned int,
137*9b09c481Shaad 						   const char *);
138*9b09c481Shaad 
139774eb1a3Sthorpej __END_DECLS
140774eb1a3Sthorpej 
141774eb1a3Sthorpej #endif /* _PROPLIB_PROP_ARRAY_H_ */
142