Chapter 4. YAZ C++ API

Table of Contents

1. Interfaces
1.1. ISocketObservable
1.2. ISocketObserver
1.3. IPDU_Observable
1.4. IPDU_Observer
1.5. Yaz_Query
2. Implementations
2.1. Yaz_SocketManager
2.2. PDU_Assoc
2.3. Z_Assoc
2.4. IR_Assoc
2.5. Z_Server

The YAZ C++ API is a client and server API that exposes all YAZ features. The API doesn't hide YAZ C data structures, but provides a set of useful high-level objects for creating clients and servers.

All definitions from YAZ++ are part of namespace yazpp_1.

The following sections include a short description of the interfaces and implementations (concrete classes).

In order to understand the structure, you should look at the example client yaz-my-client.cpp and the example server yaz-my-server.cpp. If that is too easy, you can always turn to the implementation of the proxy itself and send us a patch if you implement a new useful feature.

Note

The documentation here is very limited. We plan to enhance it - provided there is interest for it.

1. Interfaces

1.1. ISocketObservable

This interface is capable of observing sockets. When a socket event occurs, it invokes an object implementing the ISocketObserver interface.

     #include <yazpp/socket-observer.h>

     class my_socketobservable : public ISocketObservable {
        // Add an observer interested in socket fd
        virtual void addObserver(int fd, ISocketObserver *observer) = 0;
        // Delete an observer
        virtual void deleteObserver(ISocketObserver *observer) = 0;
        // Delete all observers
        virtual void deleteObservers() = 0;
        // Specify the events that the observer is interested in.
        virtual void maskObserver(ISocketObserver *observer,
                                  int mask) = 0;
        // Specify timeout
        virtual void timeoutObserver(ISocketObserver *observer,
                                     int timeout)=0;
     };
    

1.2. ISocketObserver

This interface is interested in socket events supporting the ISocketObservable interface.

     #include <yazpp/socket-observer.h>

     class my_socketobserver : public ISocketObserver {
         public:
          // Notify the observer that something happened to socket
          virtual void socketNotify(int event) = 0;
     }
    

1.3. IPDU_Observable

This interface is responsible for sending and receiving PDUs over the network (YAZ COMSTACK). When events occur, an instance implementing IPDU_Observer is notified.

     #include <yazpp/pdu-observer.h>

     class my_pduobservable : public IPDU_Observable {
       public:
         // Send encoded PDU buffer of specified length
         virtual int send_PDU(const char *buf, int len) = 0;
         // Connect with server specified by addr.
         virtual void connect(IPDU_Observer *observer,
                     const char *addr) = 0;
         // Listen on address addr.
         virtual void listen(IPDU_Observer *observer, const char *addr)=0;
         // Close connection
         virtual void close() = 0;
         // Make clone of this object using this interface
         virtual IPDU_Observable *clone() = 0;
         // Destroy completely
         virtual void destroy() = 0;
         // Set Idle Time
         virtual void idleTime (int timeout) = 0;
         // Get peername
         virtual const char *getpeername() = 0;

         virtual ~IPDU_Observable();
     };
    

1.4. IPDU_Observer

This interface is interested in PDUs, and uses an object implementing IPDU_Observable.

     #include <yazpp/pdu-observer.h>

     class my_pduobserver : public IPDU_Observer {
       public:
         // A PDU has been received
         virtual void recv_PDU(const char *buf, int len) = 0;
         // Called when Iyaz_PDU_Observable::connect was successful.
         virtual void connectNotify() = 0;
         // Called whenever the connection was closed
         virtual void failNotify() = 0;
         // Called whenever there is a timeout
         virtual void timeoutNotify() = 0;
         // Make clone of observer using IPDU_Observable interface
         virtual IPDU_Observer *sessionNotify(
         IPDU_Observable *the_PDU_Observable, int fd) = 0;
     };
    

1.5. Yaz_Query

Abstract query.

     #include <yazpp/query.h>
     class my_query : public Yaz_Query {
       public:
         // Print query in buffer described by str and len
         virtual void print (char *str, int len) = 0;
     };