YAZ  5.23.1
zoom-event.c
Go to the documentation of this file.
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) Index Data
3  * See the file LICENSE for details.
4  */
9 #if HAVE_CONFIG_H
10 #include <config.h>
11 #endif
12 
13 #include <assert.h>
14 #include <string.h>
15 #include <errno.h>
16 #include "zoom-p.h"
17 
18 ZOOM_API(const char *) ZOOM_get_event_str(int event)
19 {
20  static const char *ar[] = {
21  "NONE",
22  "CONNECT",
23  "SEND_DATA",
24  "RECV_DATA",
25  "TIMEOUT",
26  "UNKNOWN",
27  "SEND_APDU",
28  "RECV_APDU",
29  "RECV_RECORD",
30  "RECV_SEARCH",
31  "END"
32  };
33  return ar[event];
34 }
35 
36 struct ZOOM_Event_p {
37  int kind;
40 };
41 
43 {
44  ZOOM_Event event = (ZOOM_Event) xmalloc(sizeof(*event));
45  event->kind = kind;
46  event->next = 0;
47  event->prev = 0;
48  return event;
49 }
50 
51 
53 {
54  ZOOM_Event event = c->m_queue_front;
55  if (!event)
56  {
58  return 0;
59  }
60  assert(c->m_queue_back);
61  c->m_queue_front = event->prev;
62  if (c->m_queue_front)
63  {
64  assert(c->m_queue_back);
65  c->m_queue_front->next = 0;
66  }
67  else
68  c->m_queue_back = 0;
69  c->last_event = event->kind;
70  return event;
71 }
72 
74 {
75  if (c->m_queue_back)
76  {
77  c->m_queue_back->prev = event;
78  assert(c->m_queue_front);
79  }
80  else
81  {
82  assert(!c->m_queue_front);
83  c->m_queue_front = event;
84  }
85  event->next = c->m_queue_back;
86  event->prev = 0;
87  c->m_queue_back = event;
88 }
89 
91 {
92  xfree(event);
93 }
94 
96 {
97  ZOOM_Event event;
98  while ((event = ZOOM_connection_get_event(c)))
99  ZOOM_Event_destroy(event);
100 }
101 
103 {
104  ZOOM_Event event = c->m_queue_front;
105 
106  return event ? event->kind : ZOOM_EVENT_NONE;
107 }
108 
109 
110 /*
111  * Local variables:
112  * c-basic-offset: 4
113  * c-file-style: "Stroustrup"
114  * indent-tabs-mode: nil
115  * End:
116  * vim: shiftwidth=4 tabstop=8 expandtab
117  */
118 
ZOOM_connection_peek_event(ZOOM_connection c)
peek at next event
void ZOOM_Event_destroy(ZOOM_Event event)
Definition: zoom-event.c:90
Header for errno utilities.
Internal header for ZOOM implementation.
ZOOM_Event next
Definition: zoom-event.c:38
ZOOM_API(const char *)
Definition: zoom-event.c:18
#define ZOOM_EVENT_NONE
Definition: zoom.h:151
ZOOM_Event m_queue_back
Definition: zoom-p.h:110
ZOOM_Event m_queue_front
Definition: zoom-p.h:109
#define xfree(x)
utility macro which calls xfree_f
Definition: xmalloc.h:53
ZOOM_Event ZOOM_Event_create(int kind)
Definition: zoom-event.c:42
struct ZOOM_Event_p * ZOOM_Event
Definition: zoom-p.h:48
void ZOOM_connection_put_event(ZOOM_connection c, ZOOM_Event event)
Definition: zoom-event.c:73
#define xmalloc(x)
utility macro which calls malloc_f
Definition: xmalloc.h:49
void ZOOM_connection_remove_events(ZOOM_connection c)
Definition: zoom-event.c:95
ZOOM_Event prev
Definition: zoom-event.c:39
ZOOM_Event ZOOM_connection_get_event(ZOOM_connection c)
Definition: zoom-event.c:52
ZOOM_get_event_str(int event)