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.2 1999-01-28 13:08:43 adam
8 * Yaz_PDU_Assoc better encapsulated. Memory leak fix in
9 * yaz-socket-manager.cc.
11 * Revision 1.1.1.1 1999/01/28 09:41:07 adam
12 * First implementation of YAZ++.
17 #include <yaz-ir-assoc.h>
19 Yaz_IR_Assoc::Yaz_IR_Assoc(IYaz_PDU_Observable *the_PDU_Observable)
21 m_PDU_Observable = the_PDU_Observable;
22 m_odr_in = odr_createmem (ODR_DECODE);
23 m_odr_out = odr_createmem (ODR_ENCODE);
24 m_odr_print = odr_createmem (ODR_PRINT);
27 Yaz_IR_Assoc::~Yaz_IR_Assoc()
29 m_PDU_Observable->destroy();
30 delete m_PDU_Observable;
31 odr_destroy (m_odr_print);
32 odr_destroy (m_odr_out);
33 odr_destroy (m_odr_in);
36 void Yaz_IR_Assoc::recv_PDU(const char *buf, int len)
38 logf (LOG_LOG, "recv_PDU len=%d", len);
39 Z_APDU *apdu = decode_Z_PDU (buf, len);
44 Z_APDU *Yaz_IR_Assoc::create_Z_PDU(int type)
46 return zget_APDU(m_odr_out, type);
49 int Yaz_IR_Assoc::send_Z_PDU(Z_APDU *apdu)
53 if (encode_Z_PDU(apdu, &buf, &len) > 0)
54 return m_PDU_Observable->send_PDU(buf, len);
58 Z_APDU *Yaz_IR_Assoc::decode_Z_PDU(const char *buf, int len)
63 odr_setbuf (m_odr_in, (char*) buf, len, 0);
65 if (!z_APDU(m_odr_in, &apdu, 0))
67 logf(LOG_LOG, "ODR error on incoming PDU: %s [near byte %d] ",
68 odr_errmsg(odr_geterror(m_odr_in)),
69 odr_offset(m_odr_in));
70 logf(LOG_LOG, "PDU dump:");
71 odr_dumpBER(log_file(), buf, len);
76 logf (LOG_LOG, "decoded ok");
81 int Yaz_IR_Assoc::encode_Z_PDU(Z_APDU *apdu, char **buf, int *len)
83 if (!z_APDU(m_odr_out, &apdu, 0))
85 *buf = odr_getbuf (m_odr_out, len, 0);
86 odr_reset (m_odr_out);
90 void Yaz_IR_Assoc::connectNotify()
92 logf (LOG_LOG, "connectNotify");
95 void Yaz_IR_Assoc::failNotify()
97 logf (LOG_LOG, "failNotify");
100 void Yaz_IR_Assoc::client(const char *addr)
102 m_PDU_Observable->connect (this, addr);
105 void Yaz_IR_Assoc::server(const char *addr)
107 m_PDU_Observable->listen (this, addr);