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/log_private.hh"
30 #include "common/glib_private.hh"
34 class AppCoreEflBase::Impl {
36 Impl(AppCoreEflBase* parent);
39 void Init(int argc, char** argv);
46 friend class AppCoreEflBase;
47 AppCoreEflBase* parent_;
50 bool thread_started_ = false;
51 std::condition_variable cond_;
52 std::unique_ptr<VoiceElm> vc_elm_;
55 bool initialized_ = false;
58 AppCoreEflBase::Impl::Impl(AppCoreEflBase* parent) : parent_(parent) {}
60 AppCoreEflBase::Impl::~Impl() {
61 if (thread_.joinable())
65 GLib::SourceRemove(source_id_);
68 void AppCoreEflBase::Impl::Init(int argc, char** argv) {
73 unsigned int hint = parent_->GetHint();
74 if ((hint & HINT_HW_ACC_CONTROL) && !getenv("AUL_HWACC")) {
75 const char* hwacc = getenv("HWACC");
76 if (hwacc == nullptr) {
77 _D("elm_config_accel_preference_set is not called");
78 } else if (strcmp(hwacc, "USE") == 0) {
79 elm_config_accel_preference_set("hw");
80 _D("elm_config_accel_preference_set : hw");
81 } else if (strcmp(hwacc, "NOT_USE") == 0) {
82 elm_config_accel_preference_set("none");
83 _D("elm_config_accel_preference_set : none");
85 _D("elm_config_accel_preference_set is not called");
89 if (VoiceElm::IsVtAutoMode()) {
90 std::unique_lock<std::mutex> lock(mutex_);
91 thread_ = std::thread([&] {
92 std::unique_lock<std::mutex> lock(mutex_);
93 thread_started_ = true;
98 if (vc_elm_.get() == nullptr)
99 vc_elm_.reset(VoiceElm::Load());
101 if (vc_elm_.get() != nullptr) {
102 source_id_ = GLib::IdleAdd([](gpointer user_data) {
103 auto* impl = static_cast<AppCoreEflBase::Impl*>(user_data);
104 if (impl->vc_elm_.get() != nullptr)
105 impl->vc_elm_->Init();
107 impl->source_id_ = 0;
108 return G_SOURCE_REMOVE;
112 } while (retry_count--);
114 cond_.wait(lock, [&] { return thread_started_; });
120 void AppCoreEflBase::Impl::Finish() {
124 if (thread_.joinable())
127 thread_started_ = false;
129 if (source_id_ != 0) {
130 GLib::SourceRemove(source_id_);
137 const char* env = getenv("AUL_LOADER_INIT");
138 if (env && env[0] == '1') {
139 setenv("AUL_LOADER_INIT", "0", 1);
143 initialized_ = false;
146 void AppCoreEflBase::Impl::LoopRun() {
150 void AppCoreEflBase::Impl::LoopExit() {
154 void AppCoreEflBase::Impl::TrimMemory() {
155 elm_cache_all_flush();
158 AppCoreEflBase::AppCoreEflBase(unsigned int hint)
159 : AppCoreUiBase(hint),
160 impl_(new Impl(this)) {
163 AppCoreEflBase::~AppCoreEflBase() = default;
165 void AppCoreEflBase::OnLoopInit(int argc, char** argv) {
166 impl_->Init(argc, argv);
169 void AppCoreEflBase::OnLoopFinish() {
173 void AppCoreEflBase::OnLoopRun() {
177 void AppCoreEflBase::OnLoopExit() {
181 int AppCoreEflBase::OnTrimMemory() {
184 return AppCoreUiBase::OnTrimMemory();
187 } // namespace tizen_cpp