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