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.3 1999-02-02 14:01:19 adam
8 * First WIN32 port of YAZ++.
10 * Revision 1.2 1999/01/28 13:08:43 adam
11 * Yaz_PDU_Assoc better encapsulated. Memory leak fix in
12 * yaz-socket-manager.cc.
14 * Revision 1.1.1.1 1999/01/28 09:41:07 adam
15 * First implementation of YAZ++.
20 #include <yaz-ir-assoc.h>
22 int Yaz_IR_Assoc::yaz_init_func()
24 logf (LOG_LOG, "nmem_init");
26 logf (LOG_LOG, "done");
30 int Yaz_IR_Assoc::yaz_init_flag = Yaz_IR_Assoc::yaz_init_func();
32 Yaz_IR_Assoc::Yaz_IR_Assoc(IYaz_PDU_Observable *the_PDU_Observable)
34 m_PDU_Observable = the_PDU_Observable;
35 m_odr_in = odr_createmem (ODR_DECODE);
36 m_odr_out = odr_createmem (ODR_ENCODE);
37 m_odr_print = odr_createmem (ODR_PRINT);
40 Yaz_IR_Assoc::~Yaz_IR_Assoc()
42 m_PDU_Observable->destroy();
43 delete m_PDU_Observable;
44 odr_destroy (m_odr_print);
45 odr_destroy (m_odr_out);
46 odr_destroy (m_odr_in);
49 void Yaz_IR_Assoc::recv_PDU(const char *buf, int len)
51 logf (LOG_LOG, "recv_PDU len=%d", len);
52 Z_APDU *apdu = decode_Z_PDU (buf, len);
57 Z_APDU *Yaz_IR_Assoc::create_Z_PDU(int type)
59 return zget_APDU(m_odr_out, type);
62 int Yaz_IR_Assoc::send_Z_PDU(Z_APDU *apdu)
66 if (encode_Z_PDU(apdu, &buf, &len) > 0)
67 return m_PDU_Observable->send_PDU(buf, len);
71 Z_APDU *Yaz_IR_Assoc::decode_Z_PDU(const char *buf, int len)
76 odr_setbuf (m_odr_in, (char*) buf, len, 0);
78 if (!z_APDU(m_odr_in, &apdu, 0))
80 logf(LOG_LOG, "ODR error on incoming PDU: %s [near byte %d] ",
81 odr_errmsg(odr_geterror(m_odr_in)),
82 odr_offset(m_odr_in));
83 logf(LOG_LOG, "PDU dump:");
84 odr_dumpBER(log_file(), buf, len);
89 logf (LOG_LOG, "decoded ok");
94 int Yaz_IR_Assoc::encode_Z_PDU(Z_APDU *apdu, char **buf, int *len)
96 if (!z_APDU(m_odr_out, &apdu, 0))
98 *buf = odr_getbuf (m_odr_out, len, 0);
99 odr_reset (m_odr_out);
103 void Yaz_IR_Assoc::connectNotify()
105 logf (LOG_LOG, "connectNotify");
108 void Yaz_IR_Assoc::failNotify()
110 logf (LOG_LOG, "failNotify");
113 void Yaz_IR_Assoc::client(const char *addr)
115 m_PDU_Observable->connect (this, addr);
118 void Yaz_IR_Assoc::server(const char *addr)
120 m_PDU_Observable->listen (this, addr);