2 * Copyright (C) 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
26 #include "swfdec_as_relay.h"
27 #include "swfdec_as_context.h"
28 #include "swfdec_as_object.h"
29 #include "swfdec_as_function.h"
31 G_DEFINE_ABSTRACT_TYPE (SwfdecAsRelay
, swfdec_as_relay
, SWFDEC_TYPE_GC_OBJECT
)
34 swfdec_as_relay_mark (SwfdecGcObject
*object
)
36 SwfdecAsRelay
*relay
= SWFDEC_AS_RELAY (object
);
39 swfdec_gc_object_mark (relay
->relay
);
41 SWFDEC_GC_OBJECT_CLASS (swfdec_as_relay_parent_class
)->mark (object
);
45 swfdec_as_relay_class_init (SwfdecAsRelayClass
*klass
)
47 SwfdecGcObjectClass
*gc_class
= SWFDEC_GC_OBJECT_CLASS (klass
);
49 gc_class
->mark
= swfdec_as_relay_mark
;
53 swfdec_as_relay_init (SwfdecAsRelay
*object
)
58 * swfdec_as_relay_get_as_object:
59 * @object: a #SwfdecAsRelay.
61 * Gets the Actionscript object associated with this object.
63 * Returns: The #SwfdecAsObject associated with this relay.
66 swfdec_as_relay_get_as_object (SwfdecAsRelay
*relay
)
68 g_return_val_if_fail (SWFDEC_IS_AS_RELAY (relay
), NULL
);
69 g_return_val_if_fail (relay
->relay
!= NULL
, NULL
);
75 * swfdec_as_relay_call:
76 * @object: a #SwfdecAsRelay
77 * @name: garbage-collected string naming the function to call.
78 * @argc: number of arguments to provide to function
79 * @argv: arguments or %NULL when @argc is 0
80 * @return_value: location to take the return value of the call or %NULL to
81 * ignore the return value.
83 * Calls the function named @name on the given object. This function is
84 * essentially equal to the folloeing Actionscript code:
85 * <informalexample><programlisting>
86 * @return_value = @object.@name (@argv[0], ..., @argv[argc-1]);
87 * </programlisting></informalexample>
89 * Returns: %TRUE if @object had a function with the given name, %FALSE otherwise
92 swfdec_as_relay_call (SwfdecAsRelay
*relay
, const char *name
, guint argc
,
93 SwfdecAsValue
*argv
, SwfdecAsValue
*return_value
)
96 SwfdecAsFunction
*fun
;
98 g_return_val_if_fail (SWFDEC_IS_AS_RELAY (relay
), TRUE
);
99 g_return_val_if_fail (name
!= NULL
, TRUE
);
100 g_return_val_if_fail (argc
== 0 || argv
!= NULL
, TRUE
);
101 g_return_val_if_fail (swfdec_gc_object_get_context (relay
)->global
!= NULL
, TRUE
); /* for SwfdecPlayer */
103 /* If this doesn't hold, we need to use swfdec_as_relay_get_as_object()
104 * and have that function create the relay on demand. */
105 g_assert (relay
->relay
);
108 SWFDEC_AS_VALUE_SET_UNDEFINED (return_value
);
109 swfdec_as_object_get_variable (relay
->relay
, name
, &tmp
);
110 if (!SWFDEC_AS_VALUE_IS_OBJECT (&tmp
))
112 fun
= (SwfdecAsFunction
*) (SWFDEC_AS_VALUE_GET_OBJECT (&tmp
)->relay
);
113 if (!SWFDEC_IS_AS_FUNCTION (fun
))
115 swfdec_as_function_call (fun
, relay
->relay
, argc
, argv
, return_value
? return_value
: &tmp
);