#pragma once
#include <pthread.h>
#include "track_info.h"
/* To signal to main() what to do */
typedef enum
{
ACTION_PLAY,
ACTION_PAUSE,
ACTION_QUIT,
ACTION_TRACK_NEXT,
ACTION_TRACK_PREV,
ACTION_TRACK_REWIND,
ACTION_TRACK_FIRST,
ACTION_NONE
} Action;
typedef enum
{
STATE_PLAYING,
STATE_PAUSED,
} _Atomic Player_state;
/* Share stuff around between main thread and IPC thread */
typedef struct
{
Track_info *tinfo;
Player_state *pstate;
_Atomic Action action;
int udsockfd;
const char *udsock_path;
pthread_mutex_t track_lock; /* To avoid processing commands during track
* changes */
pthread_mutex_t pause_lock;
pthread_cond_t pause_cond;
pthread_t tid;
} Ipc_ctx;
/* Easy wrapper to spawn the IPC thread */
Ipc_ctx * ipc_thread_spawn(const char *udsock_path);
void ipc_thread_join(Ipc_ctx *ctx);