fix build for --disable-gtk-doc
[swfdec.git] / swfdec / swfdec_as_movie_value.c
blob821c4afae7caf57fd5e0be90e0623f3511fb48c8
1 /* Swfdec
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.
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_movie_value.h"
26 #include <string.h>
28 #include "swfdec_as_gcable.h"
29 #include "swfdec_as_strings.h"
30 #include "swfdec_movie.h"
31 #include "swfdec_player_internal.h"
33 SwfdecAsMovieValue *
34 swfdec_as_movie_value_new (SwfdecMovie *movie, const char *name)
36 SwfdecAsMovieValue *val, *parent;
37 SwfdecAsContext *context;
38 guint i, n_names;
40 g_assert (SWFDEC_IS_MOVIE (movie));
41 g_assert (name != NULL);
42 g_assert (name != SWFDEC_AS_STR_EMPTY);
44 context = swfdec_gc_object_get_context (movie);
45 parent = movie->parent ? movie->parent->as_value : NULL;
46 n_names = parent ? parent->n_names + 1 : 1;
48 val = swfdec_as_gcable_alloc (context, sizeof (SwfdecAsMovieValue) + n_names * sizeof (const char *));
49 val->player = SWFDEC_PLAYER (context);
50 val->movie = movie;
51 val->n_names = n_names;
52 val->names[n_names - 1] = name;
53 movie = movie->parent;
54 for (i = n_names - 2; movie; i--) {
55 if (movie->name != SWFDEC_AS_STR_EMPTY) {
56 val->names[i] = movie->name;
57 } else {
58 val->names[i] = movie->as_value->names[i];
60 movie = movie->parent;
63 SWFDEC_AS_GCABLE_SET_NEXT (val, context->movies);
64 context->movies = val;
66 return val;
69 void
70 swfdec_as_movie_value_mark (SwfdecAsMovieValue *value)
72 guint i;
74 g_assert (value != NULL);
76 SWFDEC_AS_GCABLE_SET_FLAG ((SwfdecAsGcable *) value, SWFDEC_AS_GC_MARK);
78 if (value->movie)
79 swfdec_gc_object_mark (value->movie);
80 for (i = 0; i < value->n_names; i++) {
81 swfdec_as_string_mark (value->names[i]);
85 static SwfdecMovie *
86 swfdec_player_get_movie_by_name (SwfdecPlayer *player, const char *name)
88 GList *walk;
90 for (walk = player->priv->roots; walk; walk = walk->next) {
91 SwfdecMovie *cur = walk->data;
92 if (cur->as_value->names[0] == name)
93 return cur;
95 return NULL;
98 SwfdecMovie *
99 swfdec_as_movie_value_get (SwfdecAsMovieValue *value)
101 SwfdecMovie *movie;
102 guint i;
104 g_assert (value != NULL);
105 g_assert (value->movie == NULL); /* checked by macros */
107 /* FIXME: getting a root movie by name should be simpler */
108 movie = swfdec_player_get_movie_by_name (value->player, value->names[0]);
109 for (i = 1; i < value->n_names && movie; i++) {
110 movie = swfdec_movie_get_by_name (movie, value->names[i], TRUE);
112 return movie;