rygel r127 - in trunk: . src



Author: zeeshanak
Date: Tue Oct 28 21:00:59 2008
New Revision: 127
URL: http://svn.gnome.org/viewvc/rygel?rev=127&view=rev

Log:
- Introduce a plugins system. Ross should be happy now. :) - Remove MediaTracker module.

Removed:
   trunk/src/gupnp-media-tracker.vala
Modified:
   trunk/ChangeLog
   trunk/src/Makefile.am
   trunk/src/cstuff.vapi
   trunk/src/gupnp-media-manager.vala

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am	(original)
+++ trunk/src/Makefile.am	Tue Oct 28 21:00:59 2008
@@ -4,17 +4,24 @@
 shareddir = $(datadir)/gupnp-media-server
 endif
 
+if UNINSTALLED
+plugindir = $(abs_top_builddir)/src/media-providers
+else
+plugindir = $(libdir)/gupnp-media-server-1.0
+endif
+
 AM_CFLAGS = $(LIBGUPNP_CFLAGS) \
 	    $(LIBGUPNP_AV_CFLAGS) \
 	    $(LIBGCONF_CFLAGS) \
-	    $(LIBDBUS_GLIB_CFLAGS) \
 	    $(LIBGSTREAMER_CFLAGS) \
 	    $(GIO_CFLAGS) \
-	    -I$(top_srcdir) -DDATA_DIR='"$(shareddir)"'
+	    -I$(top_srcdir) -DDATA_DIR='"$(shareddir)"' \
+	    -DPLUGIN_DIR='"$(plugindir)"'
 
 bin_PROGRAMS = gupnp-media-server
 
-BUILT_SOURCES = gupnp-media-server.stamp \
+BUILT_SOURCES = gupnp-media-server-1.0.vapi \
+		gupnp-media-server.stamp \
 		gupnp-media-server.h \
 		gupnp-media-server.c \
 		gupnp-content-directory.h \
@@ -23,14 +30,13 @@
 		gupnp-connection-manager.c \
 		gupnp-media-receiver-registrar.h \
 		gupnp-media-receiver-registrar.c \
-		gupnp-media-tracker.h \
-		gupnp-media-tracker.c \
 		gupnp-media-provider.h \
 		gupnp-media-provider.c \
 		gupnp-media-manager.h \
 		gupnp-media-manager.c
 
-gupnp_media_server_SOURCES = cstuff.c \
+gupnp_media_server_SOURCES = gupnp-media-server-1.0.vapi \
+			     cstuff.c \
 			     cstuff.h \
 			     gupnp-media-server.h \
 			     gupnp-media-server.c \
@@ -44,12 +50,8 @@
 			     gupnp-media-receiver-registrar.h \
 			     gupnp-media-receiver-registrar.c \
 			     gupnp-media-receiver-registrar.vala \
-			     gupnp-media-tracker.h \
-			     gupnp-media-tracker.c \
-			     gupnp-media-tracker.vala \
 			     gupnp-media-provider.h \
 			     gupnp-media-provider.c \
-			     gupnp-media-provider.vala \
 			     gupnp-media-manager.h \
 			     gupnp-media-manager.c \
 			     gupnp-media-manager.vala \
@@ -58,19 +60,23 @@
 			     gupnp-metadata-extractor.vala
 
 gupnp-media-server.stamp: $(filter %.vala,$(gupnp_media_server_SOURCES))
-	$(VALAC) -C --vapidir=$(srcdir) --pkg cstuff --pkg gupnp-1.0 \
-	--pkg gupnp-av-1.0 --pkg dbus-glib-1 --pkg gconf-2.0 \
-	--pkg gstreamer-0.10 --pkg gio-2.0 $^
+	$(VALAC) -C --vapidir=$(srcdir) --pkg gupnp-media-server-1.0 \
+	--pkg cstuff --pkg gupnp-1.0 --pkg gupnp-av-1.0 --pkg dbus-glib-1 \
+	--pkg gconf-2.0 --pkg gstreamer-0.10 --pkg gio-2.0 $^
 	touch $@
 
 gupnp_media_server_LDADD = $(LIBGUPNP_LIBS) \
 			   $(LIBGUPNP_AV_LIBS) \
 			   $(LIBGCONF_LIBS) \
-			   $(LIBDBUS_GLIB_LIBS) \
 			   $(LIBGSTREAMER_LIBS) \
 			   $(GIO_LIBS)
 gupnp_media_server_LDFLAGS = -export-dynamic
 
+VAPI_FILES = gupnp-media-server-1.0.vapi
+
+gupnp-media-server-1.0.vapi: gupnp-media-provider.vala
+	$(VALAC) -C --library=gupnp-media-server-1.0 --pkg gupnp-1.0 $^
+
 CLEANFILES = $(BUILT_SOURCES)
 MAINTAINERCLEANFILES = Makefile.in
 EXTRA_DIST = cstuff.vapi

Modified: trunk/src/cstuff.vapi
==============================================================================
--- trunk/src/cstuff.vapi	(original)
+++ trunk/src/cstuff.vapi	Tue Oct 28 21:00:59 2008
@@ -22,6 +22,9 @@
     class BuildConfig {
         [CCode (cname = "DATA_DIR")]
         public static const string DATA_DIR;
+
+        [CCode (cname = "PLUGIN_DIR")]
+        public static const string PLUGIN_DIR;
     }
 
     public class Utils {

Modified: trunk/src/gupnp-media-manager.vala
==============================================================================
--- trunk/src/gupnp-media-manager.vala	(original)
+++ trunk/src/gupnp-media-manager.vala	Tue Oct 28 21:00:59 2008
@@ -22,6 +22,8 @@
  * version 2 of the License, or (at your option) any later version.
  */
 
+using CStuff;
+
 public class GUPnP.MediaManager : GLib.Object, MediaProvider {
     private DIDLLiteWriter didl_writer;
 
@@ -38,19 +40,24 @@
      */
     HashTable<string, MediaProvider> providers;
 
+    /* We need to keep the modules somewhere */
+    List<Module> modules;
+
+    private delegate MediaProvider RegisterMediaProviderFunc
+                                    (string        root_id,
+                                     string        root_parent_id,
+                                     GUPnP.Context context);
+
     construct {
         this.providers = new HashTable<string, MediaProvider>
                                 ((HashFunc) id_hash_func,
                                  (EqualFunc) is_root_equal);
-
-        MediaTracker tracker = new MediaTracker ("1",
-                                                 this.root_id,
-                                                 this.context);
-        providers.insert ("1", tracker);
-
+        this.modules = new List<Module> ();
         this.didl_writer = new DIDLLiteWriter ();
 
         this.system_update_id = 0;
+
+        this.register_media_providers ();
     }
 
     /* Pubic methods */
@@ -229,5 +236,77 @@
 
         return id1_tokens[0] == id2_tokens[0];
     }
+
+    // Plugin loading functions
+
+    private void register_media_providers () {
+        assert (Module.supported());
+
+        string dir_path = BuildConfig.PLUGIN_DIR;
+
+        Dir dir;
+        try {
+            dir = Dir.open (dir_path, 0);
+        } catch (FileError error) {
+            critical ("Error loading plugins from '%s'\n", dir_path);
+
+            return;
+        }
+
+        string file_name;
+
+        while ((file_name = dir.read_name ()) != null) {
+            string path = Path.build_filename (dir_path, file_name);
+
+            MediaProvider provider;
+            Module module;
+
+            provider = this.load_media_provider_from_file (path, out module);
+            if (provider != null) {
+                this.providers.insert (provider.root_id, provider);
+                this.modules.append (#module);
+            }
+        }
+    }
+
+    private MediaProvider? load_media_provider_from_file (string     file_path,
+                                                          out Module module) {
+        module = Module.open (file_path, ModuleFlags.BIND_LOCAL);
+        if (module == null) {
+            debug ("Failed to load plugin from path: '%s'\n", file_path);
+
+            return null;
+        }
+
+        void* function;
+        RegisterMediaProviderFunc register_media_provider;
+
+        module.symbol("register_media_provider", out function);
+
+        register_media_provider = (RegisterMediaProviderFunc) function;
+
+        if (register_media_provider == null) {
+            warning ("Failed to load plugin from path: '%s'\n", file_path);
+
+            return null;
+        }
+
+        debug ("Loaded plugin: '%s'\n", module.name());
+
+        return register_media_provider (this.generate_id (),
+                                        this.root_id,
+                                        this.context);
+    }
+
+    private string generate_id () {
+        string id = Random.next_int ().to_string ();
+
+        // See if generated ID is already in use
+        if (this.providers.lookup (id) != null) {
+            return generate_id ();
+        } else {
+            return id;
+        }
+    }
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]