Code moved from callback.c
[clg] / glib / alien / callback.c
1 /* Common Lisp bindings for GTK+ v2.0
2 * Copyright (C) 1999-2002 Espen S. Johnsen <espen@users.sourceforge.net>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
19 /* $Id: callback.c,v 1.2 2004-10-31 11:34:47 espen Exp $ */
20
21 #include <glib-object.h>
22
23 #ifdef CMUCL
24 #include "lisp.h"
25 #include "alloc.h"
26 #include "arch.h"
27
28 lispobj callback_trampoline;
29 lispobj destroy_user_data;
30 lispobj log_handler;
31 #endif
32
33
34 void callback_marshal (guint callback_id, GValue *return_value,
35 guint n_params, const GValue *param_values)
36 {
37 #ifdef CMUCL
38 funcall3 (callback_trampoline, alloc_number ((unsigned int)callback_id),
39 alloc_cons (alloc_number (n_params), alloc_sap (param_values)),
40 alloc_sap (return_value));
41 #elif defined(CLISP)
42 callback_trampoline ((unsigned long)callback_id,
43 n_params, (unsigned int)param_values,
44 (unsigned int)return_value);
45 #endif
46 }
47
48 void destroy_notify (gpointer data)
49 {
50 #ifdef CMUCL
51 funcall1 (destroy_user_data, alloc_number ((unsigned long)data));
52 #elif defined(CLISP)
53 destroy_user_data ((unsigned long)data);
54 #endif
55 }
56
57 /* #ifndef CMUCL */
58 /* void* */
59 /* destroy_notify_address () */
60 /* { */
61 /* return (void*)destroy_notify; */
62 /* } */
63 /* #endif */
64
65
66
67 void closure_callback_marshal (GClosure *closure,
68 GValue *return_value,
69 guint n_params,
70 const GValue *param_values,
71 gpointer invocation_hint,
72 gpointer marshal_data)
73 {
74 callback_marshal ((guint)closure->data, return_value, n_params, param_values);
75 }
76
77 void closure_destroy_notify (gpointer data, GClosure *closure)
78 {
79 destroy_notify (data);
80 }
81
82 GClosure*
83 g_lisp_callback_closure_new (guint callback_id)
84 {
85 GClosure *closure;
86
87 closure = g_closure_new_simple (sizeof (GClosure), (gpointer)callback_id);
88 g_closure_set_marshal (closure, closure_callback_marshal);
89 g_closure_add_finalize_notifier (closure, (gpointer)callback_id, closure_destroy_notify);
90
91 return closure;
92 }
93
94
95 /* Callback function used for idle and timeout */
96 gboolean source_callback_marshal (gpointer data)
97 {
98 GValue return_value;
99
100 memset (&return_value, 0, sizeof (GValue));
101 g_value_init (&return_value, G_TYPE_BOOLEAN);
102 callback_marshal ((guint)data, &return_value, 0, NULL);
103
104 return g_value_get_boolean (&return_value);
105 }
106
107 void
108 g_logv (const gchar *log_domain,
109 GLogLevelFlags log_level,
110 const gchar *format,
111 va_list args1)
112 {
113 gchar *msg = g_strdup_vprintf (format, args1);
114 lispobj lisp_msg = alloc_string (msg);
115 g_free (msg);
116
117 funcall3 (log_handler, alloc_string (log_domain),
118 alloc_number ((unsigned int)log_level), lisp_msg);
119 }