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