xref: /netbsd/common/include/prop/prop_array.h (revision ca95539f)
1*ca95539fSthorpej /*     $NetBSD: prop_array.h,v 1.17 2020/06/06 21:25:59 thorpej Exp $    */
2774eb1a3Sthorpej 
3774eb1a3Sthorpej /*-
4*ca95539fSthorpej  * Copyright (c) 2006, 2009, 2020 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__)
69133d4142Sbad struct plistref;
70133d4142Sbad 
711aea07a3Sthorpej #if !defined(_KERNEL) && !defined(_STANDALONE)
72133d4142Sbad bool		prop_array_externalize_to_pref(prop_array_t, struct plistref *);
7314d305f3Sjym bool		prop_array_internalize_from_pref(const struct plistref *,
7414d305f3Sjym 		                                 prop_array_t *);
751aea07a3Sthorpej int		prop_array_send_ioctl(prop_array_t, int, unsigned long);
761aea07a3Sthorpej int		prop_array_recv_ioctl(int, unsigned long, prop_array_t *);
7714d305f3Sjym int		prop_array_send_syscall(prop_array_t, struct plistref *);
7814d305f3Sjym int		prop_array_recv_syscall(const struct plistref *,
798e917281Sbouyer 					prop_array_t *);
801aea07a3Sthorpej #elif defined(_KERNEL)
81133d4142Sbad int		prop_array_copyin(const struct plistref *, prop_array_t *);
82387431baSchristos int		prop_array_copyin_size(const struct plistref *, prop_array_t *,
83387431baSchristos 				       size_t);
84e50fbcf3Sbouyer int		prop_array_copyout(struct plistref *, prop_array_t);
851aea07a3Sthorpej int		prop_array_copyin_ioctl(const struct plistref *, const u_long,
861aea07a3Sthorpej 					prop_array_t *);
87c5c48cdbSchristos int		prop_array_copyin_ioctl_size(const struct plistref *,
88c5c48cdbSchristos 					     const u_long, prop_array_t *,
89c5c48cdbSchristos 					     size_t);
901aea07a3Sthorpej int		prop_array_copyout_ioctl(struct plistref *, const u_long,
911aea07a3Sthorpej 					 prop_array_t);
921aea07a3Sthorpej #endif
931aea07a3Sthorpej #endif /* __NetBSD__ */
941aea07a3Sthorpej 
959b09c481Shaad /*
969b09c481Shaad  * Utility routines to make it more convenient to work with values
979b09c481Shaad  * stored in dictionaries.
989b09c481Shaad  */
999b09c481Shaad bool		prop_array_get_bool(prop_array_t, unsigned int,
1009b09c481Shaad 					 bool *);
1019b09c481Shaad bool		prop_array_set_bool(prop_array_t, unsigned int,
1029b09c481Shaad 					 bool);
1039b09c481Shaad 
104*ca95539fSthorpej bool		prop_array_get_schar(prop_array_t, unsigned int,
105*ca95539fSthorpej 					 signed char *);
106*ca95539fSthorpej bool		prop_array_get_uchar(prop_array_t, unsigned int,
107*ca95539fSthorpej 					 unsigned char *);
108*ca95539fSthorpej bool		prop_array_set_schar(prop_array_t, unsigned int,
109*ca95539fSthorpej 					 signed char);
110*ca95539fSthorpej bool		prop_array_set_uchar(prop_array_t, unsigned int,
111*ca95539fSthorpej 					 unsigned char);
112*ca95539fSthorpej 
113*ca95539fSthorpej bool		prop_array_get_short(prop_array_t, unsigned int,
114*ca95539fSthorpej 					 short *);
115*ca95539fSthorpej bool		prop_array_get_ushort(prop_array_t, unsigned int,
116*ca95539fSthorpej 					 unsigned short *);
117*ca95539fSthorpej bool		prop_array_set_short(prop_array_t, unsigned int,
118*ca95539fSthorpej 					 short);
119*ca95539fSthorpej bool		prop_array_set_ushort(prop_array_t, unsigned int,
120*ca95539fSthorpej 					 unsigned short);
121*ca95539fSthorpej 
122*ca95539fSthorpej bool		prop_array_get_int(prop_array_t, unsigned int,
123*ca95539fSthorpej 					 int *);
124*ca95539fSthorpej bool		prop_array_get_uint(prop_array_t, unsigned int,
125*ca95539fSthorpej 					 unsigned int *);
126*ca95539fSthorpej bool		prop_array_set_int(prop_array_t, unsigned int,
127*ca95539fSthorpej 					 int);
128*ca95539fSthorpej bool		prop_array_set_uint(prop_array_t, unsigned int,
129*ca95539fSthorpej 					 unsigned int);
130*ca95539fSthorpej 
131*ca95539fSthorpej bool		prop_array_get_long(prop_array_t, unsigned int,
132*ca95539fSthorpej 					 long *);
133*ca95539fSthorpej bool		prop_array_get_ulong(prop_array_t, unsigned int,
134*ca95539fSthorpej 					 unsigned long *);
135*ca95539fSthorpej bool		prop_array_set_long(prop_array_t, unsigned int,
136*ca95539fSthorpej 					 long);
137*ca95539fSthorpej bool		prop_array_set_ulong(prop_array_t, unsigned int,
138*ca95539fSthorpej 					 unsigned long);
139*ca95539fSthorpej 
140*ca95539fSthorpej bool		prop_array_get_longlong(prop_array_t, unsigned int,
141*ca95539fSthorpej 					 long long *);
142*ca95539fSthorpej bool		prop_array_get_ulonglong(prop_array_t, unsigned int,
143*ca95539fSthorpej 					 unsigned long long *);
144*ca95539fSthorpej bool		prop_array_set_longlong(prop_array_t, unsigned int,
145*ca95539fSthorpej 					 long long);
146*ca95539fSthorpej bool		prop_array_set_ulonglong(prop_array_t, unsigned int,
147*ca95539fSthorpej 					 unsigned long long);
148*ca95539fSthorpej 
149*ca95539fSthorpej bool		prop_array_get_intptr(prop_array_t, unsigned int,
150*ca95539fSthorpej 					 intptr_t *);
151*ca95539fSthorpej bool		prop_array_get_uintptr(prop_array_t, unsigned int,
152*ca95539fSthorpej 					 uintptr_t *);
153*ca95539fSthorpej bool		prop_array_set_intptr(prop_array_t, unsigned int,
154*ca95539fSthorpej 					 intptr_t);
155*ca95539fSthorpej bool		prop_array_set_uintptr(prop_array_t, unsigned int,
156*ca95539fSthorpej 					 uintptr_t);
157*ca95539fSthorpej 
1589b09c481Shaad bool		prop_array_get_int8(prop_array_t, unsigned int,
1599b09c481Shaad 					 int8_t *);
1609b09c481Shaad bool		prop_array_get_uint8(prop_array_t, unsigned int,
1619b09c481Shaad 					  uint8_t *);
1629b09c481Shaad bool		prop_array_set_int8(prop_array_t, unsigned int,
1639b09c481Shaad 					 int8_t);
1649b09c481Shaad bool		prop_array_set_uint8(prop_array_t, unsigned int,
1659b09c481Shaad 					  uint8_t);
1669b09c481Shaad 
1679b09c481Shaad bool		prop_array_get_int16(prop_array_t, unsigned int,
1689b09c481Shaad 					  int16_t *);
1699b09c481Shaad bool		prop_array_get_uint16(prop_array_t, unsigned int,
1709b09c481Shaad 					   uint16_t *);
1719b09c481Shaad bool		prop_array_set_int16(prop_array_t, unsigned int,
1729b09c481Shaad 					  int16_t);
1739b09c481Shaad bool		prop_array_set_uint16(prop_array_t, unsigned int,
1749b09c481Shaad 					   uint16_t);
1759b09c481Shaad 
1769b09c481Shaad bool		prop_array_get_int32(prop_array_t, unsigned int,
1779b09c481Shaad 					  int32_t *);
1789b09c481Shaad bool		prop_array_get_uint32(prop_array_t, unsigned int,
1799b09c481Shaad 					   uint32_t *);
1809b09c481Shaad bool		prop_array_set_int32(prop_array_t, unsigned int,
1819b09c481Shaad 					  int32_t);
1829b09c481Shaad bool		prop_array_set_uint32(prop_array_t, unsigned int,
1839b09c481Shaad 					   uint32_t);
1849b09c481Shaad 
1859b09c481Shaad bool		prop_array_get_int64(prop_array_t, unsigned int,
1869b09c481Shaad 					  int64_t *);
1879b09c481Shaad bool		prop_array_get_uint64(prop_array_t, unsigned int,
1889b09c481Shaad 					   uint64_t *);
1899b09c481Shaad bool		prop_array_set_int64(prop_array_t, unsigned int,
1909b09c481Shaad 					  int64_t);
1919b09c481Shaad bool		prop_array_set_uint64(prop_array_t, unsigned int,
1929b09c481Shaad 					   uint64_t);
1939b09c481Shaad 
194*ca95539fSthorpej bool		prop_array_set_and_rel(prop_array_t, unsigned int,
195*ca95539fSthorpej 				       prop_object_t);
196*ca95539fSthorpej 
197*ca95539fSthorpej bool		prop_array_add_bool(prop_array_t, bool);
198*ca95539fSthorpej 
199*ca95539fSthorpej bool		prop_array_add_schar(prop_array_t, signed char);
200*ca95539fSthorpej bool		prop_array_add_uchar(prop_array_t, unsigned char);
201*ca95539fSthorpej 
202*ca95539fSthorpej bool		prop_array_add_short(prop_array_t, short);
203*ca95539fSthorpej bool		prop_array_add_ushort(prop_array_t, unsigned short);
204*ca95539fSthorpej 
205*ca95539fSthorpej bool		prop_array_add_int(prop_array_t, int);
206*ca95539fSthorpej bool		prop_array_add_uint(prop_array_t, unsigned int);
207*ca95539fSthorpej 
208*ca95539fSthorpej bool		prop_array_add_long(prop_array_t, long);
209*ca95539fSthorpej bool		prop_array_add_ulong(prop_array_t, unsigned long);
210*ca95539fSthorpej 
211*ca95539fSthorpej bool		prop_array_add_longlong(prop_array_t, long long);
212*ca95539fSthorpej bool		prop_array_add_ulonglong(prop_array_t, unsigned long long);
213*ca95539fSthorpej 
214*ca95539fSthorpej bool		prop_array_add_intptr(prop_array_t, intptr_t);
215*ca95539fSthorpej bool		prop_array_add_uintptr(prop_array_t, uintptr_t);
216*ca95539fSthorpej 
217185aec71Shaad bool		prop_array_add_int8(prop_array_t, int8_t);
218185aec71Shaad bool		prop_array_add_uint8(prop_array_t, uint8_t);
219185aec71Shaad 
220185aec71Shaad bool		prop_array_add_int16(prop_array_t, int16_t);
221185aec71Shaad bool		prop_array_add_uint16(prop_array_t, uint16_t);
222185aec71Shaad 
223185aec71Shaad bool		prop_array_add_int32(prop_array_t, int32_t);
224185aec71Shaad bool		prop_array_add_uint32(prop_array_t, uint32_t);
225185aec71Shaad 
226185aec71Shaad bool		prop_array_add_int64(prop_array_t, int64_t);
227185aec71Shaad bool		prop_array_add_uint64(prop_array_t, uint64_t);
228185aec71Shaad 
229*ca95539fSthorpej bool		prop_array_get_string(prop_array_t, unsigned int,
230*ca95539fSthorpej 						const char **);
231*ca95539fSthorpej bool		prop_array_set_string(prop_array_t, unsigned int,
232*ca95539fSthorpej 						const char *);
233*ca95539fSthorpej bool		prop_array_add_string(prop_array_t, const char *);
234*ca95539fSthorpej bool		prop_array_set_string_nocopy(prop_array_t, unsigned int,
235*ca95539fSthorpej 						const char *);
236*ca95539fSthorpej bool		prop_array_add_string_nocopy(prop_array_t, const char *);
237*ca95539fSthorpej 
238*ca95539fSthorpej bool		prop_array_get_data(prop_array_t, unsigned int,
239*ca95539fSthorpej 					const void **, size_t *);
240*ca95539fSthorpej bool		prop_array_set_data(prop_array_t, unsigned int,
241*ca95539fSthorpej 					const void *, size_t);
242*ca95539fSthorpej bool		prop_array_add_data(prop_array_t,
243*ca95539fSthorpej 					const void *, size_t);
244*ca95539fSthorpej bool		prop_array_set_data_nocopy(prop_array_t, unsigned int,
245*ca95539fSthorpej 					const void *, size_t);
246*ca95539fSthorpej bool		prop_array_add_data_nocopy(prop_array_t,
247*ca95539fSthorpej 					const void *, size_t);
248*ca95539fSthorpej 
249*ca95539fSthorpej bool		prop_array_add_and_rel(prop_array_t, prop_object_t);
250*ca95539fSthorpej 
251*ca95539fSthorpej 
252*ca95539fSthorpej /* Deprecated functions. */
253*ca95539fSthorpej 
2540ba895e6Spgoyette bool		prop_array_add_cstring(prop_array_t, const char *);
2559b09c481Shaad bool		prop_array_get_cstring(prop_array_t, unsigned int,
2569b09c481Shaad 					     char **);
2579b09c481Shaad bool		prop_array_set_cstring(prop_array_t, unsigned int,
2589b09c481Shaad 					    const char *);
2599b09c481Shaad 
2600ba895e6Spgoyette bool		prop_array_add_cstring_nocopy(prop_array_t, const char *);
2619b09c481Shaad bool		prop_array_get_cstring_nocopy(prop_array_t,
2629b09c481Shaad                                                    unsigned int,
2639b09c481Shaad 						   const char **);
2649b09c481Shaad bool		prop_array_set_cstring_nocopy(prop_array_t,
2659b09c481Shaad 						   unsigned int,
2669b09c481Shaad 						   const char *);
267774eb1a3Sthorpej __END_DECLS
268774eb1a3Sthorpej 
269774eb1a3Sthorpej #endif /* _PROPLIB_PROP_ARRAY_H_ */
270