[vlc-commits] variables: add helper function when adding/removing variable callbacks
Felix Abecassis
git at videolan.org
Mon Aug 4 12:16:06 CEST 2014
vlc | branch: master | Felix Abecassis <felix.abecassis at gmail.com> | Mon Aug 4 12:06:18 2014 +0200| [f8187680bdee75e53bc722403bf06fdd4d845c47] | committer: Felix Abecassis
variables: add helper function when adding/removing variable callbacks
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f8187680bdee75e53bc722403bf06fdd4d845c47
---
src/misc/variables.c | 80 ++++++++++++++++++++++++++++++--------------------
1 file changed, 48 insertions(+), 32 deletions(-)
diff --git a/src/misc/variables.c b/src/misc/variables.c
index a631863..69d0dce 100644
--- a/src/misc/variables.c
+++ b/src/misc/variables.c
@@ -804,36 +804,15 @@ int var_Get( vlc_object_t *p_this, const char *psz_name, vlc_value_t *p_val )
return var_GetChecked( p_this, psz_name, 0, p_val );
}
-#undef var_AddCallback
-/**
- * Register a callback in a variable
- *
- * We store a function pointer that will be called upon variable
- * modification.
- *
- * \param p_this The object that holds the variable
- * \param psz_name The name of the variable
- * \param pf_callback The function pointer
- * \param p_data A generic pointer that will be passed as the last
- * argument to the callback function.
- *
- * \warning The callback function is run in the thread that calls var_Set on
- * the variable. Use proper locking. This thread may not have much
- * time to spare, so keep callback functions short.
- */
-int var_AddCallback( vlc_object_t *p_this, const char *psz_name,
- vlc_callback_t pf_callback, void *p_data )
+static int AddCallback( vlc_object_t *p_this, const char *psz_name,
+ callback_entry_t entry )
{
variable_t *p_var;
- callback_entry_t entry;
assert( p_this );
vlc_object_internals_t *p_priv = vlc_internals( p_this );
- entry.pf_callback = pf_callback;
- entry.p_data = p_data;
-
vlc_mutex_lock( &p_priv->var_lock );
p_var = Lookup( p_this, psz_name );
@@ -841,7 +820,7 @@ int var_AddCallback( vlc_object_t *p_this, const char *psz_name,
{
vlc_mutex_unlock( &p_priv->var_lock );
msg_Err( p_this, "cannot add callback %p to nonexistent "
- "variable '%s'", pf_callback, psz_name );
+ "variable '%s'", entry.pf_callback, psz_name );
return VLC_ENOVAR;
}
@@ -856,16 +835,36 @@ int var_AddCallback( vlc_object_t *p_this, const char *psz_name,
return VLC_SUCCESS;
}
-#undef var_DelCallback
+#undef var_AddCallback
/**
- * Remove a callback from a variable
+ * Register a callback in a variable
*
- * pf_callback and p_data have to be given again, because different objects
- * might have registered the same callback function.
+ * We store a function pointer that will be called upon variable
+ * modification.
+ *
+ * \param p_this The object that holds the variable
+ * \param psz_name The name of the variable
+ * \param pf_callback The function pointer
+ * \param p_data A generic pointer that will be passed as the last
+ * argument to the callback function.
+ *
+ * \warning The callback function is run in the thread that calls var_Set on
+ * the variable. Use proper locking. This thread may not have much
+ * time to spare, so keep callback functions short.
*/
-int var_DelCallback( vlc_object_t *p_this, const char *psz_name,
+int var_AddCallback( vlc_object_t *p_this, const char *psz_name,
vlc_callback_t pf_callback, void *p_data )
{
+ callback_entry_t entry;
+ entry.pf_callback = pf_callback;
+ entry.p_data = p_data;
+
+ return AddCallback(p_this, psz_name, entry);
+}
+
+static int DelCallback( vlc_object_t *p_this, const char *psz_name,
+ callback_entry_t entry )
+{
int i_entry;
variable_t *p_var;
#ifndef NDEBUG
@@ -889,13 +888,13 @@ int var_DelCallback( vlc_object_t *p_this, const char *psz_name,
for( i_entry = p_var->i_entries ; i_entry-- ; )
{
- if( p_var->p_entries[i_entry].pf_callback == pf_callback
- && p_var->p_entries[i_entry].p_data == p_data )
+ if( p_var->p_entries[i_entry].pf_callback == entry.pf_callback
+ && p_var->p_entries[i_entry].p_data == entry.p_data )
{
break;
}
#ifndef NDEBUG
- else if( p_var->p_entries[i_entry].pf_callback == pf_callback )
+ else if( p_var->p_entries[i_entry].pf_callback == entry.pf_callback )
b_found_similar = true;
#endif
}
@@ -919,6 +918,23 @@ int var_DelCallback( vlc_object_t *p_this, const char *psz_name,
return VLC_SUCCESS;
}
+#undef var_DelCallback
+/**
+ * Remove a callback from a variable
+ *
+ * pf_callback and p_data have to be given again, because different objects
+ * might have registered the same callback function.
+ */
+int var_DelCallback( vlc_object_t *p_this, const char *psz_name,
+ vlc_callback_t pf_callback, void *p_data )
+{
+ callback_entry_t entry;
+ entry.pf_callback = pf_callback;
+ entry.p_data = p_data;
+
+ return DelCallback(p_this, psz_name, entry);
+}
+
#undef var_TriggerCallback
/**
* Trigger callback on a variable
More information about the vlc-commits
mailing list