1 #ifndef DALI_INTERNAL_ADAPTOR_COMMON_FRAMEWORK_H
2 #define DALI_INTERNAL_ADAPTOR_COMMON_FRAMEWORK_H
5 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/public-api/signals/callback.h>
25 #ifdef APPCORE_WATCH_AVAILABLE
26 #include <dali/public-api/watch/watch-application.h>
30 #include <dali/internal/system/common/abort-handler.h>
31 #include <dali/public-api/adaptor-framework/device-status.h>
33 #ifdef COMPONENT_APPLICATION_SUPPORT
34 #include <dali/devel-api/adaptor-framework/component-application.h>
44 * The Framework class is ideally placed to provide key API required by Applications.
46 * The class is also used to register callbacks with the TIZEN platform so that
47 * we know when any of the application lifecycle events occur. This includes events
48 * like when our application is to be initialised, terminated, paused, resumed etc.
55 NORMAL, ///< normal appFramework
56 WATCH, ///< watch appFramework
57 WIDGET, ///< widget appFramework
58 COMPONENT ///< component appFramework
62 * Observer class for the framework.
63 * @brief When the UI thread is enabled, the events are emitted on the UI thread.
64 * When it is disabled, the events are emitted on the main thread.
70 * Invoked when the application is to be initialised.
77 * Invoked when the application is to be terminated.
79 virtual void OnTerminate()
84 * Invoked when the application is to be paused.
86 virtual void OnPause()
91 * Invoked when the application is to be resumed.
93 virtual void OnResume()
98 * Invoked when the application is to be reset.
100 virtual void OnReset()
105 * Invoked when the AppControl message is received.
106 * @param[in] The bundle data of AppControl message.
108 virtual void OnAppControl(void*)
112 #ifdef APPCORE_WATCH_AVAILABLE
114 * Invoked at every second
116 virtual void OnTimeTick(WatchTime&)
121 * Invoked at every second in ambient mode
123 virtual void OnAmbientTick(WatchTime&)
128 * Invoked when the device enters or exits ambient mode
130 virtual void OnAmbientChanged(bool ambient)
136 * Invoked when the language of the device is changed.
138 virtual void OnLanguageChanged()
143 * Invoked when the region is changed.
145 virtual void OnRegionChanged()
150 * Invoked when the battery level of the device is low.
152 virtual void OnBatteryLow(Dali::DeviceStatus::Battery::Status status)
157 * Invoked when the memory level of the device is low.
159 virtual void OnMemoryLow(Dali::DeviceStatus::Memory::Status status)
164 * Invoked when the device orientation is changed.
166 virtual void OnDeviceOrientationChanged(Dali::DeviceStatus::Orientation::Status status)
171 * Invoked when the platform surface is created.
173 virtual void OnSurfaceCreated(Any newSurface)
178 * Invoked when the platform surface is destroyed.
180 virtual void OnSurfaceDestroyed(Any newSurface)
184 #ifdef COMPONENT_APPLICATION_SUPPORT
186 * Invoked when the component application is created.
188 virtual Any OnCreate()
196 * TaskObserver class for the framework.
197 * @brief This is used only when UiThread is enabled. the events are emitted on the main thread.
203 * Invoked when the application is to be initialised.
205 virtual void OnTaskInit()
210 * Invoked when the application is to be terminated.
212 virtual void OnTaskTerminate()
217 * Invoked when the AppControl message is received.
218 * @param[in] The bundle data of AppControl message.
220 virtual void OnTaskAppControl(void*)
225 * Invoked when the language of the device is changed.
227 virtual void OnTaskLanguageChanged()
232 * Invoked when the region is changed.
234 virtual void OnTaskRegionChanged()
239 * Invoked when the battery level of the device is low.
241 virtual void OnTaskBatteryLow(Dali::DeviceStatus::Battery::Status status)
246 * Invoked when the memory level of the device is low.
248 virtual void OnTaskMemoryLow(Dali::DeviceStatus::Memory::Status status)
253 * Invoked when the device orientation is changed.
255 * Device orientation changed event is from Application Framework(Sensor Framework), it means it is system event.
256 * If UIThreading is enable, DALI application has the main thread and UI thread.
257 * This event is emitted in main thread, then it is posted to the UI thread in this callback function.
259 virtual void OnTaskDeviceOrientationChanged(Dali::DeviceStatus::Orientation::Status status)
267 * @param[in] observer The observer of the Framework.
268 * @param[in] taskObserver The task observer of the Framework.
269 * @param[in] argc A pointer to the number of arguments.
270 * @param[in] argv A pointer the the argument list.
271 * @param[in] type The type of application
272 * @param[in] useUiThread True if the application would create a UI thread
274 Framework(Observer& observer, TaskObserver& taskObserver, int* argc, char*** argv, Type type, bool useUiThread);
279 virtual ~Framework();
283 * Runs the main loop of framework
285 virtual void Run() = 0;
288 * Quits the main loop
290 virtual void Quit() = 0;
293 * Gets system language.
295 virtual std::string GetLanguage() const;
298 * Gets system region.
300 virtual std::string GetRegion() const;
303 * Gets the context of the main loop
304 * @return Platform dependent context handle
306 virtual Any GetMainLoopContext() const;
309 * Checks whether the main loop of the framework is running.
310 * @return true, if the main loop is running, false otherwise.
312 bool IsMainLoopRunning();
315 * If the main loop aborts unexpectedly, then the connected callback function is called.
316 * @param[in] callBack The function to call.
317 * @note Only one callback can be registered. The last callback to be set will be called on abort.
318 * @note The ownership of callback is passed onto this class.
320 void AddAbortCallback(CallbackBase* callback);
323 * Sets a command line options.
324 * This is used in case of the preinitialized application.
325 * @param[in] argc A pointer to the number of arguments
326 * @param[in] argv A pointer to the argument list
328 void SetCommandLineOptions(int* argc, char** argv[])
336 * Called if the application is aborted.
338 void AbortCallback();
342 Framework(const Framework&) = delete;
343 Framework& operator=(Framework&) = delete;
347 TaskObserver& mTaskObserver;
348 AbortHandler mAbortHandler;
351 std::unique_ptr<CallbackBase> mAbortCallBack;
358 using Runner = std::function<void()>;
362 * @param[in] argc A pointer to the number of arguments.
363 * @param[in] argv A pointer the the argument list.
365 UIThreadLoader(int* argc, char*** argv);
374 * Runs the main loop of framework
376 void Run(Runner runner);
380 UIThreadLoader(const UIThreadLoader&) = delete;
381 UIThreadLoader& operator=(UIThreadLoader&) = delete;
387 private: // impl members
392 } // namespace Adaptor
394 } // namespace Internal
398 #endif // DALI_INTERNAL_ADAPTOR_COMMON_FRAMEWORK_H