Hi all,

In some cases it's useful to be able to specify which interface implementation is probed first; e.g. when you have multiple JPEG image providers, one hardware-accelerated but more restrictive, one fully compliant but software. I'm attaching a patch that adds priorities to interfaces; the priority is specified by using DEFINE_INTERFACE_WITH_PRIO. The default priority is 1000; lower values mean higher priority.

I hope you'll find the patch useful.

Sorin
diff -u -N -r1.11 -r1.12
--- dcchd_project/directfb/install/dfb-smp86xx/lib/direct/interface.c	23 May 2008 19:16:17 -0000	1.11
+++ dcchd_project/directfb/install/dfb-smp86xx/lib/direct/interface.c	30 Sep 2009 00:56:36 -0000	1.12
@@ -64,6 +64,7 @@
      const char           *implementation;
 
      int                   references;
+     int                   priority;         /* lower means higher priority */
 } DirectInterfaceImplementation;
 
 static pthread_mutex_t  implementations_mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -72,17 +73,38 @@
 /**************************************************************************************************/
 
 void
-DirectRegisterInterface( DirectInterfaceFuncs *funcs )
+DirectRegisterInterface( DirectInterfaceFuncs *funcs, int priority )
 {
      DirectInterfaceImplementation *impl;
+     DirectLink *link;
 
      impl = calloc( 1, sizeof(DirectInterfaceImplementation) );
 
      impl->funcs          = funcs;
      impl->type           = funcs->GetType();
      impl->implementation = funcs->GetImplementation();
+     impl->priority       = priority;
 
-     direct_list_prepend( &implementations, &impl->link );
+     /*
+      * Check existing implementations priorities and insert before first one 
+      * with higher order number (higher is less important)
+      */
+     direct_list_foreach( link, implementations ) {
+          DirectInterfaceImplementation *impl2 = (DirectInterfaceImplementation*) link;
+
+          if (impl2->priority > priority) {
+               if (link == implementations)
+                    direct_list_prepend( &implementations, &impl->link );
+               else
+                    /* We use a trick: prepend changes 'link', but we don't care */
+                    direct_list_prepend( &link, &impl->link );
+
+               return;
+          }
+     }
+
+     /* Just add it to the end - lowest priority yet */
+     direct_list_append( &implementations, &impl->link );
 }
 
 DirectResult
diff -u -N -r1.7 -r1.8
--- dcchd_project/directfb/install/dfb-smp86xx/lib/direct/interface.h	14 Mar 2007 15:32:38 -0000	1.7
+++ dcchd_project/directfb/install/dfb-smp86xx/lib/direct/interface.h	30 Sep 2009 00:56:36 -0000	1.8
@@ -84,7 +84,7 @@
  * Called by implementation modules during 'dlopen'ing or at startup if linked
  * into the executable.
  */
-void DirectRegisterInterface( DirectInterfaceFuncs *funcs );
+void DirectRegisterInterface( DirectInterfaceFuncs *funcs, int priority );
 
 
 void direct_print_interface_leaks(void);
diff -u -N -r1.6 -r1.7
--- dcchd_project/directfb/install/dfb-smp86xx/lib/direct/interface_implementation.h	14 Mar 2007 15:32:38 -0000	1.6
+++ dcchd_project/directfb/install/dfb-smp86xx/lib/direct/interface_implementation.h	30 Sep 2009 00:56:36 -0000	1.7
@@ -44,34 +44,64 @@
      Construct:          (DirectInterfaceGenericConstructFunc) Construct
 };
 
-#define DIRECT_INTERFACE_IMPLEMENTATION(type, impl)    \
-                                                       \
-static const char *                                    \
-GetType( void )                                        \
-{                                                      \
-     return #type;                                     \
-}                                                      \
-                                                       \
-static const char *                                    \
-GetImplementation( void )                              \
-{                                                      \
-     return #impl;                                     \
-}                                                      \
-                                                       \
-static DirectResult                                    \
-Allocate( void **interface )                           \
-{                                                      \
-     DIRECT_ALLOCATE_INTERFACE( *interface, type );    \
-     return DFB_OK;                                    \
-}                                                      \
-                                                       \
-__attribute__((constructor)) void type##_##impl(void); \
-                                                       \
-void                                                   \
-type##_##impl(void)                                    \
-{                                                      \
-     DirectRegisterInterface( &interface_funcs );      \
+#define DIRECT_INTERFACE_IMPLEMENTATION(type, impl)    	\
+														\
+static const char *                                    	\
+GetType( void )                                       	\
+{                                                      	\
+     return #type;                                     	\
+}                                                      	\
+														\
+static const char *                                    	\
+GetImplementation( void )                              	\
+{                                                      	\
+     return #impl;                                     	\
+}                                                      	\
+														\
+static DirectResult                                    	\
+Allocate( void **interface )                           	\
+{                                                      	\
+     DIRECT_ALLOCATE_INTERFACE( *interface, type );    	\
+     return DFB_OK;                                    	\
+}                                                      	\
+														\
+__attribute__((constructor)) void type##_##impl(void);	\
+														\
+void                                                   	\
+type##_##impl(void)                                    	\
+{                                                      	\
+     DirectRegisterInterface( &interface_funcs, 1000 ); \
 }
 
+
+#define DIRECT_INTERFACE_IMPLEMENTATION_WITH_PRIO(type, impl, prio)	\
+																	\
+static const char *                                    				\
+GetType( void )                                        				\
+{                                                      				\
+     return #type;                                     				\
+}                                                      				\
+																	\
+static const char *                                    				\
+GetImplementation( void )                              				\
+{                                                      				\
+     return #impl;                                     				\
+}                                                      				\
+																	\
+static DirectResult                                    				\
+Allocate( void **interface )                           				\
+{                                                      				\
+     DIRECT_ALLOCATE_INTERFACE( *interface, type );    				\
+     return DFB_OK;                                    				\
+}                                                      				\
+																	\
+__attribute__((constructor)) void type##_##impl(void); 				\
+																	\
+void                                                   				\
+type##_##impl(void)                                    				\
+{                                                      				\
+     DirectRegisterInterface( &interface_funcs, prio );				\
+}
+
 #endif
 
_______________________________________________
directfb-dev mailing list
directfb-dev@directfb.org
http://mail.directfb.org/cgi-bin/mailman/listinfo/directfb-dev

Reply via email to