--- /dev/null
+/*
+ * Copyright (c) 1998-2005, Index Data.
+ * See the file LICENSE for details.
+ *
+ * $Id: gdu.h,v 1.1 2005-06-21 17:37:15 adam Exp $
+ */
+
+#ifndef YAZPP_GDU_INCLUDED
+#define YAZPP_GDU_INCLUDED
+
+#include <yaz/yconfig.h>
+#include <yaz/proto.h>
+
+namespace yazpp_1 {
+
+ class YAZ_EXPORT GDU {
+ public:
+ GDU(Z_GDU *gdu);
+ GDU(Z_APDU *apdu);
+ ~GDU();
+ Z_GDU *get();
+ void extract_odr_to(ODR dst);
+ private:
+ void base(Z_GDU *gdu, ODR o);
+ Z_GDU *m_gdu;
+ ODR m_decode;
+ };
+
+ class GDUQueue_List {
+ friend class GDUQueue;
+ private:
+ GDU *m_item;
+ GDUQueue_List *m_next;
+ };
+
+ class GDUQueue {
+ public:
+ GDUQueue();
+ ~GDUQueue();
+ void clear();
+ void enqueue(GDU *gdu);
+ GDU *dequeue();
+ int size();
+ private:
+ GDUQueue_List *m_list;
+ };
+};
+
+#endif
/*
- * Copyright (c) 1998-2000, Index Data.
+ * Copyright (c) 1998-2005, Index Data.
* See the file LICENSE for details.
*
- * $Id: z-assoc.h,v 1.8 2005-06-08 13:28:05 adam Exp $
+ * $Id: z-assoc.h,v 1.9 2005-06-21 17:37:15 adam Exp $
*/
#ifndef YAZ_Z_ASSOC_INCLUDED
-## $Id: Makefile.am,v 1.25 2004-05-12 07:45:06 adam Exp $
+## $Id: Makefile.am,v 1.26 2005-06-21 17:37:15 adam Exp $
AM_CXXFLAGS = -I$(srcdir)/../include $(YAZINC)
yaz-z-assoc.cpp yaz-z-query.cpp yaz-ir-assoc.cpp \
yaz-z-server.cpp yaz-pdu-assoc-thread.cpp yaz-z-server-sr.cpp \
yaz-z-server-ill.cpp yaz-z-server-update.cpp yaz-z-databases.cpp \
- yaz-z-cache.cpp yaz-cql2rpn.cpp
+ yaz-z-cache.cpp yaz-cql2rpn.cpp gdu.cpp
noinst_PROGRAMS = yaz-my-server yaz-my-client
bin_SCRIPTS = yaz++-config
--- /dev/null
+/*
+ * Copyright (c) 1998-2005, Index Data.
+ * See the file LICENSE for details.
+ *
+ * $Id: gdu.cpp,v 1.1 2005-06-21 17:37:15 adam Exp $
+ */
+
+#include <yaz++/gdu.h>
+
+using namespace yazpp_1;
+
+GDU::GDU(Z_APDU *apdu)
+{
+ ODR encode = odr_createmem(ODR_ENCODE);
+ Z_GDU *gdu = (Z_GDU *) odr_malloc(encode, sizeof(*gdu));
+ gdu->which = Z_GDU_Z3950;
+ gdu->u.z3950 = apdu;
+ base(gdu, encode);
+}
+
+GDU::GDU(Z_GDU *gdu)
+{
+ base(gdu, odr_createmem(ODR_ENCODE));
+}
+
+void GDU::base(Z_GDU *gdu, ODR encode)
+{
+ m_decode = odr_createmem(ODR_DECODE);
+ m_gdu = 0;
+ if (z_GDU(encode, &gdu, 0, "encode"))
+ {
+ int len;
+ char *buf = odr_getbuf(encode, &len, 0);
+
+ odr_setbuf(m_decode, buf, len, 0);
+ z_GDU(m_decode, &m_gdu, 0, 0);
+ }
+ odr_destroy(encode);
+}
+
+GDU::~GDU()
+{
+ odr_destroy(m_decode);
+}
+
+Z_GDU *GDU::get()
+{
+ return m_gdu;
+}
+
+void GDU::extract_odr_to(ODR dst)
+{
+ NMEM nmem = odr_extract_mem(m_decode);
+ if (!dst->mem)
+ dst->mem = nmem_create();
+ nmem_transfer(dst->mem, nmem);
+ nmem_destroy(nmem);
+}
+
+
+GDUQueue::GDUQueue()
+{
+ m_list = 0;
+}
+
+int GDUQueue::size()
+{
+ int no = 0;
+ GDUQueue_List *l;
+ for (l = m_list; l; l = l->m_next)
+ no++;
+ return no;
+}
+
+void GDUQueue::enqueue(GDU *gdu)
+{
+ GDUQueue_List *l = new GDUQueue_List;
+ l->m_next = m_list;
+ l->m_item = gdu;
+ m_list = l;
+}
+
+GDU *GDUQueue::dequeue()
+{
+ GDUQueue_List **l = &m_list;
+ if (!*l)
+ return 0;
+ while ((*l)->m_next)
+ l = &(*l)->m_next;
+ GDU *m = (*l)->m_item;
+ delete *l;
+ *l = 0;
+ return m;
+}
+
+void GDUQueue::clear()
+{
+ GDU *g;
+ while ((g = dequeue()))
+ delete g;
+}
+
+GDUQueue::~GDUQueue()
+{
+ clear();
+}