COMPOSITE => OBJECT for PrintJob
[swfdec.git] / vivified / core / vivi_breakpoint.c
blob627c3b7250bb4cfea6998c10762fb825de8a5f3f
1 /* Vivified
2 * Copyright (C) 2007-2008 Benjamin Otte <otte@gnome.org>
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.1 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.
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., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301 USA
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
24 #include "vivi_breakpoint.h"
25 #include "vivi_application.h"
26 #include "vivi_function.h"
27 #include "vivi_wrap.h"
29 G_DEFINE_TYPE (ViviBreakpoint, vivi_breakpoint, SWFDEC_TYPE_AS_RELAY)
31 static gboolean
32 vivi_breakpoint_step (ViviDebugger *debugger, ViviBreakpoint *breakpoint)
34 SwfdecAsObject *obj = SWFDEC_AS_OBJECT (breakpoint);
35 SwfdecAsValue retval;
37 swfdec_as_object_call (obj, swfdec_as_context_get_string (swfdec_gc_object_get_context (obj), "onCommand"), 0, NULL, &retval);
38 return swfdec_as_value_to_boolean (swfdec_gc_object_get_context (obj), &retval);
41 static gboolean
42 vivi_breakpoint_enter_frame (ViviDebugger *debugger, SwfdecAsFrame *frame, ViviBreakpoint *breakpoint)
44 SwfdecAsObject *obj = SWFDEC_AS_OBJECT (breakpoint);
45 SwfdecAsValue val;
46 SwfdecAsValue retval;
48 SWFDEC_AS_VALUE_SET_OBJECT (&val, vivi_wrap_object (VIVI_APPLICATION (swfdec_gc_object_get_context (obj)), SWFDEC_AS_OBJECT (frame)));
49 swfdec_as_object_call (obj, swfdec_as_context_get_string (swfdec_gc_object_get_context (obj), "onEnterFrame"), 1, &val, &retval);
50 return swfdec_as_value_to_boolean (swfdec_gc_object_get_context (obj), &retval);
53 static gboolean
54 vivi_breakpoint_leave_frame (ViviDebugger *debugger, SwfdecAsFrame *frame, const SwfdecAsValue *ret, ViviBreakpoint *breakpoint)
56 SwfdecAsObject *obj = SWFDEC_AS_OBJECT (breakpoint);
57 SwfdecAsValue vals[2];
58 SwfdecAsValue retval;
60 SWFDEC_AS_VALUE_SET_OBJECT (&vals[0], vivi_wrap_object (VIVI_APPLICATION (swfdec_gc_object_get_context (obj)), SWFDEC_AS_OBJECT (frame)));
61 vivi_wrap_value (VIVI_APPLICATION (swfdec_gc_object_get_context (obj)), &vals[1], ret);
62 swfdec_as_object_call (obj, swfdec_as_context_get_string (swfdec_gc_object_get_context (obj), "onLeaveFrame"), 2, vals, &retval);
63 return swfdec_as_value_to_boolean (swfdec_gc_object_get_context (obj), &retval);
66 static gboolean
67 vivi_breakpoint_set_variable (ViviDebugger *debugger, SwfdecAsObject *object,
68 const char *variable, const SwfdecAsValue *value, ViviBreakpoint *breakpoint)
70 SwfdecAsObject *obj = SWFDEC_AS_OBJECT (breakpoint);
71 SwfdecAsValue vals[3];
72 SwfdecAsValue retval;
74 SWFDEC_AS_VALUE_SET_OBJECT (&vals[0], vivi_wrap_object (VIVI_APPLICATION (swfdec_gc_object_get_context (obj)), object));
75 SWFDEC_AS_VALUE_SET_STRING (&vals[1], swfdec_as_context_get_string (swfdec_gc_object_get_context (obj), variable));
76 vivi_wrap_value (VIVI_APPLICATION (swfdec_gc_object_get_context (obj)), &vals[2], value);
77 swfdec_as_object_call (obj, swfdec_as_context_get_string (swfdec_gc_object_get_context (obj), "onSetVariable"), 3, vals, &retval);
78 return swfdec_as_value_to_boolean (swfdec_gc_object_get_context (obj), &retval);
81 static const struct {
82 const char * event;
83 const char * signal;
84 GCallback handler;
85 } events[] = {
86 { NULL, NULL, NULL }, /* invalid */
87 { "onCommand", "step", G_CALLBACK (vivi_breakpoint_step) },
88 { "onEnterFrame", "enter-frame", G_CALLBACK (vivi_breakpoint_enter_frame) },
89 { "onLeaveFrame", "leave-frame", G_CALLBACK (vivi_breakpoint_leave_frame) },
90 { "onSetVariable", "set-variable", G_CALLBACK (vivi_breakpoint_set_variable) }
93 static void
94 vivi_breakpoint_add (ViviBreakpoint *breakpoint, guint i)
96 ViviDebugger *debugger = VIVI_APPLICATION (swfdec_gc_object_get_context (breakpoint))->debugger;
98 g_assert (i != 0);
99 if (breakpoint->active) {
100 breakpoint->handlers[i] = g_signal_connect (debugger, events[i].signal,
101 events[i].handler, breakpoint);
102 } else {
103 breakpoint->handlers[i] = 1;
107 static void
108 vivi_breakpoint_remove (ViviBreakpoint *breakpoint, guint i)
110 ViviDebugger *debugger = VIVI_APPLICATION (swfdec_gc_object_get_context (breakpoint))->debugger;
112 g_assert (i != 0);
113 if (breakpoint->active)
114 g_signal_handler_disconnect (debugger, breakpoint->handlers[i]);
115 breakpoint->handlers[i] = 0;
118 static void
119 vivi_breakpoint_dispose (GObject *object)
121 ViviBreakpoint *breakpoint = VIVI_BREAKPOINT (object);
123 vivi_breakpoint_set_active (breakpoint, FALSE);
125 G_OBJECT_CLASS (vivi_breakpoint_parent_class)->dispose (object);
128 static void
129 vivi_breakpoint_class_init (ViviBreakpointClass *klass)
131 GObjectClass *object_class = G_OBJECT_CLASS (klass);
133 object_class->dispose = vivi_breakpoint_dispose;
136 static void
137 vivi_breakpoint_init (ViviBreakpoint *breakpoint)
139 breakpoint->active = TRUE;
142 void
143 vivi_breakpoint_set_active (ViviBreakpoint *breakpoint, gboolean active)
145 guint i;
147 g_return_if_fail (VIVI_IS_BREAKPOINT (breakpoint));
149 g_print ("active = %d", active);
150 if (breakpoint->active == active)
151 return;
152 breakpoint->active = !breakpoint->active;
153 for (i = 1; i < G_N_ELEMENTS (events); i++) {
154 if (breakpoint->handlers[i] == 0)
155 continue;
156 /* FIXME: this is hacky */
157 breakpoint->active = !breakpoint->active;
158 vivi_breakpoint_remove (breakpoint, i);
159 breakpoint->active = !breakpoint->active;
160 vivi_breakpoint_add (breakpoint, i);
164 /*** AS CODE ***/
166 VIVI_FUNCTION ("breakpoint_active_get", vivi_breakpoint_as_get_active)
167 void
168 vivi_breakpoint_as_get_active (SwfdecAsContext *cx, SwfdecAsObject *this,
169 guint argc, SwfdecAsValue *argv, SwfdecAsValue *retval)
171 if (!VIVI_IS_BREAKPOINT (this))
172 return;
174 SWFDEC_AS_VALUE_SET_BOOLEAN (retval, VIVI_BREAKPOINT (this)->active);
177 VIVI_FUNCTION ("breakpoint_active_set", vivi_breakpoint_as_set_active)
178 void
179 vivi_breakpoint_as_set_active (SwfdecAsContext *cx, SwfdecAsObject *this,
180 guint argc, SwfdecAsValue *argv, SwfdecAsValue *retval)
182 if (!VIVI_IS_BREAKPOINT (this) ||
183 argc == 0)
184 return;
185 vivi_breakpoint_set_active (VIVI_BREAKPOINT (this), swfdec_as_value_to_boolean (cx, &argv[0]));