[vlc-commits] core: Add a private pointer for hotkeys/actions handler
Rémi Denis-Courmont
git at videolan.org
Sat Feb 12 22:57:38 CET 2011
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Feb 12 23:13:18 2011 +0200| [cd1e2f6a68c2acb18db5956a4807a03e72a06692] | committer: Rémi Denis-Courmont
core: Add a private pointer for hotkeys/actions handler
We cannot fully privatize this, as the global hotkeys plugin read the
list of actions through the public LibVLC instance pointer.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=cd1e2f6a68c2acb18db5956a4807a03e72a06692
---
src/config/keys.c | 48 +++++++++++++++++++++++++++---------------------
src/libvlc.c | 4 ++--
src/libvlc.h | 6 ++++--
3 files changed, 33 insertions(+), 25 deletions(-)
diff --git a/src/config/keys.c b/src/config/keys.c
index 8ae8aa9..36c2f84 100644
--- a/src/config/keys.c
+++ b/src/config/keys.c
@@ -334,6 +334,11 @@ static int keycmp (const void *a, const void *b)
#endif
}
+struct vlc_actions
+{
+ struct hotkey keys[0];
+};
+
/**
* Get the action ID associated with a VLC key code, if any.
*/
@@ -362,29 +367,27 @@ static int vlc_key_to_action (vlc_object_t *libvlc, const char *varname,
}
-int vlc_InitActions (libvlc_int_t *libvlc)
+struct vlc_actions *vlc_InitActions (libvlc_int_t *libvlc)
{
struct hotkey *keys;
+ struct vlc_actions *as = malloc (sizeof (*as) + (ACTIONS_COUNT + 1) * sizeof (*keys));
+
+ if (unlikely(as == NULL))
+ return NULL;
+ keys = as->keys;
var_Create (libvlc, "key-pressed", VLC_VAR_INTEGER);
var_Create (libvlc, "key-action", VLC_VAR_INTEGER);
- keys = malloc ((ACTIONS_COUNT + 1) * sizeof (*keys));
- if (keys == NULL)
- {
- libvlc->p_hotkeys = NULL;
- return VLC_ENOMEM;
- }
-
/* Initialize from configuration */
for (size_t i = 0; i < ACTIONS_COUNT; i++)
{
char *str = var_InheritString (libvlc, actions[i].name);
uint32_t code = str ? vlc_str2keycode (str) : KEY_UNSET;
- keys[i].psz_action = actions[i].name;
- keys[i].i_key = code;
- keys[i].i_action = actions[i].value;
+ keys->psz_action = actions[i].name;
+ keys->i_key = code;
+ keys->i_action = actions[i].value;
#ifndef NDEBUG
if (i > 0
&& strcmp (actions[i-1].name, actions[i].name) >= 0)
@@ -394,24 +397,27 @@ int vlc_InitActions (libvlc_int_t *libvlc)
abort ();
}
#endif
+ keys++;
}
- qsort (keys, ACTIONS_COUNT, sizeof (*keys), keycmp);
+ qsort (as->keys, ACTIONS_COUNT, sizeof (*keys), keycmp);
- keys[ACTIONS_COUNT].psz_action = NULL;
- keys[ACTIONS_COUNT].i_key = 0;
- keys[ACTIONS_COUNT].i_action = 0;
+ keys->psz_action = NULL;
+ keys->i_key = 0;
+ keys->i_action = 0;
- libvlc->p_hotkeys = keys;
- var_AddCallback (libvlc, "key-pressed", vlc_key_to_action, NULL);
+ libvlc->p_hotkeys = as->keys;
+ var_AddCallback (libvlc, "key-pressed", vlc_key_to_action, as);
return VLC_SUCCESS;
}
-void vlc_DeinitActions (libvlc_int_t *libvlc)
+void vlc_DeinitActions (libvlc_int_t *libvlc, struct vlc_actions *as)
{
- if (unlikely(libvlc->p_hotkeys == NULL))
+ if (unlikely(as == NULL))
return;
- var_DelCallback (libvlc, "key-pressed", vlc_key_to_action, NULL);
- free ((void *)libvlc->p_hotkeys);
+
+ var_DelCallback (libvlc, "key-pressed", vlc_key_to_action, as);
+ free (as);
+ libvlc->p_hotkeys = NULL;
}
diff --git a/src/libvlc.c b/src/libvlc.c
index b82d720..1d4a1d5 100644
--- a/src/libvlc.c
+++ b/src/libvlc.c
@@ -763,7 +763,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
/*
* Initialize hotkey handling
*/
- vlc_InitActions( p_libvlc );
+ priv->actions = vlc_InitActions( p_libvlc );
/* Create a variable for showing the fullscreen interface */
var_Create( p_libvlc, "intf-show", VLC_VAR_BOOL );
@@ -1054,7 +1054,7 @@ void libvlc_InternalCleanup( libvlc_int_t *p_libvlc )
/* Free module bank. It is refcounted, so we call this each time */
module_EndBank( p_libvlc, true );
- vlc_DeinitActions( p_libvlc );
+ vlc_DeinitActions( p_libvlc, priv->actions );
}
/**
diff --git a/src/libvlc.h b/src/libvlc.h
index d443848..6eeedc1 100644
--- a/src/libvlc.h
+++ b/src/libvlc.h
@@ -28,8 +28,9 @@
typedef struct variable_t variable_t;
/* Actions (hot keys) */
-extern int vlc_InitActions (libvlc_int_t *);
-extern void vlc_DeinitActions (libvlc_int_t *);
+struct vlc_actions;
+struct vlc_actions *vlc_InitActions (libvlc_int_t *);
+extern void vlc_DeinitActions (libvlc_int_t *, struct vlc_actions *);
size_t vlc_towc (const char *str, uint32_t *restrict pwc);
@@ -211,6 +212,7 @@ typedef struct libvlc_priv_t
#ifdef ENABLE_SOUT
sap_handler_t *p_sap; ///< SAP SDP advertiser
#endif
+ struct vlc_actions *actions; ///< Hotkeys handler
/* Interfaces */
struct intf_thread_t *p_intf; ///< Interfaces linked-list
More information about the vlc-commits
mailing list