546762497ebb505d309f0b62e3c69d8d4ec6f868
[framework/osp/net.git] / inc / FNetSockISocketEventListener.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18
19 /**
20 * @file         FNetSockISocketEventListener.h
21 * @brief        This is the header file for the %ISocketEventListener interface.
22 *
23 * This header file contains the declarations of the %ISocketEventListener interface.
24 */
25
26 #ifndef _FNET_SOCK_ISOCKET_EVENT_LISTENER_H_
27 #define _FNET_SOCK_ISOCKET_EVENT_LISTENER_H_
28
29 #include <FBaseRtIEventListener.h>
30 #include <FNetSockSocketTypes.h>
31
32 namespace Tizen { namespace Net { namespace Sockets
33 {
34
35 class Socket;
36
37 /**
38 * @interface    ISocketEventListener
39 * @brief                This interface contains a listener for the socket events.
40 *
41 * @since        2.0
42 *
43 *                               The %ISocketEventListener interface specifies methods used for creating notifications about the different kinds of socket events.
44 *                               These events are only sent out when using the socket in a non-blocking mode. A listener is registered by calling the AddSocketListener()
45 *                               method. One of these methods is called when a socket event is generated.
46 *
47 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/net/sockets.htm">Sockets Guide</a>.
48 *
49 * The following example demonstrates how to use the %ISocketEventListener interface.
50 *
51 * @code
52 using namespace Tizen::Net::Sockets;
53
54 class TestListener
55         : public Object
56         , public virtual ISocketEventListener
57 {
58 public:
59         TestListener() {}
60
61         ~TestListener() {}
62
63         void OnSocketConnected(Socket& socket)
64         {
65                 AppLog("OnConnected\n");
66         }
67
68         void OnSocketClosed(Socket& socket, NetSocketClosedReason reason)
69         {
70                 AppLog("OnClosed\n");
71         }
72
73         void OnSocketReadyToReceive(Socket& socket)
74         {
75                 AppLog("OnReadyToReceive\n");
76         }
77
78         void OnSocketReadyToSend(Socket& socket)
79         {
80                 AppLog("OnReadyToSend\n");
81         }
82 };
83 * @endcode
84 */
85 class _OSP_EXPORT_ ISocketEventListener
86         : virtual public Tizen::Base::Runtime::IEventListener
87 {
88
89
90 public:
91         /**
92          * This polymorphic destructor should be overridden if required. This way, the destructors of the derived classes are called when the destructor of this interface is called.
93          *
94          * @since 2.0
95          */
96         virtual ~ISocketEventListener(void) {}
97
98
99 public:
100         /**
101         * Called to notify a connecting socket that its connection attempt has been completed successfully.
102         *
103         * @since        2.0
104         *
105         * @param[in]    socket          The Socket instance
106         */
107         virtual void OnSocketConnected(Socket& socket) = 0;
108
109         /**
110         * Called to notify the registered socket that the peer socket has been closed due to normal or forced termination of the network. @n
111         * It is also used to notify a connecting socket that its connection attempt has resulted in an error.
112         *
113         * @since        2.0
114         *
115         * @param[in]    socket          The Socket instance
116         * @param[in]    reason          The reason of type NetSocketClosedReason for a closed socket
117         */
118         virtual void OnSocketClosed(Socket& socket, NetSocketClosedReason reason) = 0;
119
120         /**
121         * Called to notify a socket that the data is ready to be retrieved.
122         *
123         * @since        2.0
124         *
125         * @param[in]    socket          The Socket instance
126         * @remarks              The data can be retrieved by calling Receive() or ReceiveFrom().
127         */
128         virtual void OnSocketReadyToReceive(Socket& socket) = 0;
129
130         /**
131         * Called to notify a socket that the data can be sent.
132         *
133         * @since        2.0
134         *
135         * @param[in]    socket          The Socket instance
136         * @remarks              The data can be sent using Send() or SendTo().
137         */
138         virtual void OnSocketReadyToSend(Socket& socket) = 0;
139
140         /**
141         * Called to notify a socket that it has received a new connection from a peer.
142         *
143         * @since        2.0
144         *
145         * @param[in]    socket          The Socket instance
146         */
147         virtual void OnSocketAccept(Socket& socket) = 0;
148
149 protected:
150         //
151         // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application.
152         //
153         // This method is reserved and may change its name at any time without prior notice.
154         //
155         // @since       2.0
156         //
157         virtual void ISocketEventListener_Reserved1(void) {}
158
159         //
160         // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application.
161         //
162         // This method is reserved and may change its name at any time without prior notice.
163         //
164         // @since       2.0
165         //
166         virtual void ISocketEventListener_Reserved2(void) {}
167
168 };
169
170 } } } // Tizen::Net::Sockets
171 #endif // _FNET_SOCK_ISOCKET_EVENT_LISTENER_H_