From ad0c0f361be0c7fcae50dabb21e28be728755096 Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Sat, 30 Jul 2011 18:50:58 +0100 Subject: [PATCH] Support global prefs through eclient interface. Organization: Straylight/Edgeware From: Richard Kettlewell Additionally, cope a bit better with NULL callbacks. --- lib/eclient.c | 53 ++++++++++++++++++++++++++++++++++++++++++--------- lib/eclient.h | 18 +++++++++++++++++ 2 files changed, 62 insertions(+), 9 deletions(-) diff --git a/lib/eclient.c b/lib/eclient.c index 5eda674..d03306e 100644 --- a/lib/eclient.c +++ b/lib/eclient.c @@ -193,6 +193,7 @@ static void logentry_adopted(disorder_eclient *c, int nvec, char **vec); static void logentry_playlist_created(disorder_eclient *c, int nvec, char **vec); static void logentry_playlist_deleted(disorder_eclient *c, int nvec, char **vec); static void logentry_playlist_modified(disorder_eclient *c, int nvec, char **vec); +static void logentry_global_pref(disorder_eclient *c, int nvec, char **vec); /* Tables ********************************************************************/ @@ -212,6 +213,7 @@ static const struct logentry_handler logentry_handlers[] = { LE(adopted, 2, 2), LE(completed, 1, 1), LE(failed, 2, 2), + LE(global_pref, 1, 2), LE(moved, 1, 1), LE(playing, 1, 2), LE(playlist_created, 2, 2), @@ -916,8 +918,8 @@ static void string_response_opcallback(disorder_eclient *c, = (disorder_eclient_string_response *)op->completed; D(("string_response_callback")); - if(c->rc / 100 == 2 || c->rc == 555) { - if(op->completed) { + if(completed) { + if(c->rc / 100 == 2 || c->rc == 555) { if(c->rc == 555) completed(op->v, NULL, NULL); else if(c->protocol >= 2) { @@ -931,9 +933,9 @@ static void string_response_opcallback(disorder_eclient *c, completed(op->v, "error parsing response", NULL); } else completed(op->v, NULL, c->line + 4); - } - } else - completed(op->v, errorstring(c), NULL); + } else + completed(op->v, errorstring(c), NULL); + } } /* for commands with a simple integer response */ @@ -963,10 +965,12 @@ static void no_response_opcallback(disorder_eclient *c, = (disorder_eclient_no_response *)op->completed; D(("no_response_callback")); - if(c->rc / 100 == 2) - completed(op->v, NULL); - else - completed(op->v, errorstring(c)); + if(completed) { + if(c->rc / 100 == 2) + completed(op->v, NULL); + else + completed(op->v, errorstring(c)); + } } /* error callback for queue_unmarshall */ @@ -1356,6 +1360,31 @@ int disorder_eclient_nop(disorder_eclient *c, "nop", (char *)0); } +int disorder_eclient_get_global(disorder_eclient *c, + disorder_eclient_string_response *completed, + const char *pref, + void *v) { + return simple(c, string_response_opcallback, (void (*)())completed, v, + "get-global", pref, (char *)0); +} + +int disorder_eclient_set_global(disorder_eclient *c, + disorder_eclient_no_response *completed, + const char *pref, + const char *value, + void *v) { + return simple(c, no_response_opcallback, (void (*)())completed, v, + "set-global", pref, value, (char *)0); +} + +int disorder_eclient_unset_global(disorder_eclient *c, + disorder_eclient_no_response *completed, + const char *pref, + void *v) { + return simple(c, no_response_opcallback, (void (*)())completed, v, + "unset-global", pref, (char *)0); +} + /** @brief Get the last @p max added tracks * @param c Client * @param completed Called with list @@ -1919,6 +1948,12 @@ static void logentry_adopted(disorder_eclient *c, c->log_callbacks->adopted(c->log_v, vec[0], vec[1]); } +static void logentry_global_pref(disorder_eclient *c, + int nvec, char **vec) { + if(c->log_callbacks->global_pref) + c->log_callbacks->global_pref(c->log_v, vec[0], nvec > 1 ? vec[1] : 0); +} + /* Local Variables: c-basic-offset:2 diff --git a/lib/eclient.h b/lib/eclient.h index b100106..c44c5dc 100644 --- a/lib/eclient.h +++ b/lib/eclient.h @@ -177,6 +177,9 @@ typedef struct disorder_eclient_log_callbacks { /** @brief Called when a new playlist is deleted */ void (*playlist_deleted)(void *v, const char *playlist); + + /** @brief Called when a global pref is changed or delete */ + void (*global_pref)(void *v, const char *pref, const char *value/*or NULL*/); } disorder_eclient_log_callbacks; /* State bits */ @@ -461,6 +464,21 @@ int disorder_eclient_unset(disorder_eclient *c, void *v); /* Get/set preference values */ +int disorder_eclient_get_global(disorder_eclient *c, + disorder_eclient_string_response *completed, + const char *pref, + void *v); +int disorder_eclient_set_global(disorder_eclient *c, + disorder_eclient_no_response *completed, + const char *pref, + const char *value, + void *v); +int disorder_eclient_unset_global(disorder_eclient *c, + disorder_eclient_no_response *completed, + const char *pref, + void *v); +/* Get/set global prefs */ + int disorder_eclient_search(disorder_eclient *c, disorder_eclient_list_response *completed, const char *terms, -- [mdw]