[Swfdec] Branch 'vivi' - 2 commits - vivified/core

Benjamin Otte company at kemper.freedesktop.org
Mon Aug 13 05:25:59 PDT 2007


 vivified/core/.gitignore            |    2 +
 vivified/core/Makefile.am           |   17 +++++++++
 vivified/core/vivi_application.c    |   48 ++++++++++++++++++++++++++
 vivified/core/vivi_application.h    |    8 ++++
 vivified/core/vivi_application_as.c |   66 ++++++++++++++++++++++++++++++++++++
 vivified/core/vivi_function.c       |   63 ++++++++++++++++++++++++++++++++++
 vivified/core/vivi_function.h       |   36 +++++++++++++++++++
 7 files changed, 240 insertions(+)

New commits:
diff-tree aa9c233ed15e37e156d05f1e296126c2a8933132 (from 41394382ea0de8a1937d2392baf699e28589f059)
Author: Benjamin Otte <otte at gnome.org>
Date:   Sun Aug 12 02:02:39 2007 +0200

    add stubs for missing functions

diff --git a/vivified/core/vivi_application.c b/vivified/core/vivi_application.c
index b2ec3bd..f93fb16 100644
--- a/vivified/core/vivi_application.c
+++ b/vivified/core/vivi_application.c
@@ -201,6 +201,9 @@ vivi_application_send_message (ViviAppli
   va_list args;
   char *msg;
 
+  g_return_if_fail (VIVI_IS_APPLICATION (app));
+  g_return_if_fail (format != NULL);
+
   va_start (args, format);
   msg = g_strdup_vprintf (format, args);
   va_end (args);
@@ -208,3 +211,31 @@ vivi_application_send_message (ViviAppli
   g_free (msg);
 }
 
+typedef enum {
+  VIVI_APPLICATION_STOPPED,
+  VIVI_APPLICATION_PLAYING,
+  VIVI_APPLICATION_STEPPING,
+} ViviApplicationPlayback;
+
+static void
+vivi_application_set_playback (ViviApplication *app, ViviApplicationPlayback playback, guint steps)
+{
+  app->playback_state = playback;
+  app->playback_count = steps;
+}
+
+void
+vivi_application_play (ViviApplication *app)
+{
+  g_return_if_fail (VIVI_IS_APPLICATION (app));
+
+  vivi_application_set_playback (app, VIVI_APPLICATION_PLAYING, 1);
+}
+
+void
+vivi_application_step (ViviApplication *app, guint n_times)
+{
+  g_return_if_fail (VIVI_IS_APPLICATION (app));
+
+  vivi_application_set_playback (app, VIVI_APPLICATION_STEPPING, n_times);
+}
diff-tree 41394382ea0de8a1937d2392baf699e28589f059 (from bd466511d940904f33e8b3553f529e1b2eca5c7d)
Author: Benjamin Otte <otte at gnome.org>
Date:   Fri Aug 10 13:14:12 2007 +0200

    add infrastructure for native functions

diff --git a/vivified/core/.gitignore b/vivified/core/.gitignore
index b580c89..da08114 100644
--- a/vivified/core/.gitignore
+++ b/vivified/core/.gitignore
@@ -10,3 +10,5 @@ Makefile.in
 *.la
 *.lo
 *.loT
+
+vivi_function_list.h
diff --git a/vivified/core/Makefile.am b/vivified/core/Makefile.am
index 0bcac39..8639fb4 100644
--- a/vivified/core/Makefile.am
+++ b/vivified/core/Makefile.am
@@ -5,9 +5,26 @@ libvivified_core_la_LDFLAGS = $(SWFDEC_G
 
 libvivified_core_la_SOURCES = \
 	vivi_application.c \
+	vivi_application_as.c \
+	vivi_function.c \
 	vivi_ming.c
 
 noinst_HEADERS = \
 	vivi_application.h \
+	vivi_function.h \
+	vivi_function_list.h \
 	vivi_ming.h \
 	vivified-core.h
+
+BUILT_SOURCES = \
+	vivi_function_list.h
+
+CLEANFILES = \
+	$(BUILT_SOURCES)
+
+vivi_function_list.h: $(libvivified_core_la_SOURCES)
+	(cd $(srcdir) \
+	  && grep -he "^VIVI_FUNCTION" $(libvivified_core_la_SOURCES) \
+	 ) >> xgen-vfl \
+	&& (cmp -s xgen-vfl swfdec_asnative.h || cp xgen-vfl vivi_function_list.h) \
+	&& rm -f xgen-vfl
diff --git a/vivified/core/vivi_application.c b/vivified/core/vivi_application.c
index 783a3f9..b2ec3bd 100644
--- a/vivified/core/vivi_application.c
+++ b/vivified/core/vivi_application.c
@@ -122,12 +122,29 @@ vivi_application_new (void)
 }
 
 void
+vivi_application_init_player (ViviApplication *app)
+{
+  SwfdecLoader *loader;
+
+  g_return_if_fail (VIVI_IS_APPLICATION (app));
+
+  if (app->player_inited ||
+      app->filename == NULL)
+    return;
+
+  loader = swfdec_file_loader_new (app->filename);
+  swfdec_player_set_loader (app->player, loader);
+  app->player_inited = TRUE;
+}
+
+void
 vivi_application_reset (ViviApplication *app)
 {
   g_return_if_fail (VIVI_IS_APPLICATION (app));
 
   g_object_unref (app->player);
   app->player = swfdec_gtk_player_new (NULL);
+  app->player_inited = FALSE;
 }
 
 void
diff --git a/vivified/core/vivi_application.h b/vivified/core/vivi_application.h
index 40bdc64..f45540e 100644
--- a/vivified/core/vivi_application.h
+++ b/vivified/core/vivi_application.h
@@ -47,6 +47,9 @@ struct _ViviApplication
 
   char *		filename;	/* name of the file we play back or NULL if none set yet */
   SwfdecPlayer *	player;		/* the current player */
+  gboolean		player_inited;	/* if the player is inited already */
+  guint			playback_state;	/* (running, stepping or stopped) */
+  guint			playback_count;	/* how often to just restart this on breakpoints */
 };
 
 struct _ViviApplicationClass
@@ -74,7 +77,12 @@ void			vivi_application_set_filename	(Vi
 const char *		vivi_application_get_filename	(ViviApplication *	app);
 SwfdecPlayer *	      	vivi_application_get_player	(ViviApplication *	app);
 
+void			vivi_application_init_player	(ViviApplication *	app);
 void			vivi_application_reset		(ViviApplication *	app);
+void			vivi_application_play		(ViviApplication *	app);
+void			vivi_application_step		(ViviApplication *	app,
+							 guint			n_times);
+
 void			vivi_application_run		(ViviApplication *	app,
 							 const char *		command);
 
diff --git a/vivified/core/vivi_application_as.c b/vivified/core/vivi_application_as.c
new file mode 100644
index 0000000..988e650
--- /dev/null
+++ b/vivified/core/vivi_application_as.c
@@ -0,0 +1,66 @@
+/* Vivified
+ * Copyright (C) 2007 Benjamin Otte <otte at gnome.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, 
+ * Boston, MA  02110-1301  USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "vivi_application.h"
+#include "vivi_function.h"
+
+VIVI_FUNCTION ("run", vivi_application_as_run)
+void
+vivi_application_as_run (SwfdecAsContext *cx, SwfdecAsObject *this,
+    guint argc, SwfdecAsValue *argv, SwfdecAsValue *retval)
+{
+  ViviApplication *app = VIVI_APPLICATION (cx);
+
+  vivi_application_reset (app);
+  vivi_application_init_player (app);
+  vivi_application_play (app);
+}
+
+VIVI_FUNCTION ("continue", vivi_application_as_continue)
+void
+vivi_application_as_continue (SwfdecAsContext *cx, SwfdecAsObject *this,
+    guint argc, SwfdecAsValue *argv, SwfdecAsValue *retval)
+{
+  ViviApplication *app = VIVI_APPLICATION (cx);
+
+  vivi_application_init_player (app);
+  vivi_application_play (app);
+}
+
+VIVI_FUNCTION ("step", vivi_application_as_step)
+void
+vivi_application_as_step (SwfdecAsContext *cx, SwfdecAsObject *this, 
+    guint argc, SwfdecAsValue *argv, SwfdecAsValue *retval)
+{
+  ViviApplication *app = VIVI_APPLICATION (cx);
+  int steps;
+
+  if (argc > 0) {
+    steps = swfdec_as_value_to_integer (cx, &argv[0]);
+    if (steps <= 1)
+      steps = 1;
+  } else {
+    steps = 1;
+  }
+  vivi_application_step (app, steps);
+}
diff --git a/vivified/core/vivi_function.c b/vivified/core/vivi_function.c
new file mode 100644
index 0000000..5dc64e1
--- /dev/null
+++ b/vivified/core/vivi_function.c
@@ -0,0 +1,63 @@
+/* Vivified
+ * Copyright (C) 2007 Benjamin Otte <otte at gnome.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, 
+ * Boston, MA  02110-1301  USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "vivi_function.h"
+#include "vivi_function_list.h"
+
+/* include vivi_function_list with special macro definition, so we get a nice
+ * way to initialize it */
+#undef VIVI_FUNCTION
+#define VIVI_FUNCTION(name, fun) \
+  { name, fun },
+static const struct {
+  const char *		name;
+  SwfdecAsNative	fun;
+} functions[] = {
+#include "vivi_function_list.h"
+  { NULL, NULL }
+};
+#undef VIVI_FUNCTION
+
+
+void
+vivi_function_init_context (ViviApplication *app)
+{ 
+  SwfdecAsContext *cx = SWFDEC_AS_CONTEXT (app);
+  SwfdecAsObject *obj;
+  SwfdecAsValue val;
+  guint i;
+
+  obj = swfdec_as_object_new (cx);
+  if (obj == NULL)
+    return;
+  SWFDEC_AS_VALUE_SET_OBJECT (&val, obj);
+  swfdec_as_object_set_variable (cx->global, 
+      swfdec_as_context_get_string (cx, "Native"), &val);
+
+  for (i = 0; functions[i].name; i++) {
+    swfdec_as_object_add_function (obj,
+      swfdec_as_context_get_string (cx, functions[i].name),
+      G_TYPE_NONE, functions[i].fun, 0);
+  }
+}
+
diff --git a/vivified/core/vivi_function.h b/vivified/core/vivi_function.h
new file mode 100644
index 0000000..2642579
--- /dev/null
+++ b/vivified/core/vivi_function.h
@@ -0,0 +1,36 @@
+/* Vivified
+ * Copyright (C) 2007 Benjamin Otte <otte at gnome.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, 
+ * Boston, MA  02110-1301  USA
+ */
+
+#include <libswfdec/swfdec.h>
+#include <vivified/core/vivi_application.h>
+
+#ifndef _VIVI_FUNCTION_H_
+#define _VIVI_FUNCTION_H_
+
+G_BEGIN_DECLS
+
+
+#define VIVI_FUNCTION(name, fun) \
+  void fun (SwfdecAsContext *cx, SwfdecAsObject *this, guint argc, SwfdecAsValue *argv, SwfdecAsValue *retval);
+
+void		vivi_function_init_context	(ViviApplication *	app);
+
+
+G_END_DECLS
+#endif


More information about the Swfdec mailing list