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