diff src/c/urweb.c @ 1997:c93fbd139732

Define uw_loggers structure, allow FFI code to access it
author Sergey Mironov <grrwlf@gmail.com>
date Wed, 26 Feb 2014 08:21:52 +0000
parents 94529780bbcf
children cc7e5d469d1b
line wrap: on
line diff
--- a/src/c/urweb.c	Sun Apr 13 21:36:44 2014 -0400
+++ b/src/c/urweb.c	Wed Feb 26 08:21:52 2014 +0000
@@ -460,8 +460,7 @@
 
   void *client_data;
 
-  void *logger_data;
-  uw_logger log_debug;
+  uw_loggers *loggers;
 
   int isPost, hasPostBody;
   uw_Basis_postBody postBody;
@@ -484,7 +483,7 @@
 size_t uw_heap_max = SIZE_MAX;
 size_t uw_script_max = SIZE_MAX;
 
-uw_context uw_init(int id, void *logger_data, uw_logger log_debug) {
+uw_context uw_init(int id, uw_loggers *lg) {
   uw_context ctx = malloc(sizeof(struct uw_context));
 
   ctx->app = NULL;
@@ -543,8 +542,7 @@
 
   ctx->client_data = uw_init_client_data();
 
-  ctx->logger_data = logger_data;
-  ctx->log_debug = log_debug;
+  ctx->loggers = lg;
 
   ctx->isPost = ctx->hasPostBody = 0;
 
@@ -596,6 +594,11 @@
   return ctx->db;
 }
 
+
+uw_loggers* uw_get_loggers(struct uw_context *ctx) {
+  return ctx->loggers;
+}
+
 void uw_free(uw_context ctx) {
   size_t i;
 
@@ -4118,8 +4121,8 @@
 }
 
 uw_Basis_unit uw_Basis_debug(uw_context ctx, uw_Basis_string s) {
-  if (ctx->log_debug)
-    ctx->log_debug(ctx->logger_data, "%s\n", s);
+  if (ctx->loggers->log_debug)
+    ctx->loggers->log_debug(ctx->loggers->logger_data, "%s\n", s);
   else
     fprintf(stderr, "%s\n", s);
   return uw_unit_v;