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, see <http://www.gnu.org/licenses/>.
22 #include "pygi-ccallback.h"
24 #include <girepository.h>
25 #include <pyglib-python-compat.h>
29 _ccallback_call(PyGICCallback
*self
, PyObject
*args
, PyObject
*kwargs
)
33 if (self
->cache
== NULL
) {
34 self
->cache
= (PyGICCallbackCache
*)pygi_ccallback_cache_new (self
->info
,
36 if (self
->cache
== NULL
)
40 result
= pygi_ccallback_cache_invoke (self
->cache
,
47 PYGLIB_DEFINE_TYPE("gi.CCallback", PyGICCallback_Type
, PyGICCallback
);
50 _pygi_ccallback_new (GCallback callback
,
54 GDestroyNotify destroy_notify
)
62 self
= (PyGICCallback
*) PyGICCallback_Type
.tp_alloc (&PyGICCallback_Type
, 0);
67 self
->callback
= (GCallback
) callback
;
68 self
->user_data
= user_data
;
70 self
->destroy_notify_func
= destroy_notify
;
71 self
->info
= g_base_info_ref( (GIBaseInfo
*) info
);
73 return (PyObject
*) self
;
77 _ccallback_dealloc (PyGICCallback
*self
)
79 g_base_info_unref ( (GIBaseInfo
*)self
->info
);
81 if (self
->cache
!= NULL
) {
82 pygi_callable_cache_free ( (PyGICallableCache
*)self
->cache
);
85 Py_TYPE (self
)->tp_free ((PyObject
*)self
);
89 _pygi_ccallback_register_types (PyObject
*m
)
91 Py_TYPE(&PyGICCallback_Type
) = &PyType_Type
;
92 PyGICCallback_Type
.tp_flags
= (Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_BASETYPE
);
93 PyGICCallback_Type
.tp_dealloc
= (destructor
) _ccallback_dealloc
;
94 PyGICCallback_Type
.tp_call
= (ternaryfunc
) _ccallback_call
;
97 if (PyType_Ready (&PyGICCallback_Type
))
99 if (PyModule_AddObject (m
, "CCallback", (PyObject
*) &PyGICCallback_Type
))