2 * Copyright (c) 1998-1999, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
6 * $Log: yaz-z-assoc.cpp,v $
7 * Revision 1.1 1999-04-09 11:46:57 adam
8 * Added object Yaz_Z_Assoc. Much more functional client.
13 #include <yaz-z-assoc.h>
15 int Yaz_Z_Assoc::yaz_init_func()
17 logf (LOG_LOG, "nmem_init");
19 logf (LOG_LOG, "done");
23 int Yaz_Z_Assoc::yaz_init_flag = Yaz_Z_Assoc::yaz_init_func();
25 Yaz_Z_Assoc::Yaz_Z_Assoc(IYaz_PDU_Observable *the_PDU_Observable)
27 m_PDU_Observable = the_PDU_Observable;
28 m_odr_in = odr_createmem (ODR_DECODE);
29 m_odr_out = odr_createmem (ODR_ENCODE);
30 m_odr_print = odr_createmem (ODR_PRINT);
33 Yaz_Z_Assoc::~Yaz_Z_Assoc()
35 m_PDU_Observable->destroy();
36 delete m_PDU_Observable;
37 odr_destroy (m_odr_print);
38 odr_destroy (m_odr_out);
39 odr_destroy (m_odr_in);
42 void Yaz_Z_Assoc::recv_PDU(const char *buf, int len)
44 logf (LOG_LOG, "recv_PDU len=%d", len);
45 Z_APDU *apdu = decode_Z_PDU (buf, len);
50 Z_APDU *Yaz_Z_Assoc::create_Z_PDU(int type)
52 return zget_APDU(m_odr_out, type);
55 int Yaz_Z_Assoc::send_Z_PDU(Z_APDU *apdu)
59 logf (LOG_LOG, "Yaz_Z_Assoc:send_Z_PDU");
60 if (encode_Z_PDU(apdu, &buf, &len) > 0)
61 return m_PDU_Observable->send_PDU(buf, len);
65 Z_APDU *Yaz_Z_Assoc::decode_Z_PDU(const char *buf, int len)
70 odr_setbuf (m_odr_in, (char*) buf, len, 0);
72 if (!z_APDU(m_odr_in, &apdu, 0))
74 logf(LOG_LOG, "ODR error on incoming PDU: %s [near byte %d] ",
75 odr_errmsg(odr_geterror(m_odr_in)),
76 odr_offset(m_odr_in));
77 logf(LOG_LOG, "PDU dump:");
78 odr_dumpBER(log_file(), buf, len);
83 logf (LOG_LOG, "decoded ok");
88 int Yaz_Z_Assoc::encode_Z_PDU(Z_APDU *apdu, char **buf, int *len)
90 if (!z_APDU(m_odr_out, &apdu, 0))
92 logf (LOG_LOG, "yaz_Z_Assoc::encode_Z_PDU failed");
95 *buf = odr_getbuf (m_odr_out, len, 0);
96 odr_reset (m_odr_out);
100 void Yaz_Z_Assoc::connectNotify()
102 logf (LOG_LOG, "connectNotify");
105 void Yaz_Z_Assoc::failNotify()
107 logf (LOG_LOG, "failNotify");
110 void Yaz_Z_Assoc::timeoutNotify()
112 logf (LOG_LOG, "timeoutNotify");
115 void Yaz_Z_Assoc::client(const char *addr)
117 m_PDU_Observable->connect (this, addr);
120 void Yaz_Z_Assoc::close()
122 m_PDU_Observable->close ();
125 void Yaz_Z_Assoc::server(const char *addr)
127 m_PDU_Observable->listen (this, addr);
130 ODR Yaz_Z_Assoc::odr_encode()