01110685c167d4ff6968aa960872bd51dfc6e54b
[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 request from another application using the %ServerChannel class. The instance of %ServerChannel is retrieved using ServerChannel::GetInstance().
46 *
47 * The following example demonstrates how to use the %ServerChannel class.
48 *
49 * @code
50 *
51 * #include <FBase.h>
52 * #include <FIo.h>
53 *
54 * using namespace Tizen::Base;
55 * using namespace Tizen::Base::Collection;
56 * using namespace Tizen::Io;
57 * using namespace Tizen::App;
58 *
59 * class MyAppClass
60 *       : public Tizen::Io::IChannelRequestEventListener
61 * {
62 * public:
63 *       result Initialize(void);
64 *       ArrayList* GetOnlineFriends(void);
65 *       void virtual OnChannelRequestReceivedN(RequestId reqId, Tizen::Io::ServerChannel& serverChannel
66 *                                                                               , const Tizen::Base::String& clientChannelId
67 *                                                                               , Tizen::Base::Collection::IList* pArgs);
68 * };
69 *
70 * result
71 * MyAppClass::Initialize(void)
72 * {
73 *       result r = E_SUCCESS;
74 *
75 *       // Sets the channel request event listener.
76 *       ServerChannel::GetInstance()->SetChannelRequestEventListener(this);
77 *
78 *       return r;
79 * }
80 *
81 * ArrayList*
82 * MyAppClass::GetOnlineFriends(void)
83 * {
84 *       ArrayList* pDataList = new ArrayList();
85 *       pDataList->Construct();
86
87 *       String* pData = new String(L"Tom");
88 *       String* pData2 = new String(L"Jane");
89 *
90 *       pDataList->Add(*pData);
91 *       pDataList->Add(*pData2);
92 *
93 *       return pDataList;
94 * }
95 *
96 * void
97 * MyAppClass::OnChannelRequestReceivedN(RequestId reqId, ServerChannel& serverChannel
98 *                                                                               , const String& clientChannelId
99 *                                                                               , IList* pArgs)
100 * {
101 *       // Handles the request.
102 *       ArrayList* pList = GetOnlineFriends();
103 *
104 *       // Sends the response to the client.
105 *       serverChannel.SendResponse(clientChannelId, reqId, pList);
106 *
107 *       // Removes the arguments.
108 *       pList->RemoveAll(true);
109 *       delete pList;
110 *
111 *       pArgs->RemoveAll(true);
112 *       delete pArgs;
113 * }
114 *
115 * @endcode
116 * @endif
117 */
118
119 class _OSP_EXPORT_ ServerChannel
120         : public Tizen::Base::Object
121 {
122 public:
123         /**
124         * Sets the request event listener. @n
125         * The listener is called when a request arrives. To reset the event listener, @c null must be passed.
126         *
127         * @since 2.0
128         *
129         * @param[in] pRequestListener    The request event listener
130         */
131         void SetChannelRequestEventListener(IChannelRequestEventListener* pRequestListener);
132
133         /**
134         * Gets the default server channel of the application.
135         *
136         * @since    2.0
137         *
138         * @return       A pointer to the %ServerChannel instance, @n
139         *                       else @c null if it fails
140         * @exception    E_SUCCESS           The method is successful.
141         * @exception    E_SYSTEM            The method cannot proceed due to a severe system error.
142         * @remarks              The specific error code can be accessed using the GetLastResult() method.
143         */
144
145         static ServerChannel* GetInstance(void);
146
147         /**
148         * Gets the specific server channel of the application.
149         *
150         * @since        2.0
151         *
152         * @return       A pointer to the %ServerChannel instance, @n
153         *                       else @c null if it fails
154         * @param[in]    channelName         The channel name
155         * @exception    E_SUCCESS           The method is successful.
156         * @exception    E_SYSTEM            The method cannot proceed due to a severe system error.
157         * @remarks              The specific error code can be accessed using the GetLastResult() method.
158         */
159         static ServerChannel* GetInstance(const Tizen::Base::String& channelName);
160
161         /**
162         * Sends a response to the specific client channel of an application specified by the clientChannelId.
163         *
164         * @since        2.0
165         *
166         * @return    An error code
167         * @param[in]    clientChannelId     The client channel ID which can be either application ID or appicationID.ChannelName
168         * @param[in]    reqId               The request ID
169         * @param[in]    pArgs               A pointer to an argument list of type String
170         * @exception    E_SUCCESS           The method is successful.
171         * @exception    E_OBJ_NOT_FOUND     The specified client channel is not found.
172         * @exception    E_SYSTEM            The method cannot proceed due to a severe system error.
173         */
174         result SendResponse(const Tizen::Base::String& clientChannelId, RequestId reqId, const Tizen::Base::Collection::IList* pArgs);
175
176
177 private:
178         /**
179          * This default constructor is intentionally declared as private to implement the Singleton semantic.
180          */
181         ServerChannel(void);
182
183         /**
184         * This destructor is intentionally declared as private to implement the Singleton semantic.
185         */
186         virtual ~ServerChannel(void);
187
188         /**
189         * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
190         */
191         ServerChannel(const ServerChannel& serverChannel);
192
193         /**
194         * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
195         */
196         ServerChannel& operator =(const ServerChannel& serverChannel);
197
198         static void InitSingleton(void);
199
200         static void DestroySingleton(void);
201
202         friend class _ServerChannelImpl;
203
204         class _ServerChannelImpl * __pServerChannelImpl;
205
206         static ServerChannel* __pServerChannelInstance;
207 }; // ServerChannel
208
209 } } // Tizen::Io
210
211 #endif //_FIO_SERVER_CHANNEL_H_