Merge "Update deprecated libprivilege-control API functions." into tizen
[platform/framework/native/appfw.git] / src / app / inc / FApp_AppControlImpl.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        FApp_AppControlImpl.h
19  * @brief       This is the header file for the _AppControlImpl class.
20  */
21
22 #ifndef _FAPP_INTERNAL_APP_CONTROL_IMPL_H_
23 #define _FAPP_INTERNAL_APP_CONTROL_IMPL_H_
24
25 #include <FBaseObject.h>
26 #include <FAppTypes.h>
27 #include <FOspConfig.h>
28 #include <FAppAppControl.h>
29 #include <FBaseColArrayListT.h>
30
31 #include <FBaseRt_LibraryImpl.h>
32
33 #include "FApp_AppManagerImpl.h"
34 #include "FApp_IAppControlResponseEventListener.h"
35
36 typedef struct _bundle_t bundle;
37
38
39 namespace Tizen { namespace Base { class String; } }
40 namespace Tizen { namespace Base { namespace Collection { class IList; } } }
41 namespace Tizen { namespace Base { namespace Runtime { class IEventListener; } } }
42
43 namespace Tizen { namespace App
44 {
45
46 class AppControl;
47 class IAppControlEventListener;
48 class IAppControlResponseListener;
49 class _IAppControlPluginProvider;
50 class _AppMessageImpl;
51
52 enum _AppControlProperty
53 {
54         _APPCONTROL_PROPERTY_NONE = 0x0,
55         _APPCONTROL_PROPERTY_PUBLIC = 0x01,
56         _APPCONTROL_PROPERTY_RAISE_MODE = 0x1000,
57 };
58
59 class _OSP_LOCAL_ _AppControlImpl
60         : public Tizen::Base::Object
61         , public Tizen::App::_IAppControlResponseEventListener
62         , virtual public Tizen::Base::Runtime::IEventListener
63 {
64 public:
65         /**
66          * AppControl delegate constructor
67          */
68         static AppControl* CreateN(const Tizen::Base::String& path, const Tizen::Base::String& aId, const Tizen::Base::String& oId, int prop);
69
70         /**
71          * Internal GetImpl() method.
72          */
73         static const _AppControlImpl* GetInstance(const AppControl& ac)
74         {
75                 return ac.__pAppControlImpl;
76         }
77
78         /**
79          * Internal GetImpl() method.
80          */
81         static _AppControlImpl* GetInstance(AppControl& ac)
82         {
83                 return ac.__pAppControlImpl;
84         }
85
86         /**
87          * Starts the resolved application control. @n
88          * Once the application starts, it goes to the background and the target
89          * application control is displayed.
90          *
91          * @return              An error code
92          * @param[in]   pDataList       The data list to deliver to the resolved application control @n
93          *                                                      The maximum size of the list is 4096 bytes.
94          * @param[in]   pListener       The application control callback listener @n
95          *                                                      Some application controls need to get the callback result by implementing
96          *                                                      the IAppControlEventListener interface.
97          * @exception   E_SUCCESS                               The method is successful.
98          * @exception   E_MAX_EXCEEDED                  The size of @c pDataList has exceeded the maximum limit.
99          * @exception   E_OUT_OF_MEMORY                 The memory is insufficient.
100          * @exception   E_OBJ_NOT_FOUND                 The target application control resource is not found.
101          * @exception   E_IN_PROGRESS                   The application control is in progress: @n
102          *                                       - The application has already started an _AppControlImpl. @n
103          *                                       - The target application has already started.
104          * @exception   E_SYSTEM                                A system error has occurred.
105          * @remarks             If the %IAppControlEventListener instance (@c pListener) needs to get the
106          *               callback result for an application control, it should be valid till
107          *               IAppControlEventListener::OnAppControlCompleted() is invoked.
108          *               For example, a form object listener should not be deleted before the
109          *               system invokes IAppControlEventListener::OnAppControlCompleted().
110          */
111         result Start(const Tizen::Base::Collection::IList* pDataList, IAppControlEventListener* pListener);
112
113         /**
114          * Starts the found application control. @n
115          * Once the found application starts, the calling application goes to the background and the found
116          * application is displayed.
117          *
118          * @return      An error code
119          * @param[in]   pUriData    A pointer to the URI data
120          * @param[in]   pDataType   A pointer to the MIME type (RFC 2046) data
121          * @param[in]   pExtraData  The Tizen::Base::String key and Tizen::Base::String value pair map to deliver to the resolved application @n
122          *                          The maximum size is 16 kilo bytes.
123          * @param[in]   pListener   The application control callback listener @n
124          *                          Some application need to get the result by implementing the IAppControlResponseListener interface.
125          * @exception   E_SUCCESS               The method is successful.
126          * @exception   E_MAX_EXCEEDED          The size of @c pExtraData has exceeded the maximum limit.
127          * @exception   E_OBJ_NOT_FOUND         The target application control is not found.
128          * @exception   E_IN_PROGRESS           The application control is in progress: @n
129          *                                       - The application has already started an %AppControl.
130          * @exception   E_SYSTEM                The method cannot proceed due to a severe system error.
131          * @remarks     If the calling application needs to get some result for application control,
132          *              it must be valid till %IAppControlResponseListener::OnAppControlCompleteResponseReceived() is invoked.
133          *              For example, a form object listener must not be deleted before the
134          *              system invokes %IAppControlResponseListener::OnAppControlCompleteResponseReceived().
135          * @see IAppControlResponseListener, AppManager::FindAppControlN(), AppManager::FindAppControlsN()
136          */
137         result Start(const Tizen::Base::String* pUriData, const Tizen::Base::String* pDataType, const Tizen::Base::Collection::IMap* pExtraData, IAppControlResponseListener* pListener);
138
139         /**
140          * Gets the name of the application that provides the features represented by this %_AppControlImpl instance.
141          *
142          * @return              The name of the application providing this %_AppControlImpl instance
143          */
144         Tizen::Base::String GetAppName(void) const;
145
146         /**
147          * Gets the associated application ID. @n
148          *
149          * @return              The application control ID
150          */
151         Tizen::Base::String GetAppId(void) const
152         {
153                 return _appId;
154         }
155
156         /**
157          * Gets the associated application control provider ID. @n
158          *
159          * @return              The application control provider ID
160          */
161         Tizen::Base::String GetAppControlProviderId(void) const
162         {
163                 return _appId;
164         }
165
166         /**
167          * Gets the associated operation ID. @n
168          *
169          * @return              The operation ID
170          */
171         Tizen::Base::String GetOperationId(void) const
172         {
173                 return _opId;
174         }
175
176         /**
177          * Returns the associated application control categories.
178          *
179          * @return      A pointer to the list of application control categories, @n
180               *               else @c null if an error occurs
181          * @exception   E_SUCCESS       The method is successful.
182          * @exception   E_OUT_OF_MEMORY         The memory is insufficient.
183          * @exception   E_SYSTEM                        A system error has occurred.
184          * @remarks     The specific error code can be accessed using the GetLastResult() method.
185          */
186         Tizen::Base::Collection::IList* GetCategoryListN(void) const;
187
188         /**
189          * Stops the activated application control. @n
190          *
191          * @return          An error code
192          * @exception E_SUCCESS                        The method is successful.
193          * @exception E_SYSTEM                         A system error has occurred.
194          * @exception E_INVALID_OPERATION        The application control is not permitted to call this method.
195          * @remarks     This method is asynchronous.
196          */
197         result Stop(void);
198
199         /**
200          * Finds the matching application control with given operation ID, URI pattern, data type and category and
201          * starts the found one. @n
202          * If there are more than one application controls found, then the selection is shown for user and the one that the user selects is started.
203          * When the found application control is started, the URI pattern, MIME type, and extra data is delivered via IAppControlProviderEventListener.
204          *
205          * @return  An error code
206          * @param[in]   pOperationId   The operation ID
207          * @param[in]   pUriPattern           A URI pattern which is used for application control resolution and to be delivered as the argument
208          * @param[in]   pDataType   The MIME type (RFC 2046) or file extension @n
209          *                          The '.' prefix must be used when specifying the file extension.
210          * @param[in]   pCategory      The application control category
211          * @param[in]   pExtraData     The extra collection data to be delivered to the resolved application @n
212          *                                                   The maximum size is 16 kilo bytes.
213          * @param[in]   pListener   A listener that gets notified
214          * @exception   E_SUCCESS           The method is successful.
215          * @exception   E_MAX_EXCEEDED      The size of @c pDataList has exceeded the maximum limit.
216          * @exception   E_OBJ_NOT_FOUND     The application control is not found.
217          * @exception  E_SYSTEM                              The method cannot proceed due to a severe system error.
218          * @see IAppControlResponseListener, IAppControlProviderEventListener
219          */
220         _OSP_EXPORT_ static result FindAndStart(const Tizen::Base::String& operationId, const Tizen::Base::String* pUriPattern, const Tizen::Base::String* pDataType, const Tizen::Base::String* pCategory, const Tizen::Base::Collection::IMap* pExtraData, IAppControlResponseListener* pListener);
221
222         /**
223          * Stops the event listener for receiving application control result.
224          *
225          * @param[in]  pListener      The listener to stop receiving the application control result
226          */
227         static void StopAppControlResponseListener(IAppControlResponseListener* pListener);
228
229         static result StartImplicit(bundle* pBundle, const Tizen::Base::Collection::IList* pDataList, IAppControlEventListener* pListener);
230
231         static result StartImplicit(bundle* pBundle, const Tizen::Base::Collection::IMap* pData, IAppControlResponseListener* pListener);
232
233         static result StartImplicit(const _AppMessageImpl& msg, Tizen::Base::Runtime::IEventListener* pListener, bool isLegacy);
234
235         bool IsPublic(void) const
236         {
237                 return (_property & _APPCONTROL_PROPERTY_PUBLIC);
238         }
239
240         void SetProperty(int prop)
241         {
242                 _property |= prop;
243         }
244
245         virtual void OnAppControlResponseEventReceivedN(const Tizen::Base::Runtime::IEventArg* arg);
246 private:
247         explicit _AppControlImpl(const AppControl& value);
248
249         /**
250          * This is the default constructor for this class.
251          */
252         _AppControlImpl(void);
253
254         _AppControlImpl(const _AppControlImpl& rhs);
255
256         _AppControlImpl& operator =(const _AppControlImpl& rhs);
257
258         /**
259          * This is the destructor for this class.
260          */
261         virtual ~_AppControlImpl(void);
262
263         static _IAppControlPluginProvider* GetAppControlPluginProvider(const Tizen::Base::String& path);
264
265         static result InvokeStartAppControl(_IAppControlPluginProvider* pProvider, int req, const Tizen::Base::String& appId, const Tizen::Base::String& oId, const Tizen::Base::String* pUri, const Tizen::Base::String* pMime, const Tizen::Base::Collection::IMap* pMap);
266
267         static result InvokeStartAppControl(_IAppControlPluginProvider* pProvider, int req, const Tizen::Base::String& appId, const Tizen::Base::String& oId, const Tizen::Base::Collection::IList* pList);
268
269         static result InvokeStartAppControl(_IAppControlPluginProvider* pProvider, int req, const Tizen::Base::String& appId, const _AppMessageImpl& message);
270
271 protected:
272         static const unsigned long _LIBRARY_OPTION = Tizen::Base::Runtime::_LIBRARY_LOAD_OPTION_LAZY | Tizen::Base::Runtime::_LIBRARY_LOAD_OPTION_NODELETE;
273
274         const AppControl& _appControl;
275
276         Tizen::Base::String _path;
277         Tizen::Base::String _appId;
278         Tizen::Base::String _opId;
279         mutable Tizen::Base::String _appName;
280         int     _reqId;
281         int     _property;
282         int _processId;
283
284 private:
285         Tizen::Base::Collection::ArrayListT<int> __appControlResponseEventList;
286
287         friend class AppControl;
288 }; // _AppControlImpl
289
290 } } // Tizen::App
291
292 #endif // _FAPP_INTERNAL_APP_CONTROL_IMPL_H_