~ubuntu-branches/ubuntu/trusty/libpeas/trusty

« back to all changes in this revision

Viewing changes to .pc/gint_is_not_gtype/libpeas/peas-extension.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2011-08-10 07:15:52 UTC
  • Revision ID: james.westby@ubuntu.com-20110810071552-akj88j7f12wsu46a
Tags: 1.1.1-0ubuntu2
debian/patches/gint_is_not_gtype: do not cast pointers to unsigned
integers.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * peas-extension.c
 
3
 * This file is part of libpeas
 
4
 *
 
5
 * Copyright (C) 2010 Steve Frécinaux
 
6
 *
 
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.
 
11
 *
 
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.
 
16
 *
 
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.
 
20
 */
 
21
 
 
22
#ifdef HAVE_CONFIG_H
 
23
#include <config.h>
 
24
#endif
 
25
 
 
26
#include "peas-extension.h"
 
27
#include "peas-extension-wrapper.h"
 
28
#include "peas-introspection.h"
 
29
 
 
30
/**
 
31
 * SECTION:peas-extension
 
32
 * @short_description: Proxy for extensions.
 
33
 * @see_also: #PeasExtensionSet
 
34
 *
 
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
 
38
 * loaded plugins.
 
39
 *
 
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:
 
45
 *
 
46
 * |[
 
47
 * g_irepository_require (g_irepository_get_default (),
 
48
 *                        "Peas", "1.0", 0, NULL);
 
49
 * ]|
 
50
 *
 
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.
 
54
 *
 
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
 
60
 * with.
 
61
 *
 
62
 * See peas_extension_call() for more information.
 
63
 **/
 
64
GType
 
65
peas_extension_get_type (void)
 
66
{
 
67
  return G_TYPE_OBJECT;
 
68
}
 
69
 
 
70
/**
 
71
 * peas_extension_get_extension_type:
 
72
 * @exten: A #PeasExtension.
 
73
 *
 
74
 * Get the type of the extension interface of the object proxied by @exten.
 
75
 *
 
76
 * Return value: The #Gtype proxied by @exten.
 
77
 */
 
78
GType
 
79
peas_extension_get_extension_type (PeasExtension *exten)
 
80
{
 
81
  if (PEAS_IS_EXTENSION_WRAPPER (exten))
 
82
    {
 
83
      return peas_extension_wrapper_get_extension_type (PEAS_EXTENSION_WRAPPER (exten));
 
84
    }
 
85
  else
 
86
    {
 
87
      return GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (exten), "peas-extension-type"));
 
88
    }
 
89
}
 
90
 
 
91
/**
 
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.
 
96
 *
 
97
 * Call a method of the object behind @extension.
 
98
 *
 
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.
 
104
 *
 
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); ]|
 
109
 *
 
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().
 
112
 *
 
113
 * Return value: %TRUE on successful call.
 
114
 *
 
115
 * Deprecated: 1.2. Use the dynamically implemented interface instead.
 
116
 */
 
117
gboolean
 
118
peas_extension_call (PeasExtension *exten,
 
119
                     const gchar   *method_name,
 
120
                     ...)
 
121
{
 
122
  va_list args;
 
123
  gboolean result;
 
124
 
 
125
  g_return_val_if_fail (PEAS_IS_EXTENSION (exten), FALSE);
 
126
  g_return_val_if_fail (method_name != NULL, FALSE);
 
127
 
 
128
  va_start (args, method_name);
 
129
  result = peas_extension_call_valist (exten, method_name, args);
 
130
  va_end (args);
 
131
 
 
132
  return result;
 
133
}
 
134
 
 
135
/**
 
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.
 
140
 *
 
141
 * Call a method of the object behind @extension, using @args as arguments.
 
142
 *
 
143
 * See peas_extension_call() for more information.
 
144
 *
 
145
 * Return value: %TRUE on successful call.
 
146
 *
 
147
 * Deprecated: 1.2. Use the dynamically implemented interface instead.
 
148
 */
 
149
gboolean
 
150
peas_extension_call_valist (PeasExtension *exten,
 
151
                            const gchar   *method_name,
 
152
                            va_list        args)
 
153
{
 
154
  GICallableInfo *callable_info;
 
155
  GITypeInfo retval_info;
 
156
  GIArgument *gargs;
 
157
  GIArgument retval;
 
158
  gpointer retval_ptr;
 
159
  gboolean ret;
 
160
  gint n_args;
 
161
 
 
162
  g_return_val_if_fail (PEAS_IS_EXTENSION (exten), FALSE);
 
163
  g_return_val_if_fail (method_name != NULL, FALSE);
 
164
 
 
165
  callable_info = peas_gi_get_method_info (peas_extension_get_extension_type (exten),
 
166
                                           method_name);
 
167
 
 
168
  /* Already warned */
 
169
  if (callable_info == NULL)
 
170
    return FALSE;
 
171
 
 
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);
 
176
 
 
177
  ret = peas_extension_callv (exten, method_name, gargs, &retval);
 
178
 
 
179
  if (retval_ptr != NULL)
 
180
    {
 
181
      g_callable_info_load_return_type (callable_info, &retval_info);
 
182
      peas_gi_argument_to_pointer (&retval_info, &retval, retval_ptr);
 
183
    }
 
184
 
 
185
  g_base_info_unref ((GIBaseInfo *) callable_info);
 
186
 
 
187
  return ret;
 
188
}
 
189
 
 
190
/**
 
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.
 
196
 *
 
197
 * Call a method of the object behind @extension, using @args as arguments.
 
198
 *
 
199
 * See peas_extension_call() for more information.
 
200
 *
 
201
 * Return value: (transfer full): %TRUE on successful call.
 
202
 *
 
203
 * Deprecated: 1.2. Use the dynamically implemented interface instead.
 
204
 *
 
205
 * Rename to: peas_extension_call
 
206
 */
 
207
gboolean
 
208
peas_extension_callv (PeasExtension *exten,
 
209
                      const gchar   *method_name,
 
210
                      GIArgument    *args,
 
211
                      GIArgument    *return_value)
 
212
{
 
213
  if (PEAS_IS_EXTENSION_WRAPPER (exten))
 
214
    {
 
215
      return peas_extension_wrapper_callv (PEAS_EXTENSION_WRAPPER (exten),
 
216
                                           method_name,
 
217
                                           args,
 
218
                                           return_value);
 
219
    }
 
220
  else
 
221
    {
 
222
      GType gtype = peas_extension_get_extension_type (exten);
 
223
 
 
224
      return peas_method_apply (G_OBJECT (exten),
 
225
                                gtype,
 
226
                                method_name,
 
227
                                args,
 
228
                                return_value);
 
229
    }
 
230
}