Introduce struct spk_flags to reduce argument count for enumeration callback

This commit is contained in:
Julien BLACHE 2011-03-05 10:25:44 +01:00
parent c1fae0012d
commit f3e7836453
3 changed files with 20 additions and 8 deletions

View File

@ -1344,7 +1344,7 @@ dacp_reply_setproperty(struct evhttp_request *req, struct evbuffer *evbuf, char
}
static void
speaker_enum_cb(uint64_t id, const char *name, int relvol, int selected, int has_password, void *arg)
speaker_enum_cb(uint64_t id, const char *name, int relvol, struct spk_flags flags, void *arg)
{
struct evbuffer *evbuf;
int len;
@ -1352,15 +1352,15 @@ speaker_enum_cb(uint64_t id, const char *name, int relvol, int selected, int has
evbuf = (struct evbuffer *)arg;
len = 8 + strlen(name) + 28;
if (selected)
if (flags.selected)
len += 9;
if (has_password)
if (flags.has_password)
len += 9;
dmap_add_container(evbuf, "mdcl", len); /* 8 + len */
if (selected)
if (flags.selected)
dmap_add_char(evbuf, "caia", 1); /* 9 */
if (has_password)
if (flags.has_password)
dmap_add_char(evbuf, "cahp", 1); /* 9 */
dmap_add_string(evbuf, "minm", name); /* 8 + len */
dmap_add_long(evbuf, "msma", id); /* 16 */

View File

@ -2385,6 +2385,7 @@ speaker_enumerate(struct player_command *cmd)
{
struct raop_device *rd;
struct spk_enum *spk_enum;
struct spk_flags flags;
char *laudio_name;
spk_enum = cmd->arg.spk_enum;
@ -2395,7 +2396,10 @@ speaker_enumerate(struct player_command *cmd)
if (!dev_list && !laudio_selected)
speaker_select_laudio();
spk_enum->cb(0, laudio_name, laudio_relvol, laudio_selected, 0, spk_enum->arg);
flags.selected = laudio_selected;
flags.has_password = 0;
spk_enum->cb(0, laudio_name, laudio_relvol, flags, spk_enum->arg);
#ifdef DEBUG_RELVOL
DPRINTF(E_DBG, L_PLAYER, "*** master: %d\n", master_volume);
@ -2406,7 +2410,10 @@ speaker_enumerate(struct player_command *cmd)
{
if (rd->advertised || rd->selected)
{
spk_enum->cb(rd->id, rd->name, rd->relvol, rd->selected, rd->has_password, spk_enum->arg);
flags.selected = rd->selected;
flags.has_password = rd->has_password;
spk_enum->cb(rd->id, rd->name, rd->relvol, flags, spk_enum->arg);
#ifdef DEBUG_RELVOL
DPRINTF(E_DBG, L_PLAYER, "*** %s: abs %d rel %d\n", rd->name, rd->volume, rd->relvol);

View File

@ -32,6 +32,11 @@ enum repeat_mode {
REPEAT_ALL = 2,
};
struct spk_flags {
unsigned selected:1;
unsigned has_password:1;
};
struct player_status {
enum play_status status;
enum repeat_mode repeat;
@ -45,7 +50,7 @@ struct player_status {
int pos_pl;
};
typedef void (*spk_enum_cb)(uint64_t id, const char *name, int relvol, int selected, int has_password, void *arg);
typedef void (*spk_enum_cb)(uint64_t id, const char *name, int relvol, struct spk_flags flags, void *arg);
typedef void (*player_status_handler)(void);
struct player_source;