a0f67ff3a10852708f393a2dd1d0364878892e2a
[yazpp-moved-to-github.git] / include / yazpp / pdu-observer.h
1 /* This file is part of the yazpp toolkit.
2  * Copyright (C) 1998-2013 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 #ifndef YAZ_PDU_OBSERVER_H
29 #define YAZ_PDU_OBSERVER_H
30
31 #include <yaz/yconfig.h>
32
33 namespace yazpp_1 {
34
35 class IPDU_Observer;
36
37 /** Protocol Data Unit Observable.
38     This interface implements a Protocol Data Unit (PDU) network driver.
39     The PDU's is not encoded/decoded by this interface. They are simply
40     transmitted/received over the network. To use this interface the
41     IPDU_Observer interface must be implemented.
42  */
43 class YAZ_EXPORT IPDU_Observable {
44  public:
45     /// Send encoded PDU buffer of specified length
46     virtual int send_PDU(const char *buf, int len) = 0;
47     /// Connect with server specified by addr.
48     virtual int connect(IPDU_Observer *observer, const char *addr) = 0;
49     /// Listen on address addr.
50     virtual int listen(IPDU_Observer *observer, const char *addr) = 0;
51     /// Close connection
52     virtual void shutdown() = 0;
53     /// Make clone of this object using this interface
54     virtual IPDU_Observable *clone() = 0;
55     /// Destroy completely
56     virtual void destroy() = 0;
57     /// Set Idle Time
58     virtual void idleTime (int timeout) = 0;
59     /// Get peername
60     virtual const char *getpeername() = 0;
61     /// Close session
62     virtual void close_session() = 0;
63
64     virtual ~IPDU_Observable();
65 };
66
67 /** Protocol Data Unit Observer.
68     This interface is used together with the IPDU_Observable interface
69     and acts as a callback interface for it.
70  */
71 class YAZ_EXPORT IPDU_Observer {
72  public:
73     /// A PDU has been received
74     virtual void recv_PDU(const char *buf, int len) = 0;
75     /// Called when Iyaz_PDU_Observable::connect was successful.
76     virtual void connectNotify() = 0;
77     /// Called whenever the connection was closed
78     virtual void failNotify() = 0;
79     /// Called whenever there is a timeout
80     virtual void timeoutNotify() = 0;
81     /// Make clone of observer using IPDU_Observable interface
82     virtual IPDU_Observer *sessionNotify(
83         IPDU_Observable *the_PDU_Observable, int fd) = 0;
84
85     virtual ~IPDU_Observer();
86 };
87 };
88
89 #endif
90 /*
91  * Local variables:
92  * c-basic-offset: 4
93  * c-file-style: "Stroustrup"
94  * indent-tabs-mode: nil
95  * End:
96  * vim: shiftwidth=4 tabstop=8 expandtab
97  */
98