diff options
author | waker <wakeroid@gmail.com> | 2013-08-04 19:32:58 +0200 |
---|---|---|
committer | waker <wakeroid@gmail.com> | 2013-08-04 19:32:58 +0200 |
commit | aa7b6ad5b0e94004a0e27007fcdf807baa34bce0 (patch) | |
tree | a87d1c43133867fb2dd5e5f45019c2d374724135 | |
parent | 3add6598c6ac4aadc29b6ce77bb99ab2bb0a163b (diff) |
added new API for querying/handling background jobs
-rw-r--r-- | deadbeef.h | 8 | ||||
-rw-r--r-- | plugins.c | 31 | ||||
-rw-r--r-- | plugins.h | 9 |
3 files changed, 48 insertions, 0 deletions
@@ -795,9 +795,17 @@ typedef struct { // data size must be float[DDB_AUDIO_MEMORY_FRAMES] void (*audio_get_waveform_data) (int type, float *data); + // this is useful to mute/unmute audio, and query the muted status, from + // plugins, without touching the volume control void (*audio_set_mute) (int mute); int (*audio_is_mute) (void); + // this is useful for prompting a user when he attempts to quit the player + // while something is working in background, e.g. the Converter, + // and let him finish or cancel the background jobs. + void (*background_job_increment) (void); + void (*background_job_decrement) (void); + int (*have_background_jobs) (void); } DB_functions_t; // NOTE: an item placement must be selected like this @@ -344,6 +344,9 @@ static DB_functions_t deadbeef_api = { .audio_get_waveform_data = audio_get_waveform_data, .audio_set_mute = audio_set_mute, .audio_is_mute = audio_is_mute, + .background_job_increment = background_job_increment, + .background_job_decrement = background_job_decrement, + .have_background_jobs = have_background_jobs, }; DB_functions_t *deadbeef = &deadbeef_api; @@ -407,6 +410,9 @@ DB_output_t *output_plugin = NULL; #define MAX_PLAYLIST_PLUGINS 10 DB_playlist_t *g_playlist_plugins[MAX_PLAYLIST_PLUGINS+1]; +static uintptr_t background_jobs_mutex; +static int num_background_jobs; + void plug_md5 (uint8_t sig[16], const char *in, int len) { md5_state_t st; @@ -786,6 +792,8 @@ plug_load_all (void) { trace ("\033[0;31mDISABLE_VERSIONCHECK=1! do not distribute!\033[0;m\n"); #endif + background_jobs_mutex = mutex_create (); + const char *dirname = deadbeef->get_plugin_dir (); #ifndef ANDROID @@ -1062,6 +1070,10 @@ plug_unload_all (void) { memset (g_playlist_plugins, 0, sizeof (g_playlist_plugins)); trace ("all plugins had been unloaded\n"); + if (background_jobs_mutex) { + mutex_free (background_jobs_mutex); + background_jobs_mutex = 0; + } } void @@ -1260,3 +1272,22 @@ plug_is_local_file (const char *fname) { return 1; } + +void +background_job_increment (void) { + mutex_lock (background_jobs_mutex); + num_background_jobs++; + mutex_unlock (background_jobs_mutex); +} + +void +background_job_decrement (void) { + mutex_lock (background_jobs_mutex); + num_background_jobs--; + mutex_unlock (background_jobs_mutex); +} + +int +have_background_jobs (void) { + return num_background_jobs; +} @@ -136,4 +136,13 @@ plug_get_gui_names (void); void plug_event_call (ddb_event_t *ev); +void +background_job_increment (void); + +void +background_job_decrement (void); + +int +have_background_jobs (void); + #endif // __PLUGINS_H |