initial commit
This commit is contained in:
50
mpd_ws.h
Normal file
50
mpd_ws.h
Normal file
@@ -0,0 +1,50 @@
|
||||
#ifndef MPD_WS_H
|
||||
#define MPD_WS_H
|
||||
|
||||
#include <libwebsockets.h>
|
||||
#include <mpd/client.h>
|
||||
|
||||
/* Configuration constants */
|
||||
#define MPD_HOST "localhost"
|
||||
#define MPD_PORT 6600
|
||||
#define WEBSOCKET_PORT 8765
|
||||
#define MAX_MESSAGE_SIZE 1024
|
||||
#define RECONNECT_INTERVAL_SEC 5
|
||||
#define SELECT_TIMEOUT_SEC 1
|
||||
|
||||
/* Client session structure */
|
||||
struct client_session {
|
||||
struct lws *wsi;
|
||||
struct client_session *next;
|
||||
};
|
||||
|
||||
/* Global state structure */
|
||||
struct mpd_ws_server {
|
||||
struct lws_context *ws_context;
|
||||
struct mpd_connection *mpd_conn;
|
||||
struct client_session *clients;
|
||||
char current_song[MAX_MESSAGE_SIZE];
|
||||
volatile int running;
|
||||
int mpd_idle_active;
|
||||
};
|
||||
|
||||
/* Function declarations */
|
||||
int mpd_ws_init(struct mpd_ws_server *server);
|
||||
void mpd_ws_run(struct mpd_ws_server *server);
|
||||
void mpd_ws_cleanup(struct mpd_ws_server *server);
|
||||
void mpd_ws_stop(struct mpd_ws_server *server);
|
||||
|
||||
/* MPD functions */
|
||||
int mpd_ws_connect(struct mpd_ws_server *server);
|
||||
void mpd_ws_disconnect(struct mpd_ws_server *server);
|
||||
int mpd_ws_is_connected(struct mpd_ws_server *server);
|
||||
void mpd_ws_update_song(struct mpd_ws_server *server);
|
||||
int mpd_ws_start_idle(struct mpd_ws_server *server);
|
||||
void mpd_ws_process_idle(struct mpd_ws_server *server);
|
||||
|
||||
/* Client management */
|
||||
void client_add(struct mpd_ws_server *server, struct lws *wsi);
|
||||
void client_remove(struct mpd_ws_server *server, struct lws *wsi);
|
||||
void client_broadcast(struct mpd_ws_server *server, const char *message);
|
||||
|
||||
#endif /* MPD_WS_H */
|
||||
Reference in New Issue
Block a user