From 0ae46bd1e19dcc853c758af505c6f62f1f6be060 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 12 Aug 2010 09:59:29 +0200 Subject: [PATCH] Refactor ZOOM event, hide more definitions --- src/Makefile.am | 1 + src/zoom-c.c | 84 --------------------------------------- src/zoom-event.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/zoom-opt.c | 16 ++++++++ src/zoom-p.h | 27 ++----------- win/makefile | 1 + 6 files changed, 137 insertions(+), 107 deletions(-) create mode 100644 src/zoom-event.c diff --git a/src/Makefile.am b/src/Makefile.am index 108d618..2c33812 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 \ diff --git a/src/zoom-c.c b/src/zoom-c.c index f5356b9..cab02e5 100644 --- a/src/zoom-c.c +++ b/src/zoom-c.c @@ -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 index 0000000..bc1c84e --- /dev/null +++ b/src/zoom-event.c @@ -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 +#include +#include +#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 + */ + diff --git a/src/zoom-opt.c b/src/zoom-opt.c index 0f5d9da..602f57d 100644 --- a/src/zoom-opt.c +++ b/src/zoom-opt.c @@ -11,6 +11,22 @@ #include +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) { diff --git a/src/zoom-p.h b/src/zoom-p.h index bb3b132..1692e5c 100644 --- a/src/zoom-p.h +++ b/src/zoom-p.h @@ -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 diff --git a/win/makefile b/win/makefile index 8df6c5e..206dfda 100644 --- a/win/makefile +++ b/win/makefile @@ -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 \ -- 1.7.10.4