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