2 * Copyright (c) 2022 Samsung Electronics Co., Ltd. All rights reserved.
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.
24 #include "app_core_efl_base.hh"
25 #include "appcore-efl.h"
26 #include "common/log_private.hh"
30 using namespace tizen_cpp;
32 class EflAppContext : public AppCoreEflBase {
35 APP_STATE_NOT_RUNNING,
40 EflAppContext(struct appcore_ops* callback, unsigned int hint)
41 : AppCoreEflBase(hint), callback_(callback) {
42 SetAppState(APP_STATE_CREATING);
45 void Run(int argc, char** argv) override {
46 SetAppState(APP_STATE_RUNNING);
47 AppCoreEflBase::Run(argc, argv);
48 SetAppState(APP_STATE_NOT_RUNNING);
51 int OnCreate() override {
52 AppCoreEflBase::OnCreate();
53 if (callback_->create == nullptr ||
54 callback_->create(callback_->data) < 0)
60 int OnControl(tizen_base::Bundle b) override {
61 AppCoreEflBase::OnControl(b);
64 callback_->reset(b.GetHandle(), callback_->data);
69 int OnTerminate() override {
70 if (callback_->terminate)
71 callback_->terminate(callback_->data);
76 int OnPause() override {
77 AppCoreEflBase::OnPause();
80 callback_->pause(callback_->data);
85 int OnResume() override {
86 AppCoreEflBase::OnResume();
88 if (callback_->resume)
89 callback_->resume(callback_->data);
94 AppState GetAppState() const { return state_; }
96 void SetAppState(AppState state) { state_ = state; }
99 struct appcore_ops* callback_;
100 AppState state_ = APP_STATE_NOT_RUNNING;
103 std::unique_ptr<EflAppContext> __context;
107 EXPORT_API int appcore_efl_init(const char* name,
110 struct appcore_ops* ops) {
111 if (*argc < 1 || *argv == nullptr || ops == nullptr) {
112 _E("Invalid parameter");
116 if (ops->create == nullptr) {
117 _E("app_create_cb() callback MUST be registerted");
121 if (__context.get() != nullptr &&
122 __context->GetAppState() != EflAppContext::APP_STATE_NOT_RUNNING) {
123 _E("Already running");
127 unsigned int hint = AppCoreEflBase::HINT_WINDOW_GROUP_CONTROL |
128 AppCoreEflBase::HINT_WINDOW_STACK_CONTROL |
129 AppCoreEflBase::HINT_BG_LAUNCH_CONTROL |
130 AppCoreEflBase::HINT_HW_ACC_CONTROL |
131 AppCoreEflBase::HINT_WINDOW_AUTO_CONTROL |
132 AppCoreEflBase::HINT_LEGACY_CONTROL |
133 AppCoreEflBase::HINT_WINDOW_ID_CONTROL;
135 LOGW("appcore_efl_init()");
137 __context = std::make_unique<EflAppContext>(ops, hint);
138 __context->Run(*argc, *argv);
139 } catch (std::runtime_error& e) {
140 __context->SetAppState(EflAppContext::APP_STATE_NOT_RUNNING);
146 EXPORT_API void appcore_efl_fini(void) {
147 LOGW("appcore_efl_fini()");
148 if (__context.get() &&
149 __context->GetAppState() == EflAppContext::APP_STATE_RUNNING)
153 EXPORT_API int appcore_efl_main(const char* name,
156 struct appcore_ops* ops) {
157 int r = appcore_efl_init(name, argc, argv, ops);
165 EXPORT_API void appcore_group_attach() {
166 if (__context == nullptr)
169 __context->GroupAdd();
172 EXPORT_API void appcore_group_lower() {
173 if (__context == nullptr)
176 __context->GroupRemove();
179 EXPORT_API unsigned int appcore_get_main_window(void) {
180 if (__context == nullptr)
183 return __context->GetMainWindow();
186 EXPORT_API unsigned int appcore_get_main_surface(void) {
187 if (__context == nullptr)
190 return __context->GetMainSurface();
193 EXPORT_API int appcore_set_system_resource_reclaiming(bool enable) {
194 if (__context == nullptr)
197 __context->SetSystemResourceReclaiming(enable);