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