From: Adam Dickmeiss Date: Tue, 21 Jun 2005 17:37:15 +0000 (+0000) Subject: Added new class GDU. X-Git-Tag: YAZPP.ERE2~6 X-Git-Url: http://jsfdemo.indexdata.com/cgi-bin?a=commitdiff_plain;h=6196cb9e06a6cc83892e1ad16daa1fb921111e28;p=yazpp-moved-to-github.git Added new class GDU. --- diff --git a/include/yaz++/Makefile.am b/include/yaz++/Makefile.am index bf5ea91..1d36b1e 100644 --- a/include/yaz++/Makefile.am +++ b/include/yaz++/Makefile.am @@ -1,5 +1,6 @@ pkginclude_HEADERS = \ + gdu.h \ ir-assoc.h \ pdu-assoc.h \ pdu-observer.h \ diff --git a/include/yaz++/gdu.h b/include/yaz++/gdu.h new file mode 100644 index 0000000..ede395e --- /dev/null +++ b/include/yaz++/gdu.h @@ -0,0 +1,49 @@ +/* + * 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 +#include + +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 diff --git a/include/yaz++/z-assoc.h b/include/yaz++/z-assoc.h index 40bdb68..d9229a0 100644 --- a/include/yaz++/z-assoc.h +++ b/include/yaz++/z-assoc.h @@ -1,8 +1,8 @@ /* - * 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 diff --git a/src/Makefile.am b/src/Makefile.am index 7f9074b..c8e5aa1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,4 @@ -## $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) @@ -11,7 +11,7 @@ libyazcpp_la_SOURCES=yaz-socket-manager.cpp yaz-pdu-assoc.cpp \ 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 diff --git a/src/gdu.cpp b/src/gdu.cpp new file mode 100644 index 0000000..676a334 --- /dev/null +++ b/src/gdu.cpp @@ -0,0 +1,106 @@ +/* + * 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 + +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(); +}