Happy new year
[yazpp-moved-to-github.git] / include / yazpp / z-server.h
1 /* This file is part of the yazpp toolkit.
2  * Copyright (C) 1998-2012 Index Data and Mike Taylor
3  * All rights reserved.
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  *     * Redistributions of source code must retain the above copyright
8  *       notice, this list of conditions and the following disclaimer.
9  *     * Redistributions in binary form must reproduce the above copyright
10  *       notice, this list of conditions and the following disclaimer in the
11  *       documentation and/or other materials provided with the distribution.
12  *     * Neither the name of Index Data nor the names of its contributors
13  *       may be used to endorse or promote products derived from this
14  *       software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27
28 #include <yazpp/z-assoc.h>
29
30 namespace yazpp_1 {
31
32 class Z_Server;
33
34 class YAZ_EXPORT Z_ServerUtility {
35  public:
36     void create_databaseRecord (ODR odr, Z_NamePlusRecord *rec,
37                                 const char *dbname, const Odr_oid *format,
38                                 const void *buf, int len);
39     void create_surrogateDiagnostics(ODR odr, Z_NamePlusRecord *rec,
40                                      const char *dbname, int error,
41                                      char *const addinfo);
42     
43     Z_Records *create_nonSurrogateDiagnostics (ODR odr, int error,
44                                                const char *addinfo);
45
46     void create_diagnostics (
47         ODR odr, int error, const char *addinfo,
48         Z_DiagRec ***dreca, int *num);
49
50     virtual ~Z_ServerUtility() = 0;
51 };
52
53 class YAZ_EXPORT IServer_Facility {
54  public:
55     virtual int init(Z_Server *server,
56                      Z_InitRequest *initRequest,
57                      Z_InitResponse *initResponse) = 0;
58     virtual int recv(Z_Server *server, Z_APDU *apdu) = 0;
59
60     virtual ~IServer_Facility() = 0;
61 };
62
63 class YAZ_EXPORT Yaz_Facility_ILL : public IServer_Facility {
64  public:
65     virtual void ill_service (Z_ExtendedServicesRequest *req,
66                               Z_ItemOrder *io,
67                               Z_ExtendedServicesResponse *res) = 0;
68
69     int init(Z_Server *server,
70              Z_InitRequest *initRequest,
71              Z_InitResponse *initResponse);
72     int recv(Z_Server *server, Z_APDU *apdu);
73 };
74
75 class YAZ_EXPORT Yaz_Facility_Update : public IServer_Facility {
76  public:
77     virtual void update_service (Z_ExtendedServicesRequest *req,
78                                  Z_IUUpdate *io,
79                                  Z_ExtendedServicesResponse *res) = 0;
80
81     virtual void update_service0 (Z_ExtendedServicesRequest *req,
82                                  Z_IU0Update *io,
83                                  Z_ExtendedServicesResponse *res) = 0;
84
85     int init(Z_Server *server,
86              Z_InitRequest *initRequest,
87              Z_InitResponse *initResponse);
88     int recv(Z_Server *server, Z_APDU *apdu);
89 };
90
91
92 class YAZ_EXPORT Yaz_Facility_Retrieval : public IServer_Facility,
93     public Z_ServerUtility {
94  public:
95
96     virtual int sr_init (Z_InitRequest *initRequest,
97                          Z_InitResponse *initResponse) = 0;
98     virtual void sr_search (Z_SearchRequest *searchRequest,
99                             Z_SearchResponse *searchResponse) = 0;
100     virtual void sr_present (Z_PresentRequest *presentRequest,
101                              Z_PresentResponse *presentResponse) = 0;
102     virtual void sr_record (const char *resultSetName,
103                             int position,
104                             Odr_oid *format,
105                             Z_RecordComposition *comp,
106                             Z_NamePlusRecord *namePlusRecord,
107                             Z_Records *diagnostics) = 0;
108     int init(Z_Server *server,
109              Z_InitRequest *initRequest,
110              Z_InitResponse *initResponse);
111     int recv(Z_Server *server, Z_APDU *apdu);
112
113     ODR odr_encode();
114     ODR odr_decode();
115  private:
116     Z_Records *pack_records (Z_Server *s,
117                              const char *resultSetName,
118                              int start, int num,
119                              Z_RecordComposition *comp,
120                              Odr_int *next, Odr_int *pres,
121                              Odr_oid *oid);
122
123     void fetch_via_piggyback (Z_Server *s,
124                               Z_SearchRequest *searchRequest,
125                               Z_SearchResponse *searchResponse);
126     void fetch_via_present (Z_Server *s,
127                             Z_PresentRequest *req, Z_PresentResponse *res);
128
129     int m_preferredMessageSize;
130     int m_maximumRecordSize;
131     ODR m_odr_encode;
132     ODR m_odr_decode;
133 };
134
135 class YAZ_EXPORT Z_Server_Facility_Info {
136     friend class Z_Server;
137     IServer_Facility *m_facility;
138     char *m_name;
139     Z_Server_Facility_Info *m_next;
140 };
141
142
143
144 class YAZ_EXPORT Z_Server : public Z_Assoc {
145 public:
146     Z_Server(IPDU_Observable *the_PDU_Observable);
147     virtual ~Z_Server();
148     void recv_Z_PDU(Z_APDU *apdu, int len);
149     virtual void recv_GDU(Z_GDU *apdu, int len);
150     void facility_add(IServer_Facility *facility, const char *name);
151     void facility_reset ();
152
153
154  private:
155     Z_Server_Facility_Info *m_facilities;
156 };
157
158 class YAZ_EXPORT Yaz_USMARC {
159  public:
160     const char *get_record(size_t position);
161 };
162 };
163 /*
164  * Local variables:
165  * c-basic-offset: 4
166  * c-file-style: "Stroustrup"
167  * indent-tabs-mode: nil
168  * End:
169  * vim: shiftwidth=4 tabstop=8 expandtab
170  */
171