N_SE-44648 : fix window raise on submode
[platform/framework/native/appfw.git] / src / app / inc / FApp_AppControlManager.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_AppControlManager.h
19  * @brief       This is the header file for the _AppControlManager class.
20  */
21
22 #ifndef _FAPP_INTERNAL_APP_CONTROL_MANAGER_H_
23 #define _FAPP_INTERNAL_APP_CONTROL_MANAGER_H_
24
25 #include <app_service.h>
26
27 #include <FOspConfig.h>
28 #include <FBaseColIListT.h>
29 #include <FBaseColIList.h>
30 #include <FBaseObject.h>
31 #include <FBaseString.h>
32 #include <FBaseRtIEventListener.h>
33 #include <FAppAppManager.h>
34 #include <FAppIAppControlEventListener.h>
35 #include <FAppIAppControlResponseListener.h>
36 #include <FBaseSysLog.h>
37
38 #include "FApp_Types.h"
39 #include "FApp_AppControlEvent.h"
40 #include "FApp_IAppControlSysEventListener.h"
41 #include "FApp_AppManagerEvent.h"
42 #include "FApp_IAppManagerServiceEventListener.h"
43 #include "FApp_RequestManagerT.h"
44 #include "FApp_IAppControlResponseEventListener.h"
45
46 namespace Tizen { namespace Base
47 {
48 class String;
49 namespace Runtime
50 {
51 class _LibraryImpl;
52 }
53 namespace Collection
54 {
55 class IMap;
56 }
57 }}
58 namespace Tizen { namespace Io
59 {
60 class DataControlResultSet;
61 class _DataControlResultSetImpl;
62 }}
63
64 namespace Tizen { namespace App
65 {
66
67 class _IAppManager;
68 class _ConditionManagerProxy;
69 class _AppArg;
70 class _AppControlEventArg;
71 class _IAppManagerEventListener;
72 class _AppManagerEventArg;
73 class _AppMessageImpl;
74 class _AppControlResponseEvent;
75
76 typedef result (*LaunchCbType)(void* data, _AppArg* pArg, _AppArg* pResArg, service_result_e res, int prop, int reqId);
77
78 typedef void (*AppSvcResFn)(void* b, int requestCode, service_result_e res, void* data);
79
80
81 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
82 // _LaunchInfo handles the launch request from this process
83 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
84 const long LAUNCH_INFO_MAGIC = 0x494C;
85 const int RESPONSE_EVENT_REQID_MAGIC = 65536;
86
87 class _LaunchInfo
88 {
89 public:
90         _LaunchInfo(_AppArg* pArg, LaunchCbType pCb, void* pData, int prop)
91                 : magic(LAUNCH_INFO_MAGIC)
92                 , reqId(-1)
93                 , pArg(pArg)
94                 , launchCb(pCb)
95                 , pUserData(pData)
96                 , property(prop)
97         {
98         }
99
100         ~_LaunchInfo(void);
101
102 private:
103         _LaunchInfo(const _LaunchInfo& rhs);
104         _LaunchInfo& operator =(const _LaunchInfo& rhs);
105
106 public:
107         const long      magic;
108         int reqId;
109         _AppArg* pArg;
110         const LaunchCbType launchCb;
111         void* pUserData;
112         int property;
113 }; // _LaunchInfo
114
115
116 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
117 // _InAppRequestManager manges In-process AppControl request
118 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
119 struct _InProcessInfo
120 {
121 public:
122         _InProcessInfo(const Tizen::Base::String& aId, const Tizen::Base::String& oId, int prop, bool legacy, Tizen::Base::Runtime::_LibraryImpl& lib, Tizen::Base::Runtime::IEventListener* pListener)
123                 : reqId(-1)
124                 , providerId(aId)
125                 , operationId(oId)
126                 , property(prop)
127                 , pLib(&lib)
128                 , pListener(pListener)
129                 , isLegacy(legacy)
130         {
131         }
132
133         ~_InProcessInfo(void);
134
135 private:
136         _InProcessInfo(const _InProcessInfo& rhs);
137         _InProcessInfo& operator =(const _InProcessInfo& rhs);
138
139 public:
140         int reqId;
141         const Tizen::Base::String providerId;
142         const Tizen::Base::String operationId;
143         const int property;
144         Tizen::Base::Runtime::_LibraryImpl* pLib;       // non-empty
145         Tizen::Base::Runtime::IEventListener* pListener;
146         bool isLegacy;
147 }; // _InProcessInfo
148
149
150 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
151 // _RequestManager manges out-of-process launch request and handles the return arguments
152 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
153 class _ResultInfo
154 {
155 public:
156         _ResultInfo(_AppArg& arg)
157                 : reqId(-1)
158                 , arg(arg)
159         {
160         }
161
162         ~_ResultInfo(void)
163         {
164         }
165
166 private:
167         _ResultInfo(const _ResultInfo& rhs);
168         _ResultInfo& operator =(const _ResultInfo& rhs);
169
170 public:
171         int reqId;
172         _AppArg& arg;
173 }; // _ResultInfo
174
175 // partial specialization
176 template<> inline void _RequestManagerT<_ResultInfo>::RemoveItem(int reqId)
177 {
178         // 1st request is launch request itself and do not remove it ever.
179         if (reqId == 0)
180         {
181                 return;
182         }
183
184         _ResultInfo* pItem = FindItem(reqId);
185         if (pItem)
186         {
187                 __requestList.Remove(reqId);
188                 delete pItem;
189         }
190 }
191
192
193 class _OSP_EXPORT_ _AppControlManager
194         : public Tizen::Base::Object
195         , public _IAppControlSysEventListener
196         , public _IAppControlResponseEventListener
197         , virtual public Tizen::Base::Runtime::IEventListener
198 {
199 public:
200         class _RequestGuard
201         {
202         public:
203                 _RequestGuard(_AppControlManager& mgr, _AppArg* pArg, LaunchCbType pCb, void* pData, int prop)
204                         : __mgr(mgr)
205                         , __req(mgr.AddLaunchRequest(pArg, pCb, pData, prop))
206                 {
207                 }
208
209                 ~_RequestGuard(void)
210                 {
211                 }
212
213                 int
214                 GetRequestNumber(void) const
215                 {
216                         return __req;
217                 }
218
219                 void
220                 Invalidate(void)
221                 {
222                         __mgr.RemoveLaunchRequest(__req);
223                 }
224
225         private:
226                 _AppControlManager& __mgr;
227                 const int __req;
228         };
229
230         static _AppControlManager* GetInstance(void);
231
232         virtual void OnAppControlEventReceivedN(int reqId, _AppArg* pAppArg, int res);
233
234         virtual void OnAppControlEventReceivedN(int reqId, int res, const Tizen::Base::Collection::IMap* pArgs, int prop);
235
236         virtual void OnAppControlEventReceivedN(int reqId, const AppId& appId, const Tizen::Base::String& operationId);
237
238         _OSP_LOCAL_ result SendAppControlEvent(Tizen::Base::Runtime::IEventArg& arg);
239
240         _OSP_LOCAL_ Tizen::Base::Collection::IMapT<int,_AppControlResponseEvent*>* GetAppControlResponseEventContainer(void);
241         _OSP_LOCAL_ result RegisterRequest(service_s* service, int& req, _AppHandler& handler);
242
243         _OSP_LOCAL_ void RemoveResultRequest(int reqId)
244         {
245                 __resultManager.RemoveItem(reqId);
246         }
247
248         const _AppArg* FindResultRequest(int reqId) const;
249
250         void FinishAppControl(int reqId, int res, Tizen::Base::Collection::IMap* pArg);
251
252         result LaunchApp(const AppId& appId, _AppArg* pArg, int req = -1);
253
254         int Launch(const AppId& appId, _AppArg* pArg, int req = -1);
255         
256         int Launch(const AppId& appId, _AppArg* pArg, AppSvcResFn pCb, void* pData, int req);
257
258         int Launch(const _AppMessageImpl& msg, const AppId& aId, const Tizen::Base::String& oId, const Tizen::Base::String* pUriData, const Tizen::Base::String* pMimeType, AppSvcResFn pCb, void* pData);
259
260         result LaunchAppImplicit(_AppArg* pArg, int req);
261
262         result LaunchPkg(const char* pkg_name, const char* op, const char* mime, const char* uri, AppSvcResFn pCb, void* data);
263
264         result LaunchPkg(_AppMessageImpl& msg, const char* pkg_name, const char* op, const char* mime, const char* uri, AppSvcResFn pCb, void* data);
265
266         int LaunchPkg(_AppMessageImpl& msg, const AppId& appId, const Tizen::Base::String& opId, const Tizen::Base::String* pUri, const Tizen::Base::String* pMime, AppSvcResFn pCb, void* data);
267
268         int Launch(_AppMessageImpl& msg, const char* pkg_name, const char* op, const char* mime, const char* uri, AppSvcResFn pCb, void* data);
269         
270         result LaunchAppWithCondition(const AppId& appId, const Tizen::Base::String& condition, Tizen::Base::Collection::IList* pArgs);
271
272         result SendAppControlStartResponse(int req, const char* pValue, const char* pOp);
273
274         static bool IsAllowedAppControl(const char aTable[][2][96], int count, const Tizen::Base::String& aId, const Tizen::Base::String& oId);
275
276         static AppId GetAliasAppId(const AppId& appId);
277
278         static result GetMimeFromExt(const Tizen::Base::String& ext, Tizen::Base::String& out);
279
280         void RemoveLaunchRequest(int req);
281
282         virtual void OnAppControlResponseEventReceivedN(const Tizen::Base::Runtime::IEventArg* arg);
283
284         static AppCtrlResult ConvertAppControlResultCode(int res);
285
286         static void InvokeAppControlCompleteListener(IAppControlResponseListener& listener, const AppId& appId, const Tizen::Base::String& op, AppCtrlResult res, const Tizen::Base::Collection::IMap* pExtraData, bool isSubMode);
287
288         static void InvokeLegacyAppControlCompleteListener(IAppControlEventListener& listener, const AppId& appId, const Tizen::Base::String& op, const Tizen::Base::Collection::IList* pList, bool isSubMode);
289
290 private:
291         _OSP_LOCAL_ _AppControlManager(void);
292
293         _OSP_LOCAL_ virtual ~_AppControlManager(void);
294
295         _AppControlManager(const _AppControlManager& rhs);
296
297         _AppControlManager& operator =(const _AppControlManager& rhs);
298
299         _OSP_LOCAL_ int AddLaunchRequest(_AppArg* pArg, LaunchCbType pCb, void* data, int prop = -1);
300
301 private:
302         _AppControlEvent __appControlEvent;
303         _RequestManagerT<_LaunchInfo> __launchManager;
304         _RequestManagerT<_InProcessInfo> __inAppManager;
305         _RequestManagerT<_ResultInfo> __resultManager;
306         Tizen::Base::Collection::ArrayListT<void*> __listenerList;
307
308         Tizen::Base::Collection::HashMapT<int, _AppControlResponseEvent*>* __pAppControlResponseEventContainer;
309         Tizen::Base::Collection::ArrayListT<int> __appControlResponseEventList;
310         //friend class AppManager;
311         friend class _AppControlImpl;
312         //friend class _SqlDataControlImpl;
313         //friend class _MapDataControlImpl;
314         friend class _DataControlProviderManagerImpl;
315         friend class _AppControlProviderManagerImpl;
316         friend class Tizen::Io::_DataControlResultSetImpl;
317 }; // _AppControlManager
318
319 }} // Tizen::App
320
321 #endif // _FAPP_INTERNAL_APP_CONTROL_MANAGER_H_