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.4 1999-03-23 14:17:57 adam
8 * More work on timeout handling. Work on yaz-client.
10 * Revision 1.3 1999/02/02 14:01:19 adam
11 * First WIN32 port of YAZ++.
13 * Revision 1.2 1999/01/28 13:08:43 adam
14 * Yaz_PDU_Assoc better encapsulated. Memory leak fix in
15 * yaz-socket-manager.cc.
17 * Revision 1.1.1.1 1999/01/28 09:41:07 adam
18 * First implementation of YAZ++.
23 #include <yaz-ir-assoc.h>
25 int Yaz_IR_Assoc::yaz_init_func()
27 logf (LOG_LOG, "nmem_init");
29 logf (LOG_LOG, "done");
33 int Yaz_IR_Assoc::yaz_init_flag = Yaz_IR_Assoc::yaz_init_func();
35 Yaz_IR_Assoc::Yaz_IR_Assoc(IYaz_PDU_Observable *the_PDU_Observable)
37 m_PDU_Observable = the_PDU_Observable;
38 m_odr_in = odr_createmem (ODR_DECODE);
39 m_odr_out = odr_createmem (ODR_ENCODE);
40 m_odr_print = odr_createmem (ODR_PRINT);
43 Yaz_IR_Assoc::~Yaz_IR_Assoc()
45 m_PDU_Observable->destroy();
46 delete m_PDU_Observable;
47 odr_destroy (m_odr_print);
48 odr_destroy (m_odr_out);
49 odr_destroy (m_odr_in);
52 void Yaz_IR_Assoc::recv_PDU(const char *buf, int len)
54 logf (LOG_LOG, "recv_PDU len=%d", len);
55 Z_APDU *apdu = decode_Z_PDU (buf, len);
60 Z_APDU *Yaz_IR_Assoc::create_Z_PDU(int type)
62 return zget_APDU(m_odr_out, type);
65 int Yaz_IR_Assoc::send_Z_PDU(Z_APDU *apdu)
69 if (encode_Z_PDU(apdu, &buf, &len) > 0)
70 return m_PDU_Observable->send_PDU(buf, len);
74 Z_APDU *Yaz_IR_Assoc::decode_Z_PDU(const char *buf, int len)
79 odr_setbuf (m_odr_in, (char*) buf, len, 0);
81 if (!z_APDU(m_odr_in, &apdu, 0))
83 logf(LOG_LOG, "ODR error on incoming PDU: %s [near byte %d] ",
84 odr_errmsg(odr_geterror(m_odr_in)),
85 odr_offset(m_odr_in));
86 logf(LOG_LOG, "PDU dump:");
87 odr_dumpBER(log_file(), buf, len);
92 logf (LOG_LOG, "decoded ok");
97 int Yaz_IR_Assoc::encode_Z_PDU(Z_APDU *apdu, char **buf, int *len)
99 if (!z_APDU(m_odr_out, &apdu, 0))
101 *buf = odr_getbuf (m_odr_out, len, 0);
102 odr_reset (m_odr_out);
106 void Yaz_IR_Assoc::connectNotify()
108 logf (LOG_LOG, "connectNotify");
111 void Yaz_IR_Assoc::failNotify()
113 logf (LOG_LOG, "failNotify");
116 void Yaz_IR_Assoc::timeoutNotify()
118 logf (LOG_LOG, "timeoutNotify");
121 void Yaz_IR_Assoc::client(const char *addr)
123 m_PDU_Observable->connect (this, addr);
126 void Yaz_IR_Assoc::server(const char *addr)
128 m_PDU_Observable->listen (this, addr);
131 ODR Yaz_IR_Assoc::odr_encode()