3 <title>YAZ C++ API</title>
5 The YAZ C++ API is an client - and server API that exposes
6 all YAZ features. The API doesn't hide YAZ C datastructures, but
7 provides a set of useful high-level objects for creating clients -
11 The following sections include a short description of the
12 interfaces and implementations (concrete classes).
15 In order to understand the structure, you should look at the
16 example client <filename>yaz-my-client.cpp</filename> and
17 the example server <filename>yaz-my-server.cpp</filename>.
18 If that is too easy, you can always turn to the implementation
19 of the proxy itself and send us a patch if you implement a new
24 The documentation here is very limited. We plan to enhance it
25 provided there is interest for it.
28 <section id="interfaces"><title>Interfaces</title>
29 <section id="IYazSocketObservable"><title>IYazSocketObservable</title>
31 This interface is capable of observing sockets.
32 When a socket even occurs it invokes an object implementing the
33 <link linkend="IYazSocketObserver">IYazSocketObserver</link>
37 #include <yaz++/socket-observer.h>
39 class my_socketobservable : public IYazSocketObservable {
40 // Add an observer interested in socket fd
41 virtual void addObserver(int fd, IYazSocketObserver *observer) = 0;
43 virtual void deleteObserver(IYazSocketObserver *observer) = 0;
44 // Delete all observers
45 virtual void deleteObservers() = 0;
46 // Specify the events that the observer is intersted in.
47 virtual void maskObserver(IYazSocketObserver *observer,
50 virtual void timeoutObserver(IYazSocketObserver *observer,
55 <section id="IYazSocketObserver"><title>IYazZSocketObserver</title>
57 This interface is interested in socket events supporting
58 the <link linkend="IYazSocketObservable">IYazSocketObservable</link>
62 #include <yaz++/socket-observer.h>
64 class my_socketobserver : public IYazSocketObserver {
66 // Notify the observer that something happened to socket
67 virtual void socketNotify(int event) = 0;
71 <section id="IYaz_PDU_Observable"><title>IYaz_PDU_Observable</title>
73 This interface is is responsible for sending - and receiving PDUs over
74 the network (YAZ COMSTACK). When events occur, an instance
75 implementing <link linkend="IYaz_PDU_Observer">IYaz_PDU_Observer</link>
79 #include <yaz++/pdu-observer.h>
81 class my_pduobservable : public IYaz_PDU_Observable {
83 // Send encoded PDU buffer of specified length
84 virtual int send_PDU(const char *buf, int len) = 0;
85 // Connect with server specified by addr.
86 virtual void connect(IYaz_PDU_Observer *observer,
87 const char *addr) = 0;
88 // Listen on address addr.
89 virtual void listen(IYaz_PDU_Observer *observer, const char *addr)=0;
91 virtual void close() = 0;
92 // Make clone of this object using this interface
93 virtual IYaz_PDU_Observable *clone() = 0;
95 virtual void destroy() = 0;
97 virtual void idleTime (int timeout) = 0;
101 <section id="IYaz_PDU_Observer"><title>IYaz_PDU_Observer</title>
103 This interface is interested in PDUs and using an object implementing
104 <link linkend="IYaz_PDU_Observable">IYaz_PDU_Observable</link>.
107 #include <yaz++/pdu-observer.h>
109 class my_pduobserver : public IYaz_PDU_Observer {
111 // A PDU has been received
112 virtual void recv_PDU(const char *buf, int len) = 0;
113 // Called when Iyaz_PDU_Observable::connect was successful.
114 virtual void connectNotify() = 0;
115 // Called whenever the connection was closed
116 virtual void failNotify() = 0;
117 // Called whenever there is a timeout
118 virtual void timeoutNotify() = 0;
119 // Make clone of observer using IYaz_PDU_Observable interface
120 virtual IYaz_PDU_Observer *sessionNotify(
121 IYaz_PDU_Observable *the_PDU_Observable, int fd) = 0;
125 <section id="query"><title>Yaz_Query</title>
130 #include <yaz++/query.h>
131 class my_query : public Yaz_Query {
133 // Print query in buffer described by str and len
134 virtual void print (char *str, int len) = 0;
140 <section id="implementations"><title>Implementations</title>
141 <section><title>Yaz_SocketManager</title>
143 This class implements the <link linkend="IYazSocketObservable">
144 IYazSocketObservable</link> interface and is a portable
145 socket wrapper around the select call.
146 This implementation is useful for daemons,
147 command line clients, etc.
150 #include <yaz++/socket-manager.h>
152 class Yaz_SocketManager : public IYazSocketObservable {
155 virtual void addObserver(int fd, IYazSocketObserver *observer);
156 // Delete an observer
157 virtual void deleteObserver(IYazSocketObserver *observer);
158 // Delete all observers
159 virtual void deleteObservers();
160 // Set event mask for observer
161 virtual void maskObserver(IYazSocketObserver *observer, int mask);
163 virtual void timeoutObserver(IYazSocketObserver *observer,
165 // Process one event. return > 0 if event could be processed;
168 virtual ~Yaz_SocketManager();
172 <section><title>Yaz_PDU_Assoc</title>
174 This class implements the interfaces
175 <link linkend="IYaz_PDU_Observable">IYaz_PDU_Observable</link>
177 <link linkend="IYazSocketObserver">IYazSocketObserver</link>.
178 This object implements a non-blocking client/server channel
179 that transmits BER encoded PDUs (or those offered by YAZ COMSTACK).
182 #include <yaz++/pdu-assoc.h>
184 class Yaz_PDU_Assoc : public IYaz_PDU_Observable,
188 COMSTACK comstack(const char *type_and_host, void **vp);
189 // Create object using specified socketObservable
190 Yaz_PDU_Assoc(IYazSocketObservable *socketObservable);
191 // Create Object using existing comstack
192 Yaz_PDU_Assoc(IYazSocketObservable *socketObservable,
194 // Close socket and destroy object.
195 virtual ~Yaz_PDU_Assoc();
197 IYaz_PDU_Observable *clone();
199 int send_PDU(const char *buf, int len);
200 // connect to server (client role)
201 void connect(IYaz_PDU_Observer *observer, const char *addr);
202 // listen for clients (server role)
203 void listen(IYaz_PDU_Observer *observer, const char *addr);
204 // Socket notification
205 void socketNotify(int event);
211 void idleTime (int timeout);
213 virtual void childNotify(COMSTACK cs);
218 <section id="Yaz_Z_Assoc"><title>Yaz_Z_Assoc</title>
220 This class implements the interface
221 <link linkend="IYaz_PDU_Observer">IYaz_PDU_Obserer</link>.
222 This object implements a Z39.50 client/server channel AKA
226 #include <yaz++/z-assoc.h>
228 class Yaz_Z_Assoc : public IYaz_PDU_Observer {
230 // Create object using the PDU Observer specified
231 Yaz_Z_Assoc(IYaz_PDU_Observable *the_PDU_Observable);
232 // Destroy assocation and close PDU Observer
233 virtual ~Yaz_Z_Assoc();
235 void recv_PDU(const char *buf, int len);
236 // Connect notification
237 virtual void connectNotify() = 0;
238 // Failure notification
239 virtual void failNotify() = 0;
240 // Timeout notification
241 virtual void timeoutNotify() = 0;
243 void timeout(int timeout);
244 // Begin Z39.50 client role
245 void client(const char *addr);
246 // Begin Z39.50 server role
247 void server(const char *addr);
251 // Decode Z39.50 PDU.
252 Z_APDU *decode_Z_PDU(const char *buf, int len);
253 // Encode Z39.50 PDU.
254 int encode_Z_PDU(Z_APDU *apdu, char **buf, int *len);
256 int send_Z_PDU(Z_APDU *apdu);
257 // Receive Z39.50 PDU
258 virtual void recv_Z_PDU(Z_APDU *apdu) = 0;
259 // Create Z39.50 PDU with reasonable defaults
260 Z_APDU *create_Z_PDU(int type);
265 void set_APDU_log(const char *fname);
266 const char *get_APDU_log();
269 void get_otherInfoAPDU(Z_APDU *apdu, Z_OtherInformation ***oip);
270 Z_OtherInformationUnit *update_otherInformation (
271 Z_OtherInformation **otherInformationP, int createFlag,
272 int *oid, int categoryValue, int deleteFlag);
273 void set_otherInformationString (
274 Z_OtherInformation **otherInformationP,
275 int *oid, int categoryValue,
277 void set_otherInformationString (
278 Z_OtherInformation **otherInformation,
279 int oidval, int categoryValue,
281 void set_otherInformationString (
283 int oidval, int categoryValue,
286 Z_ReferenceId *getRefID(char* str);
287 Z_ReferenceId **get_referenceIdP(Z_APDU *apdu);
288 void transfer_referenceId(Z_APDU *from, Z_APDU *to);
290 const char *get_hostname();
294 <section id="Yaz_IR_Assoc"><title>Yaz_IR_Assoc</title>
296 This object is just a specialization of
297 <link linkend="Yaz_Z_Assoc">Yaz_Z_Assoc</link> and provides
298 more facilities for the Z39.50 client role.
301 #include <yaz++/ir-assoc.h>
303 class Yaz_IR_Assoc : public Yaz_Z_Assoc {
308 The example client, <filename>yaz-my-client.cpp</filename>,
312 <section id="Yaz_Z_Server"><title>Yaz_Z_Server</title>
314 This object is just a specialization of
315 <link linkend="Yaz_Z_Assoc">Yaz_Z_Assoc</link> and provides
316 more facilities for the Z39.50 server role.
319 #include <yaz++/z-server.h>
321 class Yaz_Z_Server : public Yaz_Z_Server {
326 The example server, <filename>yaz-my-server.cpp</filename>,
330 <section id="Yaz_Proxy"><title>Yaz_Proxy</title>
332 This object is a specialization of
333 <link linkend="Yaz_Z_Assoc">Yaz_Z_Assoc</link> and implements
337 #include <yaz++/proxy.h>
339 class Yaz_Proxy : public Yaz_Z_Server {
344 The proxy server, <filename>yaz-proxy-main.cpp</filename>,
350 <!-- Keep this comment at the end of the file
355 sgml-minimize-attributes:nil
356 sgml-always-quote-attributes:t
359 sgml-parent-document: "yaz++.xml"
360 sgml-local-catalogs: nil
361 sgml-namecase-general:t