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