2 * Copyright (c) 2011-2013 Apple Inc. All rights reserved.
4 * @APPLE_APACHE_LICENSE_HEADER_START@
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * @APPLE_APACHE_LICENSE_HEADER_END@
22 * IMPORTANT: This header file describes INTERNAL interfaces to libdispatch
23 * which are subject to change in future releases of Mac OS X. Any applications
24 * relying on these interfaces WILL break.
27 #ifndef __DISPATCH_DATA_PRIVATE__
28 #define __DISPATCH_DATA_PRIVATE__
30 #ifndef __DISPATCH_INDIRECT__
31 #error "Please #include <dispatch/dispatch.h> instead of this file directly."
32 #include <dispatch/base.h> // for HeaderDoc
35 DISPATCH_ASSUME_NONNULL_BEGIN
40 * @const DISPATCH_DATA_DESTRUCTOR_NONE
41 * @discussion The destructor for dispatch data objects that require no buffer
42 * memory management. This can be used to allow a data object to efficiently
43 * encapsulate buffers that should not be copied or freed by the system.
45 #define DISPATCH_DATA_DESTRUCTOR_NONE (_dispatch_data_destructor_none)
46 __OSX_AVAILABLE_STARTING(__MAC_10_8
, __IPHONE_6_0
)
47 DISPATCH_DATA_DESTRUCTOR_TYPE_DECL(none
);
50 * @const DISPATCH_DATA_DESTRUCTOR_VM_DEALLOCATE
51 * @discussion The destructor for dispatch data objects that have been created
52 * from buffers that require deallocation using vm_deallocate.
54 #define DISPATCH_DATA_DESTRUCTOR_VM_DEALLOCATE \
55 (_dispatch_data_destructor_vm_deallocate)
56 __OSX_AVAILABLE_STARTING(__MAC_10_8
, __IPHONE_6_0
) DISPATCH_LINUX_UNAVAILABLE()
57 DISPATCH_DATA_DESTRUCTOR_TYPE_DECL(vm_deallocate
);
60 * @function dispatch_data_create_f
61 * Creates a dispatch data object from the given contiguous buffer of memory. If
62 * a non-default destructor is provided, ownership of the buffer remains with
63 * the caller (i.e. the bytes will not be copied). The last release of the data
64 * object will result in the invocation of the specified destructor function on
65 * specified queue to free the buffer (passed as the context parameter).
67 * If the DISPATCH_DATA_DESTRUCTOR_FREE destructor is provided the buffer will
68 * be freed via free(3) and the queue argument ignored.
70 * If the DISPATCH_DATA_DESTRUCTOR_DEFAULT destructor is provided, data object
71 * creation will copy the buffer into internal memory managed by the system.
73 * @param buffer A contiguous buffer of data.
74 * @param size The size of the contiguous buffer of data.
75 * @param queue The queue to which the destructor should be submitted.
76 * @param destructor The destructor function responsible for freeing the
77 * data buffer when it is no longer needed.
78 * @result A newly created dispatch data object.
80 __OSX_AVAILABLE_STARTING(__MAC_10_9
,__IPHONE_7_0
)
81 DISPATCH_EXPORT DISPATCH_RETURNS_RETAINED DISPATCH_WARN_RESULT DISPATCH_NOTHROW
83 dispatch_data_create_f(const void *buffer
,
85 dispatch_queue_t _Nullable queue
,
86 dispatch_function_t _Nullable destructor
);
89 * @function dispatch_data_create_alloc
90 * Creates a dispatch data object representing a newly allocated memory region
91 * of the given size. If a non-NULL reference to a pointer is provided, it is
92 * filled with the location of the memory region.
94 * It is the responsibility of the application to ensure that the data object
95 * becomes immutable (i.e. the returned memory region is not further modified)
96 * once the dispatch data object is passed to other API.
98 * @param size The size of the required allocation.
99 * @param buffer_ptr A pointer to a pointer variable to be filled with the
100 * location of the newly allocated memory region, or NULL.
101 * @result A newly created dispatch data object.
103 __OSX_AVAILABLE_STARTING(__MAC_10_9
,__IPHONE_6_0
)
104 DISPATCH_EXPORT DISPATCH_RETURNS_RETAINED
105 DISPATCH_WARN_RESULT DISPATCH_NOTHROW
107 dispatch_data_create_alloc(size_t size
, void *_Nullable
*_Nullable buffer_ptr
);
110 * @typedef dispatch_data_applier_function_t
111 * A function to be invoked for every contiguous memory region in a data object.
113 * @param context Application-defined context parameter.
114 * @param region A data object representing the current region.
115 * @param offset The logical offset of the current region to the start
116 * of the data object.
117 * @param buffer The location of the memory for the current region.
118 * @param size The size of the memory for the current region.
119 * @result A Boolean indicating whether traversal should continue.
121 typedef bool (*dispatch_data_applier_function_t
)(void *_Nullable context
,
122 dispatch_data_t region
, size_t offset
, const void *buffer
, size_t size
);
125 * @function dispatch_data_apply_f
126 * Traverse the memory regions represented by the specified dispatch data object
127 * in logical order and invoke the specified function once for every contiguous
128 * memory region encountered.
130 * Each invocation of the function is passed a data object representing the
131 * current region and its logical offset, along with the memory location and
132 * extent of the region. These allow direct read access to the memory region,
133 * but are only valid until the passed-in region object is released. Note that
134 * the region object is released by the system when the function returns, it is
135 * the responsibility of the application to retain it if the region object or
136 * the associated memory location are needed after the function returns.
138 * @param data The data object to traverse.
139 * @param context The application-defined context to pass to the function.
140 * @param applier The function to be invoked for every contiguous memory
141 * region in the data object.
142 * @result A Boolean indicating whether traversal completed
145 __OSX_AVAILABLE_STARTING(__MAC_10_9
,__IPHONE_6_0
)
146 DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_NOTHROW
148 dispatch_data_apply_f(dispatch_data_t data
, void *_Nullable context
,
149 dispatch_data_applier_function_t applier
);
153 * @function dispatch_data_make_memory_entry
154 * Return a mach memory entry for the memory regions represented by the
155 * specified dispatch data object.
157 * For data objects created with the DISPATCH_DATA_DESTRUCTOR_VM_DEALLOCATE
158 * destructor, directly makes a memory entry from the represented region;
159 * otherwise, makes a memory entry from newly allocated pages containing a copy
160 * of the represented memory regions.
162 * @param data The data object to make a memory entry for.
163 * @result A mach port for the newly made memory entry, or
164 * MACH_PORT_NULL if an error occurred.
166 __OSX_AVAILABLE_STARTING(__MAC_10_9
,__IPHONE_6_0
)
167 DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_NOTHROW
169 dispatch_data_make_memory_entry(dispatch_data_t data
);
173 * @functiongroup Dispatch data transform SPI
177 * @typedef dispatch_data_format_type_t
180 * Data formats are used to specify the input and output types of data supplied
181 * to dispatch_data_create_transform.
183 typedef const struct dispatch_data_format_type_s
*dispatch_data_format_type_t
;
186 #define DISPATCH_DATA_FORMAT_TYPE_DECL(name) \
187 DISPATCH_EXPORT const struct dispatch_data_format_type_s \
188 _dispatch_data_format_type_##name
190 #define DISPATCH_DATA_FORMAT_TYPE_DECL(name) \
191 DISPATCH_EXPORT struct dispatch_data_format_type_s \
192 _dispatch_data_format_type_##name
196 * @const DISPATCH_DATA_FORMAT_TYPE_NONE
197 * @discussion A data format denoting that the given input or output format is,
198 * or should be, comprised of raw data bytes with no given encoding.
200 #define DISPATCH_DATA_FORMAT_TYPE_NONE (&_dispatch_data_format_type_none)
201 __OSX_AVAILABLE_STARTING(__MAC_10_8
, __IPHONE_6_0
)
202 DISPATCH_DATA_FORMAT_TYPE_DECL(none
);
205 * @const DISPATCH_DATA_FORMAT_TYPE_BASE32
206 * @discussion A data format denoting that the given input or output format is,
207 * or should be, encoded in Base32 (RFC 4648) format. On input, this format will
208 * skip whitespace characters. Cannot be used in conjunction with UTF format
211 #define DISPATCH_DATA_FORMAT_TYPE_BASE32 (&_dispatch_data_format_type_base32)
212 __OSX_AVAILABLE_STARTING(__MAC_10_8
, __IPHONE_6_0
)
213 DISPATCH_DATA_FORMAT_TYPE_DECL(base32
);
216 * @const DISPATCH_DATA_FORMAT_TYPE_BASE32HEX
217 * @discussion A data format denoting that the given input or output format is,
218 * or should be, encoded in Base32Hex (RFC 4648) format. On input, this format
219 * will skip whitespace characters. Cannot be used in conjunction with UTF
222 #define DISPATCH_DATA_FORMAT_TYPE_BASE32HEX \
223 (&_dispatch_data_format_type_base32hex)
224 __OSX_AVAILABLE_STARTING(__MAC_10_9
, __IPHONE_7_0
)
225 DISPATCH_DATA_FORMAT_TYPE_DECL(base32hex
);
228 * @const DISPATCH_DATA_FORMAT_TYPE_BASE64
229 * @discussion A data format denoting that the given input or output format is,
230 * or should be, encoded in Base64 (RFC 4648) format. On input, this format will
231 * skip whitespace characters. Cannot be used in conjunction with UTF format
234 #define DISPATCH_DATA_FORMAT_TYPE_BASE64 (&_dispatch_data_format_type_base64)
235 __OSX_AVAILABLE_STARTING(__MAC_10_8
, __IPHONE_6_0
)
236 DISPATCH_DATA_FORMAT_TYPE_DECL(base64
);
239 * @const DISPATCH_DATA_FORMAT_TYPE_UTF8
240 * @discussion A data format denoting that the given input or output format is,
241 * or should be, encoded in UTF-8 format. Is only valid when used in conjunction
242 * with other UTF format types.
244 #define DISPATCH_DATA_FORMAT_TYPE_UTF8 (&_dispatch_data_format_type_utf8)
245 __OSX_AVAILABLE_STARTING(__MAC_10_8
, __IPHONE_6_0
)
246 DISPATCH_DATA_FORMAT_TYPE_DECL(utf8
);
249 * @const DISPATCH_DATA_FORMAT_TYPE_UTF16LE
250 * @discussion A data format denoting that the given input or output format is,
251 * or should be, encoded in UTF-16LE format. Is only valid when used in
252 * conjunction with other UTF format types.
254 #define DISPATCH_DATA_FORMAT_TYPE_UTF16LE (&_dispatch_data_format_type_utf16le)
255 __OSX_AVAILABLE_STARTING(__MAC_10_8
, __IPHONE_6_0
)
256 DISPATCH_DATA_FORMAT_TYPE_DECL(utf16le
);
259 * @const DISPATCH_DATA_FORMAT_TYPE_UTF16BE
260 * @discussion A data format denoting that the given input or output format is,
261 * or should be, encoded in UTF-16BE format. Is only valid when used in
262 * conjunction with other UTF format types.
264 #define DISPATCH_DATA_FORMAT_TYPE_UTF16BE (&_dispatch_data_format_type_utf16be)
265 __OSX_AVAILABLE_STARTING(__MAC_10_8
, __IPHONE_6_0
)
266 DISPATCH_DATA_FORMAT_TYPE_DECL(utf16be
);
269 * @const DISPATCH_DATA_FORMAT_TYPE_UTFANY
270 * @discussion A data format denoting that dispatch_data_create_transform should
271 * attempt to automatically detect the input type based on the presence of a
272 * byte order mark character at the beginning of the data. In the absence of a
273 * BOM, the data will be assumed to be in UTF-8 format. Only valid as an input
276 #define DISPATCH_DATA_FORMAT_TYPE_UTF_ANY (&_dispatch_data_format_type_utf_any)
277 __OSX_AVAILABLE_STARTING(__MAC_10_8
, __IPHONE_6_0
)
278 DISPATCH_DATA_FORMAT_TYPE_DECL(utf_any
);
281 * @function dispatch_data_create_transform
282 * Returns a new dispatch data object after transforming the given data object
283 * from the supplied format, into the given output format.
286 * The data object representing the region(s) of memory to transform.
288 * Flags specifying the input format of the source dispatch_data_t
291 * Flags specifying the expected output format of the resulting transformation.
294 * A newly created dispatch data object, dispatch_data_empty if no has been
295 * produced, or NULL if an error occurred.
298 __OSX_AVAILABLE_STARTING(__MAC_10_8
, __IPHONE_6_0
)
299 DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_RETURNS_RETAINED
300 DISPATCH_WARN_RESULT DISPATCH_NOTHROW
302 dispatch_data_create_with_transform(dispatch_data_t data
,
303 dispatch_data_format_type_t input_type
,
304 dispatch_data_format_type_t output_type
);
308 DISPATCH_ASSUME_NONNULL_END
310 #endif // __DISPATCH_DATA_PRIVATE__