Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 271 lines (238 sloc) 8.14 kb
5b9d7e19 »
2009-12-23 initial commit
1 /*
2 * Copyright (c) 2008-2009, Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. Neither the name of Apple Inc. ("Apple") nor the names of
13 * its contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR
20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
25 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #ifndef __BS_H_
30 #define __BS_H_
31
32 #if defined(__cplusplus)
33 extern "C" {
34 #endif
35
36 #include <CoreFoundation/CoreFoundation.h>
37 #include <objc/runtime.h>
38
39 /* Attribute and element representations.
40 * See BridgeSupport(5) for more information.
41 */
42
43 typedef enum {
44 BS_CARRAY_ARG_UNDEFINED = 0,
45 BS_CARRAY_ARG_LENGTH_IN_ARG,
46 BS_CARRAY_ARG_FIXED_LENGTH,
47 BS_CARRAY_ARG_VARIABLE_LENGTH,
48 BS_CARRAY_ARG_DELIMITED_BY_NULL
49 } bs_carray_arg_type_t;
50
51 typedef enum {
52 BS_TYPE_MODIFIER_UNDEFINED = 0,
53 BS_TYPE_MODIFIER_IN,
54 BS_TYPE_MODIFIER_OUT,
55 BS_TYPE_MODIFIER_INOUT
56 } bs_type_modifier_t;
57
58 typedef struct {
59 char *name;
60 char *type;
61 } bs_element_struct_field_t;
62
63 typedef struct {
64 char *name;
65 char *type;
66 bs_element_struct_field_t *fields;
67 unsigned fields_count;
68 bool opaque;
69 } bs_element_struct_t;
70
71 typedef struct {
72 char *name;
73 char *type;
74 char *tollfree;
75 CFTypeID type_id; /* 0 if unknown */
76 } bs_element_cftype_t;
77
78 typedef struct {
79 char *name;
80 char *type;
81 } bs_element_opaque_t;
82
83 typedef struct {
84 char *name;
85 char *type;
86 bool magic_cookie;
87 bool ignore;
88 char *suggestion;
89 } bs_element_constant_t;
90
91 typedef struct {
92 char *name;
93 char *value;
94 bool nsstring;
95 } bs_element_string_constant_t;
96
97 typedef struct {
98 char *name;
99 char *value;
100 bool ignore;
101 char *suggestion;
102 } bs_element_enum_t;
103
104 struct __bs_element_arg;
105 struct __bs_element_retval;
106 typedef struct __bs_element_arg bs_element_arg_t;
107 typedef struct __bs_element_retval bs_element_retval_t;
108
109 typedef struct {
110 bs_element_arg_t *args;
111 unsigned args_count;
112 bs_element_retval_t *retval;
113 } bs_element_function_pointer_t;
114
115 struct __bs_element_arg {
116 int index; /* if -1, not used */
117 char *type;
118 bs_type_modifier_t type_modifier;
119 bs_carray_arg_type_t carray_type;
120 bs_element_function_pointer_t *function_pointer; /* can be NULL */
121 int carray_type_value;
122 bool null_accepted;
123 bool printf_format;
124 char *sel_of_type;
125 };
126
127 struct __bs_element_retval {
128 char *type;
129 bs_carray_arg_type_t carray_type;
130 bs_element_function_pointer_t *function_pointer; /* can be NULL */
131 int carray_type_value;
132 bool already_retained;
133 };
134
135 typedef struct {
136 char *name;
137 bs_element_arg_t *args;
138 unsigned args_count;
139 bs_element_retval_t *retval;
140 bool variadic;
141 } bs_element_function_t;
142
143 typedef struct {
144 char *name;
145 char *original;
146 } bs_element_function_alias_t;
147
148 typedef struct {
149 SEL name;
150 bs_element_arg_t *args;
151 unsigned args_count;
152 bs_element_retval_t *retval;
153 bool class_method;
154 bool variadic;
155 bool ignore;
156 char *suggestion;
157 } bs_element_method_t;
158
159 typedef struct {
160 char *name;
161 bs_element_method_t *class_methods;
162 unsigned class_methods_count;
163 bs_element_method_t *instance_methods;
164 unsigned instance_methods_count;
165 } bs_element_class_t;
166
167 typedef struct {
168 SEL name;
169 char *type;
170 char *protocol_name;
171 bool class_method;
172 } bs_element_informal_protocol_method_t;
173
174 typedef enum {
175 BS_ELEMENT_STRUCT, /* bs_element_struct_t */
176 BS_ELEMENT_CFTYPE, /* bs_element_cftype_t */
177 BS_ELEMENT_OPAQUE, /* bs_element_opaque_t */
178 BS_ELEMENT_CONSTANT, /* bs_element_constant_t */
179 BS_ELEMENT_STRING_CONSTANT, /* bs_element_string_constant_t */
180 BS_ELEMENT_ENUM, /* bs_element_enum_t */
181 BS_ELEMENT_FUNCTION, /* bs_element_function_t */
182 BS_ELEMENT_FUNCTION_ALIAS, /* bs_element_function_alias_t */
183 BS_ELEMENT_CLASS, /* bs_element_class_t */
184 BS_ELEMENT_INFORMAL_PROTOCOL_METHOD
185 /* bs_element_informal_protocol_method_t */
186 } bs_element_type_t;
187
188 /* bs_find_path()
189 *
190 * Finds the path of a framework's bridge support file, by looking at the
191 * following locations, in order of priority:
192 * - inside the main executable bundle (if any), in the Resources/BridgeSupport directory ;
193 * - inside the framework bundle, in the Resources/BridgeSupport directory ;
194 * - in ~/Library/BridgeSupport ;
195 * - in /Library/BridgeSupport ;
196 * - in /System/Library/BridgeSupport.
197 * Returns true on success, false otherwise.
198 *
199 * framework_path: the full path of the framework.
200 * path: a pointer to a pre-allocated string that will contain the bridge
201 * support path on success.
202 * path_len: the size of the path argument.
203 */
204 bool bs_find_path(const char *framework_path, char *path, const size_t path_len);
205
206 /* bs_parser_new()
207 *
208 * Creates and returns a parser object, required for bs_parser_parse().
209 * Use bs_parser_free() when you're done.
210 */
211 typedef struct _bs_parser bs_parser_t;
212 bs_parser_t *bs_parser_new(void);
213
214 /* bs_parser_free()
215 *
216 * Frees a previously-created parser object.
217 */
218 void bs_parser_free(bs_parser_t *parser);
219
220 typedef void (*bs_parse_callback_t)
221 (bs_parser_t *parser, const char *path, bs_element_type_t type, void *value,
222 void *context);
223
224 typedef enum {
225 /* Default option: parse bridge support files. */
226 BS_PARSE_OPTIONS_DEFAULT = 0,
227 /* Parse bridge support files and dlopen(3) the dylib files, if any. */
228 BS_PARSE_OPTIONS_LOAD_DYLIBS
229 } bs_parse_options_t;
230
231 /* bs_parse()
232 *
233 * Parses a given bridge support file, calling back a given function pointer
234 * for every parsed element. You are responsible to free every element passed
235 * to the callback function, using bs_element_free().
236 * Returns true on success, otherwise false.
237 *
238 * parser: the parser object.
239 * path: the full path of the bridge support file to parse.
240 * framework_path: the full path of the framework this bridge support file
241 * comes from. This is only required if options is BS_PARSE_OPTIONS_LOAD_DYLIBS
242 * in order to locate the dylib files. Pass NULL if you are passing the
243 * default BS_PARSE_OPTIONS_DEFAULT option.
244 * options: parsing options.
245 * callback: a callback function pointer.
246 * context: a contextual data pointer that will be passed to the callback
247 * function.
248 * error: in case this function returns false, this variable is set to a newly
249 * allocated error message. You are responsible to free it. Pass NULL if you
250 * don't need it.
251 */
252 bool bs_parser_parse(bs_parser_t *parser, const char *path,
253 const char *framework_path, bs_parse_options_t options,
254 bs_parse_callback_t callback, void *context, char **error);
255
256 /* bs_element_free()
257 *
258 * Frees a bridge support element that was returned by bs_parse() through the
259 * callback method.
260 *
261 * type: the type of the bridge support element.
262 * value: a pointer to the bridge support element.
263 */
264 void bs_element_free(bs_element_type_t type, void *value);
265
266 #if defined(__cplusplus)
267 }
268 #endif
269
270 #endif /* __BS_H_ */
Something went wrong with that request. Please try again.