Further hide module_t layout from plugins
authorRémi Denis-Courmont <rem@videolan.org>
Sat, 14 Apr 2007 18:17:17 +0000 (18:17 +0000)
committerRémi Denis-Courmont <rem@videolan.org>
Sat, 14 Apr 2007 18:17:17 +0000 (18:17 +0000)
include/vlc_modules.h
include/vlc_modules_macros.h
src/modules/entry.c
src/modules/modules.c

index 7d15e58..c8c1acd 100644 (file)
@@ -111,6 +111,7 @@ VLC_EXPORT( void, __module_Unneed, ( vlc_object_t *, module_t * ) );
 #define module_Exists(a,b) __module_Exists(VLC_OBJECT(a),b)
 VLC_EXPORT( vlc_bool_t,  __module_Exists, ( vlc_object_t *, const char * ) );
 
+VLC_EXPORT( module_t *, vlc_module_create, ( vlc_object_t * ) );
 VLC_EXPORT( module_t *, vlc_submodule_create, ( module_t * ) );
 VLC_EXPORT( int, vlc_module_set, (module_t *module, int propid, void *value) );
 
@@ -128,6 +129,7 @@ enum
     VLC_MODULE_PROGRAM,
     VLC_MODULE_CB_OPEN,
     VLC_MODULE_CB_CLOSE,
-    VLC_MODULE_UNLOADABLE
+    VLC_MODULE_UNLOADABLE,
+    VLC_MODULE_NAME
 };
 
index 3a76428..02a1072 100644 (file)
@@ -117,22 +117,9 @@ E_(vlc_entry) ( module_t *p_module );
         size_t i_config = (size_t)(-1);                                       \
         module_config_t *p_config = NULL;                                     \
         STORE_SYMBOLS;                                                        \
-        p_module->b_submodule = VLC_FALSE;                                    \
-        p_module->b_unloadable = VLC_TRUE;                                    \
-        p_module->b_reentrant = VLC_TRUE;                                     \
-        p_module->psz_object_name = MODULE_STRING;                            \
-        p_module->psz_shortname = NULL;                                       \
-        p_module->psz_longname = MODULE_STRING;                               \
-        p_module->psz_help = NULL;                                            \
-        p_module->pp_shortcuts[ 0 ] = MODULE_STRING;                          \
-        for( unsigned i = 1; i < MODULE_SHORTCUT_MAX; i++ )                   \
-            p_module->pp_shortcuts[i] = NULL;                                 \
-        p_module->i_cpu = 0;                                                  \
-        p_module->psz_program = NULL;                                         \
-        p_module->psz_capability = "";                                        \
-        p_module->i_score = 1;                                                \
-        p_module->pf_activate = NULL;                                         \
-        p_module->pf_deactivate = NULL;                                       \
+        if (vlc_module_set (p_module, VLC_MODULE_NAME,                        \
+                            (void *)(MODULE_STRING)))                         \
+            goto error;                                                       \
         {                                                                     \
             module_t *p_submodule = p_module /* the ; gets added */
 
@@ -153,6 +140,11 @@ E_(vlc_entry) ( module_t *p_module );
             return res;                                                       \
         (void)i_shortcut;                                                     \
         return VLC_SUCCESS;                                                   \
+                                                                              \
+    error:                                                                    \
+        free( p_config );                                                     \
+        /* FIXME: cleanup submodules objects ??? */                           \
+        return VLC_EGENERIC;                                                  \
     }                                                                         \
     struct _u_n_u_s_e_d_ /* the ; gets added */
 
@@ -161,32 +153,40 @@ E_(vlc_entry) ( module_t *p_module );
     p_submodule = vlc_submodule_create( p_module )
 
 #define add_requirement( cap ) \
-    vlc_module_set (p_module, VLC_MODULE_CPU_REQUIREMENT, \
-                    (void *)(CPU_CAPABILITY_##cap))
+    if (vlc_module_set (p_module, VLC_MODULE_CPU_REQUIREMENT, \
+                        (void *)(CPU_CAPABILITY_##cap))) goto error
 
 #define add_shortcut( shortcut ) \
-    vlc_module_set (p_submodule, VLC_MODULE_SHORTCUT, (void*)(shortcut))
+    if (vlc_module_set (p_submodule, VLC_MODULE_SHORTCUT, (void*)(shortcut))) \
+        goto error
 
 #define set_shortname( shortname ) \
-    vlc_module_set (p_submodule, VLC_MODULE_SHORTNAME, (void*)(shortname))
+    if (vlc_module_set (p_submodule, VLC_MODULE_SHORTNAME, \
+                        (void*)(shortname))) goto error;
 
 #define set_description( desc ) \
-    vlc_module_set (p_submodule, VLC_MODULE_DESCRIPTION, (void*)(desc))
+    if (vlc_module_set (p_submodule, VLC_MODULE_DESCRIPTION, (void*)(desc))) \
+        goto error;
 
 #define set_help( help ) \
-    vlc_module_set (p_submodule, VLC_MODULE_HELP, (void*)(help))
+    if (vlc_module_set (p_submodule, VLC_MODULE_HELP, (void*)(help))) \
+        goto error
 
 #define set_capability( cap, score ) \
-    vlc_module_set (p_submodule, VLC_MODULE_CAPABILITY, (void *)(cap)); \
-    vlc_module_set (p_submodule, VLC_MODULE_SCORE, (void *)(score))
+    if (vlc_module_set (p_submodule, VLC_MODULE_CAPABILITY, (void *)(cap)) \
+     || vlc_module_set (p_submodule, VLC_MODULE_SCORE, (void *)(score))) \
+        goto error
 
 #define set_program( program ) \
-    vlc_module_set (p_submodule, VLC_MODULE_PROGRAM, (void *)(program))
+    if (vlc_module_set (p_submodule, VLC_MODULE_PROGRAM, (void *)(program))) \
+        goto error
 
 #define set_callbacks( activate, deactivate ) \
-    vlc_module_set (p_submodule, VLC_MODULE_CB_OPEN, (void *)(activate)); \
-    vlc_module_set (p_submodule, VLC_MODULE_CB_CLOSE, (void *)(deactivate))
+    if (vlc_module_set (p_submodule, VLC_MODULE_CB_OPEN, (void *)(activate)) \
+     || vlc_module_set (p_submodule, VLC_MODULE_CB_CLOSE, \
+                        (void *)(deactivate))) \
+        goto error
 
 #define linked_with_a_crap_library_which_uses_atexit( ) \
-    vlc_module_set (p_submodule, VLC_MODULE_UNLOADABLE, NULL)
+    if (vlc_module_set (p_submodule, VLC_MODULE_UNLOADABLE, NULL)) goto error
 
index 76ca57d..8dff09a 100644 (file)
 #include <vlc/vlc.h>
 #include <assert.h>
 
+static const char default_name[] = "unnamed";
+
+module_t *vlc_module_create (vlc_object_t *obj)
+{
+    module_t *module = vlc_object_create (obj, VLC_OBJECT_MODULE);
+    if (module == NULL)
+        return NULL;
+
+#ifndef HAVE_SHARED_LIBVLC
+    module->p_symbols = &obj->p_libvlc_global->p_module_bank->symbols;
+#endif
+    module->b_loaded = module->b_submodule = VLC_FALSE;
+    module->b_reentrant = module->b_unloadable = VLC_TRUE;
+    module->psz_object_name = module->psz_longname = default_name;
+    module->psz_help = module->psz_shortname = NULL;
+    module->pp_shortcuts[0] = default_name;
+    for (unsigned i = 1; i < MODULE_SHORTCUT_MAX; i++)
+         module->pp_shortcuts[i] = NULL;
+
+    module->i_cpu = 0;
+    module->psz_program = NULL;
+    module->psz_capability = "";
+    module->i_score = 1;
+    module->pf_activate = NULL;
+    module->pf_deactivate = NULL;
+    return module;
+}
+
 
 module_t *vlc_submodule_create (module_t *module)
 {
@@ -51,6 +79,7 @@ module_t *vlc_submodule_create (module_t *module)
     return submodule;
 }
 
+
 int vlc_module_set (module_t *module, int propid, void *value)
 {
     switch (propid)
@@ -107,6 +136,12 @@ int vlc_module_set (module_t *module, int propid, void *value)
             module->b_unloadable = (value != NULL);
             break;
 
+        case VLC_MODULE_NAME:
+            module->pp_shortcuts[0] = module->psz_object_name = (char *)value;
+            if (module->psz_longname == default_name)
+                module->psz_longname = (char *)value;
+            break;
+
         default:
             msg_Err (module, "unknown module property %d", propid);
             msg_Err (module, "LibVLC might be too old to use this module.");
index 9e426c6..3611b7d 100644 (file)
@@ -1119,7 +1119,7 @@ static module_t * AllocatePlugin( vlc_object_t * p_this, char * psz_file )
 
     /* Now that we have successfully loaded the module, we can
      * allocate a structure for it */
-    p_module = vlc_object_create( p_this, VLC_OBJECT_MODULE );
+    p_module = vlc_module_create( p_this );
     if( p_module == NULL )
     {
         msg_Err( p_this, "out of memory" );
@@ -1130,9 +1130,6 @@ static module_t * AllocatePlugin( vlc_object_t * p_this, char * psz_file )
     /* We need to fill these since they may be needed by CallEntry() */
     p_module->psz_filename = psz_file;
     p_module->handle = handle;
-#ifndef HAVE_SHARED_LIBVLC
-    p_module->p_symbols = &p_this->p_libvlc_global->p_module_bank->symbols;
-#endif
     p_module->b_loaded = VLC_TRUE;
 
     /* Initialize the module: fill p_module, default config */