sync with tizen_2.0
[platform/framework/native/appfw.git] / inc / FIoClientChannel.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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  * @file                FIoClientChannel.h
19  * @brief               This is the header file for the %ClientChannel class.
20  *
21  * This header file contains the declarations of the %ClientChannel class.
22  */
23 #ifndef _FIO_CLIENT_CHANNEL_H_
24 #define _FIO_CLIENT_CHANNEL_H_
25
26 #include <FBaseResult.h>
27 #include <FBaseObject.h>
28 #include <FBaseDataType.h>
29 #include <FAppTypes.h>
30 #include <FIoIChannelResponseEventListener.h>
31
32 namespace Tizen { namespace Io
33 {
34
35 /**
36 * @if OSPDEPREC
37 * @class    ClientChannel
38 * @brief    <i> [Deprecated] </i> This class provides methods for sending a request to another 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 %ClientChannel class provides methods for sending a request to another application's ServerChannel. To receive a response
46 * for the request, set the ChannelResponseEventListener interface. The instance of %ClientChannel can be retrieved
47 * using ClientChannel::GetInstance().
48 * @n
49 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/io/channels.htm">Channel Communication</a>.
50 *
51 * The following example demonstrates how to use the %ClientChannel class.
52 *
53 * @code
54 *
55 * #include <FBase.h>
56 * #include <FIo.h>
57 *
58 * using namespace Tizen::Base;
59 * using namespace Tizen::Base::Collection;
60 * using namespace Tizen::Io;
61 * using namespace Tizen::App;
62 *
63 * class MyAppClass
64 *       : public Tizen::Io::IChannelResponseEventListener
65 * {
66 * public:
67 *       result Initialize(void);
68 *       void virtual OnChannelResponseReceivedN(RequestId reqId, Tizen::Io::ClientChannel& clientChannel
69 *                                                                                               , const Tizen::Base::String& serverChannelId
70 *                                                                                               , Tizen::Base::Collection::IList* pArgs);
71 *       void GetOnlineFriends(void);
72 * };
73 *
74 * void
75 * MyAppClass::Initialize(void)
76 * {
77 *       // Sets the channel response event listener.
78 *       ClientChannel::GetInstance()->SetChannelResponseEventListener(this);
79 * }
80 *
81 * void
82 * MyAppClass::OnChannelResponseReceivedN(RequestId reqId, ClientChannel& clientChannel
83 *                                                                               , const String& serverChannelId
84 *                                                                               , IList* pArgs)
85 * {
86 *       // Handles the channel response.
87 *       for(int i = 0; i < pArgs->GetCount(); i++)
88 *       {
89 *               AppLog("pData[%d]=%S", i, ((String*)(pArgs->GetAt(i)))->GetPointer());
90 *       }
91 *
92 *       // Cleans up the arguments.
93 *       pArgs->RemoveAll(true);
94 *       delete pArgs;
95 * }
96 *
97 * void
98 * MyAppClass::GetOnlineFriends(void)
99 * {
100 *       RequestId reqId = 0;
101 *
102 *       ArrayList* pDataList = new ArrayList();
103 *       pDataList->Construct();
104 *
105 *       String* pData = new String(L"GetList");
106 *       String* pData2 = new String(L"Friend");
107 *
108 *       pDataList->Add(*pData);
109 *       pDataList->Add(*pData2);
110 *
111 *       ClientChannel::GetInstance()->SendRequest(L"1234567890.ContactSvc", pDataList, reqId);
112 *
113 *       pDataList->RemoveAll(true);
114 *       delete pDataList;
115 * }
116 *
117 * @endcode
118 * @endif
119 */
120
121 class _OSP_EXPORT_ ClientChannel
122         : public Tizen::Base::Object
123 {
124 public:
125         /**
126         * Gets the default client channel of the application.
127         *
128         * @since 2.0
129         *
130         * @return       A pointer to the %ClientChannel instance, @n
131         *                       else @c null if it fails
132         * @exception    E_SUCCESS           The method is successful.
133         * @exception    E_SYSTEM            The method cannot proceed due to a severe system error.
134         * @remarks       The specific error code can be accessed using the GetLastResult() method.
135         */
136         static ClientChannel* GetInstance(void);
137
138         /**
139         * Gets the specific client channel of the application.
140         *
141         * @since 2.0
142         *
143         * @return       A pointer to the %ClientChannel instance, @n
144         *                       else @c null if it fails
145         * @param[in]     channelName         The channel name
146         * @exception     E_SUCCESS           The method is successful.
147         * @exception     E_SYSTEM            The method cannot proceed due to a severe system error.
148         * @remarks       The specific error code can be accessed using the GetLastResult() method.
149         */
150         static ClientChannel* GetInstance(const Tizen::Base::String& channelName);
151
152         /**
153         * Sets the response event listener. @n
154         * The listener is called when a response is received. To reset the event listener, @c null must be passed.
155         *
156         * @since 2.0
157         *
158         * @param[in] pResponseListener    The response event listener
159         */
160         void SetChannelResponseEventListener(IChannelResponseEventListener* pResponseListener);
161
162         /**
163          * Sends a request to the specific server channel of an application specified by the serverChannelId.
164          *
165          * @since 2.0
166          *
167          * @return       An error code
168          * @param[in]     serverChannelId    The server channel ID which can be either application ID or appicationID.ChannelName
169          * @param[in]     pArgs               A pointer to an argument list of type String
170          * @param[out]    reqId               The request ID
171          * @exception     E_SUCCESS           The method is successful.
172          * @exception     E_OBJ_NOT_FOUND     The server channel is not found.
173          * @exception     E_SYSTEM            The method cannot proceed due to a severe system error.
174          */
175         result SendRequest(const Tizen::Base::String& serverChannelId, const Tizen::Base::Collection::IList* pArgs, RequestId& reqId);
176
177
178 private:
179         /**
180         * This default constructor is intentionally declared as private to implement the Singleton semantic.
181         */
182         ClientChannel(void);
183
184         /**
185         * This destructor is intentionally declared as private to implement the Singleton semantic.
186         */
187         virtual ~ClientChannel(void);
188
189         /**
190         * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
191         */
192         ClientChannel(const ClientChannel& clientChannel);
193
194         /**
195         * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
196         */
197         ClientChannel& operator =(const ClientChannel& clientChannel);
198
199         static void InitSingleton(void);
200
201         static void DestroySingleton(void);
202
203         static ClientChannel* __pClientChannelInstance;
204
205         friend class _ClientChannelImpl;
206
207         class _ClientChannelImpl* __pClientChannelImpl;
208
209 }; // ClientChannel
210
211 } } // Tizen::Io
212
213 #endif //_FIO_CLIENT_CHANNEL_H_