sync with tizen_2.0
[platform/framework/native/appfw.git] / src / app / FApp_AppControlManager.cpp
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.cpp
20  * @brief       This is the implementation for the _AppControlManager class.
21  */
22
23 #include <stdint.h>
24 #include <cstdio>
25 #include <unique_ptr.h>
26
27 #include <appsvc/appsvc.h>
28 #include <aul/aul.h>
29 #include <bundle.h>
30 #include <content/mime_type.h>
31
32 #include <FBaseInteger.h>
33 #include <FBaseObject.h>
34 #include <FBaseString.h>
35 #include <FBaseColIListT.h>
36 #include <FBaseColArrayList.h>
37 #include <FBaseErrors.h>
38 #include <FAppAppControl.h>
39 #include <FAppAppManager.h>
40 #include <FAppIAppControlListener.h>
41 #include <FAppIAppControlResponseListener.h>
42 #include <FAppIAppFrame.h>
43 #include <FAppSqlDataControl.h>
44 #include <FAppMapDataControl.h>
45 #include <FAppPkgPackageInfo.h>
46
47 #include <FBaseSysLog.h>
48 #include <FBase_StringConverter.h>
49 #include <FBaseRt_LibraryImpl.h>
50 #include <FIo_DataControlResultSetImpl.h>
51
52 #include "FApp_AppArg.h"
53 #include "FApp_AppControlEventArg.h"
54 #include "FApp_AppControlRegistry.h"
55 #include "FApp_AppControlImpl.h"
56 #include "FApp_AppImpl.h"
57 #include "FApp_AppInfo.h"
58 #include "FApp_AppManagerEventArg.h"
59 #include "FApp_Aul.h"
60 #include "FApp_AppControlManager.h"
61 #include "FApp_AppManagerProxy.h"
62 #include "FApp_ConditionManagerProxy.h"
63 #include "FApp_IAppManagerEventListener.h"
64 #include "FApp_MapDataControlImpl.h"
65 #include "FApp_SqlDataControlImpl.h"
66 #include "FAppPkg_PackageManagerImpl.h"
67 #include "FAppPkg_PackageInfoImpl.h"
68 #include "FApp_AppMessageImpl.h"
69 #include "FApp_AppManagerImpl.h"
70
71 using namespace Tizen::App::Package;
72 using namespace Tizen::Base;
73 using namespace Tizen::Base::Collection;
74 using namespace Tizen::Base::Runtime;
75 using namespace Tizen::Base::Utility;
76 using namespace Tizen::Io;
77
78 //extern const char* _DATACONTROL_RESULTSET_DIR;
79
80 namespace Tizen { namespace App
81 {
82
83 const wchar_t TIZEN_OPERATION_PICK[] = L"http://tizen.org/appcontrol/operation/pick";
84 const wchar_t SELECTOR_NOTI_KEY[] = L"__APP_SVC_CALLER_NOTI__";
85 const int _MAX_PACKAGE_ID_LENGTH = 10;
86
87 _InProcessInfo::~_InProcessInfo(void)
88 {
89         delete pLib;
90 }
91
92 _LaunchInfo::~_LaunchInfo(void)
93 {
94         delete pArg;
95 }
96
97
98 _AppControlManager::_AppControlManager(void)
99 {
100         SysLog(NID_APP, "");
101
102         // AppControl event handling is expected to be performed in the main thread.
103         __appControlEvent.Construct();
104         __appControlEvent.AddListener(*dynamic_cast<_IAppControlSysEventListener*>(this));
105 }
106
107 _AppControlManager::~_AppControlManager(void)
108 {
109         SysLog(NID_APP, "");
110         __appControlEvent.RemoveListener(*dynamic_cast<_IAppControlSysEventListener*>(this));
111 }
112
113 _AppControlManager*
114 _AppControlManager::GetInstance(void)
115 {
116         static _AppControlManager inst;
117
118         return &inst;
119 }
120
121 result
122 _AppControlManager::GetMimeFromExt(const String& ext, String& out)
123 {
124         std::unique_ptr<char[]> pExtension(_StringConverter::CopyToCharArrayN(ext));
125         SysTryReturnResult(NID_APP, pExtension != null, E_OUT_OF_MEMORY, "String allocation failure.");
126
127         char* mime = NULL;
128         mime_type_get_mime_type(pExtension.get(), &mime);
129
130         SysTryReturnResult(NID_APP, mime != NULL, E_UNSUPPORTED_FORMAT, "MIME type conversion failure for %ls.", ext.GetPointer());
131
132         out = mime;
133         free(mime);
134
135         return E_SUCCESS;
136 }
137
138 void
139 _AppControlManager::OnAppControlEventReceivedN(int reqId, _AppArg* pAppArg, int res)
140 {
141         SysLog(NID_APP, "Received request Id %d, arg 0x%x", reqId, pAppArg);
142
143         //_AppArg::Print(b);
144         // get launch info from request Id
145         _LaunchInfo* pInfo = __launchManager.FindItem(reqId);
146         SysTryReturnVoidResult(NID_APP, pInfo != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] request Id %d not found with response %d", reqId,
147                                         res);
148
149         // invoke callback
150         if (pInfo->launchCb)
151         {
152                 if (pInfo->magic == LAUNCH_INFO_MAGIC)
153                 {
154                         SysLog(NID_APP, "Invoking callback 0x%x", pInfo->launchCb);
155
156                         (*pInfo->launchCb)(pInfo->pUserData, pInfo->pArg, pAppArg, static_cast<service_result_e>(res), pInfo->property);
157                 }
158                 else
159                 {
160                         SysLogException(NID_APP, E_SYSTEM, "Corrupted data structure.");
161                 }
162         }
163
164         // clean up argument
165         __launchManager.RemoveItem(reqId);
166 }
167
168
169 // callback for out-of-process AppControl start event
170 void
171 _AppControlManager::OnAppControlEventReceivedN(int reqId, const AppId& appId, const String& operationId)
172 {
173         SysLog(NID_APP, "Received request Id %d, appId %ls, operationId %ls", reqId, appId.GetPointer(), operationId.GetPointer());
174
175         // get launch info from request Id
176         _LaunchInfo* pInfo = __launchManager.FindItem(reqId);
177         SysTryReturnVoidResult(NID_APP, pInfo != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] request Id %d not found.", reqId);
178
179         // at least listener
180         IAppControlResponseListener* pListener = static_cast<IAppControlResponseListener*>(pInfo->pUserData);
181         SysTryReturnVoidResult(NID_APP, typeid(pListener) == typeid(IAppControlResponseListener*), E_SYSTEM, "[E_SYSTEM] Invalid result callback.");
182
183         if (pListener)
184         {
185                 result r = E_SUCCESS;
186                 AppId actualAppId = appId;
187                 if (appId == L'c')
188                 {
189                         actualAppId.Clear();
190                         r = E_OPERATION_CANCELED;
191                 }
192                 SysLog(NID_APP, "Invoking callback 0x%x.", pListener);
193                 pListener->OnAppControlStartResponseReceived(actualAppId, operationId, r);
194         }
195         else
196         {
197                 SysLog(NID_APP, "No listener registered.");
198         }
199 }
200
201
202 // callback for in-process event handling
203 void
204 _AppControlManager::OnAppControlEventReceivedN(int reqId, int res, const IMap* pArgs)
205 {
206         SysLog(NID_APP, "Received request Id %d, args 0x%x", reqId, pArgs);
207
208         // process proper callback
209         _InProcessInfo* pInfo = __inAppManager.FindItem(reqId);
210         SysTryReturnVoidResult(NID_APP, pInfo != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] request Id %d not found with args 0x%x", reqId,
211                                         pArgs);
212
213         if (pInfo->pListener)
214         {
215                 String aId = pInfo->providerId;
216                 String oId = pInfo->operationId;
217
218                 SysLog(NID_APP, "Invoking callback 0x%x for (%ls, %ls).", pInfo->pListener, aId.GetPointer(), oId.GetPointer());
219
220                 if (pInfo->property & _APPCONTROL_PROPERTY_ALIAS)
221                 {
222                         _AppControlRegistry::_AppControlAliasEntry* pEntry = null;
223                         pEntry = _AppControlRegistry::GetInstance()->GetReverseAppControlAliasEntry(aId, oId);
224                         if (pEntry)
225                         {
226                                 aId = pEntry->provider;
227                                 oId = pEntry->operation;
228
229                                 SysLog(NID_APP, "Legacy AppControl name (%ls, %ls).", aId.GetPointer(), oId.GetPointer());
230                         }
231                 }
232
233                 if (pInfo->isLegacy)
234                 {
235                         IAppControlEventListener* pListener = dynamic_cast<IAppControlEventListener*>(pInfo->pListener);
236                         if (pListener)
237                         {
238                                 ArrayList list(SingleObjectDeleter);
239                                 _AppArg::FillLegacyAppControlResult(list, res, pArgs, aId);
240
241                                 pListener->OnAppControlCompleted(aId, oId, &list);
242                         }
243                         else
244                         {
245                                 SysLog(NID_APP, "Wrong AppControl listener type.");
246                         }
247                 }
248                 else
249                 {
250                         IAppControlResponseListener* pListener = dynamic_cast<IAppControlResponseListener*>(pInfo->pListener);
251                         if (pListener)
252                         {
253                                 pListener->OnAppControlCompleteResponseReceived(aId, oId, static_cast<AppCtrlResult>(res), pArgs);
254                         }
255                         else
256                         {
257                                 SysLog(NID_APP, "Wrong AppControl listener type.");
258                         }
259                 }
260         }
261         else
262         {
263                 SysLogException(NID_APP, E_SYSTEM, "Invalid AppControl listener.");
264         }
265
266         // call TerminateAppControl
267         result (* pFunc)(int req) = null;
268         pFunc = reinterpret_cast<result (*)(int)>(pInfo->pLib->GetProcAddress(L"TerminateAppControl"));
269         if (pFunc)
270         {
271                 (*pFunc)(pInfo->reqId);
272         }
273         else
274         {
275                 SysLogException(NID_APP, E_SYSTEM, "No TerminateAppControl() function.");
276         }
277
278         // remove from list and unload dll
279         __inAppManager.RemoveItem(reqId);
280 }
281
282
283 result
284 _AppControlManager::SendAppControlEvent(IEventArg& arg)
285 {
286         return __appControlEvent.FireAsync(arg);
287 }
288
289 // generic launch callback
290 static void
291 LaunchResultCb(bundle* b, int request_code, appsvc_result_val res, void* data)
292 {
293         SysLog(NID_APP, "SLP callee result: %d", res);
294
295         _AppControlManager* pImpl = static_cast<_AppControlManager*>(data);
296         if (pImpl == null)
297         {
298                 return;
299         }
300
301         _AppArg* pAppArg = new (std::nothrow) _AppArg;
302         SysTryReturnVoidResult(NID_APP, pAppArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] AppControl event argument creation failure.");
303
304         _AppControlEventArg* pArg = null;
305         result r = pAppArg->Construct(b);
306         SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] AppControl event argument creation failure.", GetErrorMessage(r));
307
308         pArg = new (std::nothrow) _AppControlEventArg(request_code, pAppArg, res);
309         SysTryCatch(NID_APP, pArg != null, r = E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] AppControl event argument creation failure.");
310
311         //_AppArg::Print(b);
312         pImpl->SendAppControlEvent(*pArg);
313
314         return;
315
316 CATCH:
317         delete pAppArg;
318 }
319
320
321 result
322 _AppControlManager::SendAppControlStartResponse(int req, const char* pValue, const char* pOp)
323 {
324         _AppControlStartEventArg* pArg = new (std::nothrow) _AppControlStartEventArg(req, AppId(pValue), String(pOp));
325         SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "AppControl start event creation failure.");
326
327         SendAppControlEvent(*pArg);
328
329         return E_SUCCESS;
330 }
331
332
333 result
334 _AppControlManager::LaunchPkg(_AppMessageImpl& msg, const char* pkg_name, const char* op, const char* mime, const char* uri, AppSvcResFn pCb, void* data)
335 {
336         bundle* kb = msg.GetBundle();
337         SysTryReturnResult(NID_APP, kb != NULL, E_OUT_OF_MEMORY, "Bundle allocation failure.");
338
339         if (pkg_name)
340         {
341                 appsvc_set_pkgname(kb, pkg_name);
342         }
343
344         appsvc_set_operation(kb, (op) ? op : APPSVC_OPERATION_DEFAULT);
345
346         if (mime)
347         {
348                 appsvc_set_mime(kb, mime);
349         }
350
351         if (uri)
352         {
353                 appsvc_set_uri(kb, uri);
354         }
355
356         const long handle = _AppImpl::GetInstance()->GetWindowHandle();
357         _AppArg::UpdateWindowHandle(kb, handle);
358
359         SysLog(NID_APP, "MIME(%s), URI(%s).", appsvc_get_mime(kb), appsvc_get_uri(kb));
360         int pid = appsvc_run_service(kb, 0, reinterpret_cast<appsvc_res_fn>(pCb), this);
361
362         SysTryReturnResult(NID_APP, pid >= 0, E_SYSTEM, "Launching service %s failure with %d", pkg_name, pid);
363
364         return E_SUCCESS;
365 }
366 int
367 _AppControlManager::Launch(_AppMessageImpl& msg, const char* pkg_name, const char* op, const char* mime, const char* uri, AppSvcResFn pCb, void* data)
368 {
369         bundle* kb = msg.GetBundle();
370         SysTryReturn(NID_APP, kb != NULL, -1, E_OUT_OF_MEMORY, "Bundle allocation failure.");
371
372         if (pkg_name)
373         {
374                 appsvc_set_pkgname(kb, pkg_name);
375         }
376
377         appsvc_set_operation(kb, (op) ? op : APPSVC_OPERATION_DEFAULT);
378
379         if (mime)
380         {
381                 appsvc_set_mime(kb, mime);
382         }
383
384         if (uri)
385         {
386                 appsvc_set_uri(kb, uri);
387         }
388
389         const long handle = _AppImpl::GetInstance()->GetWindowHandle();
390         _AppArg::UpdateWindowHandle(kb, handle);
391
392         SysLog(NID_APP, "MIME(%s), URI(%s).", appsvc_get_mime(kb), appsvc_get_uri(kb));
393         int pid = appsvc_run_service(kb, 0, reinterpret_cast<appsvc_res_fn>(pCb), this);
394
395         SysTryReturn(NID_APP, pid >= 0, -1, E_SYSTEM, "Launching service %s failure with %d", pkg_name, pid);
396
397         return pid;
398 }
399
400
401 result
402 _AppControlManager::LaunchPkg(const char* pkg_name, const char* op, const char* mime, const char* uri, AppSvcResFn pCb, void* data)
403 {
404         _AppMessageImpl msg;
405
406         return LaunchPkg(msg, pkg_name, op, mime, uri, pCb, data);
407 }
408
409 result
410 _AppControlManager::LaunchAppWithCondition(const AppId& appId, const String& executableName, const String& condition, IList* pArrayArgs)
411 {
412         result r = E_SUCCESS;
413         const String& actualAppId = appId + L'.' + executableName;
414         _AppArg * pArg = new (std::nothrow) _AppArg();
415         SysTryCatch(NID_APP, pArg != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]");
416
417         r = pArg->ConstructForAppLaunchCondition(condition, pArrayArgs);
418         SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] ConstructForAppLaunchCondition(%ls, .. ) fails", GetErrorMessage(r), condition.GetPointer());
419
420         r = _AppControlManager::LaunchApp(actualAppId, pArg);
421
422 CATCH:
423         delete pArg;
424         return r;
425 }
426
427 result
428 _AppControlManager::LaunchApp(const AppId& appId, _AppArg* pArg, int req)
429 {
430         SysTryReturnResult(NID_APP, pArg != null, E_INVALID_ARG, "Invalid launch argument");
431         SysLog(NID_APP, "AppId: %ls.", appId.GetPointer());
432
433         String actualAppId = appId;
434         if (appId.GetLength() == 10)
435         {
436                 const String& name = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(appId);
437
438                 if (!name.IsEmpty())
439                 {
440                         actualAppId.Append(L'.');
441                         actualAppId.Append(name);
442                 }
443         }
444
445         pArg->UpdateRequestId(req);
446
447         const long handle = _AppImpl::GetInstance()->GetWindowHandle();
448         pArg->UpdateWindowHandle(handle);
449
450         int pid = -1;
451         bundle* kb = NULL;
452         String tempId;
453         actualAppId.SubString(0, 10, tempId);
454         tempId += L'.';
455         tempId += L"_AppControl";
456
457         // [INFO] Ugly solution for submode support
458         pArg->UpdateAppId(tempId);
459         kb = pArg->GetBundle();
460         
461         pid = appsvc_run_service(kb, req, LaunchResultCb, this);
462         if (pid > 0)
463         {
464                 SysLog(NID_APP, "Submode launch successful");
465                 return E_SUCCESS;
466         }
467
468         pArg->UpdateAppId(actualAppId);
469
470         // retry for possible failure
471         int count = 0;
472         const int TRY_COUNT = 3;
473         const int TRY_SLEEP_TIME = 65;
474         do
475         {
476                 kb = pArg->GetBundle();
477                 pid = appsvc_run_service(kb, req, LaunchResultCb, this);
478                 if (pid > 0)
479                 {
480                         SysLog(NID_APP, "Application(%d) launched with reqId(%d) and arg(0x%x).", pid, req, pArg);
481                         return E_SUCCESS;
482                 }
483                 count++;
484                 SysLog(NID_APP, "Waiting %dth time.", count);
485                 Thread::Sleep(TRY_SLEEP_TIME);
486         }
487         while (count < TRY_COUNT);
488
489         SysLogException(NID_APP, E_SYSTEM, "[E_SYSTEM] Launching service failure for %ls with %d", appId.GetPointer(), pid);
490
491         return E_SYSTEM;
492 }
493
494 int
495 _AppControlManager::Launch(const AppId& appId, _AppArg* pArg, int req)
496 {
497         SysTryReturn(NID_APP, pArg != null, -1, E_INVALID_ARG, "[E_INVALID_ARG] Invalid launch argument");
498         SysLog(NID_APP, "AppId: %ls.", appId.GetPointer());
499
500         String actualAppId = appId;
501         if (appId.GetLength() == 10)
502         {
503                 const String& name = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(appId);
504
505                 if (!name.IsEmpty())
506                 {
507                         actualAppId.Append(L'.');
508                         actualAppId.Append(name);
509                 }
510         }
511
512         pArg->UpdateRequestId(req);
513
514         const long handle = _AppImpl::GetInstance()->GetWindowHandle();
515         pArg->UpdateWindowHandle(handle);
516
517         int pid = -1;
518         bundle* kb = NULL;
519         String tempId;
520         actualAppId.SubString(0, 10, tempId);
521         tempId += L'.';
522         tempId += L"_AppControl";
523
524         // [INFO] Ugly solution for submode support
525         pArg->UpdateAppId(tempId);
526         kb = pArg->GetBundle();
527         
528         pid = appsvc_run_service(kb, req, LaunchResultCb, this);
529         if (pid > 0)
530         {
531                 SysLog(NID_APP, "Submode launch successful");
532                 return pid;
533         }
534
535         pArg->UpdateAppId(actualAppId);
536
537         // retry for possible failure
538         int count = 0;
539         const int TRY_COUNT = 3;
540         const int TRY_SLEEP_TIME = 65;
541         do
542         {
543                 kb = pArg->GetBundle();
544                 pid = appsvc_run_service(kb, req, LaunchResultCb, this);
545                 if (pid > 0)
546                 {
547                         SysLog(NID_APP, "Application(%d) launched with reqId(%d) and arg(0x%x).", pid, req, pArg);
548                         return pid;
549                 }
550                 count++;
551                 SysLog(NID_APP, "Waiting %dth time.", count);
552                 Thread::Sleep(TRY_SLEEP_TIME);
553         }
554         while (count < TRY_COUNT);
555
556         SysLogException(NID_APP, E_SYSTEM, "[E_SYSTEM] Launching service failure for %ls with %d", appId.GetPointer(), pid);
557
558         return pid;
559 }
560
561 result
562 _AppControlManager::LaunchAppImplicit(_AppArg* pArg, int req)
563 {
564         SysTryReturnResult(NID_APP, pArg != null, E_INVALID_ARG, "Invalid launch argument");
565
566         result r = E_SUCCESS;
567         bundle* kb = pArg->GetBundle();
568
569         if (req >= 0)
570         {
571                 pArg->UpdateRequestId(req);
572                 _AppMessageImpl::AddData(kb, SELECTOR_NOTI_KEY, _AppInfo::GetApplicationId());
573         }
574
575         int pid = appsvc_run_service(kb, req, LaunchResultCb, this);
576         switch (pid)
577         {
578         case APPSVC_RET_EINVAL:
579                 r = E_OBJ_NOT_FOUND;
580                 break;
581         case APPSVC_RET_ENOMATCH:
582                 r = E_OBJ_NOT_FOUND;
583                 break;
584         case APPSVC_RET_ERROR:
585                 // fall through
586         case APPSVC_RET_ELAUNCH:
587                 r = E_SYSTEM;
588                 break;
589         default:
590                 break;
591         }
592
593         SysLog(NID_APP, "[%s] Application(%d) launched with reqId(%d) and arg(0x%x).", GetErrorMessage(r), pid, req, pArg);
594
595         return r;
596 }
597
598 void
599 _AppControlManager::FinishAppControl(int reqId, int res, const IMap* pMap)
600 {
601         _NativeAppControlEventArg* pArg = new (std::nothrow) _NativeAppControlEventArg(reqId, res, pMap);
602         SysTryReturnVoidResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Return argument allocation failure.");
603
604         SendAppControlEvent(*pArg);
605 }
606
607 const _AppArg*
608 _AppControlManager::FindResultRequest(int reqId) const
609 {
610         const _ResultInfo* pInfo = __resultManager.FindItem(reqId);
611         return (pInfo) ? &(pInfo->arg) : null;
612 }
613
614 int
615 _AppControlManager::AddLaunchRequest(_AppArg* pArg, LaunchCbType pCb, void* pData, int prop)
616 {
617         SysTryReturn(NID_APP, pArg != null, -1, E_INVALID_ARG, "[E_INVALID_ARG] Empty argument.");
618
619         _LaunchInfo* pItem = new (std::nothrow) _LaunchInfo(pArg, pCb, pData, prop);
620         SysTryReturn(NID_APP, pItem != null, -1, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Empty argument.");
621
622         SysLog(NID_APP, "Registering callback 0x%x, 0x%x", pCb, pData);
623
624         return __launchManager.InsertItem(pItem);
625 }
626
627 void
628 _AppControlManager::RemoveLaunchRequest(int req)
629 {
630         __launchManager.RemoveItem(req);
631 }
632
633 result
634 _AppControlManager::RegisterRequest(service_s* service, int& req, _AppHandler& handler)
635 {
636         bundle* b = _AppArg::GetBundleFromSvc(service);
637
638         _AppArg* pArg = new (std::nothrow) _AppArg();
639         SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "rrayList creation failure.");
640         pArg->Construct(b);
641
642         result r = E_SUCCESS;
643
644         // ownership is transfered to RequestManager
645         _ResultInfo* pItem = new (std::nothrow) _ResultInfo(*pArg);
646         SysTryCatch(NID_APP, pItem != null, , r = E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Empty argument.");
647
648         req = __resultManager.InsertItem(pItem);
649         SysTryCatch(NID_APP, req != -1, , r = E_INVALID_STATE, "[E_INVALID_STATE] Invalid argument handling state.");
650
651         handler = _AppArg::GetHandler(b);
652
653         return E_SUCCESS;
654
655 CATCH:
656         delete pArg;
657
658         return r;
659 }
660
661
662 bool
663 _AppControlManager::IsAllowedAppControl(const wchar_t aTable[][2][64], int count, const String& aId, const String& oId)
664 {
665         for (int i = 0; i < count; i++)
666         {
667                 if (aId == aTable[i][0] && oId == aTable[i][1])
668                 {
669                         SysLog(NID_APP, "Found entry (%ls, %ls)", aTable[i][0], aTable[i][1]);
670                         return true;
671                 }
672         }
673
674         return false;
675 }
676
677 }} // Tizen::App