261af7b55a2d4926163582a90d70e8c71edf8333
[platform/upstream/python-gobject.git] / gi / _glib / pyglib.h
1 /* -*- Mode: C; c-basic-offset: 4 -*-
2  * pyglib - Python bindings for GLib toolkit.
3  * Copyright (C) 1998-2003  James Henstridge
4  *               2004-2008  Johan Dahlin
5  *
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.
10  *
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.
15  *
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
19  * USA
20  */
21
22 #ifndef __PYGLIB_H__
23 #define __PYGLIB_H__
24
25 #include <Python.h>
26
27 #include <glib.h>
28
29 G_BEGIN_DECLS
30
31 typedef void (*PyGLibThreadsEnabledFunc) (void);
32 typedef void (*PyGLibThreadBlockFunc) (void);
33
34 void pyglib_init(void);
35 void pyglib_init_internal(PyObject *api);
36 PyGILState_STATE pyglib_gil_state_ensure(void);
37 void pyglib_gil_state_release(PyGILState_STATE state);
38 int pyglib_enable_threads(void);
39 gboolean pyglib_error_check(GError **error);
40 PyObject *pyglib_error_marshal (GError **error);
41 gboolean pyglib_gerror_exception_check(GError **error);
42 PyObject *pyglib_register_exception_for_domain(gchar *name,
43                                                gint error_domain);
44 gboolean pyglib_threads_enabled(void);
45 PyObject * pyglib_main_context_new(GMainContext *context);
46 void pyglib_set_thread_block_funcs(PyGLibThreadBlockFunc block_threads_func,
47                                    PyGLibThreadBlockFunc unblock_threads_func);
48 void pyglib_block_threads(void);
49 void pyglib_unblock_threads(void);
50 PyObject * pyglib_option_context_new(GOptionContext *context);
51 PyObject * pyglib_option_group_new(GOptionGroup *group);
52 GOptionGroup * pyglib_option_group_transfer_group(PyObject *self);
53 PyObject * pyglib_float_from_timeval(GTimeVal timeval);
54
55 /* Private: for gobject <-> glib interaction only. */
56 void _pyglib_notify_on_enabling_threads(PyGLibThreadsEnabledFunc callback);
57 PyObject* _pyglib_generic_ptr_richcompare(void* a, void *b, int op);
58 PyObject* _pyglib_generic_long_richcompare(long a, long b, int op);
59
60 #define pyglib_begin_allow_threads              \
61     G_STMT_START {                              \
62         PyThreadState *_save = NULL;            \
63         if (pyglib_threads_enabled())           \
64             _save = PyEval_SaveThread();
65
66 #define pyglib_end_allow_threads                \
67         if (pyglib_threads_enabled())           \
68             PyEval_RestoreThread(_save);        \
69     } G_STMT_END
70
71 #define PYGLIB_REGISTER_TYPE(d, type, name)             \
72     if (!type.tp_alloc)                                 \
73         type.tp_alloc = PyType_GenericAlloc;            \
74     if (!type.tp_new)                                   \
75         type.tp_new = PyType_GenericNew;                \
76     if (PyType_Ready(&type))                            \
77         return;                                         \
78     PyDict_SetItemString(d, name, (PyObject *)&type);
79
80
81 G_END_DECLS
82
83 #endif /* __PYGLIB_H__ */
84