634b5b6cbad84ecf3d8d4cc373313679982aad0d
[platform/framework/native/appfw.git] / src / app / inc / FApp_AppControlManager.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_AppControlManager.h
20  * @brief       This is the header file for the _AppControlManager class.
21  */
22
23 #ifndef _FAPP_INTERNAL_APP_CONTROL_MANAGER_H_
24 #define _FAPP_INTERNAL_APP_CONTROL_MANAGER_H_
25
26 #include <app_service.h>
27
28 #include <FOspConfig.h>
29 #include <FBaseColIListT.h>
30 #include <FBaseColIList.h>
31 #include <FBaseObject.h>
32 #include <FBaseString.h>
33 #include <FBaseRtIEventListener.h>
34 #include <FAppAppManager.h>
35 #include <FAppIAppControlEventListener.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
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
74 typedef result (*LaunchCbType)(void* data, _AppArg* pArg, _AppArg* pResArg, service_result_e res, int prop);
75
76 typedef void (*AppSvcResFn)(void* b, int requestCode, service_result_e res, void* data);
77
78
79 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
80 // _LaunchInfo handles the launch request from this process
81 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
82 const long LAUNCH_INFO_MAGIC = 0x494C;
83
84 class _LaunchInfo
85 {
86 public:
87         _LaunchInfo(_AppArg* pArg, LaunchCbType pCb, void* pData, int prop)
88                 : magic(LAUNCH_INFO_MAGIC)
89                 , reqId(-1)
90                 , pArg(pArg)
91                 , launchCb(pCb)
92                 , pUserData(pData)
93                 , property(prop)
94         {
95         }
96
97         ~_LaunchInfo(void);
98
99 private:
100         _LaunchInfo(const _LaunchInfo& rhs);
101         _LaunchInfo& operator =(const _LaunchInfo& rhs);
102
103 public:
104         const long      magic;
105         int reqId;
106         _AppArg* pArg;
107         const LaunchCbType launchCb;
108         void* pUserData;
109         const int property;
110 }; // _LaunchInfo
111
112
113 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
114 // _InAppRequestManager manges In-process AppControl request
115 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
116 struct _InProcessInfo
117 {
118 public:
119         _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)
120                 : reqId(-1)
121                 , providerId(aId)
122                 , operationId(oId)
123                 , property(prop)
124                 , pLib(&lib)
125                 , pListener(pListener)
126                 , isLegacy(legacy)
127         {
128         }
129
130         ~_InProcessInfo(void);
131
132 private:
133         _InProcessInfo(const _InProcessInfo& rhs);
134         _InProcessInfo& operator =(const _InProcessInfo& rhs);
135
136 public:
137         int reqId;
138         const Tizen::Base::String providerId;
139         const Tizen::Base::String operationId;
140         const int property;
141         Tizen::Base::Runtime::_LibraryImpl* pLib;       // non-empty
142         Tizen::Base::Runtime::IEventListener* pListener;
143         bool isLegacy;
144 }; // _InProcessInfo
145
146
147 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
148 // _RequestManager manges out-of-process launch request and handles the return arguments
149 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
150 class _ResultInfo
151 {
152 public:
153         _ResultInfo(_AppArg& arg)
154                 : reqId(-1)
155                 , arg(arg)
156         {
157         }
158
159         ~_ResultInfo(void)
160         {
161         }
162
163 private:
164         _ResultInfo(const _ResultInfo& rhs);
165         _ResultInfo& operator =(const _ResultInfo& rhs);
166
167 public:
168         int reqId;
169         _AppArg& arg;
170 }; // _ResultInfo
171
172 // partial specialization
173 template<> inline void _RequestManagerT<_ResultInfo>::RemoveItem(int reqId)
174 {
175         // 1st request is launch request itself and do not remove it ever.
176         if (reqId == 0)
177         {
178                 return;
179         }
180
181         _ResultInfo* pItem = FindItem(reqId);
182         if (pItem)
183         {
184                 __requestList.Remove(reqId);
185                 delete pItem;
186         }
187 }
188
189
190 class _OSP_EXPORT_ _AppControlManager
191         : public Tizen::Base::Object
192         , public _IAppControlSysEventListener
193         , virtual public Tizen::Base::Runtime::IEventListener
194 {
195 public:
196         class _RequestGuard
197         {
198         public:
199                 _RequestGuard(_AppControlManager& mgr, _AppArg* pArg, LaunchCbType pCb, void* pData, int prop)
200                         : __mgr(mgr)
201                         , __req(mgr.AddLaunchRequest(pArg, pCb, pData, prop))
202                 {
203                 }
204
205                 ~_RequestGuard(void)
206                 {
207                 }
208
209                 int
210                 GetRequestNumber(void) const
211                 {
212                         return __req;
213                 }
214
215                 void
216                 Invalidate(void)
217                 {
218                         __mgr.RemoveLaunchRequest(__req);
219                 }
220
221         private:
222                 _AppControlManager& __mgr;
223                 const int __req;
224         };
225
226         static _AppControlManager* GetInstance(void);
227
228         virtual void OnAppControlEventReceivedN(int reqId, _AppArg* pAppArg, int res);
229
230         virtual void OnAppControlEventReceivedN(int reqId, int res, const Tizen::Base::Collection::IMap* pArgs);
231
232         virtual void OnAppControlEventReceivedN(int reqId, const AppId& appId, const Tizen::Base::String& operationId);
233
234         _OSP_LOCAL_ result SendAppControlEvent(Tizen::Base::Runtime::IEventArg& arg);
235
236         _OSP_LOCAL_ result RegisterRequest(service_s* service, int& req, _AppHandler& handler);
237
238         _OSP_LOCAL_ void RemoveResultRequest(int reqId)
239         {
240                 __resultManager.RemoveItem(reqId);
241         }
242
243         const _AppArg* FindResultRequest(int reqId) const;
244
245         void FinishAppControl(int reqId, int res, const Tizen::Base::Collection::IMap* pArg);
246
247         result LaunchApp(const AppId& appId, _AppArg* pArg, int req = -1);
248         int Launch(const AppId& appId, _AppArg* pArg, int req = -1);
249         
250         result LaunchAppImplicit(_AppArg* pArg, int req);
251
252         result LaunchPkg(const char* pkg_name, const char* op, const char* mime, const char* uri, AppSvcResFn pCb, void* data);
253
254         result LaunchPkg(_AppMessageImpl& msg, const char* pkg_name, const char* op, const char* mime, const char* uri, AppSvcResFn pCb, void* data);
255
256         int Launch(_AppMessageImpl& msg, const char* pkg_name, const char* op, const char* mime, const char* uri, AppSvcResFn pCb, void* data);
257         result LaunchAppWithCondition(const AppId& appId, const Tizen::Base::String& condition, Tizen::Base::Collection::IList* pArgs);
258
259         result SendAppControlStartResponse(int req, const char* pValue, const char* pOp);
260
261         static bool IsAllowedAppControl(const wchar_t aTable[][2][64], int count, const Tizen::Base::String& aId, const Tizen::Base::String& oId);
262
263         static result GetMimeFromExt(const Tizen::Base::String& ext, Tizen::Base::String& out);
264
265         void RemoveLaunchRequest(int req);
266
267         int GetLaunchRequestCount(void);
268
269 private:
270         _OSP_LOCAL_ _AppControlManager(void);
271
272         _OSP_LOCAL_ virtual ~_AppControlManager(void);
273
274         _AppControlManager(const _AppControlManager& rhs);
275
276         _AppControlManager& operator =(const _AppControlManager& rhs);
277
278         _OSP_LOCAL_ int AddLaunchRequest(_AppArg* pArg, LaunchCbType pCb, void* data, int prop = -1);
279
280 private:
281         _AppControlEvent __appControlEvent;
282         _RequestManagerT<_LaunchInfo> __launchManager;
283         _RequestManagerT<_InProcessInfo> __inAppManager;
284         _RequestManagerT<_ResultInfo> __resultManager;
285         Tizen::Base::Collection::ArrayListT<void*> __listenerList;
286
287         //friend class AppManager;
288         friend class _AppControlImpl;
289         //friend class _SqlDataControlImpl;
290         //friend class _MapDataControlImpl;
291         friend class _DataControlProviderManagerImpl;
292         friend class _AppControlProviderManagerImpl;
293         friend class Tizen::Io::_DataControlResultSetImpl;
294 }; // _AppControlManager
295
296 }} // Tizen::App
297
298 #endif // _FAPP_INTERNAL_APP_CONTROL_MANAGER_H_