e6942bc8c02b16d1104564d2a10d0dc7f5cadf54
[yazpp-moved-to-github.git] / include / yazpp / socket-observer.h
1 /* This file is part of the yazpp toolkit.
2  * Copyright (C) 1998-2012 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_SOCKET_OBSERVER_H
29 #define YAZ_SOCKET_OBSERVER_H
30
31 #include <yaz/yconfig.h>
32
33 namespace yazpp_1 {
34
35     enum SocketObserve {
36         SOCKET_OBSERVE_READ=1,
37         SOCKET_OBSERVE_WRITE=2,
38         SOCKET_OBSERVE_EXCEPT=4,
39         SOCKET_OBSERVE_TIMEOUT=8
40     };
41
42 /**
43    Forward reference
44 */
45     class ISocketObserver;
46
47 /** Socket Observable.
48     This interface implements notification of socket events.
49     The module interested in (observing) the sockets
50     must implement the ISocketObserver interface. The
51     ISocketObserver only have to implement one function, so it's
52     quite simple to observe sockets change state.
53     The socket events below specifies read, write, exception,
54     and timeout respectively:
55     <pre>
56     SOCKET_OBSERVE_READ
57     SOCKET_OBSERVE_WRITE
58     SOCKET_OBSERVE_EXCEPT
59     SOCKET_OBSERVE_TIMEOUT
60     </pre>
61     The maskObserver method specifies which of these events the
62     observer is intertested in.
63 */
64     class YAZ_EXPORT ISocketObservable {
65     public:
66         /// Add an observer interested in socket fd
67         virtual void addObserver(int fd, ISocketObserver *observer) = 0;
68         /// Delete an observer
69         virtual void deleteObserver(ISocketObserver *observer) = 0;
70         /// Delete all observers
71         virtual void deleteObservers() = 0;
72         /// Specify the events that the observer is intersted in.
73         virtual void maskObserver(ISocketObserver *observer, int mask) = 0;
74         /// Specify timeout
75         virtual void timeoutObserver(ISocketObserver *observer,
76                                      int timeout)=0;
77         virtual ~ISocketObservable();
78     };
79
80 /** Socket Observer.
81     The ISocketObserver interface implements a module interested
82     socket events. Look for objects that implements the
83     ISocketObservable interface!
84 */
85     class YAZ_EXPORT ISocketObserver {
86     public:
87         /// Notify the observer that something happened to socket
88         virtual void socketNotify(int event) = 0;
89         virtual ~ISocketObserver();
90     };
91
92 };
93 #endif
94 /*
95  * Local variables:
96  * c-basic-offset: 4
97  * c-file-style: "Stroustrup"
98  * indent-tabs-mode: nil
99  * End:
100  * vim: shiftwidth=4 tabstop=8 expandtab
101  */
102