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