1 /* -*- Mode: C; c-basic-offset: 4 -*-
2 * vim: tabstop=4 shiftwidth=4 expandtab
4 * Copyright (C) 2011 John (J5) Palmieri <johnp@redhat.com>, Red Hat, Inc.
6 * pygi-boxed-closure.c: wrapper to handle GClosure box types with C callbacks.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
24 #include "pygi-private.h"
26 #include <pygobject.h>
27 #include <girepository.h>
28 #include <pyglib-python-compat.h>
32 _ccallback_call(PyGICCallback *self, PyObject *args, PyObject *kwargs)
37 if (self->cache == NULL) {
38 self->cache = _pygi_callable_cache_new (self->info, TRUE);
39 if (self->cache == NULL)
43 result = pygi_callable_info_invoke( (GIBaseInfo *) self->info,
52 PYGLIB_DEFINE_TYPE("gi.CCallback", PyGICCallback_Type, PyGICCallback);
55 _pygi_ccallback_new (GCallback callback,
59 GDestroyNotify destroy_notify)
67 self = (PyGICCallback *) PyGICCallback_Type.tp_alloc (&PyGICCallback_Type, 0);
72 self->callback = (GCallback) callback;
73 self->user_data = user_data;
75 self->destroy_notify_func = destroy_notify;
76 self->info = g_base_info_ref( (GIBaseInfo *) info);
78 return (PyObject *) self;
82 _ccallback_dealloc (PyGICCallback *self)
84 g_base_info_unref ( (GIBaseInfo *)self->info);
88 _pygi_ccallback_register_types (PyObject *m)
90 Py_TYPE(&PyGICCallback_Type) = &PyType_Type;
91 PyGICCallback_Type.tp_flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE);
92 PyGICCallback_Type.tp_dealloc = (destructor) _ccallback_dealloc;
93 PyGICCallback_Type.tp_call = (ternaryfunc) _ccallback_call;
96 if (PyType_Ready (&PyGICCallback_Type))
98 if (PyModule_AddObject (m, "CCallback", (PyObject *) &PyGICCallback_Type))