From 74d7a877387d522e5caa8b8b8d012686b5d488b2 Mon Sep 17 00:00:00 2001
From: Philippe PITTOLI
Date: Wed, 14 Sep 2016 23:05:02 +0200
Subject: [PATCH] updates in misc/ and new (future) program "msg" for CBOR msg
---
misc/Makefile | 4 +--
misc/init-connection.c | 81 ++++++++++++++++++++++++++++--------------
misc/msg.c | 38 ++++++++++++++++++++
pubsub/pubsubd.c | 2 +-
4 files changed, 95 insertions(+), 30 deletions(-)
create mode 100644 misc/msg.c
diff --git a/misc/Makefile b/misc/Makefile
index 22d244e..41eafb8 100644
--- a/misc/Makefile
+++ b/misc/Makefile
@@ -1,6 +1,6 @@
CC=gcc
-CFLAGS=-Wall -g
-LDFLAGS=
+CFLAGS=-Wall -g -Wextra
+LDFLAGS= -pthread
CFILES=$(wildcard *.c) # CFILES => recompiles everything on a C file change
EXEC=$(basename $(wildcard *.c))
SOURCES=$(wildcard ../lib/*.c)
diff --git a/misc/init-connection.c b/misc/init-connection.c
index 4326a69..c0a384f 100644
--- a/misc/init-connection.c
+++ b/misc/init-connection.c
@@ -1,43 +1,70 @@
#include "../lib/communication.h"
+#define SERVICE "windowing"
+
+void
+ohshit(int rvalue, const char* str) {
+ fprintf(stderr, "%s\n", str);
+ exit(rvalue);
+}
+
/*
* pipes creation and removal test program
*
- * 1. to create the named pipe /tmp/
- * 2. to create the named pipes in & out
- * 3. to remove the named pipes in & out
- * 4. to remove the named pipe /tmp/
+ * 1. S creates the named pipe /tmp/ipc/
+ * 2. App creates named pipes in & out, /tmp/ipc/$pid-$index-$version-{in,out}
+ *
+ * ... some communication between S and App...
+ * App wants to stop
+ *
+ * 3. App removes the named pipes in and out
+ * 4. S removes the named pipe /tmp/ipc/
*/
-int main(int argc, char * argv[])
+int main(int argc, char * argv[], char *env[])
{
- // service path (/tmp/)
- char spath[PATH_MAX];
- service_path (spath, "windows");
+ struct service srv;
+ memset (&srv, 0, sizeof (struct service));
+ srv_init (argc, argv, env, &srv, SERVICE, NULL);
+ printf ("Listening on %s.\n", srv.spath);
- int ret;
- if ((ret = service_create (spath))) {
- fprintf(stdout, "error service_create %d\n", ret);
- exit (1);
- }
+ // creates the service named pipe, that listens to client applications
+ if (srv_create (&srv))
+ ohshit(1, "service_create error");
- struct process proc;
- if ((ret = process_create (&proc, 0))) {
- fprintf(stdout, "error process_create %d\n", ret);
- exit (1);
- }
+ /*
+ * PROCESS
+ */
- /* specific code, talks between applications */
+ struct process p;
+ memset (&p, 0, sizeof (struct process));
- if ((ret = process_destroy (&proc))) {
- fprintf(stdout, "error process_destroy %d\n", ret);
- exit (1);
- }
+ pid_t pid = getpid();
+ int index = 0; // first time we communication with the service
+ int version = 1;
- if ((ret = service_close (spath))) {
- fprintf(stdout, "error service_close %d\n", ret);
- exit (1);
- }
+ printf ("app creation\n");
+ if (app_create (&p, pid, index, version)) // called by the application
+ ohshit (1, "app_create");
+
+ /*
+ * some exchanges between App and S
+ * specific code, talks between applications
+ * then App wants to end the communication
+ */
+
+ printf ("destroying app\n");
+ // the application will shut down, and remove the application named pipes
+ if (app_destroy (&p))
+ ohshit (1, "app_destroy");
+
+ /*
+ * /PROCESS
+ */
+
+ // the application will shut down, and remove the service named pipe
+ if (srv_close (&srv))
+ ohshit (1, "srv_close error");
return EXIT_SUCCESS;
}
diff --git a/misc/msg.c b/misc/msg.c
new file mode 100644
index 0000000..4d1dbe7
--- /dev/null
+++ b/misc/msg.c
@@ -0,0 +1,38 @@
+#include "../lib/pubsubd.h"
+#include
+#include
+
+void
+ohshit(int rvalue, const char* str) {
+ fprintf (stderr, "\033[31merr: %s\033[00m\n", str);
+ exit (rvalue);
+}
+
+void usage (char **argv)
+{
+ printf ( "NOT DONE YET\n");
+ printf ( "usage: %s [type [param]]...\n", argv[0]);
+ printf ( "ex: echo data | %s char_t 1\n", argv[0]);
+ printf ( " This sends a CBOR msg [ 1, \"data\" ]\n");
+}
+
+/*
+ * implemented types:
+ * bstr_t (default)
+ * tstr_t
+ * int_t
+ *
+ * future types:
+ * nint_t
+ */
+
+int
+main(int argc, char **argv)
+{
+ if (argc == 2 && strcmp ("-h", argv[1]) == 0) {
+ usage (argv);
+ exit (1);
+ }
+
+ return EXIT_SUCCESS;
+}
diff --git a/pubsub/pubsubd.c b/pubsub/pubsubd.c
index 1616c95..bf127d8 100644
--- a/pubsub/pubsubd.c
+++ b/pubsub/pubsubd.c
@@ -74,7 +74,7 @@ main(int argc, char **argv, char **env)
// the application will shut down, and remove the service named pipe
if (srv_close (&srv))
- ohshit (1, "service_close error");
+ ohshit (1, "srv_close error");
return EXIT_SUCCESS;
}