fix first AppControl result handling
[platform/framework/native/appfw.git] / src / app / FApp_AppControlProviderManagerImpl.cpp
index 9e40660..1bc79a9 100644 (file)
@@ -76,11 +76,16 @@ _AppControlProviderManagerImpl::SendAppControlResult(RequestId reqId, const ILis
 
        _AppArg resArg;
        result r = resArg.ConstructResult(arg, pResultList);
-       SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
+       if (IsFailed(r))
+       {
+               // erase _AppArg after sending the result back to the caller
+               pAppMgr->__resultManager.RemoveItem(reqId);
+
+               SysPropagate(NID_APP, r);
+               return r;
+       }
 
-       //resArg.Print();
-       r = _Aul::SendResult(resArg.GetBundle(), static_cast<appsvc_result_val>(0), _AppInfo::IsSubMode());
-       SysLog(NID_APP, "Sent AppControl event for %d.", reqId);
+       r = SendAppControlResultPrimitive(reqId, resArg, 0);
 
        // erase _AppArg after sending the result back to the caller
        pAppMgr->__resultManager.RemoveItem(reqId);
@@ -102,7 +107,14 @@ _AppControlProviderManagerImpl::SendAppControlResult(RequestId reqId, AppCtrlRes
 
        _AppArg resArg;
        result r = resArg.ConstructResult(arg, pResultMap);
-       SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
+       if (IsFailed(r))
+       {
+               // erase _AppArg after sending the result back to the caller
+               pAppMgr->__resultManager.RemoveItem(reqId);
+
+               SysPropagate(NID_APP, r);
+               return r;
+       }
 
        const int code = appControlResult;
        int res = APPSVC_RES_NOT_OK;
@@ -128,9 +140,7 @@ _AppControlProviderManagerImpl::SendAppControlResult(RequestId reqId, AppCtrlRes
                break;
        }
 
-       //resArg.Print();
-       r = _Aul::SendResult(resArg.GetBundle(), static_cast<appsvc_result_val>(res), _AppInfo::IsSubMode());
-       SysLog(NID_APP, "Sent AppControl event for %d.", reqId);
+       r = SendAppControlResultPrimitive(reqId, resArg, res);
 
        // erase _AppArg after sending the result back to the caller
        pAppMgr->__resultManager.RemoveItem(reqId);
@@ -138,6 +148,36 @@ _AppControlProviderManagerImpl::SendAppControlResult(RequestId reqId, AppCtrlRes
        return r;
 }
 
+
+result
+_AppControlProviderManagerImpl::SendAppControlResultPrimitive(RequestId reqId, _AppArg& arg, int ret)
+{
+       static bool firstRequestSent = false;
+
+       if (reqId == 0 && firstRequestSent)
+       {
+               SysLog(NID_APP, "Sent main AppControl request already.");
+
+               return E_SUCCESS;
+       }
+       else
+       {
+               if (reqId == 0)
+               {
+                       firstRequestSent = true;
+               }
+
+               const bool isService = _AppInfo::GetAppType() & _APP_TYPE_SERVICE_APP;
+
+               //resArg.Print();
+               result r = _Aul::SendResult(arg.GetBundle(), static_cast<appsvc_result_val>(ret), _AppInfo::IsSubMode(), isService);
+               SysLog(NID_APP, "Sent AppControl event for %d.", reqId);
+
+               return r;
+       }
+}
+
+
 AppId
 _AppControlProviderManagerImpl::GetClientAppId(RequestId reqId) const
 {