3
* This file is part of libpeas
5
* Copyright (C) 2010 Steve Frécinaux
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU Library General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU Library General Public License for more details.
17
* You should have received a copy of the GNU Library General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
#include "peas-extension.h"
27
#include "peas-extension-wrapper.h"
28
#include "peas-introspection.h"
31
* SECTION:peas-extension
32
* @short_description: Proxy for extensions.
33
* @see_also: #PeasExtensionSet
35
* #PeasExtension is a proxy class used to access actual extensions
36
* implemented using various languages. As such, the application writer will
37
* use #PeasExtension instances to call methods on extension provided by
40
* To properly use the proxy instances, you will need GObject-introspection
41
* data for the #GInterface or #GObjectClass you want to use as an extension
42
* point. For instance, if you wish to use #PeasActivatable, you will need to
43
* put the following code excerpt in the engine initialization code, in order
44
* to load the required "Peas" typelib:
47
* g_irepository_require (g_irepository_get_default (),
48
* "Peas", "1.0", 0, NULL);
51
* You should proceed the same way for any namespace which provides interfaces
52
* you want to use as extension points. GObject-introspection data is required
53
* for all the supported languages, even for C.
55
* #PeasExtension does not provide any way to access the underlying object.
56
* The main reason is that some loaders may not rely on proper GObject
57
* inheritance for the definition of extensions, and hence it would not be
58
* possible for libpeas to provide a functional GObject instance at all.
59
* Another reason is that it makes reference counting issues easier to deal
62
* See peas_extension_call() for more information.
65
peas_extension_get_type (void)
71
* peas_extension_get_extension_type:
72
* @exten: A #PeasExtension.
74
* Get the type of the extension interface of the object proxied by @exten.
76
* Return value: The #Gtype proxied by @exten.
79
peas_extension_get_extension_type (PeasExtension *exten)
81
if (PEAS_IS_EXTENSION_WRAPPER (exten))
83
return peas_extension_wrapper_get_extension_type (PEAS_EXTENSION_WRAPPER (exten));
87
return GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (exten), "peas-extension-type"));
92
* peas_extension_call: (skip)
93
* @exten: A #PeasExtension.
94
* @method_name: the name of the method that should be called.
95
* @...: arguments for the method.
97
* Call a method of the object behind @extension.
99
* The arguments provided to this functions should be of the same type as
100
* those defined in the #GInterface or #GObjectClass used as a base for the
101
* proxied extension. They should be provided in the same order, and if its
102
* return type is not void, then a pointer to a variable of that type should
103
* be passed as the last argument.
105
* For instance, if the method prototype is:
106
* |[ gint (*my_method) (MyClass *instance, const gchar *str, SomeObject *obj); ]|
107
* you should call peas_extension_call() this way:
108
* |[ peas_extension_call (extension, "my_method", "some_str", obj, &gint_var); ]|
110
* This function will not do anything if the introspection data for the proxied
111
* object's class has not been loaded previously through g_irepository_require().
113
* Return value: %TRUE on successful call.
115
* Deprecated: 1.2. Use the dynamically implemented interface instead.
118
peas_extension_call (PeasExtension *exten,
119
const gchar *method_name,
125
g_return_val_if_fail (PEAS_IS_EXTENSION (exten), FALSE);
126
g_return_val_if_fail (method_name != NULL, FALSE);
128
va_start (args, method_name);
129
result = peas_extension_call_valist (exten, method_name, args);
136
* peas_extension_call_valist: (skip)
137
* @exten: A #PeasExtension.
138
* @method_name: the name of the method that should be called.
139
* @args: the arguments for the method.
141
* Call a method of the object behind @extension, using @args as arguments.
143
* See peas_extension_call() for more information.
145
* Return value: %TRUE on successful call.
147
* Deprecated: 1.2. Use the dynamically implemented interface instead.
150
peas_extension_call_valist (PeasExtension *exten,
151
const gchar *method_name,
154
GICallableInfo *callable_info;
155
GITypeInfo retval_info;
162
g_return_val_if_fail (PEAS_IS_EXTENSION (exten), FALSE);
163
g_return_val_if_fail (method_name != NULL, FALSE);
165
callable_info = peas_gi_get_method_info (peas_extension_get_extension_type (exten),
169
if (callable_info == NULL)
172
n_args = g_callable_info_get_n_args (callable_info);
173
g_return_val_if_fail (n_args >= 0, FALSE);
174
gargs = g_newa (GIArgument, n_args);
175
peas_gi_valist_to_arguments (callable_info, args, gargs, &retval_ptr);
177
ret = peas_extension_callv (exten, method_name, gargs, &retval);
179
if (retval_ptr != NULL)
181
g_callable_info_load_return_type (callable_info, &retval_info);
182
peas_gi_argument_to_pointer (&retval_info, &retval, retval_ptr);
185
g_base_info_unref ((GIBaseInfo *) callable_info);
191
* peas_extension_callv:
192
* @exten: A #PeasExtension.
193
* @method_name: the name of the method that should be called.
194
* @args: the arguments for the method.
195
* @return_value: the return falue for the method.
197
* Call a method of the object behind @extension, using @args as arguments.
199
* See peas_extension_call() for more information.
201
* Return value: (transfer full): %TRUE on successful call.
203
* Deprecated: 1.2. Use the dynamically implemented interface instead.
205
* Rename to: peas_extension_call
208
peas_extension_callv (PeasExtension *exten,
209
const gchar *method_name,
211
GIArgument *return_value)
213
if (PEAS_IS_EXTENSION_WRAPPER (exten))
215
return peas_extension_wrapper_callv (PEAS_EXTENSION_WRAPPER (exten),
222
GType gtype = peas_extension_get_extension_type (exten);
224
return peas_method_apply (G_OBJECT (exten),