From 94fd370df28d4e4bf9a764984660929225fb0248 Mon Sep 17 00:00:00 2001
From: chme <christian.meffert@googlemail.com>
Date: Wed, 7 Feb 2018 21:30:38 +0100
Subject: [PATCH] [player] Simplify parameter passing to player commands

---
 src/player.c | 115 +++++++++++++++++++--------------------------------
 1 file changed, 42 insertions(+), 73 deletions(-)

diff --git a/src/player.c b/src/player.c
index b908760a..8f0f60b2 100644
--- a/src/player.c
+++ b/src/player.c
@@ -155,16 +155,7 @@ struct speaker_auth_param
 
 union player_arg
 {
-  struct volume_param vol_param;
-  void *noarg;
-  struct spk_enum *spk_enum;
   struct output_device *device;
-  struct player_status *status;
-  struct player_source *ps;
-  struct metadata_param metadata_param;
-  uint32_t *id_ptr;
-  struct speaker_set_param speaker_set_param;
-  enum repeat_mode mode;
   struct speaker_auth_param auth;
   uint32_t id;
   int intval;
@@ -1375,13 +1366,12 @@ device_auth_kickoff(void *arg, int *retval)
 static enum command_state
 device_metadata_send(void *arg, int *retval)
 {
-  union player_arg *cmdarg;
+  struct metadata_param *metadata_param = arg;
   struct input_metadata *imd;
   struct output_metadata *omd;
 
-  cmdarg = arg;
-  imd = cmdarg->metadata_param.input;
-  omd = cmdarg->metadata_param.output;
+  imd = metadata_param->input;
+  omd = metadata_param->output;
 
   outputs_metadata_send(omd, imd->rtptime, imd->offset, imd->startup);
 
@@ -1777,15 +1767,12 @@ playback_suspend(void)
 static enum command_state
 get_status(void *arg, int *retval)
 {
-  union player_arg *cmdarg = arg;
+  struct player_status *status = arg;
   struct timespec ts;
   struct player_source *ps;
-  struct player_status *status;
   uint64_t pos;
   int ret;
 
-  status = cmdarg->status;
-
   memset(status, 0, sizeof(struct player_status));
 
   status->shuffle = shuffle;
@@ -1865,12 +1852,9 @@ get_status(void *arg, int *retval)
 static enum command_state
 now_playing(void *arg, int *retval)
 {
-  union player_arg *cmdarg = arg;
-  uint32_t *id;
+  uint32_t *id = arg;
   struct player_source *ps_playing;
 
-  id = cmdarg->id_ptr;
-
   ps_playing = source_now_playing();
 
   if (ps_playing)
@@ -2398,13 +2382,10 @@ player_speaker_status_trigger(void)
 static enum command_state
 speaker_enumerate(void *arg, int *retval)
 {
-  union player_arg *cmdarg = arg;
+  struct spk_enum *spk_enum = arg;
   struct output_device *device;
-  struct spk_enum *spk_enum;
   struct spk_flags flags;
 
-  spk_enum = cmdarg->spk_enum;
-
 #ifdef DEBUG_RELVOL
   DPRINTF(E_DBG, L_PLAYER, "*** master: %d\n", master_volume);
 #endif
@@ -2501,7 +2482,7 @@ speaker_deactivate(struct output_device *device)
 static enum command_state
 speaker_set(void *arg, int *retval)
 {
-  union player_arg *cmdarg = arg;
+  struct speaker_set_param *speaker_set_param = arg;
   struct output_device *device;
   uint64_t *ids;
   int nspk;
@@ -2509,7 +2490,7 @@ speaker_set(void *arg, int *retval)
   int ret;
 
   *retval = 0;
-  ids = cmdarg->speaker_set_param.device_ids;
+  ids = speaker_set_param->device_ids;
 
   if (ids)
     nspk = ids[0];
@@ -2536,8 +2517,8 @@ speaker_set(void *arg, int *retval)
 
 	  if (ret > 0)
 	    (*retval)++;
-	  else if (ret < 0 && cmdarg->speaker_set_param.intval != -2)
-	    cmdarg->speaker_set_param.intval = ret;
+	  else if (ret < 0 && speaker_set_param->intval != -2)
+	    speaker_set_param->intval = ret;
 	}
       else
 	{
@@ -2551,7 +2532,7 @@ speaker_set(void *arg, int *retval)
   if (*retval > 0)
     return COMMAND_PENDING; // async
 
-  *retval = cmdarg->speaker_set_param.intval;
+  *retval = speaker_set_param->intval;
   return COMMAND_END;
 }
 
@@ -2596,14 +2577,14 @@ volume_set(void *arg, int *retval)
 static enum command_state
 volume_setrel_speaker(void *arg, int *retval)
 {
-  union player_arg *cmdarg = arg;
+  struct volume_param *vol_param = arg;
   struct output_device *device;
   uint64_t id;
   int relvol;
 
   *retval = 0;
-  id = cmdarg->vol_param.spk_id;
-  relvol = cmdarg->vol_param.volume;
+  id = vol_param->spk_id;
+  relvol = vol_param->volume;
 
   for (device = dev_list; device; device = device->next)
     {
@@ -2640,14 +2621,14 @@ volume_setrel_speaker(void *arg, int *retval)
 static enum command_state
 volume_setabs_speaker(void *arg, int *retval)
 {
-  union player_arg *cmdarg = arg;
+  struct volume_param *vol_param = arg;
   struct output_device *device;
   uint64_t id;
   int volume;
 
   *retval = 0;
-  id = cmdarg->vol_param.spk_id;
-  volume = cmdarg->vol_param.volume;
+  id = vol_param->spk_id;
+  volume = vol_param->volume;
 
   master_volume = volume;
 
@@ -2690,24 +2671,24 @@ volume_setabs_speaker(void *arg, int *retval)
 static enum command_state
 repeat_set(void *arg, int *retval)
 {
-  union player_arg *cmdarg = arg;
+  enum repeat_mode *mode = arg;
 
-  if (cmdarg->mode == repeat)
+  if (*mode == repeat)
     {
       *retval = 0;
       return COMMAND_END;
     }
 
-  switch (cmdarg->mode)
+  switch (*mode)
     {
       case REPEAT_OFF:
       case REPEAT_SONG:
       case REPEAT_ALL:
-	repeat = cmdarg->mode;
+	repeat = *mode;
 	break;
 
       default:
-	DPRINTF(E_LOG, L_PLAYER, "Invalid repeat mode: %d\n", cmdarg->mode);
+	DPRINTF(E_LOG, L_PLAYER, "Invalid repeat mode: %d\n", *mode);
 	*retval = -1;
 	return COMMAND_END;
     }
@@ -2837,12 +2818,9 @@ player_get_current_pos(uint64_t *pos, struct timespec *ts, int commit)
 int
 player_get_status(struct player_status *status)
 {
-  union player_arg cmdarg;
   int ret;
 
-  cmdarg.status = status;
-
-  ret = commands_exec_sync(cmdbase, get_status, NULL, &cmdarg);
+  ret = commands_exec_sync(cmdbase, get_status, NULL, status);
   return ret;
 }
 
@@ -2858,12 +2836,9 @@ player_get_status(struct player_status *status)
 int
 player_now_playing(uint32_t *id)
 {
-  union player_arg cmdarg;
   int ret;
 
-  cmdarg.id_ptr = id;
-
-  ret = commands_exec_sync(cmdbase, now_playing, NULL, &cmdarg);
+  ret = commands_exec_sync(cmdbase, now_playing, NULL, id);
   return ret;
 }
 
@@ -2968,27 +2943,24 @@ player_playback_prev(void)
 void
 player_speaker_enumerate(spk_enum_cb cb, void *arg)
 {
-  union player_arg cmdarg;
   struct spk_enum spk_enum;
 
   spk_enum.cb = cb;
   spk_enum.arg = arg;
 
-  cmdarg.spk_enum = &spk_enum;
-
-  commands_exec_sync(cmdbase, speaker_enumerate, NULL, &cmdarg);
+  commands_exec_sync(cmdbase, speaker_enumerate, NULL, &spk_enum);
 }
 
 int
 player_speaker_set(uint64_t *ids)
 {
-  union player_arg cmdarg;
+  struct speaker_set_param speaker_set_param;
   int ret;
 
-  cmdarg.speaker_set_param.device_ids = ids;
-  cmdarg.speaker_set_param.intval = 0;
+  speaker_set_param.device_ids = ids;
+  speaker_set_param.intval = 0;
 
-  ret = commands_exec_sync(cmdbase, speaker_set, NULL, &cmdarg);
+  ret = commands_exec_sync(cmdbase, speaker_set, NULL, &speaker_set_param);
 
   listener_notify(LISTENER_SPEAKER);
 
@@ -3016,7 +2988,7 @@ player_volume_set(int vol)
 int
 player_volume_setrel_speaker(uint64_t id, int relvol)
 {
-  union player_arg cmdarg;
+  struct volume_param vol_param;
   int ret;
 
   if (relvol < 0 || relvol > 100)
@@ -3025,17 +2997,17 @@ player_volume_setrel_speaker(uint64_t id, int relvol)
       return -1;
     }
 
-  cmdarg.vol_param.spk_id = id;
-  cmdarg.vol_param.volume = relvol;
+  vol_param.spk_id = id;
+  vol_param.volume = relvol;
 
-  ret = commands_exec_sync(cmdbase, volume_setrel_speaker, NULL, &cmdarg);
+  ret = commands_exec_sync(cmdbase, volume_setrel_speaker, NULL, &vol_param);
   return ret;
 }
 
 int
 player_volume_setabs_speaker(uint64_t id, int vol)
 {
-  union player_arg cmdarg;
+  struct volume_param vol_param;
   int ret;
 
   if (vol < 0 || vol > 100)
@@ -3044,22 +3016,19 @@ player_volume_setabs_speaker(uint64_t id, int vol)
       return -1;
     }
 
-  cmdarg.vol_param.spk_id = id;
-  cmdarg.vol_param.volume = vol;
+  vol_param.spk_id = id;
+  vol_param.volume = vol;
 
-  ret = commands_exec_sync(cmdbase, volume_setabs_speaker, NULL, &cmdarg);
+  ret = commands_exec_sync(cmdbase, volume_setabs_speaker, NULL, &vol_param);
   return ret;
 }
 
 int
 player_repeat_set(enum repeat_mode mode)
 {
-  union player_arg cmdarg;
   int ret;
 
-  cmdarg.mode = mode;
-
-  ret = commands_exec_sync(cmdbase, repeat_set, NULL, &cmdarg);
+  ret = commands_exec_sync(cmdbase, repeat_set, NULL, &mode);
   return ret;
 }
 
@@ -3183,12 +3152,12 @@ player_raop_verification_kickoff(char **arglist)
 void
 player_metadata_send(void *imd, void *omd)
 {
-  union player_arg cmdarg;
+  struct metadata_param metadata_param;
 
-  cmdarg.metadata_param.input = imd;
-  cmdarg.metadata_param.output = omd;
+  metadata_param.input = imd;
+  metadata_param.output = omd;
 
-  commands_exec_sync(cmdbase, device_metadata_send, NULL, &cmdarg);
+  commands_exec_sync(cmdbase, device_metadata_send, NULL, &metadata_param);
 }