sync with tizen_2.0
[platform/framework/native/appfw.git] / inc / FAppIMapDataControlProviderEventListener.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 /**
19  * @file        FAppIMapDataControlProviderEventListener.h
20  * @brief       This is the header file for the %IMapDataControlProviderEventListener interface.
21  *
22  * This header file contains the declarations of the %IMapDataControlProviderEventListener interface.
23  */
24
25 #ifndef _FAPP_IMAP_DATACONTROL_REQUESTEVENT_LISTENER_H_
26 #define _FAPP_IMAP_DATACONTROL_REQUESTEVENT_LISTENER_H_
27
28 #include <FBaseDataType.h>
29 #include <FBaseString.h>
30 #include <FBaseRtIEventListener.h>
31
32 namespace Tizen { namespace App
33 {
34
35 /**
36  * @interface   IMapDataControlProviderEventListener
37  * @brief               This interface defines a listener for dealing with MAP-type data control request.
38  *
39  * @since       2.0
40  *
41  * The %IMapDataControlProviderEventListener interface defines a listener for dealing with MAP-type data control request.
42  *
43  * The following example demonstrates how to use the %IMapDataControlProviderEventListener interface.
44  * @code
45 #include <FBase.h>
46 #include <FApp.h>
47 #include <FIo.h>
48
49 class MyServiceApp
50         : public Tizen::App::ServiceApp
51         : public Tizen::App::IMapDataControlProviderEventListener
52 {
53 public:
54         MyServiceApp(void);
55         virtual ~MyServiceApp(void);
56
57         virtual bool OnAppInitializing(Tizen::App::AppRegistry& appRegistry);
58         virtual bool OnAppTerminating(Tizen::App::AppRegistry& appRegistry, bool forcedTermination = false);
59
60         virtual void OnMapDataControlGetValueRequestReceived(RequestId reqId, const Tizen::Base::String& providerId,
61                         const Tizen::Base::String& dataId, const Tizen::Base::String& key);
62         virtual void OnMapDataControlAddValueRequestReceived(RequestId reqId, const Tizen::Base::String& providerId,
63                         const Tizen::Base::String& dataId, const Tizen::Base::String& key, const Tizen::Base::String& value);
64         virtual void OnMapDataControlSetValueRequestReceived(RequestId reqId, const Tizen::Base::String& providerId,
65                         const Tizen::Base::String& dataId, const Tizen::Base::String& key, const Tizen::Base::String& oldValue,
66                         const Tizen::Base::String& newValue);
67         virtual void OnMapDataControlRemoveValueRequestReceived(RequestId reqId, const Tizen::Base::String& providerId,
68                         const Tizen::Base::String& dataId, const Tizen::Base::String& key, const Tizen::Base::String& value);
69 };
70
71 bool
72 MyServiceApp::OnAppInitializing(Tizen::App::AppRegistry& appRegistry)
73 {
74     result r = E_SUCCESS;
75
76         DataControlProviderManager* pDcMgr = DataControlProviderManager::GetInstance();
77         if (pDcMgr == null)
78         {
79                 AppLog("Failed to get the instance of data control provider manager.");
80                 return false;
81         }
82
83         r = pDcMgr->SetMapDataControlProviderEventListener(this);
84         if (IsFailed(r))
85         {
86                 AppLog("Failed to set the data control provider listener.");
87                 return false;
88         }
89
90         return true;
91 }
92
93 void
94 MyServiceApp::OnMapDataControlGetValueRequestReceived(RequestId reqId, const Tizen::Base::String& providerId,
95                 const Tizen::Base::String& dataId, const Tizen::Base::String& key)
96 {
97         Registry* pReg = null;
98         String retValue;
99         ArrayList* pResultValueList = null;
100         String errorMsg;
101         result r = E_SUCCESS;
102
103         if (providerId.compareTo(L"http://tizen.org/datacontrol/provider/example") == 0)
104         {
105                 if (dataId.compareTo(L"test") == 0)
106                 {
107                         String regPath(GetAppRootPath() + L"data/test.ini");
108
109                         pReg = new Registry();
110                         if (pReg == null)
111                         {
112                                 errorMsg.Append(L"The memory is insufficient.");
113                                 goto CATCH;
114                         }
115
116                         r = pReg->Construct(regPath, false);
117                         if (IsFailed(r))
118                         {
119                                 errorMsg.Append(L"The data control provider failed to open the registry file.");
120                                 goto CATCH;
121                         }
122
123                         r = pReg->GetValue(dataId, key, retValue);
124                         if (IsFailed(r))
125                         {
126                                 errorMsg.Append(L"The data control provider failed to get the value.");
127                                 goto CATCH:
128                         }
129
130                         pResultValueList = new ArrayList();
131                         pResultValueList->Add(retValue);
132
133                         delete pReg;
134                 }
135                 else
136                 {
137                         errorMsg.Append(L"The data ID is invalid.");
138                 }
139         }
140         else
141         {
142                 errorMsg.Append(L"The provider ID is invalid.");
143         }
144
145         r = DataControlProviderManager::GetInstance()->SendMapDataControlResult(reqId, pResultValueList);
146         if (IsFailed(r))
147         {
148                 AppLog("The data control provider failed to send the result.");
149         }
150
151         if (pResultValueList)
152         {
153                 pResultValueList->RemoveAll();
154                 delete pResultValueList;
155         }
156         return;
157
158 CATCH:
159         r = DataControlProviderManager::GetInstance()->SendDataControlError(reqId, errorMsg);
160         if (IsFailed(r))
161         {
162                 AppLog("The data control provider failed to send the result.");
163         }
164
165         delete pReg;
166         if (pResultValueList)
167         {
168                 pResultValueList->RemoveAll();
169                 delete pResultValueList;
170         }
171         return;
172 }
173 * @endcode
174 */
175 class _OSP_EXPORT_ IMapDataControlProviderEventListener
176         : virtual public Tizen::Base::Runtime::IEventListener
177 {
178
179 public:
180         /**
181          * This polymorphic destructor should be overridden if required.
182          * This way, the destructors of the derived classes are called when the destructor of this interface is called.
183          *
184          * @since       2.0
185          */
186         virtual ~IMapDataControlProviderEventListener(void) {}
187
188         /**
189         * Called when the request for getting the value list is received from MAP-type data control consumer. @n
190         * The provider must implement this listener for providing its own data.
191         *
192         * @since        2.0
193         *
194         * @param[in]            reqId                           The request ID
195         * @param[in]            providerId                      The data control provider ID
196         * @param[in]            dataId                          A string for identifying a specific map to get from @n
197         *                                                                               The string consists of one or more components, separated by a slash('/').
198         * @param[in]            key                                     A key of the value list to obtain
199         * @remarks                      For replying to the data control request, use DataControlProviderManager::SendMapDataControlResult()
200         *                                       or DataControlProviderManager::SendDataControlError().
201         */
202         virtual void OnMapDataControlGetValueRequestReceived(RequestId reqId, const Tizen::Base::String& providerId,
203                         const Tizen::Base::String& dataId, const Tizen::Base::String& key) = 0;
204
205         /**
206         * Called when the request for adding the value is received from MAP-type data control consumer. @n
207         * The provider must implement this listener for providing its own data.
208         *
209         * @since        2.0
210         *
211         * @param[in]            reqId                           The request ID
212         * @param[in]            providerId                      The data control provider ID
213         * @param[in]            dataId                          A string for identifying a specific map to add to @n
214         *                                                                               The string consists of one or more components, separated by a slash('/').
215         * @param[in]            key                                     A key of the value list to add
216         * @param[in]            value                           A value to add
217         * @remarks                      For replying to the data control request, use DataControlProviderManager::SendMapDataControlResult()
218         *                                       or DataControlProviderManager::SendDataControlError().
219         */
220         virtual void OnMapDataControlAddValueRequestReceived(RequestId reqId, const Tizen::Base::String& providerId,
221                         const Tizen::Base::String& dataId, const Tizen::Base::String& key, const Tizen::Base::String& value) = 0;
222
223         /**
224         * Called when the request for replacing the value is received from MAP-type data control consumer. @n
225         * The provider must implement this listener for providing its own data.
226         *
227         * @since        2.0
228         *
229         * @param[in]            reqId                           The request ID
230         * @param[in]            providerId                      The data control provider ID
231         * @param[in]            dataId                          A string for identifying a specific map to update @n
232         *                                                                               The string consists of one or more components, separated by a slash('/').
233         * @param[in]            key                                     A key of the value to replace
234         * @param[in]            oldValue                        A value to replace
235         * @param[in]            newValue                        A new value to replace the existing value
236         * @remarks                      For replying to the data control request, use DataControlProviderManager::SendMapDataControlResult()
237         *                                       or DataControlProviderManager::SendDataControlError().
238         */
239         virtual void OnMapDataControlSetValueRequestReceived(RequestId reqId, const Tizen::Base::String& providerId,
240                         const Tizen::Base::String& dataId, const Tizen::Base::String& key, const Tizen::Base::String& oldValue,
241                         const Tizen::Base::String& newValue) = 0;
242
243         /**
244         * Called when the request for removing the value is received from MAP-type data control consumer. @n
245         * The provider must implement this listener for providing its own data.
246         *
247         * @since        2.0
248         *
249         * @param[in]            reqId                           The request ID
250         * @param[in]            providerId                      The data control provider ID
251         * @param[in]            dataId                          A string for identifying a specific map to remove from @n
252         *                                                                               The string consists of one or more components, separated by a slash('/').
253         * @param[in]            key                                     A key of the value to remove
254         * @param[in]            value                           A value to remove
255         * @remarks                      For replying to the data control request, use DataControlProviderManager::SendMapDataControlResult()
256         *                                       or DataControlProviderManager::SendDataControlError().
257         */
258         virtual void OnMapDataControlRemoveValueRequestReceived(RequestId reqId, const Tizen::Base::String& providerId,
259                         const Tizen::Base::String& dataId, const Tizen::Base::String& key, const Tizen::Base::String& value) = 0;
260
261 protected:
262         //
263         // This method is for internal use only.
264         // Using this method can cause behavioral, security-related, and consistency-related issues in the application.
265         //
266         // This method is reserved and may change its name at any time without prior notice.
267         //
268         // @since       2.0
269         //
270         virtual void IMapDataControlProviderEventListener_Reserved1(void) {}
271
272         //
273         // This method is for internal use only.
274         // Using this method can cause behavioral, security-related, and consistency-related issues in the application.
275         //
276         // This method is reserved and may change its name at any time without prior notice.
277         //
278         // @since       2.0
279         //
280         virtual void IMapDataControlProviderEventListener_Reserved2(void) {}
281
282         //
283         // This method is for internal use only.
284         // Using this method can cause behavioral, security-related, and consistency-related issues in the application.
285         //
286         // This method is reserved and may change its name at any time without prior notice.
287         //
288         // @since       2.0
289         //
290         virtual void IMapDataControlProviderEventListener_Reserved3(void) {}
291
292         //
293         // This method is for internal use only.
294         // Using this method can cause behavioral, security-related, and consistency-related issues in the application.
295         //
296         // This method is reserved and may change its name at any time without prior notice.
297         //
298         // @since       2.0
299         //
300         virtual void IMapDataControlProviderEventListener_Reserved4(void) {}
301
302         //
303         // This method is for internal use only.
304         // Using this method can cause behavioral, security-related, and consistency-related issues in the application.
305         //
306         // This method is reserved and may change its name at any time without prior notice.
307         //
308         // @since       2.0
309         //
310         virtual void IMapDataControlProviderEventListener_Reserved5(void) {}
311
312 }; // IMapDataControlProviderEventListener
313
314 }} // Tizen::App
315
316 #endif // _FAPP_IMAP_DATACONTROL_REQUESTEVENT_LISTENER_H_
317