aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCalvin Morrison <calvin@fastmailteam.com>2022-07-27 21:06:36 -0400
committerCalvin Morrison <calvin@fastmailteam.com>2022-07-27 21:06:36 -0400
commit1d74edfd2df37cf7bd71ce7c6e74fe3fedc0a555 (patch)
tree35e81ce0633d5a361e26fdc91b07fd2dbee5a970
parentbcd8da8b1a3d02a90b3c9c8ca73d8b26760bb219 (diff)
reset moc structure on stop
-rw-r--r--moc_library.c42
1 files changed, 25 insertions, 17 deletions
diff --git a/moc_library.c b/moc_library.c
index 1e382aa..a76d5aa 100644
--- a/moc_library.c
+++ b/moc_library.c
@@ -108,6 +108,15 @@ char *get_str (int sock);
int send_int (int sock, int i);
int get_int (int sock, int *i);
+
+void reset_data(struct moc *data) {
+ data->filename = NULL;
+ data->title = NULL;
+ data->album = NULL;
+ data->artist = NULL;
+ data->time = -1;
+}
+
static char *get_curr_file (const int sock) {
send_int (sock, CMD_GET_SNAME);
int ev;
@@ -309,17 +318,21 @@ void *moc_loop(void *input) {
get_int(srv_sock, &state);
update_state(data, state);
- char *file = get_curr_file(srv_sock);
- fprintf(stderr, "moc: current file %s\n", file);
- // if it's the same file as we had, don't update.
- if(data->filename == NULL || strcmp(file, data->filename) != 0) {
- fprintf(stderr, "moc: new file, asking for tags\n");
- data->filename = file;
- // get tags.
- send_int(srv_sock, CMD_GET_FILE_TAGS);
- send_str(srv_sock, file);
- send_int(srv_sock,TAGS_COMMENTS | TAGS_TIME);
- last_cmd = EV_FILE_TAGS;
+ if(state != STATE_STOP) {
+ char *file = get_curr_file(srv_sock);
+ fprintf(stderr, "moc: current file %s\n", file);
+ // if it's the same file as we had, don't update.
+ if(data->filename == NULL || strcmp(file, data->filename) != 0) {
+ fprintf(stderr, "moc: new file, asking for tags\n");
+ data->filename = file;
+ // get tags.
+ send_int(srv_sock, CMD_GET_FILE_TAGS);
+ send_str(srv_sock, file);
+ send_int(srv_sock,TAGS_COMMENTS | TAGS_TIME);
+ last_cmd = EV_FILE_TAGS;
+ }
+ } else {
+ reset_data(data);
}
}
else {
@@ -519,15 +532,10 @@ void *moc_loop2(void *input) {
fprintf(stderr, "moc: end of loop\n");
return NULL;
}
-
extern struct moc *moc_init() {
struct moc *moc = (struct moc*)malloc(sizeof(struct moc));
- moc->filename = NULL;
- moc->title = NULL;
- moc->album = NULL;
- moc->artist = NULL;
- moc->time = -1;
+ reset_data(moc);
pthread_t thread_id;
if (pthread_mutex_init(&moc->lock, NULL) != 0) {