summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--SConstruct1
-rw-r--r--control_commands.c14
-rw-r--r--control_commands.h8
-rw-r--r--control_service.c59
-rw-r--r--control_service.h9
-rw-r--r--main.c5
6 files changed, 96 insertions, 0 deletions
diff --git a/SConstruct b/SConstruct
index f85f2a3..44efee8 100644
--- a/SConstruct
+++ b/SConstruct
@@ -15,6 +15,7 @@ else:
env.ParseConfig('pkg-config --cflags --libs glib-2.0')
env.ParseConfig('pkg-config --cflags --libs gio-2.0')
+env.ParseConfig('pkg-config --cflags --libs gio-unix-2.0')
env.ParseConfig('pkg-config --cflags --libs libmpg123')
env.ParseConfig('pkg-config --cflags --libs id3tag')
diff --git a/control_commands.c b/control_commands.c
new file mode 100644
index 0000000..1ee261c
--- /dev/null
+++ b/control_commands.c
@@ -0,0 +1,14 @@
+#include "control_commands.h"
+
+#include <glib.h>
+#include <string.h>
+
+void control_commands_handle(const gchar *cmd) {
+ gchar *args = strchr(cmd, ' ');
+ if(args != NULL) {
+ *args = '\0';
+ args++;
+ }
+
+ g_debug("handling command %s with arguments %s", cmd, args);
+}
diff --git a/control_commands.h b/control_commands.h
new file mode 100644
index 0000000..03d557b
--- /dev/null
+++ b/control_commands.h
@@ -0,0 +1,8 @@
+#ifndef CONTROL_COMMANDS_H
+#define CONTROL_COMMANDS_H
+
+#include <glib.h>
+
+void control_commands_handle(const gchar *cmd);
+
+#endif
diff --git a/control_service.c b/control_service.c
new file mode 100644
index 0000000..a6f035d
--- /dev/null
+++ b/control_service.c
@@ -0,0 +1,59 @@
+#include "control_service.h"
+#include "control_commands.h"
+
+#include <glib.h>
+#include <glib/gstdio.h>
+#include <gio/gio.h>
+#include <gio/gunixsocketaddress.h>
+
+static GSocketService *ss = NULL;
+static GSocketAddress *address;
+
+static gboolean service_incoming(GSocketService *service,
+ GSocketConnection *connection, GObject *source_object,
+ gpointer user_data) {
+ g_debug("local service got incoming connection");
+
+ GSocket *socket = g_socket_connection_get_socket(connection);
+ gchar buffer[0x400];
+ gssize size = g_socket_receive(socket, buffer, 0x400, NULL, NULL);
+
+ gchar *pos = g_strstr_len(buffer, size, "\r");
+ if(pos == NULL) {
+ pos = g_strstr_len(buffer, size, "\n");
+ }
+ if(pos == NULL) {
+ g_warning("EOL not found");
+ return FALSE;
+ }
+ *pos = '\0';
+
+ control_commands_handle(buffer);
+
+ return FALSE;
+}
+
+gboolean control_service_start() {
+ address = g_unix_socket_address_new("audist.sock");
+
+ ss = g_threaded_socket_service_new(2);
+
+ if(g_socket_listener_add_address((GSocketListener*)ss, address,
+ G_SOCKET_TYPE_STREAM, G_SOCKET_PROTOCOL_DEFAULT, NULL,
+ NULL, NULL) == FALSE) {
+ g_error("g_socket_listener_add_socket() failed");
+ }
+
+ g_signal_connect(ss, "incoming", (GCallback)service_incoming, NULL);
+
+ g_socket_service_start((GSocketService*)ss);
+
+ return TRUE;
+}
+
+void control_service_stop() {
+ g_socket_service_stop((GSocketService*)ss);
+ g_unlink(g_unix_socket_address_get_path((GUnixSocketAddress*)address));
+ g_object_unref(ss);
+ g_object_unref(address);
+}
diff --git a/control_service.h b/control_service.h
new file mode 100644
index 0000000..70cadc5
--- /dev/null
+++ b/control_service.h
@@ -0,0 +1,9 @@
+#ifndef CONTROL_SERVICE_H
+#define CONTROL_SERVICE_H
+
+#include <glib.h>
+
+gboolean control_service_start();
+void control_service_stop();
+
+#endif
diff --git a/main.c b/main.c
index 6b40e86..1697c6a 100644
--- a/main.c
+++ b/main.c
@@ -3,6 +3,7 @@
#include "command_service.h"
#include "conf.h"
#include "servers.h"
+#include "control_service.h"
#include <glib.h>
#include <glib-object.h>
@@ -21,6 +22,8 @@ int main(int argc, char **argv) {
conf_load();
+ control_service_start();
+
servers_init();
music_init();
@@ -41,6 +44,8 @@ int main(int argc, char **argv) {
servers_free();
+ control_service_stop();
+
conf_free();
return 0;