Fork for IVI: mesa fixing
[profile/ivi/uifw.git] / src / app / FAppUiApp.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 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        FAppUiApp.cpp
20  * @brief       This is the implementation for the UiApp class.
21  */
22
23 #include <FAppUiApp.h>
24 #include <FBaseCol.h>
25 #include <FBaseResult.h>
26
27 #include <FBaseSysLog.h>
28 #include "FApp_AppImpl.h"
29 #include "FApp_UiAppImpl.h"
30 #include "FApp_AppInfo.h"
31
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Collection;
34 using namespace Tizen::Ui::Controls;
35
36 namespace Tizen { namespace App
37 {
38
39 UiApp::UiApp(void)
40 {
41         __pUiAppImpl = new (std::nothrow) _UiAppImpl(this);
42         SysAssertf(__pUiAppImpl != null, "Allocating memory for UiApp instance failed.");
43         SysTryReturnVoidResult(NID_APP, __pUiAppImpl, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
44 }
45
46
47 UiApp::~UiApp(void)
48 {
49         delete __pUiAppImpl;
50 }
51
52
53 IAppFrame*
54 UiApp::GetAppFrame(void) const
55 {
56         SysAssertf(__pUiAppImpl != null, "Getting UiApp instance failed.");
57
58         return __pUiAppImpl->GetAppFrame();
59 }
60
61
62 result
63 UiApp::AddFrame(const Frame& frame)
64 {
65         SysAssertf(__pUiAppImpl != null, "Getting UiApp instance failed.");
66
67         return __pUiAppImpl->AddFrame(frame);
68 }
69
70
71 result
72 UiApp::RemoveFrame(const Frame& frame)
73 {
74         SysAssertf(__pUiAppImpl != null, "Getting UiApp instance failed.");
75
76         return __pUiAppImpl->RemoveFrame(frame);
77 }
78
79
80 IList*
81 UiApp::GetFrameList(void) const
82 {
83         SysAssertf(__pUiAppImpl != null, "Getting UiApp instance failed.");
84
85         return __pUiAppImpl->GetFrameList();
86 }
87
88
89 Frame*
90 UiApp::GetFrame(const String& name) const
91 {
92         SysAssertf(__pUiAppImpl != null, "Getting UiApp instance failed.");
93
94         return __pUiAppImpl->GetFrame(name);
95 }
96
97
98 Frame*
99 UiApp::GetFrameAt(int index) const
100 {
101         SysAssertf(__pUiAppImpl != null, "Getting UiApp instance failed.");
102
103         return __pUiAppImpl->GetFrameAt(index);
104 }
105
106
107 AppUiState
108 UiApp::GetAppUiState(void) const
109 {
110         SysAssertf(__pUiAppImpl != null, "Getting UiApp instance failed.");
111
112         return __pUiAppImpl->GetAppUiState();
113 }
114
115
116 void
117 UiApp::OnForeground(void)
118 {
119
120 }
121
122
123 void
124 UiApp::OnBackground(void)
125 {
126
127 }
128
129
130 UiApp*
131 UiApp::GetInstance(void)
132 {
133         _UiAppImpl* pUiAppImpl = _UiAppImpl::GetInstance();
134         if (pUiAppImpl == null)
135         {
136                 return null;
137         }
138
139         return pUiAppImpl->GetUiAppInstance();
140 }
141
142
143 result
144 UiApp::Execute(UiAppInstanceFactory pUiAppFactory, const IList* pArguments)
145 {
146         result r = E_SUCCESS;
147
148         SysTryReturnResult(NID_APP, pUiAppFactory != null, E_INVALID_ARG, "pUiAppFactory must not be null.");
149         SysTryReturnResult(NID_APP, pArguments != null, E_INVALID_ARG, "pArguments must not be null.");
150         _AppInfo::SetAppType(_APP_TYPE_UI_APP);
151
152         ClearLastResult();
153         UiApp* pUiApp = pUiAppFactory();
154         SysTryReturnResult(NID_APP, pUiApp != null, E_OUT_OF_MEMORY, "App allocation failed.");
155         SysTryReturnResult(NID_APP, !IsFailed(GetLastResult()), E_OUT_OF_MEMORY, "App allocation failed with %s.", GetLastResult());
156
157         _AppImpl* pAppImpl = _AppImpl::GetInstance();
158         SysTryReturnResult(NID_APP, pAppImpl != null, E_SYSTEM, "application instance is not available.");
159
160         _UiAppImpl* pUiAppImpl = _UiAppImpl::GetInstance();
161         SysTryReturnResult(NID_APP, pUiAppImpl != null, E_INVALID_STATE, "Getting UiApp instance failed.");
162
163         r = pAppImpl->Construct(pArguments);
164         SysTryCatch(NID_APP, !IsFailed(r), r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] %s.", GetErrorMessage(r));
165
166         r = pAppImpl->Execute(pUiAppImpl);
167         SysTryCatch(NID_APP, !IsFailed(r), r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] %s.", GetErrorMessage(r));
168
169 CATCH:
170         delete pUiApp;
171
172         return r;
173 }
174
175
176 } } //Tizen::App