fix legacy noti tc failure
[platform/framework/native/appfw.git] / src / app / FAppServiceApp.cpp
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        FAppServiceApp.cpp
19  * @brief       This is the implementation for the ServiceApp class.
20  */
21
22 #include <FAppServiceApp.h>
23 #include <FBaseCol.h>
24 #include <FBaseResult.h>
25
26 #include <FBaseSysLog.h>
27 #include "FApp_AppImpl.h"
28 #include "FApp_ServiceAppImpl.h"
29 #include "FApp_AppInfo.h"
30
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Collection;
33
34 namespace Tizen { namespace App
35 {
36
37 ServiceApp::ServiceApp(void)
38 {
39         __pServiceAppImpl = new (std::nothrow) _ServiceAppImpl(this);
40         SysAssertf(__pServiceAppImpl != null, "Allocating memory for ServiceApp instance failed.");
41         SysTryReturnVoidResult(NID_APP, __pServiceAppImpl, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
42 }
43
44
45 ServiceApp::~ServiceApp(void)
46 {
47         delete __pServiceAppImpl;
48 }
49
50
51 ServiceApp*
52 ServiceApp::GetInstance(void)
53 {
54         _ServiceAppImpl* pServiceAppImpl = _ServiceAppImpl::GetInstance();
55         if (pServiceAppImpl == null)
56         {
57                 return null;
58         }
59
60         return pServiceAppImpl->GetServiceAppInstance();
61 }
62
63
64 result
65 ServiceApp::Execute(ServiceAppInstanceFactory pServiceAppFactory, const IList* pArguments)
66 {
67         result r = E_SUCCESS;
68         ServiceApp* pServiceApp = null;
69         _AppImpl* pAppImpl = null;
70
71         SysTryReturnResult(NID_APP, pServiceAppFactory != null, E_INVALID_ARG, "pServiceAppFactory must not be null.");
72         SysTryReturnResult(NID_APP, pArguments != null, E_INVALID_ARG, "pArguments must not be null.");
73         _AppInfo::SetAppType(_APP_TYPE_SERVICE_APP);
74
75         ClearLastResult();
76         pServiceApp = pServiceAppFactory();
77         SysTryReturnResult(NID_APP, pServiceApp != null, E_OUT_OF_MEMORY, "App allocation failed.");
78         SysTryReturnResult(NID_APP, !IsFailed(GetLastResult()), E_OUT_OF_MEMORY, "App allocation failed.");
79
80         pAppImpl = _AppImpl::GetInstance();
81         SysTryReturnResult(NID_APP, pAppImpl != null, E_SYSTEM, "application instance is not available.");
82
83         _ServiceAppImpl* pServiceAppImpl = _ServiceAppImpl::GetInstance();
84         SysTryReturnResult(NID_APP, pServiceAppImpl != null, E_INVALID_STATE, "Getting UiApp instance failed.");
85
86         r = pAppImpl->Construct(pArguments);
87         SysTryCatch(NID_APP, !IsFailed(r), r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] %s.", GetErrorMessage(r));
88
89         r = pAppImpl->Execute(pServiceAppImpl);
90         SysTryCatch(NID_APP, !IsFailed(r), r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] %s.", GetErrorMessage(r));
91
92 CATCH:
93         delete pServiceApp;
94
95         return r;
96 }
97
98
99 } } //Tizen::App