Initial revision
[yazpp-moved-to-github.git] / src / yaz-proxy.cpp
1 /*
2  * Copyright (c) 1998-1999, Index Data.
3  * See the file LICENSE for details.
4  * Sebastian Hammer, Adam Dickmeiss
5  * 
6  * $Log: yaz-proxy.cpp,v $
7  * Revision 1.1  1999-01-28 09:41:07  adam
8  * Initial revision
9  *
10  */
11
12 #include <assert.h>
13
14 #include <log.h>
15
16 #include <yaz-proxy.h>
17
18 Yaz_Proxy::Yaz_Proxy(IYaz_PDU_Observable *the_PDU_Observable) :
19     Yaz_IR_Assoc(the_PDU_Observable)
20 {
21     m_PDU_Observable = the_PDU_Observable;
22     m_maps = 0;
23     m_client = 0;
24 }
25
26 Yaz_Proxy::~Yaz_Proxy()
27 {
28 }
29
30 IYaz_PDU_Observer *Yaz_Proxy::clone(IYaz_PDU_Observable
31                                     *the_PDU_Observable)
32 {
33     return new Yaz_Proxy(the_PDU_Observable);
34 }
35
36 void Yaz_Proxy::recv_Z_PDU(Z_APDU *apdu)
37 {
38     if (apdu->which == Z_APDU_initRequest)
39     {
40         assert (m_client == 0);
41         logf (LOG_LOG, "got InitRequest");
42         m_client = new Yaz_ProxyClient(m_PDU_Observable->clone());
43         m_client->m_server = this;
44         m_client->client("localhost:8888");
45     }
46     assert (m_client);
47     logf (LOG_LOG, "sending PDU");
48     m_client->send_Z_PDU(apdu);
49 }
50
51 void Yaz_Proxy::failNotify()
52 {
53     delete m_client;
54     delete this;
55 }
56
57 void Yaz_ProxyClient::failNotify()
58 {
59     delete m_server;
60     delete this;
61 }
62
63 IYaz_PDU_Observer *Yaz_ProxyClient::clone(IYaz_PDU_Observable
64                                           *the_PDU_Observable)
65 {
66     return new Yaz_ProxyClient(the_PDU_Observable);
67 }
68
69 Yaz_ProxyClient::Yaz_ProxyClient(IYaz_PDU_Observable *the_PDU_Observable) :
70     Yaz_IR_Assoc (the_PDU_Observable)
71 {
72     
73 }
74
75 void Yaz_ProxyClient::recv_Z_PDU(Z_APDU *apdu)
76 {
77     m_server->send_Z_PDU(apdu);
78 }