1 /* -*- Mode: C; c-basic-offset: 4 -*-
2 * vim: tabstop=4 shiftwidth=4 expandtab
4 * Copyright (C) 2011 John (J5) Palmieri <johnp@redhat.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
22 #ifndef __PYGI_CACHE_H__
23 #define __PYGI_CACHE_H__
26 #include <girepository.h>
28 #include "pygi-invoke-state-struct.h"
32 typedef struct _PyGICallableCache PyGICallableCache;
33 typedef struct _PyGIArgCache PyGIArgCache;
35 typedef gboolean (*PyGIMarshalFromPyFunc) (PyGIInvokeState *state,
36 PyGICallableCache *callable_cache,
37 PyGIArgCache *arg_cache,
41 typedef PyObject *(*PyGIMarshalToPyFunc) (PyGIInvokeState *state,
42 PyGICallableCache *callable_cache,
43 PyGIArgCache *arg_cache,
46 typedef void (*PyGIMarshalCleanupFunc) (PyGIInvokeState *state,
47 PyGIArgCache *arg_cache,
49 gboolean was_processed);
51 /* Argument meta types denote how we process the argument:
52 * - PYGI_META_ARG_TYPE_PARENT - parents may or may not have children
53 * but are always processed via the normal marshaller for their
54 * actual GI type. If they have children the marshaller will
55 * also handle marshalling the children.
56 * - PYGI_META_ARG_TYPE_CHILD - Children without python argument are
57 * ignored by the marshallers and handled directly by their parents
59 * - PYGI_META_ARG_TYPE_CHILD_NEEDS_UPDATE -Sometimes children arguments
60 * come before the parent. In these cases they need to be flagged
61 * so that the argument list counts must be updated for the cache to
63 * - Children with pyargs (PYGI_META_ARG_TYPE_CHILD_WITH_PYARG) are processed
64 * the same as other child args but also have an index into the
65 * python parameters passed to the invoker
68 PYGI_META_ARG_TYPE_PARENT,
69 PYGI_META_ARG_TYPE_CHILD,
70 PYGI_META_ARG_TYPE_CHILD_NEEDS_UPDATE,
71 PYGI_META_ARG_TYPE_CHILD_WITH_PYARG,
72 PYGI_META_ARG_TYPE_CLOSURE,
76 * GI determines function types via a combination of flags and info classes.
77 * Since for branching purposes they are mutually exclusive, the
78 * PyGIFunctionType enum consolidates them into one enumeration for ease of
79 * branching and debugging.
82 PYGI_FUNCTION_TYPE_FUNCTION,
83 PYGI_FUNCTION_TYPE_METHOD,
84 PYGI_FUNCTION_TYPE_CONSTRUCTOR,
85 PYGI_FUNCTION_TYPE_VFUNC,
86 PYGI_FUNCTION_TYPE_CALLBACK,
87 PYGI_FUNCTION_TYPE_CCALLBACK,
91 * In PyGI IN and OUT arguments mean different things depending on the context
92 * of the callable (e.g. is it a callback that is being called from C or a
93 * function that is being called from python). We don't as much care if the
94 * parameter is an IN or OUT C parameter, than we do if the parameter is being
95 * marshalled into Python or from Python.
98 PYGI_DIRECTION_TO_PYTHON,
99 PYGI_DIRECTION_FROM_PYTHON,
100 PYGI_DIRECTION_BIDIRECTIONAL
106 const gchar *arg_name;
108 PyGIMetaArgType meta_type;
110 gboolean is_caller_allocates;
114 PyGIDirection direction;
117 GITypeInfo *type_info;
119 PyGIMarshalFromPyFunc from_py_marshaller;
120 PyGIMarshalToPyFunc to_py_marshaller;
122 PyGIMarshalCleanupFunc from_py_cleanup;
123 PyGIMarshalCleanupFunc to_py_cleanup;
125 GDestroyNotify destroy_notify;
131 typedef struct _PyGISequenceCache
133 PyGIArgCache arg_cache;
135 gssize len_arg_index;
136 gboolean is_zero_terminated;
138 GIArrayType array_type;
139 PyGIArgCache *item_cache;
142 typedef struct _PyGIInterfaceCache
144 PyGIArgCache arg_cache;
148 GIInterfaceInfo *interface_info;
150 } PyGIInterfaceCache;
152 typedef struct _PyGIHashCache
154 PyGIArgCache arg_cache;
155 PyGIArgCache *key_cache;
156 PyGIArgCache *value_cache;
159 typedef struct _PyGICallbackCache
161 PyGIArgCache arg_cache;
162 gssize user_data_index;
163 gssize destroy_notify_index;
165 GIInterfaceInfo *interface_info;
168 struct _PyGICallableCache
172 PyGIFunctionType function_type;
174 PyGIArgCache *return_cache;
175 PyGIArgCache **args_cache;
177 GSList *arg_name_list; /* for keyword arg matching */
178 GHashTable *arg_name_hash;
181 gssize n_from_py_args;
183 gssize n_to_py_child_args;
189 void _pygi_arg_cache_clear (PyGIArgCache *cache);
190 void _pygi_callable_cache_free (PyGICallableCache *cache);
192 PyGICallableCache *_pygi_callable_cache_new (GICallableInfo *callable_info,
193 gboolean is_ccallback);
197 #endif /* __PYGI_CACHE_H__ */