1 #ifndef DALI_INTERNAL_FRAMEWORK_H
2 #define DALI_INTERNAL_FRAMEWORK_H
5 * Copyright (c) 2022 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>
24 #ifdef APPCORE_WATCH_AVAILABLE
25 #include <dali/public-api/watch/watch-application.h>
29 #include <dali/internal/system/common/abort-handler.h>
30 #include <dali/public-api/adaptor-framework/device-status.h>
32 #ifdef COMPONENT_APPLICATION_SUPPORT
33 #include <dali/devel-api/adaptor-framework/component-application.h>
43 * The Framework class is ideally placed to provide key API required by Applications.
45 * The class is also used to register callbacks with the TIZEN platform so that
46 * we know when any of the application lifecycle events occur. This includes events
47 * 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);
283 * Runs the main loop of framework
288 * Quits the main loop
293 * Checks whether the main loop of the framework is running.
294 * @return true, if the main loop is running, false otherwise.
296 bool IsMainLoopRunning();
299 * If the main loop aborts unexpectedly, then the connected callback function is called.
300 * @param[in] callBack The function to call.
301 * @note Only one callback can be registered. The last callback to be set will be called on abort.
302 * @note The ownership of callback is passed onto this class.
304 void AddAbortCallback(CallbackBase* callback);
307 * Gets bundle name which was passed in app_reset callback.
309 std::string GetBundleName() const;
312 * Gets bundle id which was passed in app_reset callback.
314 std::string GetBundleId() const;
317 * Sets a command line options.
318 * This is used in case of the preinitialized application.
319 * @param[in] argc A pointer to the number of arguments
320 * @param[in] argv A pointer to the argument list
322 void SetCommandLineOptions(int* argc, char** argv[])
329 * Gets the path at which application resources are stored.
331 static std::string GetResourcePath();
334 * Gets the path at which application data are stored.
336 static std::string GetDataPath();
339 * Sets system language.
341 void SetLanguage(const std::string& language);
344 * Sets system region.
346 void SetRegion(const std::string& region);
349 * Gets system language.
351 std::string GetLanguage() const;
354 * Gets system region.
356 std::string GetRegion() const;
359 * Called by the App framework when an application lifecycle event occurs.
360 * @param[in] type The type of event occurred.
361 * @param[in] data The data of event occurred.
363 bool AppStatusHandler(int type, void* data);
366 * Called by the adaptor when an idle callback is added.
367 * @param[in] timeout The timeout of the callback.
368 * @param[in] data The data of of the callback.
369 * @param[in] callback The callback.
370 * @return The callback id.
372 unsigned int AddIdle(int timeout, void* data, bool (*callback)(void* data));
375 * Called by the adaptor when an idle callback is removed.
376 * @param[in] id The callback id.
378 void RemoveIdle(unsigned int id);
382 Framework(const Framework&);
383 Framework& operator=(Framework&);
387 * Called when the application is created.
392 * Called app_reset callback was called with bundle.
394 void SetBundleName(const std::string& name);
397 * Called app_reset callback was called with bundle.
399 void SetBundleId(const std::string& id);
402 * Called if the application is aborted.
404 void AbortCallback();
407 * Called for initializing on specified backend. (X11 or Wayland)
413 TaskObserver& mTaskObserver;
419 std::string mBundleName;
420 std::string mBundleId;
421 AbortHandler mAbortHandler;
423 private: // impl members
428 } // namespace Adaptor
430 } // namespace Internal
434 #endif // DALI_INTERNAL_FRAMEWORK_H