PulleyBack: a null-backend (only part of the API)
authorAdriaan de Groot <groot@kde.org>
Wed, 6 Jul 2016 12:24:47 +0000 (14:24 +0200)
committerAdriaan de Groot <groot@kde.org>
Wed, 6 Jul 2016 21:25:35 +0000 (23:25 +0200)
src/pulley/CMakeLists.txt
src/pulley/pulleyback/CMakeLists.txt [new file with mode: 0644]
src/pulley/pulleyback/null.c [new file with mode: 0644]

index 90dfa4c..d5fc489 100644 (file)
@@ -18,6 +18,7 @@ find_package(SQLite3 REQUIRED)
 include_directories(${FCGI_INCLUDE_DIRS} ${LOG4CPP_INCLUDE_DIRS} ../common ../3rdparty)
 
 add_subdirectory(pulleyscript)
+add_subdirectory(pulleyback)
 
 set(PULLEY_SRC
   backend.cpp
diff --git a/src/pulley/pulleyback/CMakeLists.txt b/src/pulley/pulleyback/CMakeLists.txt
new file mode 100644 (file)
index 0000000..7bd8f00
--- /dev/null
@@ -0,0 +1,11 @@
+# Copyright (c) 2016 InternetWide.org and the ARPA2.net project
+# All rights reserved. See file LICENSE for exact terms (2-clause BSD license).
+#
+# Adriaan de Groot <groot@kde.org>
+
+set(NULL_SRC
+  null.c
+  )
+
+add_library(pulleyback_null MODULE ${NULL_SRC})
+set_target_properties(pulleyback_null PROPERTIES PREFIX "")
diff --git a/src/pulley/pulleyback/null.c b/src/pulley/pulleyback/null.c
new file mode 100644 (file)
index 0000000..1994bea
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+Copyright (c) 2016 InternetWide.org and the ARPA2.net project
+All rights reserved. See file LICENSE for exact terms (2-clause BSD license).
+
+Adriaan de Groot <groot@kde.org>
+*/
+
+#include "../pulleyback.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+
+static const char logger[] = "steamworks.pulleyback.null";
+static int num_instances = 0;
+
+typedef struct {
+       int instancenumber;
+       int varc;
+} handle_t;
+
+void *pulleyback_open (int argc, char **argv, int varc)
+{
+       char ibuf[64];
+
+       write_logger(logger, "NULL backend opened.");
+       snprintf(ibuf, sizeof(ibuf), " .. %d args", argc);
+       write_logger(logger, ibuf);
+       snprintf(ibuf, sizeof(ibuf), " .. %d variables", varc);
+
+       for (unsigned int i=0; i<argc; i++)
+       {
+               snprintf(ibuf, sizeof(ibuf), " arg %d=%s", i, argv[i]);
+               write_logger(logger, ibuf);
+       }
+
+       handle_t* handle = malloc(sizeof(handle_t));
+       if (handle == NULL)
+       {
+               /* assume malloc() has set errno */
+               return NULL;
+       }
+       else
+       {
+               handle->instancenumber = ++num_instances;
+               handle->varc = varc;
+
+               snprintf(ibuf, sizeof(ibuf), "NULL backend handle %p (#%d)", (void *)handle, handle->instancenumber);
+               write_logger(logger, ibuf);
+               return handle;
+       }
+}
+
+void pulleyback_close (void *pbh)
+{
+       char ibuf[64];
+       handle_t* handle = pbh;
+
+       snprintf(ibuf, sizeof(ibuf), "NULL backend close %p", (void *)handle);
+       write_logger(logger, ibuf);
+       snprintf(ibuf, sizeof(ibuf), " .. instance %d", handle->instancenumber);
+       write_logger(logger, ibuf);
+
+       free(pbh);
+}
+
+int pulleyback_add (void *pbh, der_t *forkdata)
+{
+       char ibuf[64];
+       handle_t* handle = pbh;
+
+       snprintf(ibuf, sizeof(ibuf), "NULL backend add %p", (void *)handle);
+       write_logger(logger, ibuf);
+       snprintf(ibuf, sizeof(ibuf), "  .. instance #%d add data @%p", handle->instancenumber, (void *)forkdata);
+       write_logger(logger, ibuf);
+
+       return 1;
+}
+
+int pulleyback_del (void *pbh, der_t *forkdata)
+{
+       char ibuf[64];
+       handle_t* handle = pbh;
+
+       snprintf(ibuf, sizeof(ibuf), "NULL backend del %p", (void *)handle);
+       write_logger(logger, ibuf);
+       snprintf(ibuf, sizeof(ibuf), "  .. instance #%d del data @%p", handle->instancenumber, (void *)forkdata);
+       write_logger(logger, ibuf);
+
+       return 1;
+}
+