Commit fa27e5e4 authored by Thomas Guillem's avatar Thomas Guillem Committed by Hugo Beauzée-Luyssen

actions: refactor init/deinit functions

Signed-off-by: default avatarHugo Beauzée-Luyssen <hugo@beauzee.fr>
parent c0d287e7
...@@ -24,6 +24,14 @@ ...@@ -24,6 +24,14 @@
#ifndef VLC_ACTIONS_H #ifndef VLC_ACTIONS_H
#define VLC_ACTIONS_H 1 #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 * \file
* This file defines keys and functions * This file defines keys and functions
......
...@@ -54,6 +54,7 @@ ...@@ -54,6 +54,7 @@
#include <vlc_playlist.h> #include <vlc_playlist.h>
#include <vlc_interface.h> #include <vlc_interface.h>
#include <vlc_actions.h>
#include <vlc_charset.h> #include <vlc_charset.h>
#include <vlc_dialog.h> #include <vlc_dialog.h>
#include <vlc_keystore.h> #include <vlc_keystore.h>
...@@ -233,8 +234,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, ...@@ -233,8 +234,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
/* /*
* Initialize hotkey handling * Initialize hotkey handling
*/ */
priv->actions = vlc_InitActions( p_libvlc ); if( libvlc_InternalActionsInit( p_libvlc ) != VLC_SUCCESS )
if( !priv->actions )
goto error; goto error;
/* /*
...@@ -416,7 +416,7 @@ void libvlc_InternalCleanup( libvlc_int_t *p_libvlc ) ...@@ -416,7 +416,7 @@ void libvlc_InternalCleanup( libvlc_int_t *p_libvlc )
if (priv->parser != NULL) if (priv->parser != NULL)
playlist_preparser_Delete(priv->parser); playlist_preparser_Delete(priv->parser);
vlc_DeinitActions( p_libvlc, priv->actions ); libvlc_InternalActionsClean( p_libvlc );
/* Save the configuration */ /* Save the configuration */
if( !var_InheritBool( p_libvlc, "ignore-config" ) ) if( !var_InheritBool( p_libvlc, "ignore-config" ) )
......
...@@ -31,8 +31,6 @@ typedef struct variable_t variable_t; ...@@ -31,8 +31,6 @@ typedef struct variable_t variable_t;
/* Actions (hot keys) */ /* Actions (hot keys) */
struct vlc_actions; struct vlc_actions;
struct vlc_actions *vlc_InitActions (libvlc_int_t *);
extern void vlc_DeinitActions (libvlc_int_t *, struct vlc_actions *);
/* /*
* OS-specific initialization * OS-specific initialization
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
# include <config.h> # include <config.h>
#endif #endif
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <limits.h> #include <limits.h>
#ifdef HAVE_SEARCH_H #ifdef HAVE_SEARCH_H
...@@ -504,14 +505,16 @@ static void vlc_InitAction (vlc_object_t *obj, void **map, ...@@ -504,14 +505,16 @@ static void vlc_InitAction (vlc_object_t *obj, void **map,
/** /**
* Initializes the key map from configuration. * 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); vlc_object_t *obj = VLC_OBJECT(libvlc);
struct hotkey *keys; struct hotkey *keys;
struct vlc_actions *as = malloc (sizeof (*as) + ACTIONS_COUNT * sizeof (*keys)); struct vlc_actions *as = malloc (sizeof (*as) + ACTIONS_COUNT * sizeof (*keys));
if (unlikely(as == NULL)) if (unlikely(as == NULL))
return NULL; return VLC_ENOMEM;
as->map = NULL; as->map = NULL;
as->global_map = NULL; as->global_map = NULL;
keys = as->keys; keys = as->keys;
...@@ -549,18 +552,22 @@ struct vlc_actions *vlc_InitActions (libvlc_int_t *libvlc) ...@@ -549,18 +552,22 @@ struct vlc_actions *vlc_InitActions (libvlc_int_t *libvlc)
vlc_AddWheelMapping (&as->map, KEY_MOUSEWHEELUP, KEY_MOUSEWHEELDOWN, vlc_AddWheelMapping (&as->map, KEY_MOUSEWHEELUP, KEY_MOUSEWHEELDOWN,
var_InheritInteger (obj, "hotkeys-y-wheel-mode")); var_InheritInteger (obj, "hotkeys-y-wheel-mode"));
libvlc_priv(libvlc)->actions = as;
libvlc->p_hotkeys = as->keys; libvlc->p_hotkeys = as->keys;
var_AddCallback (obj, "key-pressed", vlc_key_to_action, &as->map); var_AddCallback (obj, "key-pressed", vlc_key_to_action, &as->map);
var_AddCallback (obj, "global-key-pressed", vlc_key_to_action, var_AddCallback (obj, "global-key-pressed", vlc_key_to_action,
&as->global_map); &as->global_map);
return as; return VLC_SUCCESS;
} }
/** /**
* Destroys the key map. * 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)) if (unlikely(as == NULL))
return; return;
...@@ -571,6 +578,7 @@ void vlc_DeinitActions (libvlc_int_t *libvlc, struct vlc_actions *as) ...@@ -571,6 +578,7 @@ void vlc_DeinitActions (libvlc_int_t *libvlc, struct vlc_actions *as)
tdestroy (as->global_map, free); tdestroy (as->global_map, free);
tdestroy (as->map, free); tdestroy (as->map, free);
free (as); free (as);
libvlc_priv(libvlc)->actions = NULL;
libvlc->p_hotkeys = NULL; libvlc->p_hotkeys = NULL;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment