10d7523bd41ace610042483e90925cd5bbd8f6cd
[yazpp-moved-to-github.git] / include / yaz++ / z-server.h
1 /*
2  * Copyright (c) 2000-2001, Index Data.
3  * See the file LICENSE for details.
4  * 
5  * $Id: z-server.h,v 1.1 2002-10-09 12:50:26 adam Exp $
6  */
7
8 #include <yaz++/z-assoc.h>
9 #if HAVE_YAZ_URSULA_H
10 #include <yaz/zes-ursula.h>
11 #endif
12
13 class Yaz_Z_Server;
14
15 class YAZ_EXPORT Yaz_Z_ServerUtility {
16  public:
17     void create_databaseRecord (ODR odr, Z_NamePlusRecord *rec,
18                                 const char *dbname, int format,
19                                 const void *buf, int len);
20     void create_surrogateDiagnostics(ODR odr, Z_NamePlusRecord *rec,
21                                      const char *dbname, int error,
22                                      char *const addinfo);
23     
24     Z_Records *create_nonSurrogateDiagnostics (ODR odr, int error,
25                                                const char *addinfo);
26
27     void Yaz_Z_ServerUtility::create_diagnostics (
28         ODR odr, int error, const char *addinfo,
29         Z_DiagRec ***dreca, int *num);
30 };
31
32 class YAZ_EXPORT IYaz_Server_Facility {
33  public:
34     virtual int init(Yaz_Z_Server *server,
35                      Z_InitRequest *initRequest,
36                      Z_InitResponse *initResponse) = 0;
37     virtual int recv(Yaz_Z_Server *server, Z_APDU *apdu) = 0;
38 };
39
40
41 #if HAVE_YAZ_URSULA_H
42 class YAZ_EXPORT Yaz_Facility_Ursula : public IYaz_Server_Facility {
43  public:
44 //    virtual void ursula_service (Z_ExtendedServicesRequest *req,
45 //                               Z_UrsPDU *u,
46 //                               Z_ExtendedServicesResponse *res) = 0;
47     virtual void ursula_service (Z_ExtendedServicesRequest *req,
48                          Z_UrsPDU *u_req,
49                          Z_ExtendedServicesResponse *res,
50                          Z_UrsPDU *u_res) =0;
51
52     int init(Yaz_Z_Server *server,
53              Z_InitRequest *initRequest,
54              Z_InitResponse *initResponse);
55     int recv(Yaz_Z_Server *server, Z_APDU *apdu);
56 };
57 #endif
58
59 class YAZ_EXPORT Yaz_Facility_ILL : public IYaz_Server_Facility {
60  public:
61     virtual void ill_service (Z_ExtendedServicesRequest *req,
62                               Z_ItemOrder *io,
63                               Z_ExtendedServicesResponse *res) = 0;
64
65     int init(Yaz_Z_Server *server,
66              Z_InitRequest *initRequest,
67              Z_InitResponse *initResponse);
68     int recv(Yaz_Z_Server *server, Z_APDU *apdu);
69 };
70
71 class YAZ_EXPORT Yaz_Facility_Update : public IYaz_Server_Facility {
72  public:
73     virtual void update_service (Z_ExtendedServicesRequest *req,
74                                  Z_IUUpdate *io,
75                                  Z_ExtendedServicesResponse *res) = 0;
76
77     virtual void update_service0 (Z_ExtendedServicesRequest *req,
78                                  Z_IU0Update *io,
79                                  Z_ExtendedServicesResponse *res) = 0;
80
81     int init(Yaz_Z_Server *server,
82              Z_InitRequest *initRequest,
83              Z_InitResponse *initResponse);
84     int recv(Yaz_Z_Server *server, Z_APDU *apdu);
85 };
86
87
88 class YAZ_EXPORT Yaz_Facility_Retrieval : public IYaz_Server_Facility,
89     public Yaz_Z_ServerUtility {
90  public:
91
92     virtual int sr_init (Z_InitRequest *initRequest,
93                          Z_InitResponse *initResponse) = 0;
94     virtual void sr_search (Z_SearchRequest *searchRequest,
95                             Z_SearchResponse *searchResponse) = 0;
96     virtual void sr_present (Z_PresentRequest *presentRequest,
97                              Z_PresentResponse *presentResponse) = 0;
98     virtual void sr_record (const char *resultSetName,
99                             int position,
100                             int *format,
101                                 Z_RecordComposition *comp,
102                                 Z_NamePlusRecord *namePlusRecord,
103                                 Z_Records *diagnostics) = 0;
104     int init(Yaz_Z_Server *server,
105              Z_InitRequest *initRequest,
106              Z_InitResponse *initResponse);
107     int recv(Yaz_Z_Server *server, Z_APDU *apdu);
108
109     ODR odr_encode();
110     ODR odr_decode();
111  private:
112     Z_Records *pack_records (Yaz_Z_Server *s,
113                              const char *resultSetName,
114                              int start, int num,
115                              Z_RecordComposition *comp,
116                              int *next, int *pres,
117                              int *oid);
118
119     void fetch_via_piggyback (Yaz_Z_Server *s,
120                               Z_SearchRequest *searchRequest,
121                               Z_SearchResponse *searchResponse);
122     void fetch_via_present (Yaz_Z_Server *s,
123                             Z_PresentRequest *req, Z_PresentResponse *res);
124
125     int m_preferredMessageSize;
126     int m_maximumRecordSize;
127     ODR m_odr_encode;
128     ODR m_odr_decode;
129 };
130
131 class YAZ_EXPORT Yaz_Z_Server_Facility_Info {
132     friend class Yaz_Z_Server;
133     IYaz_Server_Facility *m_facility;
134     char *m_name;
135     Yaz_Z_Server_Facility_Info *m_next;
136 };
137
138
139
140 class YAZ_EXPORT Yaz_Z_Server : public Yaz_Z_Assoc {
141 public:
142     Yaz_Z_Server(IYaz_PDU_Observable *the_PDU_Observable);
143     virtual ~Yaz_Z_Server();
144     virtual void recv_Z_PDU(Z_APDU *apdu);
145     void facility_add(IYaz_Server_Facility *facility, const char *name);
146     void facility_reset ();
147
148
149  private:
150     Yaz_Z_Server_Facility_Info *m_facilities;
151 };
152
153 class YAZ_EXPORT Yaz_USMARC {
154  public:
155     const char *get_record(int position);
156 };