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.
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
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
)
32 vivi_breakpoint_step (ViviDebugger
*debugger
, ViviBreakpoint
*breakpoint
)
34 SwfdecAsObject
*obj
= SWFDEC_AS_OBJECT (breakpoint
);
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
);
42 vivi_breakpoint_enter_frame (ViviDebugger
*debugger
, SwfdecAsFrame
*frame
, ViviBreakpoint
*breakpoint
)
44 SwfdecAsObject
*obj
= SWFDEC_AS_OBJECT (breakpoint
);
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
);
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];
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
);
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];
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
);
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
) }
94 vivi_breakpoint_add (ViviBreakpoint
*breakpoint
, guint i
)
96 ViviDebugger
*debugger
= VIVI_APPLICATION (swfdec_gc_object_get_context (breakpoint
))->debugger
;
99 if (breakpoint
->active
) {
100 breakpoint
->handlers
[i
] = g_signal_connect (debugger
, events
[i
].signal
,
101 events
[i
].handler
, breakpoint
);
103 breakpoint
->handlers
[i
] = 1;
108 vivi_breakpoint_remove (ViviBreakpoint
*breakpoint
, guint i
)
110 ViviDebugger
*debugger
= VIVI_APPLICATION (swfdec_gc_object_get_context (breakpoint
))->debugger
;
113 if (breakpoint
->active
)
114 g_signal_handler_disconnect (debugger
, breakpoint
->handlers
[i
]);
115 breakpoint
->handlers
[i
] = 0;
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
);
129 vivi_breakpoint_class_init (ViviBreakpointClass
*klass
)
131 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
133 object_class
->dispose
= vivi_breakpoint_dispose
;
137 vivi_breakpoint_init (ViviBreakpoint
*breakpoint
)
139 breakpoint
->active
= TRUE
;
143 vivi_breakpoint_set_active (ViviBreakpoint
*breakpoint
, gboolean active
)
147 g_return_if_fail (VIVI_IS_BREAKPOINT (breakpoint
));
149 g_print ("active = %d", active
);
150 if (breakpoint
->active
== active
)
152 breakpoint
->active
= !breakpoint
->active
;
153 for (i
= 1; i
< G_N_ELEMENTS (events
); i
++) {
154 if (breakpoint
->handlers
[i
] == 0)
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
);
166 VIVI_FUNCTION ("breakpoint_active_get", vivi_breakpoint_as_get_active
)
168 vivi_breakpoint_as_get_active (SwfdecAsContext
*cx
, SwfdecAsObject
*this,
169 guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*retval
)
171 if (!VIVI_IS_BREAKPOINT (this))
174 SWFDEC_AS_VALUE_SET_BOOLEAN (retval
, VIVI_BREAKPOINT (this)->active
);
177 VIVI_FUNCTION ("breakpoint_active_set", vivi_breakpoint_as_set_active
)
179 vivi_breakpoint_as_set_active (SwfdecAsContext
*cx
, SwfdecAsObject
*this,
180 guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*retval
)
182 if (!VIVI_IS_BREAKPOINT (this) ||
185 vivi_breakpoint_set_active (VIVI_BREAKPOINT (this), swfdec_as_value_to_boolean (cx
, &argv
[0]));