Refactor ZOOM event, hide more definitions
authorAdam Dickmeiss <adam@indexdata.dk>
Thu, 12 Aug 2010 07:59:29 +0000 (09:59 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Thu, 12 Aug 2010 07:59:29 +0000 (09:59 +0200)
src/Makefile.am
src/zoom-c.c
src/zoom-event.c [new file with mode: 0644]
src/zoom-opt.c
src/zoom-p.h
win/makefile

index 108d618..2c33812 100644 (file)
@@ -89,6 +89,7 @@ libyaz_la_SOURCES=version.c options.c log.c \
   logrpn.c \
   otherinfo.c pquery.c sortspec.c charneg.c initopt.c \
   zoom-c.c zoom-z3950.c zoom-sru.c zoom-query.c zoom-record-cache.c \
+  zoom-event.c \
   record_render.c zoom-socket.c zoom-opt.c zoom-p.h \
   grs1disp.c zgdu.c soap.c srw.c srwutil.c uri.c \
   opacdisp.c cclfind.c ccltoken.c cclerrms.c cclqual.c cclptree.c cclp.h \
index f5356b9..cab02e5 100644 (file)
@@ -34,24 +34,6 @@ static int log_details0 = 0;
 static void resultset_destroy(ZOOM_resultset r);
 static zoom_ret do_write_ex(ZOOM_connection c, char *buf_out, int len_out);
 
-ZOOM_API(const char *) ZOOM_get_event_str(int event)
-{
-    static const char *ar[] = {
-        "NONE",
-        "CONNECT",
-        "SEND_DATA",
-        "RECV_DATA",
-        "TIMEOUT",
-        "UNKNOWN",
-        "SEND_APDU",
-        "RECV_APDU",
-        "RECV_RECORD",
-        "RECV_SEARCH",
-        "END"
-    };
-    return ar[event];
-}
-
 static void initlog(void)
 {
     static int log_level_initialized = 0;
@@ -63,72 +45,6 @@ static void initlog(void)
     }
 }
 
-ZOOM_Event ZOOM_Event_create(int kind)
-{
-    ZOOM_Event event = (ZOOM_Event) xmalloc(sizeof(*event));
-    event->kind = kind;
-    event->next = 0;
-    event->prev = 0;
-    return event;
-}
-
-static void ZOOM_Event_destroy(ZOOM_Event event)
-{
-    xfree(event);
-}
-
-void ZOOM_connection_put_event(ZOOM_connection c, ZOOM_Event event)
-{
-    if (c->m_queue_back)
-    {
-        c->m_queue_back->prev = event;
-        assert(c->m_queue_front);
-    }
-    else
-    {
-        assert(!c->m_queue_front);
-        c->m_queue_front = event;
-    }
-    event->next = c->m_queue_back;
-    event->prev = 0;
-    c->m_queue_back = event;
-}
-
-static ZOOM_Event ZOOM_connection_get_event(ZOOM_connection c)
-{
-    ZOOM_Event event = c->m_queue_front;
-    if (!event)
-    {
-        c->last_event = ZOOM_EVENT_NONE;
-        return 0;
-    }
-    assert(c->m_queue_back);
-    c->m_queue_front = event->prev;
-    if (c->m_queue_front)
-    {
-        assert(c->m_queue_back);
-        c->m_queue_front->next = 0;
-    }
-    else
-        c->m_queue_back = 0;
-    c->last_event = event->kind;
-    return event;
-}
-
-static void ZOOM_connection_remove_events(ZOOM_connection c)
-{
-    ZOOM_Event event;
-    while ((event = ZOOM_connection_get_event(c)))
-        ZOOM_Event_destroy(event);
-}
-
-ZOOM_API(int) ZOOM_connection_peek_event(ZOOM_connection c)
-{
-    ZOOM_Event event = c->m_queue_front;
-
-    return event ? event->kind : ZOOM_EVENT_NONE;
-}
-
 void ZOOM_connection_remove_tasks(ZOOM_connection c);
 
 void ZOOM_set_dset_error(ZOOM_connection c, int error,
diff --git a/src/zoom-event.c b/src/zoom-event.c
new file mode 100644 (file)
index 0000000..bc1c84e
--- /dev/null
@@ -0,0 +1,115 @@
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2010 Index Data
+ * See the file LICENSE for details.
+ */
+/**
+ * \file zoom-event.c
+ * \brief Implements ZOOM Event stuff
+ */
+
+#include <assert.h>
+#include <string.h>
+#include <errno.h>
+#include "zoom-p.h"
+
+ZOOM_API(const char *) ZOOM_get_event_str(int event)
+{
+    static const char *ar[] = {
+        "NONE",
+        "CONNECT",
+        "SEND_DATA",
+        "RECV_DATA",
+        "TIMEOUT",
+        "UNKNOWN",
+        "SEND_APDU",
+        "RECV_APDU",
+        "RECV_RECORD",
+        "RECV_SEARCH",
+        "END"
+    };
+    return ar[event];
+}
+
+struct ZOOM_Event_p {
+    int kind;
+    ZOOM_Event next;
+    ZOOM_Event prev;
+};
+
+ZOOM_Event ZOOM_Event_create(int kind)
+{
+    ZOOM_Event event = (ZOOM_Event) xmalloc(sizeof(*event));
+    event->kind = kind;
+    event->next = 0;
+    event->prev = 0;
+    return event;
+}
+
+
+ZOOM_Event ZOOM_connection_get_event(ZOOM_connection c)
+{
+    ZOOM_Event event = c->m_queue_front;
+    if (!event)
+    {
+        c->last_event = ZOOM_EVENT_NONE;
+        return 0;
+    }
+    assert(c->m_queue_back);
+    c->m_queue_front = event->prev;
+    if (c->m_queue_front)
+    {
+        assert(c->m_queue_back);
+        c->m_queue_front->next = 0;
+    }
+    else
+        c->m_queue_back = 0;
+    c->last_event = event->kind;
+    return event;
+}
+
+void ZOOM_connection_put_event(ZOOM_connection c, ZOOM_Event event)
+{
+    if (c->m_queue_back)
+    {
+        c->m_queue_back->prev = event;
+        assert(c->m_queue_front);
+    }
+    else
+    {
+        assert(!c->m_queue_front);
+        c->m_queue_front = event;
+    }
+    event->next = c->m_queue_back;
+    event->prev = 0;
+    c->m_queue_back = event;
+}
+
+void ZOOM_Event_destroy(ZOOM_Event event)
+{
+    xfree(event);
+}
+
+void ZOOM_connection_remove_events(ZOOM_connection c)
+{
+    ZOOM_Event event;
+    while ((event = ZOOM_connection_get_event(c)))
+        ZOOM_Event_destroy(event);
+}
+
+ZOOM_API(int) ZOOM_connection_peek_event(ZOOM_connection c)
+{
+    ZOOM_Event event = c->m_queue_front;
+
+    return event ? event->kind : ZOOM_EVENT_NONE;
+}
+
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
index 0f5d9da..602f57d 100644 (file)
 
 #include <yaz/xmalloc.h>
 
+struct ZOOM_options_entry {
+    char *name;
+    char *value;
+    int len;                  /* of `value', which may contain NULs */
+    struct ZOOM_options_entry *next;
+};
+
+struct ZOOM_options_p {
+    int refcount;
+    void *callback_handle;
+    ZOOM_options_callback callback_func;
+    struct ZOOM_options_entry *entries;
+    ZOOM_options parent1;
+    ZOOM_options parent2;
+};
+
 static void set_value(struct ZOOM_options_entry **e,
                       const char *value, int len)
 {
index bb3b132..1692e5c 100644 (file)
@@ -119,23 +119,6 @@ struct ZOOM_resultsets_p {
 };
 #endif
 
-struct ZOOM_options_entry {
-    char *name;
-    char *value;
-    int len;                  /* of `value', which may contain NULs */
-    struct ZOOM_options_entry *next;
-};
-
-struct ZOOM_options_p {
-    int refcount;
-    void *callback_handle;
-    ZOOM_options_callback callback_func;
-    struct ZOOM_options_entry *entries;
-    ZOOM_options parent1;
-    ZOOM_options parent2;
-};
-
-
 typedef struct ZOOM_record_cache_p *ZOOM_record_cache;
 
 #define RECORD_HASH_SIZE  131
@@ -238,12 +221,6 @@ struct ZOOM_task_p {
     ZOOM_task next;
 };
 
-struct ZOOM_Event_p {
-    int kind;
-    ZOOM_Event next;
-    ZOOM_Event prev;
-};
-
 typedef enum {
     zoom_pending,
     zoom_complete
@@ -299,6 +276,10 @@ int ZOOM_handle_sru(ZOOM_connection c, Z_HTTP_Response *hres,
 void ZOOM_set_HTTP_error(ZOOM_connection c, int error,
                          const char *addinfo, const char *addinfo2);
 
+ZOOM_Event ZOOM_connection_get_event(ZOOM_connection c);
+void ZOOM_connection_remove_events(ZOOM_connection c);
+void ZOOM_Event_destroy(ZOOM_Event event);
+
 /*
  * Local variables:
  * c-basic-offset: 4
index 8df6c5e..206dfda 100644 (file)
@@ -473,6 +473,7 @@ MISC_OBJS= \
    $(OBJDIR)\srw.obj \
    $(OBJDIR)\srwutil.obj \
    $(OBJDIR)\zoom-c.obj \
+   $(OBJDIR)\zoom-event.obj \
    $(OBJDIR)\zoom-record-cache.obj \
    $(OBJDIR)\zoom-z3950.obj \
    $(OBJDIR)\zoom-sru.obj \