[vlc-commits] actions: refactor init/deinit functions
Thomas Guillem
git at videolan.org
Wed Aug 9 10:54:52 CEST 2017
vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Thu Aug 3 15:10:36 2017 +0200| [fa27e5e41ccd5dc17c043b874fe2e06fcc6cb047] | committer: Hugo Beauzée-Luyssen
actions: refactor init/deinit functions
Signed-off-by: Hugo Beauzée-Luyssen <hugo at beauzee.fr>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=fa27e5e41ccd5dc17c043b874fe2e06fcc6cb047
---
include/vlc_actions.h | 8 ++++++++
src/libvlc.c | 6 +++---
src/libvlc.h | 2 --
src/misc/actions.c | 16 ++++++++++++----
4 files changed, 23 insertions(+), 9 deletions(-)
diff --git a/include/vlc_actions.h b/include/vlc_actions.h
index c3f4172617..6a0f2e1853 100644
--- a/include/vlc_actions.h
+++ b/include/vlc_actions.h
@@ -24,6 +24,14 @@
#ifndef VLC_ACTIONS_H
#define VLC_ACTIONS_H 1
+/* Called from src/libvlc.c */
+int
+libvlc_InternalActionsInit(libvlc_int_t *p_libvlc);
+
+/* Called from src/libvlc.c */
+void
+libvlc_InternalActionsClean(libvlc_int_t *p_libvlc);
+
/**
* \file
* This file defines keys and functions
diff --git a/src/libvlc.c b/src/libvlc.c
index c7e7b9013d..7e343a6365 100644
--- a/src/libvlc.c
+++ b/src/libvlc.c
@@ -54,6 +54,7 @@
#include <vlc_playlist.h>
#include <vlc_interface.h>
+#include <vlc_actions.h>
#include <vlc_charset.h>
#include <vlc_dialog.h>
#include <vlc_keystore.h>
@@ -233,8 +234,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
/*
* Initialize hotkey handling
*/
- priv->actions = vlc_InitActions( p_libvlc );
- if( !priv->actions )
+ if( libvlc_InternalActionsInit( p_libvlc ) != VLC_SUCCESS )
goto error;
/*
@@ -416,7 +416,7 @@ void libvlc_InternalCleanup( libvlc_int_t *p_libvlc )
if (priv->parser != NULL)
playlist_preparser_Delete(priv->parser);
- vlc_DeinitActions( p_libvlc, priv->actions );
+ libvlc_InternalActionsClean( p_libvlc );
/* Save the configuration */
if( !var_InheritBool( p_libvlc, "ignore-config" ) )
diff --git a/src/libvlc.h b/src/libvlc.h
index 299795c549..59d6f2dfb3 100644
--- a/src/libvlc.h
+++ b/src/libvlc.h
@@ -31,8 +31,6 @@ typedef struct variable_t variable_t;
/* Actions (hot keys) */
struct vlc_actions;
-struct vlc_actions *vlc_InitActions (libvlc_int_t *);
-extern void vlc_DeinitActions (libvlc_int_t *, struct vlc_actions *);
/*
* OS-specific initialization
diff --git a/src/misc/actions.c b/src/misc/actions.c
index 968a085a0b..e92b431358 100644
--- a/src/misc/actions.c
+++ b/src/misc/actions.c
@@ -33,6 +33,7 @@
# include <config.h>
#endif
+#include <assert.h>
#include <stdlib.h>
#include <limits.h>
#ifdef HAVE_SEARCH_H
@@ -504,14 +505,16 @@ static void vlc_InitAction (vlc_object_t *obj, void **map,
/**
* Initializes the key map from configuration.
*/
-struct vlc_actions *vlc_InitActions (libvlc_int_t *libvlc)
+int libvlc_InternalActionsInit (libvlc_int_t *libvlc)
{
+ assert(libvlc != NULL);
+
vlc_object_t *obj = VLC_OBJECT(libvlc);
struct hotkey *keys;
struct vlc_actions *as = malloc (sizeof (*as) + ACTIONS_COUNT * sizeof (*keys));
if (unlikely(as == NULL))
- return NULL;
+ return VLC_ENOMEM;
as->map = NULL;
as->global_map = NULL;
keys = as->keys;
@@ -549,18 +552,22 @@ struct vlc_actions *vlc_InitActions (libvlc_int_t *libvlc)
vlc_AddWheelMapping (&as->map, KEY_MOUSEWHEELUP, KEY_MOUSEWHEELDOWN,
var_InheritInteger (obj, "hotkeys-y-wheel-mode"));
+ libvlc_priv(libvlc)->actions = as;
libvlc->p_hotkeys = as->keys;
var_AddCallback (obj, "key-pressed", vlc_key_to_action, &as->map);
var_AddCallback (obj, "global-key-pressed", vlc_key_to_action,
&as->global_map);
- return as;
+ return VLC_SUCCESS;
}
/**
* Destroys the key map.
*/
-void vlc_DeinitActions (libvlc_int_t *libvlc, struct vlc_actions *as)
+void libvlc_InternalActionsClean (libvlc_int_t *libvlc)
{
+ assert(libvlc != NULL);
+
+ struct vlc_actions *as = libvlc_priv(libvlc)->actions;
if (unlikely(as == NULL))
return;
@@ -571,6 +578,7 @@ void vlc_DeinitActions (libvlc_int_t *libvlc, struct vlc_actions *as)
tdestroy (as->global_map, free);
tdestroy (as->map, free);
free (as);
+ libvlc_priv(libvlc)->actions = NULL;
libvlc->p_hotkeys = NULL;
}
More information about the vlc-commits
mailing list