2 * Copyright (c) 2022 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.
18 #include <dali/internal/adaptor/common/framework.h>
25 #include <dali/integration-api/debug.h>
28 #include <dali/internal/system/common/callback-manager.h>
36 thread_local GMainLoop* gMainLoop{nullptr};
38 GMainContext* GetMainLoopContext()
40 if(gMainLoop != nullptr)
42 return g_main_loop_get_context(gMainLoop);
48 * Impl to hide GLib data members
50 struct Framework::Impl
54 : mAbortCallBack(nullptr),
55 mCallbackManager(nullptr),
56 mLanguage("NOT_SUPPORTED"),
57 mRegion("NOT_SUPPORTED")
59 mCallbackManager = CallbackManager::New();
61 // In future, may need to change this to have own context or use Tizen context
62 gMainLoop = mMainLoop = g_main_loop_new(nullptr, false);
67 delete mAbortCallBack;
69 // we're quiting the main loop so
70 // mCallbackManager->RemoveAllCallBacks() does not need to be called
71 // to delete our abort handler
72 delete mCallbackManager;
74 g_main_loop_unref(mMainLoop);
80 g_main_loop_run(mMainLoop);
85 g_main_loop_quit(mMainLoop);
89 CallbackBase* mAbortCallBack;
90 CallbackManager* mCallbackManager;
91 GMainLoop* mMainLoop{nullptr};
92 GMainContext* mContext{nullptr};
94 std::string mLanguage;
98 Impl(const Impl& impl) = delete;
99 Impl& operator=(const Impl& impl) = delete;
102 Framework::Framework(Framework::Observer& observer, TaskObserver& taskObserver, int* argc, char*** argv, Type type, bool useUiThread)
103 : mObserver(observer),
104 mTaskObserver(taskObserver),
111 mAbortHandler(MakeCallback(this, &Framework::AbortCallback)),
114 mImpl = new Impl(this);
117 Framework::~Framework()
127 void Framework::Run()
136 void Framework::Quit()
138 mObserver.OnTerminate();
142 bool Framework::IsMainLoopRunning()
147 void Framework::AddAbortCallback(CallbackBase* callback)
149 mImpl->mAbortCallBack = callback;
152 std::string Framework::GetBundleName() const
157 void Framework::SetBundleName(const std::string& name)
161 std::string Framework::GetBundleId() const
166 std::string Framework::GetResourcePath()
168 // "DALI_APPLICATION_PACKAGE" is used by Ubuntu specifically to get the already configured Application package path.
169 const char* ubuntuEnvironmentVariable = "DALI_APPLICATION_PACKAGE";
170 char* value = getenv(ubuntuEnvironmentVariable);
171 std::string resourcePath;
174 resourcePath = value;
177 if(resourcePath.back() != '/')
185 void Framework::SetBundleId(const std::string& id)
189 void Framework::AbortCallback()
191 // if an abort call back has been installed run it.
192 if(mImpl->mAbortCallBack)
194 CallbackBase::Execute(*mImpl->mAbortCallBack);
202 bool Framework::AppStatusHandler(int type, void* bundleData)
207 std::string Framework::GetLanguage() const
209 return mImpl->mLanguage;
212 std::string Framework::GetRegion() const
214 return mImpl->mRegion;
217 std::string Framework::GetDataPath()
219 const char* ubuntuEnvironmentVariable = "DALI_APPLICATION_DATA_DIR";
220 char* value = getenv(ubuntuEnvironmentVariable);
221 std::string dataPath;
230 } // namespace Adaptor
232 } // namespace Internal