Yaz_PDU_Assoc better encapsulated. Memory leak fix in
[yazpp-moved-to-github.git] / src / yaz-client.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-client.cpp,v $
7  * Revision 1.2  1999-01-28 13:08:42  adam
8  * Yaz_PDU_Assoc better encapsulated. Memory leak fix in
9  * yaz-socket-manager.cc.
10  *
11  * Revision 1.1.1.1  1999/01/28 09:41:07  adam
12  * First implementation of YAZ++.
13  *
14  */
15
16 #include <log.h>
17 #include <yaz-ir-assoc.h>
18 #include <yaz-pdu-assoc.h>
19 #include <yaz-socket-manager.h>
20
21 class MyClient : public Yaz_IR_Assoc {
22 public:
23     MyClient(IYaz_PDU_Observable *the_PDU_Observable);
24     void recv_Z_PDU(Z_APDU *apdu);
25     IYaz_PDU_Observer *clone(IYaz_PDU_Observable *the_PDU_Observable);
26     void sendInit();
27 };
28
29 void MyClient::recv_Z_PDU(Z_APDU *apdu)
30 {
31     logf (LOG_LOG, "recv_APDU");
32     switch (apdu->which)
33     {
34     case Z_APDU_initResponse:
35         logf (LOG_LOG, "got InitResponse");
36         break;
37     case Z_APDU_searchResponse:
38         logf (LOG_LOG, "got searchResponse");
39         break;
40     }
41 }
42
43 IYaz_PDU_Observer *MyClient::clone(IYaz_PDU_Observable *the_PDU_Observable)
44 {
45     return new MyClient(the_PDU_Observable);
46 }
47
48 MyClient::MyClient(IYaz_PDU_Observable *the_PDU_Observable) :
49     Yaz_IR_Assoc (the_PDU_Observable)
50 {
51
52 }
53
54 void MyClient::sendInit()
55 {
56     Z_APDU *apdu = create_Z_PDU(Z_APDU_initRequest);
57     Z_InitRequest *req = apdu->u.initRequest;
58     
59     ODR_MASK_SET(req->options, Z_Options_search);
60     ODR_MASK_SET(req->options, Z_Options_present);
61     ODR_MASK_SET(req->options, Z_Options_namedResultSets);
62     ODR_MASK_SET(req->options, Z_Options_triggerResourceCtrl);
63     ODR_MASK_SET(req->options, Z_Options_scan);
64     ODR_MASK_SET(req->options, Z_Options_sort);
65     ODR_MASK_SET(req->options, Z_Options_extendedServices);
66     ODR_MASK_SET(req->options, Z_Options_delSet);
67
68     ODR_MASK_SET(req->protocolVersion, Z_ProtocolVersion_1);
69     ODR_MASK_SET(req->protocolVersion, Z_ProtocolVersion_2);
70     ODR_MASK_SET(req->protocolVersion, Z_ProtocolVersion_3);
71
72     send_Z_PDU(apdu);
73 }
74
75 int main(int argc, char **argv)
76 {
77     Yaz_SocketManager mySocketManager;
78
79     MyClient z(new Yaz_PDU_Assoc(&mySocketManager, 0));
80
81     z.client("localhost:9999");
82     z.sendInit();
83     
84     while (mySocketManager.processEvent() > 0)
85         ;
86 }