Release 1.6.4
[yazpp-moved-to-github.git] / include / yazpp / z-assoc.h
1 /* This file is part of the yazpp toolkit.
2  * Copyright (C) Index Data 
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 #ifndef YAZ_Z_ASSOC_INCLUDED
29 #define YAZ_Z_ASSOC_INCLUDED
30
31 #include <yaz/srw.h>
32 #include <yaz/proto.h>
33 #include <yaz/odr.h>
34 #include <yazpp/pdu-observer.h>
35
36 namespace yazpp_1 {
37     class Z_Assoc_priv;
38
39 /** Z39.50 Assocation.
40     This object implements the client - and server role of a generic
41     Z39.50 Association.
42 */
43 class YAZ_EXPORT Z_Assoc : public IPDU_Observer {
44   public:
45         /// Create object using the PDU Observer specified
46     Z_Assoc(IPDU_Observable *the_PDU_Observable);
47     /// Destroy assocation and close PDU Observer
48     virtual ~Z_Assoc();
49     /// Receive PDU
50     void recv_PDU(const char *buf, int len);
51     /// Connect notification
52     virtual void connectNotify() = 0;
53     /// Failure notification
54     virtual void failNotify() = 0;
55     /// Timeout notification
56     virtual void timeoutNotify() = 0;
57     /// Timeout specify
58     void timeout(int timeout);
59     /// Begin Z39.50 client role
60     int client(const char *addr);
61     /// Begin Z39.50 server role
62     int server(const char *addr);
63     /// Close connection
64     void close();
65     /// Decode Z39.50 PDU.
66     Z_GDU *decode_GDU(const char *buf, int len);
67     /// Encode Z39.50 PDU.
68     int encode_GDU(Z_GDU *apdu, char **buf, int *len);
69     /// Send Z39.50 PDU
70     int send_Z_PDU(Z_APDU *apdu, int *len);
71     int send_GDU(Z_GDU *apdu, int *len);
72     /// Receive Z39.50 PDU
73     virtual void recv_GDU(Z_GDU *apdu, int len) = 0;
74     /// Create Z39.50 PDU with reasonable defaults
75     Z_APDU *create_Z_PDU(int type);
76     /// Request Alloc
77     ODR odr_encode ();
78     ODR odr_decode ();
79     ODR odr_print ();
80
81     void set_APDU_log(const char *fname);
82     const char *get_APDU_log();
83
84     /// OtherInformation
85     void get_otherInfoAPDU(Z_APDU *apdu, Z_OtherInformation ***oip);
86     Z_OtherInformationUnit *update_otherInformation (
87         Z_OtherInformation **otherInformationP, int createFlag,
88         const Odr_oid *oid, int categoryValue, int deleteFlag);
89     void set_otherInformationString(
90         Z_APDU *apdu,
91         const Odr_oid *oid, int categoryValue, const char *str);
92     void set_otherInformationString (
93         Z_OtherInformation **otherInformationP,
94         const Odr_oid *oid, int categoryValue,
95         const char *str);
96     Z_ReferenceId *getRefID(char* str);
97     Z_ReferenceId **get_referenceIdP(Z_APDU *apdu);
98     void transfer_referenceId(Z_APDU *from, Z_APDU *to);
99
100     const char *get_hostname();
101
102     int set_APDU_yazlog(int v);
103   private:
104     Z_Assoc_priv *m_p;
105 };
106 };
107
108 #endif
109 /*
110  * Local variables:
111  * c-basic-offset: 4
112  * c-file-style: "Stroustrup"
113  * indent-tabs-mode: nil
114  * End:
115  * vim: shiftwidth=4 tabstop=8 expandtab
116  */
117