Bug 22803 - Make header conform to implementation
[swfdec.git] / swfdec / swfdec_asbroadcaster.c
blobd29f221765400a5cd43cc45993a87afcfd683651
1 /* Swfdec
2 * Copyright (C) 2007 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 "swfdec_as_internal.h"
25 #include "swfdec_as_object.h"
26 #include "swfdec_as_strings.h"
27 #include "swfdec_as_context.h"
28 #include "swfdec_as_frame_internal.h"
29 #include "swfdec_debug.h"
31 /*** AS CODE ***/
33 SWFDEC_AS_NATIVE (101, 12, broadcastMessage)
34 void
35 broadcastMessage (SwfdecAsContext *cx, SwfdecAsObject *object,
36 guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
38 SwfdecAsValue val;
39 SwfdecAsObject *listeners, *o;
40 gint i, length;
41 const char *name;
42 GSList *list = NULL, *walk;
44 if (object == NULL)
45 return;
47 if (argc < 1)
48 return;
49 name = swfdec_as_value_to_string (cx, argv[0]);
50 argv += 1;
51 argc--;
53 swfdec_as_object_get_variable (object, SWFDEC_AS_STR__listeners, &val);
54 if (!SWFDEC_AS_VALUE_IS_COMPOSITE (val))
55 return;
57 listeners = SWFDEC_AS_VALUE_GET_COMPOSITE (val);
58 swfdec_as_object_get_variable (listeners, SWFDEC_AS_STR_length, &val);
59 length = swfdec_as_value_to_integer (cx, val);
61 /* return undefined if we won't try to call anything */
62 if (length <= 0)
63 return;
65 /* FIXME: solve this wth foreach, so it gets faster for weird cases */
66 for (i = 0; i < length; i++) {
67 swfdec_as_object_get_variable (listeners, swfdec_as_integer_to_string (cx, i), &val);
68 o = swfdec_as_value_to_object (cx, val);
69 if (o == NULL)
70 continue;
71 list = g_slist_prepend (list, o);
73 if (list == NULL)
74 return;
76 list = g_slist_reverse (list);
77 for (walk = list; walk; walk = walk->next) {
78 swfdec_as_object_call (walk->data, name, argc, argv, &val);
80 g_slist_free (list);
82 SWFDEC_AS_VALUE_SET_BOOLEAN (ret, TRUE);