WRBUF updates
[yazpp-moved-to-github.git] / include / yazpp / z-assoc.h
1 /*
2  * Copyright (c) 1998-2005, Index Data.
3  * See the file LICENSE for details.
4  * 
5  * $Id: z-assoc.h,v 1.1 2006-03-29 13:14:15 adam Exp $
6  */
7
8 #ifndef YAZ_Z_ASSOC_INCLUDED
9 #define YAZ_Z_ASSOC_INCLUDED
10
11 #include <yaz/srw.h>
12 #include <yaz/proto.h>
13 #include <yaz/odr.h>
14 #include <yazpp/pdu-observer.h>
15
16 namespace yazpp_1 {
17 /** Z39.50 Assocation.
18     This object implements the client - and server role of a generic
19     Z39.50 Association.
20 */
21 class YAZ_EXPORT Z_Assoc : public IPDU_Observer {
22  public:
23     /// Create object using the PDU Observer specified
24     Z_Assoc(IPDU_Observable *the_PDU_Observable);
25     /// Destroy assocation and close PDU Observer
26     virtual ~Z_Assoc();
27     /// Receive PDU
28     void recv_PDU(const char *buf, int len);
29     /// Connect notification
30     virtual void connectNotify() = 0;
31     /// Failure notification
32     virtual void failNotify() = 0;
33     /// Timeout notification
34     virtual void timeoutNotify() = 0;
35     /// Timeout specify
36     void timeout(int timeout);
37     /// Begin Z39.50 client role
38     int client(const char *addr);
39     /// Begin Z39.50 server role
40     int server(const char *addr);
41     /// Close connection
42     void close();
43     /// Decode Z39.50 PDU.
44     Z_GDU *decode_GDU(const char *buf, int len);
45     /// Encode Z39.50 PDU.
46     int encode_GDU(Z_GDU *apdu, char **buf, int *len);
47     /// Send Z39.50 PDU
48     int send_Z_PDU(Z_APDU *apdu, int *len);
49     int send_GDU(Z_GDU *apdu, int *len);
50     /// Receive Z39.50 PDU
51     virtual void recv_GDU(Z_GDU *apdu, int len) = 0;
52     /// Create Z39.50 PDU with reasonable defaults
53     Z_APDU *create_Z_PDU(int type);
54     /// Request Alloc
55     ODR odr_encode ();
56     ODR odr_decode ();
57     ODR odr_print ();
58
59     void set_APDU_log(const char *fname);
60     const char *get_APDU_log();
61
62     /// OtherInformation
63     void get_otherInfoAPDU(Z_APDU *apdu, Z_OtherInformation ***oip);
64     Z_OtherInformationUnit *update_otherInformation (
65         Z_OtherInformation **otherInformationP, int createFlag,
66         int *oid, int categoryValue, int deleteFlag);
67     void set_otherInformationString (
68         Z_OtherInformation **otherInformationP,
69         int *oid, int categoryValue,
70         const char *str);
71     void set_otherInformationString (
72         Z_OtherInformation **otherInformation,
73         int oidval, int categoryValue,
74         const char *str);
75     void set_otherInformationString (
76         Z_APDU *apdu,
77         int oidval, int categoryValue,
78         const char *str);
79
80     Z_ReferenceId *getRefID(char* str);
81     Z_ReferenceId **get_referenceIdP(Z_APDU *apdu);
82     void transfer_referenceId(Z_APDU *from, Z_APDU *to);
83
84     const char *get_hostname();
85
86     int set_APDU_yazlog(int v);
87
88  private:
89     static int yaz_init_flag;
90     static int yaz_init_func();
91     IPDU_Observable *m_PDU_Observable;
92     ODR m_odr_in;
93     ODR m_odr_out;
94     ODR m_odr_print;
95     int m_log;
96     FILE *m_APDU_file;
97     char *m_APDU_fname;
98     char *m_hostname;
99     int m_APDU_yazlog;
100 };
101 };
102
103 #endif
104 /*
105  * Local variables:
106  * c-basic-offset: 4
107  * indent-tabs-mode: nil
108  * End:
109  * vim: shiftwidth=4 tabstop=8 expandtab
110  */
111