Sketched some ideas for socket I/O
authorTom Balzer <niebieskitrociny@gmail.com>
Fri, 15 Jun 2018 09:43:19 +0000 (04:43 -0500)
committerTom Balzer <niebieskitrociny@gmail.com>
Fri, 15 Jun 2018 09:43:19 +0000 (04:43 -0500)
guile/README [new file with mode: 0644]
include/messaging.h [new file with mode: 0644]
src/main.c

diff --git a/guile/README b/guile/README
new file mode 100644 (file)
index 0000000..c225096
--- /dev/null
@@ -0,0 +1,8 @@
+Specifying processes:
+
+emacs --daemon
+spoon
+fetchmail
+mu --server (created by emacs actually)
+mpvd (music)
+xst
\ No newline at end of file
diff --git a/include/messaging.h b/include/messaging.h
new file mode 100644 (file)
index 0000000..37482df
--- /dev/null
@@ -0,0 +1,42 @@
+/* Copyright (C) 2018 Thomas Balzer */
+
+/* This file is part of tomd. */
+
+/* tomd is free software: you can redistribute it and/or modify */
+/* it under the terms of the GNU General Public License as published by */
+/* the Free Software Foundation, either version 3 of the License, or */
+/* (at your option) any later version. */
+
+/* tomd is distributed in the hope that it will be useful, */
+/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
+/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the */
+/* GNU General Public License for more details. */
+
+/* You should have received a copy of the GNU General Public License */
+/* along with tomd.  If not, see <http://www.gnu.org/licenses/>. */
+
+/* Commentary: */
+/* This header contains functions and data structures intended for */
+/* use with the tomd daemon. These constitute the standard interface */
+/* for IPC with the daemon, giving commands and allowing for progress */
+/* polling and statuses. */
+
+enum tomd_code{
+  daemon_start = 0,
+  daemon_stop,
+  daemon_restart,
+  daemon_status,
+  update_title_field,
+  music_track_current,
+  music_track_skip,
+  music_vol_up,
+  music_vol_down,
+  music_vol_mute,
+  network_status,
+  run_script
+};
+
+struct tomd_message{
+  enum tomd_code code;
+  void *param;
+};
index 8d819d1..54e375e 100644 (file)
@@ -17,6 +17,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <unistd.h>
 
 static void header(void)
 {
@@ -29,22 +30,34 @@ static void init(void)
   /* TODO */
 }
 
-static void run(void)
+/* These defines are here to improve the local readability */
+#define CHDIR            0
+#define DONT_CHDIR       1
+#define CLOSE_PIPES      0
+#define DONT_CLOSE_PIPES 1
+
+static void daemonize(void)
 {
-  /* TODO */
+  /* daemon is in unistd. */
+  /* arg1 - 0 changes dir to / */
+  /* arg2 - 0 closes all pipes (/dev/null) */
+  /* WARNING > THIS BEHAVIOR IS SILENT AND EASY TO MISPLACE THE
+     PROCESS  */
+  daemon(DONT_CHDIR, CLOSE_PIPES);
 }
 
-static void daemonize(void)
+static void run(void)
 {
-  /* TODO */
+  /* listen on socket, respond to requests. */
+  /* perform all registered 'tick' operations */
 }
 
 int main(int argc, char **argv)
 {
   header();
   init();
-  run();
   daemonize();
+  run();
   
   return EXIT_SUCCESS;
 }