2 * Copyright (c) 1998-1999, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
6 * $Log: yaz-ir-assoc.cpp,v $
7 * Revision 1.1 1999-01-28 09:41:07 adam
13 #include <yaz-ir-assoc.h>
15 Yaz_IR_Assoc::Yaz_IR_Assoc(IYaz_PDU_Observable *the_PDU_Observable)
17 m_PDU_Observable = the_PDU_Observable;
18 m_odr_in = odr_createmem (ODR_DECODE);
19 m_odr_out = odr_createmem (ODR_ENCODE);
20 m_odr_print = odr_createmem (ODR_PRINT);
23 Yaz_IR_Assoc::~Yaz_IR_Assoc()
26 m_PDU_Observable->close();
27 odr_destroy (m_odr_print);
28 odr_destroy (m_odr_out);
29 odr_destroy (m_odr_in);
32 void Yaz_IR_Assoc::recv_PDU(const char *buf, int len)
34 logf (LOG_LOG, "recv_PDU len=%d", len);
35 Z_APDU *apdu = decode_Z_PDU (buf, len);
40 Z_APDU *Yaz_IR_Assoc::create_Z_PDU(int type)
42 return zget_APDU(m_odr_out, type);
45 int Yaz_IR_Assoc::send_Z_PDU(Z_APDU *apdu)
49 if (encode_Z_PDU(apdu, &buf, &len) > 0)
50 return m_PDU_Observable->send_PDU(buf, len);
54 Z_APDU *Yaz_IR_Assoc::decode_Z_PDU(const char *buf, int len)
59 odr_setbuf (m_odr_in, (char*) buf, len, 0);
61 if (!z_APDU(m_odr_in, &apdu, 0))
63 logf(LOG_LOG, "ODR error on incoming PDU: %s [near byte %d] ",
64 odr_errmsg(odr_geterror(m_odr_in)),
65 odr_offset(m_odr_in));
66 logf(LOG_LOG, "PDU dump:");
67 odr_dumpBER(log_file(), buf, len);
72 logf (LOG_LOG, "decoded ok");
77 int Yaz_IR_Assoc::encode_Z_PDU(Z_APDU *apdu, char **buf, int *len)
79 if (!z_APDU(m_odr_out, &apdu, 0))
81 *buf = odr_getbuf (m_odr_out, len, 0);
82 odr_reset (m_odr_out);
86 void Yaz_IR_Assoc::connectNotify()
88 logf (LOG_LOG, "connectNotify");
91 void Yaz_IR_Assoc::failNotify()
93 logf (LOG_LOG, "failNotify");
96 void Yaz_IR_Assoc::client(const char *addr)
98 m_PDU_Observable->connect (this, addr);
101 void Yaz_IR_Assoc::server(const char *addr)
103 m_PDU_Observable->listen (this, addr);