commit 949b5c2eb6f46f77b423a93558d196204dce2953 from: Omar Polo date: Tue Jul 12 21:43:25 2022 UTC refactor control_notify it's awkward to call it with the address of the imsgev struct inside the ctl_conn struct. Just relay the info to every client in monitor mode. After all, if a client is in monitor mode *and* issues commands, it's not strange that they're echoed back (note that this is currently impossible, the command line client can either issue commands or be in monitor mode.) commit - 3c8ce7d5563e5546fa4e8f694de4730b9cb9b757 commit + 949b5c2eb6f46f77b423a93558d196204dce2953 blob - 807d19af4e75d3e1cc13776b84f878af1b8330fe blob + f57e6cfb71160e07a8b93e2140184f870868027e --- amused.c +++ amused.c @@ -164,9 +164,9 @@ main_dispatch_player(int sig, short event, void *d) } main_playlist_advance(); if (play_state == STATE_PLAYING) - control_notify(NULL, IMSG_CTL_NEXT); + control_notify(IMSG_CTL_NEXT); else - control_notify(NULL, IMSG_CTL_STOP); + control_notify(IMSG_CTL_STOP); break; default: log_debug("%s: error handling imsg %d", __func__, blob - 589818b11fd8cb7bdf83dc9943e56ef88c4f2a6e blob + 8a2c1030cdb8036e6d3a558d4a563739144ec5d1 --- control.c +++ control.c @@ -227,12 +227,12 @@ control_close(int fd) } void -control_notify(struct imsgev *iev, int type) +control_notify(int type) { struct ctl_conn *c; TAILQ_FOREACH(c, &ctl_conns, entry) { - if (&c->iev == iev || !c->monitor) + if (!c->monitor) continue; imsg_compose_event(&c->iev, IMSG_CTL_MONITOR, 0, 0, @@ -289,7 +289,7 @@ control_dispatch_imsg(int fd, short event, void *bula) main_send_player(IMSG_RESUME, -1, NULL ,0); break; } - control_notify(&c->iev, imsg.hdr.type); + control_notify(imsg.hdr.type); break; case IMSG_CTL_TOGGLE_PLAY: switch (play_state) { @@ -305,25 +305,25 @@ control_dispatch_imsg(int fd, short event, void *bula) main_send_player(IMSG_RESUME, -1, NULL, 0); break; } - control_notify(&c->iev, imsg.hdr.type); + control_notify(imsg.hdr.type); break; case IMSG_CTL_PAUSE: if (play_state != STATE_PLAYING) break; play_state = STATE_PAUSED; main_send_player(IMSG_PAUSE, -1, NULL, 0); - control_notify(&c->iev, imsg.hdr.type); + control_notify(imsg.hdr.type); break; case IMSG_CTL_STOP: if (play_state == STATE_STOPPED) break; play_state = STATE_STOPPED; main_send_player(IMSG_STOP, -1, NULL, 0); - control_notify(&c->iev, imsg.hdr.type); + control_notify(imsg.hdr.type); break; case IMSG_CTL_FLUSH: playlist_truncate(); - control_notify(&c->iev, imsg.hdr.type); + control_notify(imsg.hdr.type); break; case IMSG_CTL_SHOW: main_send_playlist(&c->iev); @@ -334,16 +334,16 @@ control_dispatch_imsg(int fd, short event, void *bula) case IMSG_CTL_NEXT: main_send_player(IMSG_STOP, -1, NULL, 0); main_playlist_advance(); - control_notify(&c->iev, imsg.hdr.type); + control_notify(imsg.hdr.type); break; case IMSG_CTL_PREV: main_send_player(IMSG_STOP, -1, NULL, 0); main_playlist_previous(); - control_notify(&c->iev, imsg.hdr.type); + control_notify(imsg.hdr.type); break; case IMSG_CTL_JUMP: main_playlist_jump(&c->iev, &imsg); - control_notify(&c->iev, imsg.hdr.type); + control_notify(imsg.hdr.type); break; case IMSG_CTL_REPEAT: if (IMSG_DATA_SIZE(imsg) != sizeof(rp)) { @@ -355,7 +355,7 @@ control_dispatch_imsg(int fd, short event, void *bula) repeat_all = rp.repeat_all; if (rp.repeat_one != -1) repeat_one = rp.repeat_one; - control_notify(&c->iev, imsg.hdr.type); + control_notify(imsg.hdr.type); break; case IMSG_CTL_BEGIN: if (control_state.tx != -1) { @@ -375,7 +375,7 @@ control_dispatch_imsg(int fd, short event, void *bula) main_enqueue(control_state.tx != -1, &control_state.play,&c->iev, &imsg); if (control_state.tx == -1) - control_notify(&c->iev, imsg.hdr.type); + control_notify(imsg.hdr.type); break; case IMSG_CTL_COMMIT: if (control_state.tx != c->iev.ibuf.fd) { @@ -393,7 +393,7 @@ control_dispatch_imsg(int fd, short event, void *bula) control_state.tx = -1; imsg_compose_event(&c->iev, IMSG_CTL_COMMIT, 0, 0, -1, NULL, 0); - control_notify(&c->iev, imsg.hdr.type); + control_notify(imsg.hdr.type); break; case IMSG_CTL_MONITOR: c->monitor = 1; @@ -416,7 +416,7 @@ control_dispatch_imsg(int fd, short event, void *bula) } main_send_player(IMSG_CTL_SEEK, -1, imsg.data, IMSG_DATA_SIZE(imsg)); - control_notify(&c->iev, imsg.hdr.type); + control_notify(imsg.hdr.type); break; default: log_debug("%s: error handling imsg %d", __func__, blob - 198a03208d06b4478dc845c107f3789c5cd22482 blob + e3772bf83e82cca9e978ed3e2818dfefd4d04c45 --- control.h +++ control.h @@ -19,6 +19,6 @@ int control_init(char *); int control_listen(int fd); void control_accept(int, short, void *); -void control_notify(struct imsgev *, int); +void control_notify(int); void control_dispatch_imsg(int, short, void *); int control_imsg_relay(struct imsg *);