Another and hopefully, last, YAZ OID DB update
[yazpp-moved-to-github.git] / include / yazpp / socket-observer.h
1 /*
2  * Copyright (c) 1998-2005, Index Data.
3  * See the file LICENSE for details.
4  * 
5  * $Id: socket-observer.h,v 1.1 2006-03-29 13:14:15 adam Exp $
6  */
7
8 #ifndef YAZ_SOCKET_OBSERVER_H
9 #define YAZ_SOCKET_OBSERVER_H
10
11 #include <yaz/yconfig.h>
12
13 namespace yazpp_1 {
14     
15     enum SocketObserve {
16         SOCKET_OBSERVE_READ=1,
17         SOCKET_OBSERVE_WRITE=2,
18         SOCKET_OBSERVE_EXCEPT=4,
19         SOCKET_OBSERVE_TIMEOUT=8
20     };
21
22 /**
23    Forward reference
24 */
25     class ISocketObserver;
26     
27 /** Socket Observable.
28     This interface implements notification of socket events.
29     The module interested in (observing) the sockets
30     must implement the ISocketObserver interface. The
31     ISocketObserver only have to implement one function, so it's
32     quite simple to observe sockets change state.
33     The socket events below specifies read, write, exception,
34     and timeout respectively:
35     <pre>
36     SOCKET_OBSERVE_READ
37     SOCKET_OBSERVE_WRITE
38     SOCKET_OBSERVE_EXCEPT
39     SOCKET_OBSERVE_TIMEOUT
40     </pre>
41     The maskObserver method specifies which of these events the
42     observer is intertested in.
43 */
44     class YAZ_EXPORT ISocketObservable {
45     public:
46         /// Add an observer interested in socket fd
47         virtual void addObserver(int fd, ISocketObserver *observer) = 0;
48         /// Delete an observer
49         virtual void deleteObserver(ISocketObserver *observer) = 0;
50         /// Delete all observers
51         virtual void deleteObservers() = 0;
52         /// Specify the events that the observer is intersted in.
53         virtual void maskObserver(ISocketObserver *observer, int mask) = 0;
54         /// Specify timeout
55         virtual void timeoutObserver(ISocketObserver *observer,
56                                      int timeout)=0;
57         virtual ~ISocketObservable();
58     };
59     
60 /** Socket Observer.
61     The ISocketObserver interface implements a module interested
62     socket events. Look for objects that implements the
63     ISocketObservable interface!
64 */
65     class YAZ_EXPORT ISocketObserver {
66     public:
67         /// Notify the observer that something happened to socket
68         virtual void socketNotify(int event) = 0;
69         virtual ~ISocketObserver();
70     };
71     
72 };
73 #endif
74 /*
75  * Local variables:
76  * c-basic-offset: 4
77  * indent-tabs-mode: nil
78  * End:
79  * vim: shiftwidth=4 tabstop=8 expandtab
80  */
81