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 <Elementary.h>
21 #include <condition_variable>
27 #include "app-core-efl-cpp/app_core_efl_base.hh"
28 #include "app-core-efl-cpp/voice_elm_private.hh"
29 #include "common/glib_private.hh"
30 #include "common/log_private.hh"
31 #include "common/log_tracer.hh"
35 class AppCoreEflBase::Impl {
37 Impl(AppCoreEflBase* parent);
40 void Init(int argc, char** argv);
47 friend class AppCoreEflBase;
48 AppCoreEflBase* parent_;
51 bool thread_started_ = false;
52 std::condition_variable cond_;
53 std::unique_ptr<VoiceElm> vc_elm_;
56 bool initialized_ = false;
59 AppCoreEflBase::Impl::Impl(AppCoreEflBase* parent) : parent_(parent) {}
61 AppCoreEflBase::Impl::~Impl() {
62 if (thread_.joinable())
66 GLib::SourceRemove(source_id_);
69 void AppCoreEflBase::Impl::Init(int argc, char** argv) {
70 LogTracer tracer("AppCoreEflBase::Impl::Init()");
75 unsigned int hint = parent_->GetHint();
76 if ((hint & HINT_HW_ACC_CONTROL) && !getenv("AUL_HWACC")) {
77 const char* hwacc = getenv("HWACC");
78 if (hwacc == nullptr) {
79 _D("elm_config_accel_preference_set is not called");
80 } else if (strcmp(hwacc, "USE") == 0) {
81 elm_config_accel_preference_set("hw");
82 _D("elm_config_accel_preference_set : hw");
83 } else if (strcmp(hwacc, "NOT_USE") == 0) {
84 elm_config_accel_preference_set("none");
85 _D("elm_config_accel_preference_set : none");
87 _D("elm_config_accel_preference_set is not called");
91 if (VoiceElm::IsVtAutoMode()) {
92 std::unique_lock<std::mutex> lock(mutex_);
93 thread_ = std::thread([&] {
94 std::unique_lock<std::mutex> lock(mutex_);
95 thread_started_ = true;
100 if (vc_elm_.get() == nullptr)
101 vc_elm_.reset(VoiceElm::Load());
103 if (vc_elm_.get() != nullptr) {
104 source_id_ = GLib::IdleAdd([](gpointer user_data) {
105 auto* impl = static_cast<AppCoreEflBase::Impl*>(user_data);
106 if (impl->vc_elm_.get() != nullptr)
107 impl->vc_elm_->Init();
109 impl->source_id_ = 0;
110 return G_SOURCE_REMOVE;
114 } while (retry_count--);
116 cond_.wait(lock, [&] { return thread_started_; });
122 void AppCoreEflBase::Impl::Finish() {
123 LogTracer tracer("AppCoreEflBase::Impl::Finish()");
127 if (thread_.joinable())
130 thread_started_ = false;
132 if (source_id_ != 0) {
133 GLib::SourceRemove(source_id_);
140 const char* env = getenv("AUL_LOADER_INIT");
141 if (env && env[0] == '1') {
142 setenv("AUL_LOADER_INIT", "0", 1);
146 initialized_ = false;
149 void AppCoreEflBase::Impl::LoopRun() {
153 void AppCoreEflBase::Impl::LoopExit() {
157 void AppCoreEflBase::Impl::TrimMemory() {
158 elm_cache_all_flush();
161 AppCoreEflBase::AppCoreEflBase(unsigned int hint)
162 : AppCoreUiBase(hint),
163 impl_(new Impl(this)) {
166 AppCoreEflBase::~AppCoreEflBase() = default;
168 void AppCoreEflBase::OnLoopInit(int argc, char** argv) {
169 impl_->Init(argc, argv);
172 void AppCoreEflBase::OnLoopFinish() {
176 void AppCoreEflBase::OnLoopRun() {
180 void AppCoreEflBase::OnLoopExit() {
184 int AppCoreEflBase::OnTrimMemory() {
187 return AppCoreUiBase::OnTrimMemory();
190 } // namespace tizen_cpp