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