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