2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "app_core_ui_base.hh"
21 #include "appcore_ui_base.h"
24 #define EXPORT_API __attribute__ ((visibility("default")))
30 class AppCoreUi : public AppCoreUiBase {
32 AppCoreUi(unsigned int hint, appcore_ui_base_ops ops, void* data)
33 : AppCoreUiBase(hint), ops_(ops), data_(data) {}
35 void OnLoopInit(int argc, char** argv) override {
37 ops_.base.init(argc, argv, data_);
40 void OnLoopFinish() override {
42 ops_.base.finish(data_);
45 void OnLoopRun() override {
50 void OnLoopExit() override {
52 ops_.base.exit(data_);
55 int OnReceive(aul_type type, tizen_base::Bundle b) override {
56 if (ops_.base.receive)
57 return ops_.base.receive(type, b.GetHandle(), data_);
61 int OnCreate() override {
63 return ops_.base.create(data_);
67 int OnControl(tizen_base::Bundle b) override {
68 if (ops_.base.control)
69 return ops_.base.control(b.GetHandle(), data_);
73 int OnTerminate() override {
74 if (ops_.base.terminate)
75 return ops_.base.terminate(data_);
79 int OnSetI18n() override {
80 if (ops_.base.set_i18n)
81 return ops_.base.set_i18n(data_);
85 int OnSetEvent(IEvent::Type event) override {
86 if (!ops_.base.set_event)
89 ops_.base.set_event((appcore_base_event)event, data_);
93 int OnUnsetEvent(IEvent::Type event) override {
94 if (!ops_.base.unset_event)
97 ops_.base.unset_event((appcore_base_event)event, data_);
101 int OnTrimMemory() override {
102 if (!ops_.base.trim_memory)
105 ops_.base.trim_memory(data_);
109 int OnPause() override {
111 return ops_.pause(data_);
115 int OnResume() override {
117 return ops_.resume(data_);
121 void OnShow(int type, void* event) override {
122 if (ops_.window.show)
123 ops_.window.show(type, event, data_);
126 void OnHide(int type, void* event) override {
127 if (ops_.window.hide)
128 ops_.window.hide(type, event, data_);
131 void OnLower(int type, void* event) override {
132 if (ops_.window.lower)
133 ops_.window.lower(type, event, data_);
136 void OnVisibility(int type, void* event) override {
137 if (ops_.window.visibility)
138 ops_.window.visibility(type, event, data_);
141 void OnPreVisibility(int type, void* event) override {
142 if (ops_.window.pre_visibility)
143 ops_.window.pre_visibility(type, event, data_);
146 void OnAuxMessage(int type, void* event) override {
147 if (ops_.window.aux_message)
148 ops_.window.aux_message(type, event, data_);
152 appcore_ui_base_ops ops_;
156 std::unique_ptr<AppCoreUi> __context;
158 int __on_control(bundle* b, void* data) {
159 return appcore_ui_base_on_control(b);
162 int __on_set_i18n(void* data) {
163 return appcore_ui_base_on_set_i18n();
166 void __on_set_event(enum appcore_base_event event, void* data) {
167 appcore_ui_base_on_set_event(event);
170 void __on_unset_event(enum appcore_base_event event, void* data) {
171 appcore_ui_base_on_unset_event(event);
174 void __on_trim_memory(void* data) {
175 appcore_ui_base_on_trim_memory();
178 int __on_receive(aul_type type, bundle* b, void* data) {
179 return appcore_ui_base_on_receive(type, b);
182 int __on_create(void* data) {
183 return appcore_ui_base_on_create();
186 int __on_terminate(void* data) {
187 return appcore_ui_base_on_terminate();
190 int __on_pause(void* data) {
191 return appcore_ui_base_on_pause();
194 int __on_resume(void* data) {
195 return appcore_ui_base_on_resume();
198 void __window_on_show(int type, void* event, void* data) {
199 appcore_ui_base_window_on_show(type, event);
202 void __window_on_hide(int type, void* event, void* data) {
203 appcore_ui_base_window_on_hide(type, event);
206 void __window_on_lower(int type, void* event, void* data) {
207 appcore_ui_base_window_on_lower(type, event);
210 void __window_on_visibility(int type, void* event, void* data) {
211 appcore_ui_base_window_on_visibility(type, event);
214 void __window_on_pre_visibility(int type, void* event, void* data) {
215 appcore_ui_base_window_on_pre_visibility(type, event);
218 void __window_on_aux_message(int type, void* event, void* data) {
219 appcore_ui_base_window_on_aux_message(type, event);
223 } // namespace tizen_cpp
225 using namespace tizen_cpp;
227 extern "C" EXPORT_API int appcore_ui_base_on_receive(aul_type type, bundle*b) {
228 if (__context.get() == nullptr)
230 return __context->AppCoreUiBase::OnReceive(type, tizen_base::Bundle(b));
233 extern "C" EXPORT_API int appcore_ui_base_on_create(void) {
234 if (__context.get() == nullptr)
236 return __context->AppCoreUiBase::OnCreate();
239 extern "C" EXPORT_API int appcore_ui_base_on_terminate(void) {
240 if (__context.get() == nullptr)
242 return __context->AppCoreUiBase::OnTerminate();
245 extern "C" EXPORT_API int appcore_ui_base_on_pause(void) {
246 if (__context.get() == nullptr)
248 return __context->AppCoreUiBase::OnPause();
251 extern "C" EXPORT_API int appcore_ui_base_on_resume(void) {
252 if (__context.get() == nullptr)
254 return __context->AppCoreUiBase::OnResume();
257 extern "C" EXPORT_API int appcore_ui_base_on_control(bundle* b) {
258 if (__context.get() == nullptr)
260 return __context->AppCoreUiBase::OnControl(
261 b ? tizen_base::Bundle(b) : tizen_base::Bundle());
264 extern "C" EXPORT_API int appcore_ui_base_on_trim_memory(void) {
265 if (__context.get() == nullptr)
267 return __context->AppCoreUiBase::OnTrimMemory();
270 extern "C" EXPORT_API void appcore_ui_base_window_on_show(int type,
272 if (__context.get() == nullptr)
274 __context->AppCoreUiBase::OnShow(type, event);
277 extern "C" EXPORT_API void appcore_ui_base_window_on_hide(int type,
279 if (__context.get() == nullptr)
281 __context->AppCoreUiBase::OnHide(type, event);
284 extern "C" EXPORT_API void appcore_ui_base_window_on_lower(int type,
286 if (__context.get() == nullptr)
288 __context->AppCoreUiBase::OnLower(type, event);
291 extern "C" EXPORT_API void appcore_ui_base_window_on_visibility(int type,
293 if (__context.get() == nullptr)
295 __context->AppCoreUiBase::OnVisibility(type, event);
298 extern "C" EXPORT_API void appcore_ui_base_window_on_pre_visibility(int type,
300 if (__context.get() == nullptr)
302 __context->AppCoreUiBase::OnPreVisibility(type, event);
305 extern "C" EXPORT_API void appcore_ui_base_window_on_aux_message(int type,
307 if (__context.get() == nullptr)
309 __context->AppCoreUiBase::OnAuxMessage(type, event);
312 extern "C" EXPORT_API int appcore_ui_base_on_set_i18n(void) {
313 if (__context.get() == nullptr)
315 return __context->AppCoreUiBase::OnSetI18n();
318 extern "C" EXPORT_API void appcore_ui_base_on_set_event(
319 enum appcore_base_event event) {
320 if (__context.get() == nullptr)
322 __context->AppCoreUiBase::OnSetEvent(
323 static_cast<AppCoreBase::IEvent::Type>(event));
326 extern "C" EXPORT_API void appcore_ui_base_on_unset_event(
327 enum appcore_base_event event) {
328 if (__context.get() == nullptr)
330 __context->AppCoreUiBase::OnUnsetEvent(
331 static_cast<AppCoreBase::IEvent::Type>(event));
334 extern "C" EXPORT_API int appcore_ui_base_init(appcore_ui_base_ops ops,
335 int argc, char** argv, void* data, unsigned int hint) {
336 __context.reset(new AppCoreUi(hint, ops, data));
338 __context->Init(argc, argv);
339 } catch (const std::runtime_error&) {
346 extern "C" EXPORT_API void appcore_ui_base_fini(void) {
347 if (__context.get() == nullptr)
353 extern "C" EXPORT_API appcore_ui_base_ops
354 appcore_ui_base_get_default_ops(void) {
355 appcore_ui_base_ops ops;
357 ops.base.create = __on_create;
358 ops.base.control = __on_control;
359 ops.base.terminate = __on_terminate;
360 ops.base.receive = __on_receive;
361 ops.base.set_i18n = __on_set_i18n;
362 ops.base.init = nullptr;
363 ops.base.finish = nullptr;
364 ops.base.run = nullptr;
365 ops.base.exit = nullptr;
366 ops.base.set_event = __on_set_event;
367 ops.base.unset_event = __on_unset_event;
368 ops.base. trim_memory = __on_trim_memory;
369 ops.pause = __on_pause;
370 ops.resume = __on_resume;
371 ops.window.show = __window_on_show;
372 ops.window.hide = __window_on_hide;
373 ops.window.lower = __window_on_lower;
374 ops.window.visibility = __window_on_visibility;
375 ops.window.pre_visibility = __window_on_pre_visibility;
376 ops.window.aux_message = __window_on_aux_message;
381 extern "C" EXPORT_API void appcore_ui_base_pause(void) {
382 if (__context.get() == nullptr)
387 extern "C" EXPORT_API void appcore_ui_base_resume(void) {
388 if (__context.get() == nullptr)
393 extern "C" EXPORT_API bool appcore_ui_base_is_resumed(void) {
394 if (__context.get() == nullptr)
396 return __context->IsResumed();
399 extern "C" EXPORT_API void appcore_ui_base_exit(void) {
400 if (__context.get() == nullptr)
405 extern "C" EXPORT_API int appcore_ui_base_group_add() {
406 if (__context.get() == nullptr)
408 return __context->GroupAdd();
411 extern "C" EXPORT_API void appcore_ui_base_group_remove() {
412 if (__context.get() == nullptr)
414 __context->GroupRemove();
417 extern "C" EXPORT_API unsigned int appcore_ui_base_get_main_window(void) {
418 if (__context.get() == nullptr)
420 return __context->GetMainWindow();
423 extern "C" EXPORT_API unsigned int appcore_ui_base_get_main_surface(void) {
424 if (__context.get() == nullptr)
426 return __context->GetMainSurface();
429 extern "C" EXPORT_API int appcore_ui_base_get_hint(void) {
430 if (__context.get() == nullptr)
432 return __context->GetHint();
435 extern "C" EXPORT_API bool appcore_ui_base_get_bg_state(void) {
436 if (__context.get() == nullptr)
438 return __context->GetBgState();
441 extern "C" EXPORT_API void appcore_ui_base_set_bg_state(bool bg_state) {
442 if (__context.get() == nullptr)
444 __context->SetBgState(bg_state);
447 extern "C" EXPORT_API void appcore_ui_base_set_system_resource_reclaiming(
449 if (__context.get() == nullptr)
451 __context->SetSystemResourceReclaiming(enable);