Sync with tizen_2.2.1
[platform/framework/native/appfw.git] / inc / FIoServerChannel.h
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 /**
17  * @if OSPDEPREC
18  * @file                FIoServerChannel.h
19  * @brief               This is the header file for the %ServerChannel class.
20  *
21  * This header file contains the declarations of the %ServerChannel class.
22  * @endif
23  */
24 #ifndef _FIO_SERVER_CHANNEL_H_
25 #define _FIO_SERVER_CHANNEL_H_
26
27 #include <FBaseResult.h>
28 #include <FBaseObject.h>
29 #include <FBaseDataType.h>
30 #include <FAppTypes.h>
31 #include <FIoIChannelRequestEventListener.h>
32
33 namespace Tizen { namespace Io
34 {
35 /**
36 * @if OSPDEPREC
37 * @class    ServerChannel
38 * @brief    <i> [Deprecated] </i> This class provides methods to receive a request from a client application.
39 *
40 * @deprecated   This class is deprecated. Instead of using this class, use LocalMessagePort, RemoteMessagePort, and MessagePortManager classes.
41 * @since    2.0
42 *
43 * @final        This class is not intended for extension.
44 *
45 * The %ServerChannel class provides methods to receive a request from a client application. An application can receive a
46 * request from another application using the %ServerChannel class. The instance of %ServerChannel is retrieved using
47 * ServerChannel::GetInstance().
48 *
49 * The following example demonstrates how to use the %ServerChannel class.
50 *
51 * @code
52 *
53 * #include <FBase.h>
54 * #include <FIo.h>
55 *
56 * using namespace Tizen::Base;
57 * using namespace Tizen::Base::Collection;
58 * using namespace Tizen::Io;
59 * using namespace Tizen::App;
60 *
61 * class MyAppClass
62 *       : public Tizen::Io::IChannelRequestEventListener
63 * {
64 * public:
65 *       result Initialize(void);
66 *       ArrayList* GetOnlineFriends(void);
67 *       void virtual OnChannelRequestReceivedN(RequestId reqId, Tizen::Io::ServerChannel& serverChannel
68 *                                                                               , const Tizen::Base::String& clientChannelId
69 *                                                                               , Tizen::Base::Collection::IList* pArgs);
70 * };
71 *
72 * result
73 * MyAppClass::Initialize(void)
74 * {
75 *       result r = E_SUCCESS;
76 *
77 *       // Sets the channel request event listener.
78 *       ServerChannel::GetInstance()->SetChannelRequestEventListener(this);
79 *
80 *       return r;
81 * }
82 *
83 * ArrayList*
84 * MyAppClass::GetOnlineFriends(void)
85 * {
86 *       ArrayList* pDataList = new ArrayList();
87 *       pDataList->Construct();
88
89 *       String* pData = new String(L"Tom");
90 *       String* pData2 = new String(L"Jane");
91 *
92 *       pDataList->Add(*pData);
93 *       pDataList->Add(*pData2);
94 *
95 *       return pDataList;
96 * }
97 *
98 * void
99 * MyAppClass::OnChannelRequestReceivedN(RequestId reqId, ServerChannel& serverChannel
100 *                                                                               , const String& clientChannelId
101 *                                                                               , IList* pArgs)
102 * {
103 *       // Handles the request.
104 *       ArrayList* pList = GetOnlineFriends();
105 *
106 *       // Sends the response to the client.
107 *       serverChannel.SendResponse(clientChannelId, reqId, pList);
108 *
109 *       // Removes the arguments.
110 *       pList->RemoveAll(true);
111 *       delete pList;
112 *
113 *       pArgs->RemoveAll(true);
114 *       delete pArgs;
115 * }
116 *
117 * @endcode
118 * @endif
119 */
120
121 class _OSP_EXPORT_ ServerChannel
122         : public Tizen::Base::Object
123 {
124 public:
125         /**
126         * Sets the request event listener. @n
127         * The listener is called when a request arrives. To reset the event listener, @c null must be passed.
128         *
129         * @since 2.0
130         *
131         * @param[in] pRequestListener    The request event listener
132         */
133         void SetChannelRequestEventListener(IChannelRequestEventListener* pRequestListener);
134
135         /**
136         * Gets the default server channel of the application.
137         *
138         * @since    2.0
139         *
140         * @return       The pointer to the %ServerChannel instance, @n
141         *                       else @c null if it fails
142         * @exception    E_SUCCESS           The method is successful.
143         * @exception    E_SYSTEM            The method cannot proceed due to a severe system error.
144         * @remarks              The specific error code can be accessed using the GetLastResult() method.
145         */
146
147         static ServerChannel* GetInstance(void);
148
149         /**
150         * Gets the specific server channel of the application.
151         *
152         * @since        2.0
153         *
154         * @return       The pointer to the %ServerChannel instance, @n
155         *                       else @c null if it fails
156         * @param[in]    channelName         The channel name
157         * @exception    E_SUCCESS           The method is successful.
158         * @exception    E_SYSTEM            The method cannot proceed due to a severe system error.
159         * @remarks              The specific error code can be accessed using the GetLastResult() method.
160         */
161         static ServerChannel* GetInstance(const Tizen::Base::String& channelName);
162
163         /**
164         * Sends a response to the specific client channel of an application specified by the clientChannelId.
165         *
166         * @since        2.0
167         *
168         * @return    An error code
169         * @param[in]    clientChannelId     The client channel ID which can be either application ID or appicationID.ChannelName
170         * @param[in]    reqId               The request ID
171         * @param[in]    pArgs               A pointer to an argument list of type String
172         * @exception    E_SUCCESS           The method is successful.
173         * @exception    E_OBJ_NOT_FOUND     The specified client channel is not found.
174         * @exception    E_SYSTEM            The method cannot proceed due to a severe system error.
175         */
176         result SendResponse(const Tizen::Base::String& clientChannelId, RequestId reqId, const Tizen::Base::Collection::IList* pArgs);
177
178
179 private:
180         /**
181          * This default constructor is intentionally declared as private to implement the Singleton semantic.
182          */
183         ServerChannel(void);
184
185         /**
186         * This destructor is intentionally declared as private to implement the Singleton semantic.
187         */
188         virtual ~ServerChannel(void);
189
190         /**
191         * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
192         */
193         ServerChannel(const ServerChannel& serverChannel);
194
195         /**
196         * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
197         */
198         ServerChannel& operator =(const ServerChannel& serverChannel);
199
200         static void InitSingleton(void);
201
202         static void DestroySingleton(void);
203
204         friend class _ServerChannelImpl;
205
206         class _ServerChannelImpl * __pServerChannelImpl;
207
208         static ServerChannel* __pServerChannelInstance;
209 }; // ServerChannel
210
211 } } // Tizen::Io
212
213 #endif //_FIO_SERVER_CHANNEL_H_