Initial revision
[yazpp-moved-to-github.git] / src / yaz-server.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-server.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 MyServer : public Yaz_IR_Assoc {
18 public:
19     MyServer(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 };
23
24 static int stop = 0;
25
26 void MyServer::recv_Z_PDU(Z_APDU *apdu)
27 {
28     logf (LOG_LOG, "recv_Z_PDU");
29     switch (apdu->which)
30     {
31     case Z_APDU_initRequest:
32         logf (LOG_LOG, "got InitRequest");
33         apdu = create_Z_PDU(Z_APDU_initResponse);
34         send_Z_PDU(apdu);
35         break;
36     case Z_APDU_searchRequest:
37         logf (LOG_LOG, "got searchRequest");
38         apdu = create_Z_PDU(Z_APDU_searchResponse);
39         send_Z_PDU(apdu);
40         break;
41     case Z_APDU_presentRequest:
42         logf (LOG_LOG, "got presentRequest");
43         apdu = create_Z_PDU(Z_APDU_presentResponse);
44         send_Z_PDU(apdu);
45         stop = 1;
46         break;
47     }
48 }
49
50 IYaz_PDU_Observer *MyServer::clone(IYaz_PDU_Observable *the_PDU_Observable)
51 {
52     return new MyServer(the_PDU_Observable);
53 }
54
55 MyServer::MyServer(IYaz_PDU_Observable *the_PDU_Observable) :
56     Yaz_IR_Assoc (the_PDU_Observable)
57 {
58
59 }
60
61 int main(int argc, char **argv)
62 {
63     Yaz_SocketManager mySocketManager;
64
65     Yaz_PDU_Assoc my_PDU_Assoc(&mySocketManager, 0);
66     MyServer z(&my_PDU_Assoc);
67
68     z.server("@:9999");
69
70     while (!stop && mySocketManager.processEvent() > 0)
71         ;
72 }