The tizen_base directory is changed to 'tizen-core'.
The path of the tizen-core directory is changed to 'src/tizen-core'.
The path of the include directory is changed to 'src/tizen-core/include'.
src/
+ src/tizen-core
+ src/tizen-core/include
+ src/tizen-core/channel
+ src/tizen-core/event
Change-Id: I696b98c5bc7c1b1c97a54b46391a4c31456a9cf3
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
PKG_CHECK_MODULES(TIZEN_SHARED_QUEUE_DEPS REQUIRED tizen-shared-queue)
PKG_CHECK_MODULES(CAPI_SYSTEM_RESOURCE_DEPS REQUIRED capi-system-resource)
-CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/${TARGET_TIZEN_CORE}.pc.in
- ${CMAKE_SOURCE_DIR}/${TARGET_TIZEN_CORE}.pc @ONLY)
-INSTALL(FILES ${CMAKE_SOURCE_DIR}/${TARGET_TIZEN_CORE}.pc
- DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
-
INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/include/
DESTINATION include/tizen-core
FILES_MATCHING
PATTERN "*_private.h" EXCLUDE
PATTERN "include/*.h*")
-ADD_SUBDIRECTORY(tizen_base)
+ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(tests)
+++ /dev/null
-/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __TIZEN_BASE_TIZEN_CORE_H__
-#define __TIZEN_BASE_TIZEN_CORE_H__
-
-#include <stdbool.h>
-#include <stdint.h>
-#include <tizen_error.h>
-#include <poll.h>
-
-#include <tizen_core_channel.h>
-#include <tizen_core_event.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @file tizen_core.h
- */
-
-/**
- * @addtogroup CAPI_TIZEN_CORE_MODULE
- * @{
- */
-
-/**
- * @brief Enumeration for the tizen core result.
- * @since_tizen 9.0
- */
-typedef enum {
- TIZEN_CORE_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
- TIZEN_CORE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
- TIZEN_CORE_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
- TIZEN_CORE_ERROR_INVALID_CONTEXT = TIZEN_ERROR_APPLICATION | 0x01, /**< Invalid context */
-} tizen_core_error_e;
-
-/**
- * @brief Enumeration for the priority of tizen core source.
- * @since_tizen 9.0
- */
-typedef enum {
- TIZEN_CORE_PRIORITY_HIGH = -100, /**< High priority */
- TIZEN_CORE_PRIORITY_DEFAULT = 0, /**< Default priority */
- TIZEN_CORE_PRIORITY_HIGH_IDLE = 100, /**< High idle priority */
- TIZEN_CORE_PRIORITY_DEFAULT_IDLE = 200, /**< Default idle priority */
- TIZEN_CORE_PRIORITY_LOW = 300, /**< Low priority */
-} tizen_core_priority_e;
-
-/**
- * @brief Enumeration for the event of tizen core poll fd.
- * @since_tizen 9.0
- * @see tizen_core_poll_fd_set_events()
- * @see tizen_core_poll_fd_get_events()
- * @see tizen_core_poll_fd_set_returned_events()
- * @see tizen_core_poll_fd_get_returned_events()
- */
-typedef enum {
- TIZEN_CORE_POLL_EVENT_IN = POLLIN, /**< There is data to read */
- TIZEN_CORE_POLL_EVENT_PRI = POLLPRI, /**< There is some exceptional condition on the file descriptor */
- TIZEN_CORE_POLL_EVENT_OUT = POLLOUT, /**< Writing is now possible */
- TIZEN_CORE_POLL_EVENT_ERR = POLLERR, /**< Error condition */
- TIZEN_CORE_POLL_EVENT_HUP = POLLHUP, /**< Hang up */
- TIZEN_CORE_POLL_EVENT_NVAL = POLLNVAL, /**< Invalid request: fd not open */
-} tizen_core_poll_event_e;
-
-/**
- * @brief The tizen core handle.
- * @since_tizen 9.0
- */
-typedef void *tizen_core_h;
-
-
-/**
- * @brief The tizen core task handle.
- * @since_tizen 9.0
- */
-typedef void *tizen_core_task_h;
-
-/**
- * @brief The tizen core source handle.
- * @since_tizen 9.0
- */
-typedef void *tizen_core_source_h;
-
-/**
- * @brief The tizen core poll fd handle.
- * @since_tizen 9.0
- */
-typedef void *tizen_core_poll_fd_h;
-
-/**
- * @brief Called when the channel object is received.
- * @since_tizen 9.0
- * @remarks The @a object must not be deallocated by the application.
- *
- * @param[in] object The tizen core channel object handle
- * @param[in] user_data The user data passed from the registration function
- * @see tizen_core_add_channel()
- */
-typedef void (*tizen_core_channel_receive_cb)(
- tizen_core_channel_object_h object, void *user_data);
-
-/**
- * @brief Called when the tizen core idle or timer event is emitted.
- * @since_tizen 9.0
- *
- * @param[in] user_data The user data passed from the callback registration function
- * @return @c true to repeat calling the callback function,
- * otherwise @c false to remove the added source.
- * @see tizen_core_add_idle_job()
- * @see tizen_core_add_timer()
- */
-typedef bool (*tizen_core_task_cb)(void *user_data);
-
-/**
- * @brief Called before all file descriptors are polled.
- * @details The @a source is the same object for which the callback was set.
- * @details The function returns a timeout value to ensure that the poll()
- * call doesn't block too long and miss the next timeout.
- * The timeout value is -1 to indicate that it doesn't mind how long
- * the poll() call blocks.
- * @since_tizen 9.0
- * @remarks The @a source should be released using tizen_core_source_destroy() when no longer needed.
- * The @a timeout should not be released. The @a timeout can be used only in the callback.
- *
- * @param[in] source The tizen core source handle
- * @param[out] timeout The timeout
- * @param[in] user_data The user data passed from the callback registration function
- * @return @c true to indicate that the source is always ready to be processed,
- * otherwise @c false to wait until poll() has been called before it knows whether any events need to be processed.
- * @see tizen_core_source_set_prepare_cb()
- */
-typedef bool (*tizen_core_source_prepare_cb)(tizen_core_source_h source,
- int *timeout, void *user_data);
-
-/**
- * @brief Called when checks whether the source is ready to be processed or not.
- * @details The @a source is the same object for which the callback was set.
- * @details The function should return 'true' if it's ready to be dispatched.
- * @since_tizen 9.0
- * @remarks The @a source should be released using tizen_core_source_destroy() when no longer needed.
- *
- * @param[in] source The tizen core source handle
- * @param[in] user_data The user data passed from the callback registration function
- * @return @c true to indicate that the source is always ready to be processed,
- * otherwise @c false to indicate that the source is not ready to be processed.
- * @see tizen_core_source_set_check_cb()
- */
-typedef bool (*tizen_core_source_check_cb)(tizen_core_source_h source,
- void *user_data);
-
-/**
- * @brief Called when dispatches events.
- * @details The @a source is the same object for which the callback was set.
- * @since_tizen 9.0
- * @remarks The @a source should be released using tizen_core_source_destroy() when no longer needed.
- *
- * @param[in] source The tizen core source handle
- * @param[in] user_data The user data passed from the callback registration function
- * @return @c true to indicate that the process is ready to dispatch the event.
- * @see tizen_core_source_set_dispatch_cb()
- */
-typedef bool (*tizen_core_source_dispatch_cb)(tizen_core_source_h source,
- void *user_data);
-
-/**
- * @brief Called when the source is finalized.
- * @details The @a source is the same object for which the callback was set.
- * @since_tizen 9.0
- * @remarks The @a source should not be released. The @a source is managed by the platform.
- * @remarks The @a source is managed by the platform and will be released when the callback returns.
- *
- * @param[in] source The tizen core source handle
- * @param[in] user_data The user data passed from the callback registration function
- * @see tizen_core_source_set_finalize_cb()
- */
-typedef void (*tizen_core_source_finalize_cb)(tizen_core_source_h source,
- void *user_data);
-
-/**
- * @brief Initializes the tizen core.
- * @since_tizen 9.0
- *
- * @see tizen_core_shutdown()
- * @see tizen_core_ready()
- */
-void tizen_core_init(void);
-
-/**
- * @brief Shutdowns the tizen core.
- * @since_tizen 9.0
- *
- * @see tizen_core_init()
- * @see tizen_core_ready()
- */
-void tizen_core_shutdown(void);
-
-/**
- * @brief Checks whether the tizen core is ready or not.
- * @since_tizen 9.0
- *
- * @return @c true if the tizen core is ready, otherwise @c false.
- *
- * @see tizen_core_init()
- * @see tizen_core_shutdown()
- */
-bool tizen_core_ready(void);
-
-/**
- * @brief Creates the tizen core task handle.
- * @details If the @a name is "main", the @a use_thread should be set to 'false'.
- * Otherwise, it returns #TIZEN_CORE_ERROR_INVALID_PARAMETER.
- * @since_tizen 9.0
- * @remarks The @a task should be released using tizen_core_task_destroy().
- *
- * @param[in] name The name of the task
- * @param[in] use_thread true, if the task should be run in a separate thread, otherwise @c false
- * @param[out] task The tizen core task handle
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #TIZEN_CORE_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #TIZEN_CORE_ERROR_INVALID_CONTEXT Invalid context
- *
- * @code
-#include <tizen_core.h>
-{
- tizen_core_task_h task = NULL;
- int ret;
-
- tizen_core_init();
- ret = tizen_core_task_create("main", false, &task);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- tizen_core_shutdown();
- return -1;
- }
-}
- * @endcode
- *
- * @see tizen_core_task_destroy()
- */
-int tizen_core_task_create(const char *name, bool use_thread,
- tizen_core_task_h *task);
-
-/**
- * @brief Destroys the tizen core task handle.
- * @since_tizen 9.0
- *
- * @param[in] task The tizen core task handle
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @code
-#include <tizen_core.h>
-{
- tizen_core_task_h task = NULL;
- int ret;
-
- tizen_core_init();
- ret = tizen_core_task_create("main", false, &task);
- if (ret != TIZEN_CORE_ERROR_NONE)
- return ret;
-
- ret = tizen_core_task_destroy(task);
- if (ret != TIZEN_CORE_ERROR_NONE)
- return ret;
-}
- * @endcode
- *
- * @see tizen_core_task_create()
- */
-int tizen_core_task_destroy(tizen_core_task_h task);
-
-/**
- * @brief Runs the main loop of the tizen core task.
- * @since_tizen 9.0
- *
- * @param[in] task The tizen core task handle
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #TIZEN_CORE_ERROR_INVALID_CONTEXT Invalid context
- *
- * @code
-#include <tizen_core.h>
-{
- tizen_core_task_h task = NULL;
- int ret;
-
- tizen_core_init();
- ret = tizen_core_task_create("worker", true, &task);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- tizen_core_shutdown();
- return ret;
- }
-
- ret = tizen_core_task_run(task);
- if (ret != TIZEN_CORE_ERROR_NONE)
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to run task");
-}
- * @endcode
- *
- * @see tizen_core_task_quit()
- */
-int tizen_core_task_run(tizen_core_task_h task);
-
-/**
- * @brief Checks whether the tizen core task is running or not.
- * @since_tizen 9.0
- *
- * @param[in] task The tizen core task handle
- * @param[out] running @c true if the core task is running, \n
- * otherwise @c false if not running
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @code
-#include <tizen_core.h>
-{
- tizen_core_task_h task = NULL;
- bool running = false;
- int ret;
-
- tizen_core_init();
- ret = tizen_core_task_create("worker", true, &task);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- tizen_core_shutdown();
- return ret;
- }
-
- ret = tizen_core_task_run(task);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to run task");
- tizen_core_task_destroy(task);
- tizen_core_shutdown();
- return ret;
- }
-
- ret = tizen_core_task_is_running(task, &running);
- if (ret != TIZEN_CORE_ERROR_NONE)
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to check whether the task is running or not");
- else
- dlog_print(DLOG_INFO, LOG_TAG, "worker task is %s", running ? "running" : "not running");
-}
- * @endcode
- *
- * @see tizen_core_task_run()
- * @see tizen_core_task_quit()
- */
-int tizen_core_task_is_running(tizen_core_task_h task, bool *running);
-
-/**
- * @brief Exits the main loop of the tizen core task.
- * @since_tizen 9.0
- *
- * @param[in] task The tizen core task handle
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @code
-#include <tizen_core.h>
-{
- tizen_core_task_h task = NULL;
- int ret;
-
- tizen_core_init();
- tizen_core_task_create("worker", true, &task);
- tizen_core_task_run(task);
- ret = tizen_core_task_quit(task);
- if (ret != TIZEN_CORE_ERROR_NONE)
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to exit the main loop");
-}
- * @endcode
- *
- * @see tizen_core_task_run()
- */
-int tizen_core_task_quit(tizen_core_task_h task);
-
-/**
- * @brief Gets the tizen core from the tizen core task handle.
- * @since_tizen 9.0
- * @remarks The @a core should not be released.
- * @remarks The @a core is available until the @a task is released.
- *
- * @param[in] task The tizen core task handle
- * @param[out] core The tizen core handle
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @code
-#include <tizen_core.h>
-{
- tizen_core_task_h task = NULL;
- tizen_core_h core = NULL;
- int ret;
-
- tizen_core_init();
- tizen_core_task_create("worker", true, &task);
- ret = tizen_core_task_get_tizen_core(task, &core);
- if (ret != TIZEN_CORE_ERROR_NONE)
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to get tizen core");
-}
- * @endcode
- */
-int tizen_core_task_get_tizen_core(tizen_core_task_h task, tizen_core_h *core);
-
-/**
- * @brief Finds the tizen core from the name.
- * @since_tizen 9.0
- * @remarks The @a core should not be released.
- * @remarks The @a core is available until #tizen_core_task_h of the @a core is released.
- *
- * @param[in] name The tizen core task name
- * @param[out] core The tizen core handle
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #TIZEN_CORE_ERROR_INVALID_CONTEXT Invalid context
- *
- * @code
-#include <tizen_core.h>
-{
- tizen_core_h core = NULL;
- int ret;
-
- ret = tizen_core_find("worker", &core);
- if (ret != TIZEN_CORE_ERROR_NONE)
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to find tizen core");
-}
- * @endcode
- */
-int tizen_core_find(const char *name, tizen_core_h *core);
-
-/**
- * @brief Finds the tizen core from this thread.
- * @since_tizen 9.0
- * @remarks The @a core should not be released.
- * @remarks The @a core is available until #tizen_core_task_h of the @a core is released.
- *
- * @param[out] core The tizen core handle
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #TIZEN_CORE_ERROR_INVALID_CONTEXT Invalid context
- *
- * @code
-#include <tizen_core.h>
-{
- tizen_core_h core = NULL;
- int ret;
-
- ret = tizen_core_find_from_this_thread(&core);
- if (ret != TIZEN_CORE_ERROR_NONE)
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to find tizen core from this thread");
-}
- * @endcode
- */
-int tizen_core_find_from_this_thread(tizen_core_h *core);
-
-/**
- * @brief Adds an idle job to the tizen core.
- * @details The callback function will be called whenever there are
- * no higher priority events pending to the tizen core.
- * The given callback function is called repeatedly until it returns false,
- * at which point the idler @a source is automatically destroyed and
- * the callback function will not be called again.
- * @since_tizen 9.0
- * @remarks The @a source should be released using tizen_core_remove_source().
- *
- * @param[in] core The tizen core handle
- * @param[in] callback The callback function to be invoked when the idle job is emitted
- * @param[in] user_data The user data to be passed to the callback function
- * @param[out] source The tizen core source handle
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #TIZEN_CORE_ERROR_OUT_OF_MEMORY Out of memory
- *
- * @code
-#include <tizen_core.h>
-static bool idle_cb(void *user_data)
-{
- dlog_print(DLOG_INFO, LOG_TAG, "idler is invoked");
- return true;
-}
-
-static tizen_core_source_h add_idle_job(void)
-{
- tizen_core_source_h source = NULL;
- tizen_core_h core = NULL;
- int ret;
-
- tizen_core_find("main", &core);
- ret = tizen_core_add_idle_job(core, idle_cb, NULL, &source);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to add idle job");
- return NULL;
- }
-
- return source;
-}
- * @endcode
- *
- * @see tizen_core_remove_source()
- * @see tizen_core_task_cb()
- */
-int tizen_core_add_idle_job(tizen_core_h core, tizen_core_task_cb callback,
- void *user_data, tizen_core_source_h *source);
-
-/**
- * @brief Adds a timer to the tizen core.
- * @details The callback function will be called at regular intervals.
- * The given callback function is called repeatedly until it returns false,
- * at which point the timer @a source is automatically destroyed and
- * the callback function will not be called again.
- * @since_tizen 9.0
- * @remarks The @a source should be released using tizen_core_remove_source().
- *
- * @param[in] core The tizen core handle
- * @param[in] interval The interval of the timer in milliseconds
- * @param[in] callback The callback function to be invoked when the timer is expired
- * @param[in] user_data The user data to be passed to the callback function
- * @param[out] source The tizen core source handle
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #TIZEN_CORE_ERROR_OUT_OF_MEMORY Out of memory
- *
- * @code
-#include <tizen_core.h>
-
-static bool timeout_cb(void *user_data)
-{
- dlog_print(DLOG_INFO, LOG_TAG, "timeout cb is invoked");
- return true;
-}
-
-static tizen_core_source_h add_timer(unsigned int interval)
-{
- tizen_core_source_h source = NULL;
- tizen_core_h core = NULL;
- int ret;
-
- tizen_core_find("main", &core);
- ret = tizen_core_add_timer(core, interval, timeout_cb, NULL, &source);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to add timer");
- return NULL;
- }
-
- return source;
-}
- * @endcode
- *
- * @see tizen_core_remove_source()
- * @see tizen_core_task_cb()
- */
-int tizen_core_add_timer(tizen_core_h core, unsigned int interval,
- tizen_core_task_cb callback, void *user_data,
- tizen_core_source_h *source);
-
-/**
- * @brief Adds a channel receiver to the tizen core.
- * @details The callback function will be called when the channel event is received.
- * @since_tizen 9.0
- * @remarks The @a source should be released using tizen_core_remove_source().
- *
- * @param[in] core The tizen core handle
- * @param[in] receiver The channel receiver handle
- * @param[in] callback The callback function to be invoked when the channel event is received
- * @param[in] user_data The user data to be passed to the callback function
- * @param[out] source The tizen core source handle
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #TIZEN_CORE_ERROR_OUT_OF_MEMORY Out of memory
- *
- * @code
-#include <tizen_core.h>
-static void channel_receiver_cb(tizen_core_channel_object_h object, void *user_data)
-{
- dlog_print(DLOG_INFO, LOG_TAG, "channel object is received");
-}
-
-static tizen_core_source_h add_channel_event(tizen_core_channel_receiver_h receiver)
-{
- tizen_core_source_h source = NULL;
- tizen_core_h core = NULL;
- int ret;
-
- tizen_core_find("main", &core);
- ret = tizen_core_add_channel(core, receiver, channel_receiver_cb, NULL, &source);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to add channel");
- return NULL;
- }
-
- return source;
-}
- * @endcode
- *
- * @see tizen_core_remove_source()
- */
-int tizen_core_add_channel(tizen_core_h core,
- tizen_core_channel_receiver_h receiver,
- tizen_core_channel_receive_cb callback,
- void *user_data, tizen_core_source_h *source);
-
-/**
- * @brief Adds an event to the tizen core.
- * @details The event handler added to the event handle is called
- * using the corresponding core loop when the event emit occurs.
- * When this function is called the ownership of the @a event is moved
- * to the tizen core. The @a event will be released when the @a source
- * is removed using tizen_core_remove_source().
- * @since_tizen 9.0
- * @remarks The @a source should be released using tizen_core_remove_source().
- * @remarks The @a event MUST not be released using tizen_core_event_destroy()
- * after adding to the tizen core using this function.
- *
- * @param[in] core The tizen core handle
- * @param[in] event The tizen core event handle
- * @param[out] source The tizen core source handle
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #TIZEN_CORE_ERROR_OUT_OF_MEMORY Out of memory
- *
- * @code
-#include <tizen_core.h>
-static tizen_core_source_h add_event_source(tizen_core_event_h event)
-{
- tizen_core_source_h source = NULL;
- tizen_core_h core = NULL;
- int ret;
-
- tizen_core_find("main", &core);
- ret = tizen_core_add_event(core, event, &source);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to add event");
- return NULL;
- }
-
- return source;
-}
- * @endcode
- *
- * @see tizen_core_remove_source()
- */
-int tizen_core_add_event(tizen_core_h core, tizen_core_event_h event,
- tizen_core_source_h *source);
-
-/**
- * @brief Emits the event to the tizen core.
- * @details The event is emitted to the event handler registered in the corresponding tizen_core.
- * @since_tizen 9.0
- *
- * @param[in] core The tizen core handle
- * @param[in] object The tizen core event object handle
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @code
-#include <tizen_core.h>
-static int emit_event(tizen_core_event_object_h object)
-{
- tizen_core_h core = NULL;
- int ret;
-
- tizen_core_find("main", &core);
- ret = tizen_core_emit_event(core, object);
- if (ret != TIZEN_CORE_ERROR_NONE)
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to emit event");
-
- return ret;
-}
- * @endcode
- *
- * @see tizen_core_add_event()
- */
-int tizen_core_emit_event(tizen_core_h core, tizen_core_event_object_h object);
-
-/**
- * @brief Adds a source to the tizen core.
- * @since_tizen 9.0
- * @remarks The @a source should be removed using tizen_core_remove_source().
- *
- * @param[in] core The tizen core handle
- * @param[in] source The tizen core source handle
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @code
-#include <tizen_core.h>
-{
- tizen_core_source_h source = NULL;
- tizen_core_h core = NULL;
- int ret;
-
- tizen_core_source_create(&source);
- tizen_core_find("main", &core);
- ret = tizen_core_add_source(core, source);
- if (ret != TIZEN_CORE_ERROR_NONE)
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to add source");
-}
- * @endcode
- *
- * @see tizen_core_remove_source()
- */
-int tizen_core_add_source(tizen_core_h core, tizen_core_source_h source);
-
-/**
- * @brief Removes the source from the tizen core.
- * @since_tizen 9.0
- * @remarks If the source is not added to the tizen core, this function returns
- * #TIZEN_CORE_ERROR_INVALID_CONTEXT.
- *
- * @param[in] core The tizen core handle
- * @param[in] source The tizen core source handle
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #TIZEN_CORE_ERROR_INVALID_CONTEXT Invalid context
- *
- * @code
-#include <tizen_core.h>
-static void remove_source(tizen_core_source_h source)
-{
- tizen_core_h core = NULL;
- int ret;
-
- tizen_core_find("main", &core);
- ret = tizen_core_remove_source(core, source);
- if (ret != TIZEN_CORE_ERROR_NONE)
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to remove source");
- else
- dlog_print(DLOG_INFO, LOG_TAG, "source is removed");
-}
- * @endcode
- *
- * @see tizen_core_add_source()
- */
-int tizen_core_remove_source(tizen_core_h core, tizen_core_source_h source);
-
-/**
- * @brief Creates a tizen core source handle.
- * @since_tizen 9.0
- * @remarks The @a source should be released using tizen_core_source_destroy().
- *
- * @param[out] source The tizen core source handle
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #TIZEN_CORE_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #TIZEN_CORE_ERROR_INVALID_CONTEXT Invalid context
- *
- * @code
-#include <tizen_core.h>
-{
- tizen_core_source_h source = NULL;
- int ret;
-
- ret = tizen_core_source_create(&source);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create source");
- return ret;
- }
-}
- * @endcode
- *
- * @see tizen_core_add_source()
- * @see tizen_core_remove_source()
- * @see tizen_core_source_destroy()
- */
-int tizen_core_source_create(tizen_core_source_h *source);
-
-/**
- * @brief Destroys the tizen core source handle.
- * @since_tizen 9.0
- *
- * @param[in] source The tizen core source handle
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @code
-#include <tizen_core.h>
-{
- tizen_core_source_h source = NULL;
- int ret;
-
- ret = tizen_core_source_create(&source);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create source");
- return ret;
- }
-
- ret = tizen_core_source_destroy(source);
- if (ret != TIZEN_CORE_ERROR_NONE)
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to destroy source");
-}
- * @endcode
- * @see tizen_core_source_create()
- * @see tizen_core_remove_source()
- */
-int tizen_core_source_destroy(tizen_core_source_h source);
-
-/**
- * @brief Waits for some events on the file descriptor.
- * @details The tizen core source must be created using the tizen_core_source_create().
- * @since_tizen 9.0
- *
- * @param[in] source The tizen core source handle
- * @param[in] poll_fd The poll fd handle
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #TIZEN_CORE_ERROR_INVALID_CONTEXT Invalid context
- *
- * @code
-#include <tizen_core.h>
-static tizen_core_poll_fd_h add_poll_fd_to_source(tizen_core_source_h source, int fd)
-{
- tizen_core_poll_fd_h poll_fd = NULL;
- int ret;
-
- tizen_core_poll_fd_create(&poll_fd);
- tizen_core_poll_fd_set_fd(poll_fd, fd);
- tizen_core_poll_fd_set_events(poll_fd, TIZEN_CORE_POLL_EVENT_IN);
- ret = tizen_core_source_add_poll(source, poll_fd);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to add poll fd");
- tizen_core_poll_fd_destroy(poll_fd);
- return NULL;
- }
-
- return poll_fd;
-}
- * @endcode
- *
- * @see tizen_core_source_create()
- * @see tizen_core_source_set_prepare_cb()
- * @see tizen_core_source_set_check_cb()
- * @see tizen_core_source_set_dispatch_cb()
- * @see tizen_core_source_set_finalize_cb()
- * @see tizen_core_source_remove_poll()
- */
-int tizen_core_source_add_poll(tizen_core_source_h source,
- tizen_core_poll_fd_h poll_fd);
-
-/**
- * @brief Removes to wait for some events on the file descriptor.
- * @since_tizen 9.0
- *
- * @param[in] source The tizen core source handle
- * @param[in] poll_fd The poll fd handle
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #TIZEN_CORE_ERROR_INVALID_CONTEXT Invalid context
- *
- * @code
-#include <tizen_core.h>
-static void remove_poll_from_source(tizen_core_source_h source, tizen_core_poll_fd_h poll_fd)
-{
- int ret;
-
- ret = tizen_core_source_remove_poll(source, poll_fd);
- if (ret != TIZEN_CORE_ERROR_NONE)
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to remove poll fd");
- else
- dlog_print(DLOG_INFO, LOG_TAG, "Poll fd is removed");
-}
- * @endcode
- *
- * @see tizen_core_source_create()
- * @see tizen_core_source_add_poll()
- */
-int tizen_core_source_remove_poll(tizen_core_source_h source,
- tizen_core_poll_fd_h poll_fd);
-
-/**
- * @brief Sets the prepare callback function to the tizen core source.
- * @details This function is not mandatory.
- * If you want to set a timeout value to ensure that the poll(),
- * the @a callback function should be set.
- * @since_tizen 9.0
- *
- * @param[in] source The tizen core source handle
- * @param[in] callback The callback function to be invoked when the source is ready to be processed
- * @param[in] user_data The user data to be passed to the callback function
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @code
-#include <tizen_core.h>
-static bool source_prepare_cb(tizen_core_source_h source, int *timeout, void *user_data)
-{
- dlog_print(DLOG_INFO, LOG_TAG, "prepare callback is invoked");
- return true;
-}
-
-static bool source_check_cb(tizen_core_source_h source, void *user_data)
-{
- dlog_print(DLOG_INFO, LOG_TAG, "check callback is invoked");
- return true;
-}
-
-static bool source_dispatch_cb(tizen_core_source_h source, void *user_data)
-{
- dlog_print(DLOG_INFO, LOG_TAG, "dispatch callback is invoked");
- return true;
-}
-
-static tizen_core_source_h create_source(void)
-{
- tizen_core_source_h source = NULL;
- int ret;
-
- ret = tizen_core_source_create(&source);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create source");
- return NULL;
- }
-
- ret = tizen_core_source_set_prepare_cb(source, source_prepare_cb, NULL);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to set prepare callback");
- tizen_core_source_destroy(source);
- return NULL;
- }
-
- tizen_core_source_set_check_cb(source, source_check_cb, NULL);
- tizen_core_source_set_dispatch_cb(source, source_dispatch_cb, NULL);
-
- return source;
-}
- * @endcode
- *
- * @see tizen_core_source_create()
- * @see tizen_core_source_prepare_cb()
- * @see tizen_core_source_add_poll()
- */
-int tizen_core_source_set_prepare_cb(
- tizen_core_source_h source, tizen_core_source_prepare_cb callback,
- void *user_data);
-
-/**
- * @brief Sets the check callback function to the tizen core source.
- * @details This function is not mandatory.
- * If the @a callback function is not set, the tizen core source is processed.
- * @since_tizen 9.0
- *
- * @param[in] source The tizen core source handle
- * @param[in] callback The callback function to be invoked when the source is ready to be processed
- * @param[in] user_data The user data to be passed to the callback function
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @code
-#include <tizen_core.h>
-static bool source_prepare_cb(tizen_core_source_h source, int *timeout, void *user_data)
-{
- dlog_print(DLOG_INFO, LOG_TAG, "prepare callback is invoked");
- return true;
-}
-
-static bool source_check_cb(tizen_core_source_h source, void *user_data)
-{
- dlog_print(DLOG_INFO, LOG_TAG, "check callback is invoked");
- return true;
-}
-
-static bool source_dispatch_cb(tizen_core_source_h source, void *user_data)
-{
- dlog_print(DLOG_INFO, LOG_TAG, "dispatch callback is invoked");
- return true;
-}
-
-static tizen_core_source_h create_source(void)
-{
- tizen_core_source_h source = NULL;
- int ret;
-
- ret = tizen_core_source_create(&source);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create source");
- return NULL;
- }
-
- tizen_core_source_set_prepare_cb(source, source_prepare_cb, NULL);
- tizen_core_source_set_dispatch_cb(source, source_dispatch_cb, NULL);
-
- ret = tizen_core_source_set_check_cb(source, source_check_cb, NULL);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to set check callback");
- tizen_core_source_destroy(source);
- return NULL;
- }
-
- return source;
-}
- * @endcode
- *
- * @see tizen_core_source_create()
- * @see tizen_core_source_check_cb()
- */
-int tizen_core_source_set_check_cb(tizen_core_source_h source,
- tizen_core_source_check_cb callback,
- void *user_data);
-
-/**
- * @brief Sets the dispatch callback function to the tizen core source.
- * @details This function is mandatory. Before adding the @a source handle to
- * the #tizen_core_h using tizen_core_add_source(),
- * the @a callback function should be set.
- * @since_tizen 9.0
- *
- * @param[in] source The tizen core source handle
- * @param[in] callback The callback function to be dispatched events
- * @param[in] user_data The user data to be passed to the callback function
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @code
-#include <tizen_core.h>
-static bool source_prepare_cb(tizen_core_source_h source, int *timeout, void *user_data)
-{
- dlog_print(DLOG_INFO, LOG_TAG, "prepare callback is invoked");
- return true;
-}
-
-static bool source_check_cb(tizen_core_source_h source, void *user_data)
-{
- dlog_print(DLOG_INFO, LOG_TAG, "check callback is invoked");
- return true;
-}
-
-static bool source_dispatch_cb(tizen_core_source_h source, void *user_data)
-{
- dlog_print(DLOG_INFO, LOG_TAG, "dispatch callback is invoked");
- return true;
-}
-
-static tizen_core_source_h create_source(void)
-{
- tizen_core_source_h source = NULL;
- int ret;
-
- ret = tizen_core_source_create(&source);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create source");
- return NULL;
- }
-
- tizen_core_source_set_prepare_cb(source, source_prepare_cb, NULL);
- tizen_core_source_set_check_cb(source, source_check_cb, NULL);
-
- ret = tizen_core_source_set_dispatch_cb(source, source_dispatch_cb, NULL);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to set dispatch callback");
- tizen_core_source_destroy(source);
- return NULL;
- }
-
- return source;
-}
- * @endcode
- *
- * @see tizen_core_source_create()
- * @see tizen_core_source_dispatch_cb()
- */
-int tizen_core_source_set_dispatch_cb(
- tizen_core_source_h source, tizen_core_source_dispatch_cb callback,
- void *user_data);
-
-/**
- * @brief Sets the finalize callback function to the tizen core source.
- * @details This function is not mandatory.
- * If there is anything you need to do when the source is removed,
- * use this function to set the callback function.
- * @since_tizen 9.0
- *
- * @param[in] source The tizen core source handle
- * @param[in] callback The callback function to finalize the source
- * @param[in] user_data The user data to be passed to the callback function
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @code
-#include <tizen_core.h>
-static bool source_prepare_cb(tizen_core_source_h source, int *timeout, void *user_data)
-{
- dlog_print(DLOG_INFO, LOG_TAG, "prepare callback is invoked");
- return true;
-}
-
-static bool source_check_cb(tizen_core_source_h source, void *user_data)
-{
- dlog_print(DLOG_INFO, LOG_TAG, "check callback is invoked");
- return true;
-}
-
-static bool source_dispatch_cb(tizen_core_source_h source, void *user_data)
-{
- dlog_print(DLOG_INFO, LOG_TAG, "dispatch callback is invoked");
- return true;
-}
-
-static void source_finalize_cb(tizen_core_source_h source, void *user_data)
-{
- dlog_print(DLOG_INFO, LOG_TAG, "finalize callback is invoked");
-}
-
-static tizen_core_source_h create_source(void)
-{
- tizen_core_source_h source = NULL;
- int ret;
-
- ret = tizen_core_source_create(&source);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create source");
- return NULL;
- }
-
- tizen_core_source_set_prepare_cb(source, source_prepare_cb, NULL);
- tizen_core_source_set_check_cb(source, source_check_cb, NULL);
- tizen_core_source_set_dispatch_cb(source, source_dispatch_cb, NULL);
-
- ret = tizen_core_source_set_finalize_cb(source, source_finalize_cb, NULL);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to set finalize callback");
- tizen_core_source_destroy(source);
- return NULL;
- }
-
- return source;
-}
- * @endcode
- *
- * @see tizen_core_source_create()
- * @see tizen_core_source_finalize_cb()
- * @see tizen_core_remove_source()
- * @see tizen_core_source_destroy()
- */
-int tizen_core_source_set_finalize_cb(
- tizen_core_source_h source, tizen_core_source_finalize_cb callback,
- void *user_data);
-
-/**
- * @brief Sets the priority to the tizen core source.
- * @since_tizen 9.0
- *
- * @param[in] source The tizen core source handle
- * @param[in] priority The priority value
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @code
-#include <tizen_core.h>
-static bool idle_job_cb(void *user_data)
-{
- dlog_print(DLOG_INFO, LOG_TAG, "idler is invoked");
- return true;
-}
-
-static tizen_core_source_h create_idle_source(void)
-{
- tizen_core_source_h source = NULL;
- tizen_core_h core = NULL;
- int ret;
-
- tizen_core_find("main", &core);
- ret = tizen_core_add_idle_job(core, idle_job_cb, NULL, &source);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to add idle job");
- return NULL;
- }
-
- ret = tizen_core_source_set_priority(source, TIZEN_CORE_PRIORITY_HIGH);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to set priority");
- tizen_core_source_destroy(source);
- return NULL;
- }
-
- return source;
-}
- * @endcode
- *
- * @see tizen_core_priority_e
- */
-int tizen_core_source_set_priority(tizen_core_source_h source,
- tizen_core_priority_e priority);
-
-/**
- * @brief Creates a tizen core poll fd handle.
- * @since_tizen 9.0
- * @remarks The @a poll_fd should be released using tizen_core_poll_fd_destroy().
- *
- * @param[out] poll_fd The tizen core poll fd handle
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #TIZEN_CORE_ERROR_OUT_OF_MEMORY Out of memory
- *
- * @code
-#include <tizen_core.h>
-{
- tizen_core_poll_fd_h poll_fd = NULL;
- int ret;
-
- ret = tizen_core_poll_fd_create(&poll_fd);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create poll fd");
- return;
- }
-}
- * @endcode
- *
- * @see tizen_core_poll_fd_destroy()
- */
-int tizen_core_poll_fd_create(tizen_core_poll_fd_h *poll_fd);
-
-/**
- * @brief Destroys the tizen core poll fd (file descriptor) handle.
- * @since_tizen 9.0
- * @remarks If the handle is already added to the source using the tizen_core_source_add_poll(),
- * the handle will be removed from the source automatically after this function is called.
- *
- * @param[in] poll_fd The tizen core poll fd handle
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @code
-#include <tizen_core.h>
-{
- tizen_core_poll_fd_h poll_fd = NULL;
- int ret;
-
- ret = tizen_core_poll_fd_create(&poll_fd);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create poll fd");
- return;
- }
-
- ret = tizen_core_poll_fd_destroy(poll_fd);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to destroy poll fd");
- }
-}
- * @endcode
- *
- * @see tizen_core_poll_fd_create()
- */
-int tizen_core_poll_fd_destroy(tizen_core_poll_fd_h poll_fd);
-
-/**
- * @brief Sets the file descriptor to the poll fd handle.
- * @since_tizen 9.0
- *
- * @param[in] poll_fd The tizen core poll fd handle
- * @param[in] fd The file descriptor
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @code
-#include <tizen_core.h>
-{
- tizen_core_poll_fd_h poll_fd = NULL;
- int ret;
-
- ret = tizen_core_poll_fd_create(&poll_fd);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create poll fd");
- return;
- }
-
- ret = tizen_core_poll_fd_set_fd(poll_fd, 0);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to set fd to poll fd");
- tizen_core_poll_fd_destroy(poll_fd);
- return;
- }
-}
- * @endcode
- *
- * @see tizen_core_poll_fd_get_fd()
- */
-int tizen_core_poll_fd_set_fd(tizen_core_poll_fd_h poll_fd, int fd);
-
-/**
- * @brief Gets the file descriptor from the poll fd handle.
- * @since_tizen 9.0
- *
- * @param[in] poll_fd The tizen core poll fd handle
- * @param[out] fd The file descriptor
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @code
-#include <tizen_core.h>
-{
- tizen_core_poll_fd_h poll_fd = NULL;
- int fd = -1;
- int ret;
-
- ret = tizen_core_poll_fd_create(&poll_fd);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create poll fd");
- return;
- }
-
- tizen_core_poll_fd_set_fd(poll_fd, 0);
-
- ret = tizen_core_poll_fd_get_fd(poll_fd, &fd);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to get fd from poll fd");
- tizen_core_poll_fd_destroy(poll_fd);
- return;
- }
-}
- * @endcode
- *
- * @see tizen_core_poll_fd_set_fd()
- */
-int tizen_core_poll_fd_get_fd(tizen_core_poll_fd_h poll_fd, int *fd);
-
-/**
- * @brief Sets the requested events to the poll fd handle.
- * @since_tizen 9.0
- *
- * @param[in] poll_fd The tizen core poll fd handle
- * @param[in] events The requested events
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @code
-#include <tizen_core.h>
-{
- tizen_core_poll_fd_h poll_fd = NULL;
- int ret;
-
- ret = tizen_core_poll_fd_create(&poll_fd);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create poll fd");
- return;
- }
-
- tizen_core_poll_fd_set_fd(poll_fd, 0);
-
- ret = tizen_core_poll_fd_set_events(poll_fd,
- TIZEN_CORE_POLL_EVENT_IN | TIZEN_CORE_POLL_EVENT_OUT);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to set events");
- tizen_core_poll_fd_destroy(poll_fd);
- return;
- }
-}
- * @endcode
- *
- * @see tizen_core_poll_fd_get_events()
- * @see tizen_core_poll_event_e
- */
-int tizen_core_poll_fd_set_events(tizen_core_poll_fd_h poll_fd,
- uint16_t events);
-
-/**
- * @brief Gets the requested events from the poll fd handle.
- * @since_tizen 9.0
- *
- * @param[in] poll_fd The tizen core poll fd handle
- * @param[out] events The requested events
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @code
-#include <tizen_core.h>
-{
- tizen_core_poll_fd_h poll_fd = NULL;
- uint16_t events;
- int ret;
-
- ret = tizen_core_poll_fd_create(&poll_fd);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create poll fd");
- return;
- }
-
- tizen_core_poll_fd_set_fd(poll_fd, 0);
- tizen_core_poll_fd_set_events(poll_fd,
- TIZEN_CORE_POLL_EVENT_IN | TIZEN_CORE_POLL_EVENT_HUP);
-
- ret = tizen_core_poll_fd_get_events(poll_fd, &events);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to get events from poll fd");
- tizen_core_poll_fd_destroy(poll_fd);
- return;
- }
-}
- * @endcode
- *
- * @see tizen_core_poll_fd_set_events()
- * @see tizen_core_poll_event_e
- */
-int tizen_core_poll_fd_get_events(tizen_core_poll_fd_h poll_fd,
- uint16_t *events);
-
-/**
- * @brief Sets the returned events to the poll fd handle.
- * @since_tizen 9.0
- *
- * @param[in] poll_fd The tizen core poll fd handle
- * @param[in] returned_events The returned events
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @code
-#include <tizen_core.h>
-{
- tizen_core_poll_fd_h poll_fd = NULL;
- int ret;
-
- ret = tizen_core_poll_fd_create(&poll_fd);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create poll fd");
- return;
- }
-
- ret = tizen_core_poll_fd_set_returned_events(poll_fd,
- TIZEN_CORE_POLL_EVENT_IN | TIZEN_CORE_POLL_EVENT_OUT);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to set returned events");
- tizen_core_poll_fd_destroy(poll_fd);
- return;
- }
-}
- * @endcode
- *
- * @see tizen_core_poll_fd_get_events()
- * @see tizen_core_poll_event_e
- */
-int tizen_core_poll_fd_set_returned_events(tizen_core_poll_fd_h poll_fd,
- uint16_t returned_events);
-
-/**
- * @brief Gets the returned events from the poll fd handle.
- * @since_tizen 9.0
- *
- * @param[in] poll_fd The tizen core poll fd handle
- * @param[out] returned_events The returned events
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @code
-#include <tizen_core.h>
-static bool source_prepare_cb(tizen_core_source_h source, int *timeout, void *user_data)
-{
- *timeout = -1;
- return true;
-}
-
-static bool source_check_cb(tizen_core_source_h source, void *user_data)
-{
- tizen_core_poll_fd_h poll_fd = (tizen_core_poll_fd_h)user_data;
- uint16_t returned_events = 0;
-
- tizen_core_poll_fd_get_returned_events(poll_fd, &returned_events);
- if (returned_events & TIZEN_CORE_POLL_EVENT_IN)
- return true;
-
- return false;
-}
-
-static bool source_dispatch_cb(tizen_core_source_h source, void *user_data)
-{
- tizen_core_poll_fd_h poll_fd = (tizen_core_poll_fd_h)user_data;
- ssize_t bytes;
- int ret = 0;
- int fd;
-
- tizen_core_poll_fd_get_fd(poll_fd, &fd);
- bytes = read(fd, (void *)&ret, sizeof(ret));
- if (bytes < 0) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to read data. errno=%d", errno);
- } else if (bytes == 0) {
- dlog_print(DLOG_ERROR, LOG_TAG, "socket was closed. fd=%d", fd);
- tizen_core_source_destroy(source);
- } else {
- dlog_print(DLOG_INFO, LOG_TAG, "result=%d", ret);
- }
-
- return true;
-}
-
-static void source_finalize_cb(tizen_core_source_h source, void *user_data)
-{
- tizen_core_poll_fd_h poll_fd = (tizen_core_poll_fd_h)user_data;
-
- tizen_core_poll_fd_destroy(poll_fd);
-}
-
-static tizen_core_source_h create_io_source(int fd, uint16_t events)
-{
- tizen_core_source_h source = NULL;
- tizen_core_poll_fd_h poll_fd = NULL;
- tizen_core_h core = NULL;
-
- tizen_core_poll_fd_create(&poll_fd);
- tizen_core_poll_fd_set_fd(poll_fd, fd);
- tizen_core_poll_fd_set_events(poll_fd, events);
-
- tizen_core_source_create(&source);
- tizen_core_source_set_prepare_cb(source, source_prepare_cb, poll_fd);
- tizen_core_source_set_check_cb(source, source_check_cb, poll_fd);
- tizen_core_source_set_dispatch_cb(source, source_dispatch_cb, poll_fd);
- tizen_core_source_set_finalize_cb(source, source_finalize_cb, poll_fd);
-
- tizen_core_find("main", &core);
- tizen_core_add_source(core, source);
-
- return source;
-}
- * @endcode
- *
- * @see tizen_core_poll_fd_set_events()
- * @see tizen_core_poll_event_e
- */
-int tizen_core_poll_fd_get_returned_events(tizen_core_poll_fd_h poll_fd,
- uint16_t *returned_events);
-
-/**
- * @}
- */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __TIZEN_BASE_TIZEN_CORE_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __TIZEN_BASE_TIZEN_CORE_CHANNEL_H__
-#define __TIZEN_BASE_TIZEN_CORE_CHANNEL_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @file tizen_core_channel.h
- */
-
-/**
- * @addtogroup CAPI_TIZEN_CORE_CHANNEL_MODULE
- * @{
- */
-
-/**
- * @brief The tizen core channel sender handle.
- * @since_tizen 9.0
- */
-typedef void *tizen_core_channel_sender_h;
-
-/**
- * @brief The tizen core channel receiver handle.
- * @since_tizen 9.0
- */
-typedef void *tizen_core_channel_receiver_h;
-
-/**
- * @brief The tizen core channel object handle.
- * @since_tizen 9.0
- */
-typedef void *tizen_core_channel_object_h;
-
-/**
- * @brief Called when the channel object is received.
- * @since_tizen 9.0
- * @remarks The @a object must not be deallocated by the application.
- *
- * @param[in] object The tizen core channel object handle
- * @param[in] user_data The user data passed from the registration function
- * @see tizen_core_add_channel()
- */
-typedef void (*tizen_core_channel_receive_cb)(
- tizen_core_channel_object_h object, void *user_data);
-
-/**
- * @brief Makes a pair of channel sender and receiver.
- * @since_tizen 9.0
- * @remarks The @a sender should be released using tizen_core_channel_sender_destroy().
- * @remarks The @a receiver should be released using tizen_core_channel_receiver_destroy().
- *
- * @param[out] sender The tizen core channel sender handle
- * @param[out] receiver The tizen core channel receiver handle
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #TIZEN_CORE_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #TIZEN_CORE_ERROR_INVALID_CONTEXT Invalid context
- *
- * @code
-#include <tizen_core.h>
-{
- tizen_core_channel_sender_h sender = NULL;
- tizen_core_channel_receiver_h receiver = NULL;
- int ret;
-
- ret = tizen_core_channel_make_pair(&sender, &receiver);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to make channel pair");
- return;
- }
-}
- * @endcode
- *
- * @see tizen_core_channel_sender_destroy()
- * @see tizen_core_channel_receiver_destroy()
- */
-int tizen_core_channel_make_pair(tizen_core_channel_sender_h *sender,
- tizen_core_channel_receiver_h *receiver);
-
-/**
- * @brief Sends the channel object to the receiver.
- * @since_tizen 9.0
- *
- * @param[in] sender The tizen core channel sender handle
- * @param[in] object The tizen core channel object handle
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @code
-#include <tizen_core.h>
-{
- tizen_core_channel_sender_h sender = NULL;
- tizen_core_channel_receiver_h receiver = NULL;
- tizen_core_channel_object_h object = NULL;
- int ret;
-
- tizen_core_channel_make_pair(&sender, &receiver);
- tizen_core_channel_object_create(&object);
- tizen_core_channel_object_set_type(object, 22);
- tizen_core_channel_object_set_data(object, strdup("22"));
-
- int ret = tizen_core_channel_sender_send(sender, object);
- if (ret != TIZEN_CORE_ERROR_NONE)
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to send object");
-
- tizen_core_channel_object_destroy(object);
-}
- * @endcode
- *
- * @see tizen_core_channel_object_create()
- */
-int tizen_core_channel_sender_send(tizen_core_channel_sender_h sender,
- tizen_core_channel_object_h object);
-
-/**
- * @brief Destroys the channel sender handle.
- * @since_tizen 9.0
- *
- * @param[in] sender The tizen core channel sender handle
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @code
-#include <tizen_core.h>
-{
- tizen_core_channel_sender_h sender = NULL;
- tizen_core_channel_receiver_h receiver = NULL;
- int ret;
-
- tizen_core_channel_make_pair(&sender, &receiver);
- tizen_core_channel_receiver_destroy(receiver);
-
- ret = tizen_core_channel_sender_destroy(sender);
- if (ret != TIZEN_CORE_ERROR_NONE)
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to destroy channel sender");
-}
- * @endcode
- *
- * @see tizen_core_channel_make_pair()
- * @see tizen_core_channel_sender_clone()
- */
-int tizen_core_channel_sender_destroy(tizen_core_channel_sender_h sender);
-
-/**
- * @brief Creates and returns a copy of the given the @a sender handle.
- * @since_tizen 9.0
- * @remarks The @a cloned_sender should be released using tizen_core_channel_sender_destroy().
- *
- * @param[in] sender The tizen core channel sender handle
- * @param[out] cloned_sender If successful, a newly created tizen core channel sender handle will be returned
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #TIZEN_CORE_ERROR_OUT_OF_MEMORY Out of memory
- *
- * @code
-#include <tizen_core.h>
-{
- tizen_core_channel_sender_h sender = NULL;
- tizen_core_channel_sender_h cloned_sender = NULL;
- tizen_core_channel_receiver_h receiver = NULL;
- int ret;
-
- tizen_core_channel_make_pair(&sender, &receiver);
-
- ret = tizen_core_channel_sender_clone(sender, &cloned_sender);
- if (ret != TIZEN_CORE_ERROR_NONE)
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to clone channel sender");
-}
- * @endcode
- *
- * @see tizen_core_channel_sender_destroy()
- */
-int tizen_core_channel_sender_clone(tizen_core_channel_sender_h sender,
- tizen_core_channel_sender_h *cloned_sender);
-
-/**
- * @brief Receives the channel object from the sender.
- * @since_tizen 9.0
- * @remarks The @a object should be released using tizen_core_channel_object_destroy().
- *
- * @param[in] receiver The tizen core channel receiver handle
- * @param[out] object The tizen core channel object handle
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #TIZEN_CORE_ERROR_OUT_OF_MEMORY Out of memory
- *
- * @code
-#include <tizen_core.h>
-{
- tizen_core_channel_sender_h sender = NULL;
- tizen_core_channel_receiver_h receiver = NULL;
- tizen_core_channel_object_h object = NULL;
- int id = -1;
- char *data = NULL;
- int ret;
-
- tizen_core_channel_make_pair(&sender, &receiver);
- tizen_core_channel_object_create(&object);
- tizen_core_channel_object_set_id(object, 22);
- tizen_core_channel_object_set_data(object, strdup("22"));
-
- tizen_core_channel_sender_send(sender, object);
- tizen_core_channel_object_destroy(object);
- object = NULL;
-
- ret = tizen_core_channel_receiver_receive(receiver, &object);
- if (ret == TIZEN_CORE_ERROR_NONE) {
- tizen_core_channel_object_get_id(object, &id);
- tizen_core_channel_object_get_data(object, &data);
- dlog_print(DLOG_INFO, LOG_TAG, "id=%d, data=%s", id, data);
- free(data);
- tizen_core_channel_object_destroy(object);
- }
-
- tizen_core_channel_sender_destroy(sender);
- tizen_core_channel_receiver_destroy(receiver);
-}
- * @endcode
- *
- * @see tizen_core_channel_object_destroy()
- */
-int tizen_core_channel_receiver_receive(tizen_core_channel_receiver_h receiver,
- tizen_core_channel_object_h *object);
-
-/**
- * @brief Destroys the tizen core channel receiver handle.
- * @since_tizen 9.0
- *
- * @param[in] receiver The tizen core channel receiver handle
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @code
-#include <tizen_core.h>
-{
- tizen_core_channel_sender_h sender = NULL;
- tizen_core_channel_receiver_h receiver = NULL;
- int ret;
-
- tizen_core_channel_make_pair(&sender, &receiver);
- tizen_core_channel_sender_destroy(sender);
-
- ret = tizen_core_channel_receiver_destroy(receiver);
- if (ret != TIZEN_CORE_ERROR_NONE)
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to destroy channel receiver");
-}
- * @endcode
- *
- * @see tizen_core_channel_make_pair()
- */
-int tizen_core_channel_receiver_destroy(tizen_core_channel_receiver_h receiver);
-
-/**
- * @brief Creates the tizen core channel object handle.
- * @since_tizen 9.0
- * @remarks The @a object should be released using tizen_core_channel_object_destroy().
- *
- * @param[out] object The tizen core channel object handle
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #TIZEN_CORE_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #TIZEN_CORE_ERROR_INVALID_CONTEXT Invalid context
- *
- * @code
-#include <tizen_core.h>
-{
- tizen_core_channel_object_h object = NULL;
- int ret;
-
- ret = tizen_core_channel_object_create(&object);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create channel object");
- return;
- }
-
- tizen_core_channel_object_destroy(object);
-}
- * @endcode
- *
- * @see tizen_core_channel_object_destroy()
- */
-int tizen_core_channel_object_create(tizen_core_channel_object_h *object);
-
-/**
- * @brief Destroys the tizen core channel object handle.
- * @since_tizen 9.0
- *
- * @param[in] object The tizen core channel object handle
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @code
-#include <tizen_core.h>
-{
- tizen_core_channel_object_h object = NULL;
- int ret;
-
- tizen_core_channel_object_create(&object);
-
- ret = tizen_core_channel_object_destroy(object);
- if (ret != TIZEN_CORE_ERROR_NONE)
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to destroy channel object");
-}
- * @endcode
- *
- * @see tizen_core_channel_object_create()
- */
-int tizen_core_channel_object_destroy(tizen_core_channel_object_h object);
-
-/**
- * @brief Sets the ID to the tizen core channel object handle.
- * @since_tizen 9.0
- *
- * @param[in] object The tizen core channel object handle
- * @param[in] id The channel ID
- *
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @code
-#include <tizen_core.h>
-{
- tizen_core_channel_object_h object = NULL;
- int ret;
-
- tizen_core_channel_object_create(&object);
-
- ret = tizen_core_channel_object_set_id(object, 22);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to set channel type");
- tizen_core_channel_object_destroy(object);
- return;
- }
-
- tizen_core_channel_object_destroy(object);
-}
- * @endcode
- *
- * @see tizen_core_channel_object_get_type()
- */
-int tizen_core_channel_object_set_id(tizen_core_channel_object_h object,
- int id);
-
-/**
- * @brief Gets the ID from the tizen core channel object handle.
- * @since_tizen 9.0
- *
- * @param[in] object The tizen core channel object handle
- * @param[out] id The channel ID
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @code
-#include <tizen_core.h>
-{
- tizen_core_channel_object_h object = NULL;
- int id = 0;
- int ret;
-
- tizen_core_channel_object_create(&object);
- tizen_core_channel_object_set_id(object, 22);
-
- ret = tizen_core_channel_object_get_id(object, &id);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to get channel type");
- return;
- }
-
- tizen_core_channel_object_destroy(object);
-}
- * @endcode
- *
- * @see tizen_core_channel_object_set_id()
- */
-int tizen_core_channel_object_get_id(tizen_core_channel_object_h object,
- int *id);
-
-/**
- * @brief Sets the data to the tizen core channel object handle.
- * @since_tizen 9.0
- * @remarks The @a data should be released using release function
- * if the @a data is created by the memory allocation.
- *
- * @param[in] object The tizen core channel object handle
- * @param[in] data The channel data
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @code
-#include <tizen_core.h>
-{
- tizen_core_channel_object_h object = NULL;
- char *data = NULL;
- int ret;
-
- tizen_core_channel_object_create(&object);
-
- ret = tizen_core_channel_object_set_data(object, strdup("22"));
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to set channel data");
- tizen_core_channel_object_destroy(object);
- return;
- }
-
- tizen_core_channel_object_get_data(object, &data);
- free(data);
- tizen_core_channel_object_destroy(object);
-}
- * @endcode
- *
- * @see tizen_core_channel_object_get_data()
- */
-int tizen_core_channel_object_set_data(tizen_core_channel_object_h object,
- void *data);
-
-/**
- * @brief Gets the data from the tizen core channel object handle.
- * @since_tizen 9.0
- * @remarks The @a data should be released using release function.
- *
- * @param[in] object The tizen core channel object handle
- * @param[out] data The channel data
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @code
-#include <tizen_core.h>
-{
- tizen_core_channel_object_h object = NULL;
- char *data = NULL;
- int ret;
-
- tizen_core_channel_object_create(&object);
- tizen_core_channel_object_set_data(object, strdup("22"));
-
- ret = tizen_core_channel_object_get_data(object, &data);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to get channel data");
- tizen_core_channel_object_destroy(object);
- return;
- }
-
- dlog_print(DLOG_INFO, LOG_TAG, "data=%s", data);
- free(data);
- tizen_core_channel_object_destroy(object);
-}
- * @endcode
- *
- * @see tizen_core_channel_object_set_data()
- */
-int tizen_core_channel_object_get_data(tizen_core_channel_object_h object,
- void **data);
-
-/**
- * @brief Gets the sender task name from the tizen core channel object handle.
- * @since_tizen 9.0
- * @remarks The @a task_name must not be deallocated by the application.
- *
- * @param[in] object The tizen core channel object handle
- * @param[out] task_name The sender task name
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #TIZEN_CORE_ERROR_INVALID_CONTEXT Invalid context
- *
- * @code
-#include <tizen_core.h>
-
-static void print_task_name(tizen_core_channel_object_h object)
-{
- const char *task_name = NULL;
- int ret;
-
- ret = tizen_core_channel_object_get_sender_task_name(object, &task_name);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to get sender task name");
- return;
- }
-
- dlog_print(DLOG_INFO, LOG_TAG, "sender task=%s", task_name");
-}
- * @endcode
- *
- * @see tizen_core_channel_sender_send()
- * @see tizen_core_channel_receiver_receive()
- */
-int tizen_core_channel_object_get_sender_task_name(
- tizen_core_channel_object_h object, const char **task_name);
-
-/**
- * @}
- */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __TIZEN_BASE_TIZEN_CORE_CHANNEL_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __TIZEN_BASE_TIZEN_CORE_EVENT_H__
-#define __TIZEN_BASE_TIZEN_CORE_EVENT_H__
-
-#include <stdbool.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @file tizen_core_event.h
- */
-
-/**
- * @addtogroup CAPI_TIZEN_CORE_EVENT_MODULE
- * @{
- */
-
-/**
- * @brief The tizen core event handle.
- * @since_tizen 9.0
- */
-typedef void *tizen_core_event_h;
-
-/**
- * @brief The tizen core event object handle.
- * @since_tizen 9.0
- */
-typedef void *tizen_core_event_object_h;
-
-/**
- * @brief The tizen core event handler handle.
- * @since_tizen 9.0
- */
-typedef void *tizen_core_event_handler_h;
-
-/**
- * @brief Called when the event is emitted.
- * @since_tizen 9.0
- * @remarks The @a object must not be deallocated by the application.
- *
- * @param[in] object The tizen core event object handle
- * @param[in] user_data The user data passed from the callback registration function
- * @return @c true to continue with the next iteration of the loop,
- * otherwise @c false to break out of the loop
- * @see tizen_core_event_add_handler()
- */
-typedef bool (*tizen_core_event_handler_cb)(tizen_core_event_object_h object,
- void *user_data);
-
-/**
- * @brief Called when the event object is destroyed.
- * @since_tizen 9.0
- * @remarks The @a event_data should be released using release function if it's needed.
- *
- * @param[in] event_data The event data of the event object
- * @param[in] user_data The user data passed from the callback registration function
- * @see tizen_core_event_object_set_destroy_cb()
- * @see tizen_core_event_object_destroy()
- */
-typedef void (*tizen_core_event_object_destroy_cb)(void *event_data,
- void *user_data);
-
-/**
- * @brief Creates the tizen core event handle.
- * @since_tizen 9.0
- * @remarks The @a event should be released using tizen_core_event_destroy().
- *
- * @param[out] event The tizen core event handle
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #TIZEN_CORE_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #TIZEN_CORE_ERROR_INVALID_CONTEXT Invalid context
- *
- * @code
-#include <tizen_core.h>
-{
- tizen_core_event_h event = NULL;
- int ret;
-
- ret = tizen_core_event_create(&event);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create event");
- return;
- }
-
- tizen_core_event_destroy(event);
-}
- * @endcode
- *
- * @see tizen_core_event_destroy()
- */
-int tizen_core_event_create(tizen_core_event_h *event);
-
-/**
- * @brief Destroys the tizen core event handle.
- * @since_tizen 9.0
- *
- * @param[in] event The tizen core event handle
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @code
-#include <tizen_core.h>
-{
- tizen_core_event_h event = NULL;
- int ret;
-
- tizen_core_event_create(&event);
-
- ret = tizen_core_event_destroy(event);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to destroy event");
- return;
- }
-}
- * @endcode
- *
- * @see tizen_core_event_create()
- */
-int tizen_core_event_destroy(tizen_core_event_h event);
-
-/**
- * @brief Adds the event handler to the tizen core event.
- * @details The @a event_handler is added at the back of the handler list of the tizen core event.
- * When tizen_core_emit_event() is called, the @a callback function of the @a event_handler is called first.
- * @since_tizen 9.0
- * @remarks The @a event_handler should be released using tizen_core_event_remove_handler().
- *
- * @param[in] event The tizen core event handle
- * @param[in] callback The callback function to be invoked when the event is emitted
- * @param[in] user_data The user data to be passed to the callback function
- * @param[out] event_handler The tizen core event handler handle
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #TIZEN_CORE_ERROR_OUT_OF_MEMORY Out of memory
- *
- * @code
-#include <tizen_core.h>
-static void event_handler_cb(tizen_core_event_object_h object, void *user_data)
-{
- int event_id = 0;
- chat *event_data = NULL;
-
- tizen_core_event_object_get_id(object, &event_id);
- tizen_core_event_object_get_data(object, &event_data);
-
- dlog_print(DLOG_INFO, LOG_TAG, "id=%d, data=%s", event_id, event_data);
-}
-
-static void add_event_handler(tizen_core_event_h event)
-{
- tizen_core_event_handler_h event_handler = NULL;
- int ret;
-
- ret = tizen_core_event_add_handler(event, event_handler_cb, NULL, &event_handler);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to add event handler");
- return;
- }
-}
- * @endcode
- *
- * @see tizen_core_event_emit()
- * @see tizen_core_emit_event()
- * @see tizen_core_event_remove_handler()
- */
-int tizen_core_event_add_handler(
- tizen_core_event_h event, tizen_core_event_handler_cb callback,
- void *user_data, tizen_core_event_handler_h *event_handler);
-
-/**
- * @brief Prepends the event handler to the tizen core event.
- * @details The @a event_handler is added to the front of the handler list of the tizen core event.
- * When tizen_core_emit_event() is called, the @a callback function of the @a event_handler is called first.
- * @since_tizen 9.0
- * @remarks The @a event_handler should be released using tizen_core_event_remove_handler().
- *
- * @param[in] event The tizen core event handle
- * @param[in] callback The callback function to be invoked when the event is emitted
- * @param[in] user_data The user data to be passed to the callback function
- * @param[out] event_handler The tizen core event handler handle
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #TIZEN_CORE_ERROR_OUT_OF_MEMORY Out of memory
- *
- * @code
-#include <tizen_core.h>
-static void event_handler_cb(tizen_core_event_object_h object, void *user_data)
-{
- int event_id = 0;
- chat *event_data = NULL;
-
- tizen_core_event_object_get_id(object, &event_id);
- tizen_core_event_object_get_data(object, &event_data);
-
- dlog_print(DLOG_INFO, LOG_TAG, "id=%d, data=%s", event_id, data);
-}
-
-static void prepend_event_handler(tizen_core_event_h event)
-{
- tizen_core_event_handler_h event_handler = NULL;
- int ret;
-
- ret = tizen_core_event_prepend_handler(event, event_handler_cb, NULL, &event_handler);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to prepend event handler");
- return;
- }
-}
- * @endcode
- *
- * @see tizen_core_event_emit()
- * @see tizen_core_emit_event()
- * @see tizen_core_event_remove_handler()
- */
-int tizen_core_event_prepend_handler(
- tizen_core_event_h event, tizen_core_event_handler_cb callback,
- void *user_data, tizen_core_event_handler_h *event_handler);
-
-/**
- * @brief Removes the event handler from the tizen core event.
- * @since_tizen 9.0
- *
- * @param[in] event The tizen core event handle
- * @param[in] event_handler The tizen core event handler handle
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @code
-#include <tizen_core.h>
-static void remove_event_handler(tizen_core_event_h event, tizen_core_event_handler_h handler)
-{
- int ret;
-
- ret = tizen_core_event_remove_handler(event, handler);
- if (ret != TIZEN_CORE_ERROR_NONE)
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to remove event handler");
-}
- * @endcode
- *
- * @see tizen_core_event_add_handler()
- */
-int tizen_core_event_remove_handler(
- tizen_core_event_h event, tizen_core_event_handler_h event_handler);
-
-/**
- * @brief Emits the event to the tizen core event.
- * @details The event is emitted to the tizen core event.
- * @since_tizen 9.0
- * @remarks The @a object will be released automatically.
- * You MUST NOT release the @a object using tizen_core_event_object_destroy()
- * when calling the function is successful.
- * If this function returns an error, the @a object should be released
- * using tizen_core_event_object_destroy().
- *
- * @param[in] event The tizen core event handle
- * @param[in] object The tizen core event object handle
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @code
-#include <tizen_core.h>
-static void object_destroy_cb(void *event_data, void *user_data)
-{
- char* value = (char *)event_data;
-
- if (value)
- free(value);
-}
-
-static void emit_event(tizen_core_event_h event)
-{
- tizen_core_event_object_h object = NULL;
- char buf[12];
- int event_id = 99;
- int ret;
-
- snprintf(buf, sizeof(buf), "%d", event_id);
- tizen_core_event_object_create(&object, event_id, strdup(buf));
- tizen_core_event_object_set_destroy_cb(object, object_destroy_cb, NULL);
-
- ret = tizen_core_event_emit(event, object);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to emit event");
- tizen_core_event_object_destroy(object);
- return;
- }
-}
- * @endcode
- *
- * @see tizen_core_event_add_handler()
- */
-int tizen_core_event_emit(tizen_core_event_h event,
- tizen_core_event_object_h object);
-
-/**
- * @brief Creates the tizen core event object handle.
- * @details The @a data can be nullptr.
- * If the @a data is memory allocated, the @a data can be released
- * using the tizen_core_event_object_set_destroy_cb() function.
- * When tizen_core_event_object_destroy() calls, the callback function
- * set in tizen_core_event_object_set_destroy_cb() is called.
- * @since_tizen 9.0
- * @remarks The @a object should be released using tizen_core_event_object_destroy().
- * @remarks The @a object should not be released when the @a object is emitted
- * using tizen_core_event_emit().
- *
- * @param[out] object The tizen core event object handle
- * @param[in] id The event ID
- * @param[in] data The event data
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #TIZEN_CORE_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #TIZEN_CORE_ERROR_INVALID_CONTEXT Invalid context
- *
- * @code
-#include <tizen_core.h>
-
-static void object_destroy_cb(void *event_data, void *user_data)
-{
- char *value = (char *)event_data;
-
- if (value)
- free(value);
-}
-
-static tizen_core_event_object_h create_event_object(void)
-{
- tizen_core_event_object_h object = NULL;
- char buf[12];
- int event_id = 99;
- int ret;
-
- snprintf(buf, sizeof(buf), "%d", event_id);
- ret = tizen_core_event_object_create(&object, event_id, strdup(buf));
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create event object");
- return NULL;
- }
-
- tizen_core_event_object_set_destroy_cb(object, object_destroy_cb, NULL);
-
- return object;
-}
- * @endcode
- *
- * @see tizen_core_event_object_set_destroy_cb()
- * @see tizen_core_event_object_destroy()
- * @see tizen_core_event_emit()
- */
-int tizen_core_event_object_create(tizen_core_event_object_h *object,
- int id, void *data);
-
-/**
- * @brief Destroys the tizen core event object handle.
- * @since_tizen 9.0
- *
- * @param[in] object The tizen core event object handle
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @code
-#include <tizen_core.h>
-{
- tizen_core_event_object_h object = NULL;
- int event_id = 99;
- int ret;
-
- tizen_core_event_object_create(&object, event_id, NULL);
-
- ret = tizen_core_event_object_destroy(object);
- if (ret != TIZEN_CORE_ERROR_NONE)
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to destroy event object");
-}
- * @endcode
- *
- * @see tizen_core_event_object_create()
- * @see tizen_core_event_object_set_destroy_cb()
- */
-int tizen_core_event_object_destroy(tizen_core_event_object_h object);
-
-/**
- * @brief Sets the destroy callback function to invoke when the event object is destroyed.
- * @since_tizen 9.0
- *
- * @param[in] object The tizen core event object handle
- * @param[in] callback The callback function to be invoked when the event object is destroyed
- * @param[in] user_data The user data to be passed to the callback function
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @code
-#include <tizen_core.h>
-static void object_destroy_cb(void *data, void *user_data)
-{
- char *str = (char *)data;
-
- if (str)
- free(str);
-}
-
-static tizen_core_event_object_h create_event_object(int id, char *str)
-{
- tizen_core_event_object_h object = NULL;
- int ret;
-
- tizen_core_event_object_create(&object, id, str);
-
- ret = tizen_core_event_object_set_destroy_cb(object, object_destroy_cb, NULL);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to set on_destroy callback");
- tizen_core_event_object_destroy(object);
- return NULL;
- }
-
- return object;
-}
- * @endcode
- *
- * @see tizen_core_event_object_destroy()
- */
-int tizen_core_event_object_set_destroy_cb(
- tizen_core_event_object_h object,
- tizen_core_event_object_destroy_cb callback, void *user_data);
-
-/**
- * @brief Gets the event ID from the tizen core event object handle.
- * @since_tizen 9.0
- *
- * @param[in] object The tizen core event object handle
- * @param[out] id The event ID
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @code
-#include <tizen_core.h>
-{
- tizen_core_event_object_h object = NULL;
- int event_id;
- int ret;
-
- tizen_core_event_object_create(&object, 22, NULL);
-
- ret = tizen_core_event_object_get_id(object, &event_id);
- if (ret != TIZEN_CORE_ERROR_NONE)
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to get event id");
-
- tizen_core_event_object_destroy(object);
-}
- * @endcode
- *
- * @see tizen_core_event_object_create()
- */
-int tizen_core_event_object_get_id(tizen_core_event_object_h object, int *id);
-
-/**
- * @brief Gets the event data from the tizen core event object handle.
- * @since_tizen 9.0
- * @remarks The @a data should not be released if the @a object is emitted
- * using tizen_core_event_emit().
- * @remarks The @a data is available until the @a object is released.
- *
- * @param[in] object The tizen core event object handle
- * @param[out] data The event data
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @code
-#include <tizen_core.h>
-static void event_object_destroy_cb(void *event_data, void *user_data)
-{
- char *value = (char *)event_data;
-
- if (value)
- free(value);
-}
-
-static void create_and_destroy_event_object(void)
-{
- tizen_core_event_object_h object = NULL;
- char *event_data = strdup("22");
- char *value = NULL;
- int ret;
-
- tizen_core_event_object_create(&object, 22, event_data);
- tizen_core_event_object_set_destroy_cb(object, event_object_destroy_cb, NULL);
-
- ret = tizen_core_event_object_get_data(object, &value);
- if (ret != TIZEN_CORE_ERROR_NONE)
- dlog_print(DLOG_ERROR, LOG_TAG, "Failed to get event data");
-
- tizen_core_event_object_destroy(object);
-}
- * @endcode
- */
-int tizen_core_event_object_get_data(tizen_core_event_object_h object,
- void **data);
-
-/**
- * @}
- */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __TIZEN_BASE_TIZEN_CORE_EVENT_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __TIZEN_BASE_TIZEN_CORE_EVENT_INTERNAL_H__
-#define __TIZEN_BASE_TIZEN_CORE_EVENT_INTERNAL_H__
-
-#include <tizen_core.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @brief Generates the event ID.
- * @since_tizen 9.0
- *
- * @return @c the generated event ID
- *
- * @code
-#include <tizen_core.h>
-{
- tizen_core_event_object_h object = NULL;
- int id;
-
- id = tizen_core_event_generate_id();
- tizen_core_event_object_create(&object, id, NULL);
-}
- * @endcode
- */
-int tizen_core_event_generate_id(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __TIZEN_BASE_TIZEN_CORE_EVENT_INTERNAL_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __TIZEN_BASE_TIZEN_CORE_INTERNAL_H__
-#define __TIZEN_BASE_TIZEN_CORE_INTERNAL_H__
-
-#include <tizen_core.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @brief Enumeration for the tizen core cpu boosting level.
- * @since_tizen 9.0
- */
-typedef enum {
- TIZEN_CORE_CPU_BOOSTING_LEVEL_NONE, /**< None level */
- TIZEN_CORE_CPU_BOOSTING_LEVEL_STRONG, /**< Strong level */
- TIZEN_CORE_CPU_BOOSTING_LEVEL_MEDIUM, /**< Medium level */
- TIZEN_CORE_CPU_BOOSTING_LEVEL_WEAK, /**< Weak level */
-} tizen_core_cpu_boosting_level_e;
-
-/**
- * @brief Gets the glib context from the tizen core handle.
- * @since_tizen 9.0
- *
- * @param[in] core The tizen core handle
- * @return @c the glib context on success,
- * otherwise a nullptr
- */
-void *tizen_core_get_glib_context(tizen_core_h core);
-
-/**
- * @brief Sets cpu boosting of the tizen core.
- * @since_tizen 9.0
- *
- * @param[in] core The tizen core handle
- * @param[in] level The cpu boosting level
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #TIZEN_CORE_ERROR_INVALID_CONTEXT The core is not running
- *
- * @code
-#include <tizen_core_internal.h>
-{
- tizen_core_h core = NULL;
- int ret;
-
- ret = tizen_core_find("main", &core);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- return -1;
- }
-
- ret = tizen_core_set_cpu_boosting(core, TIZEN_CORE_CPU_BOOSTING_LEVEL_STRONG);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- return -1;
- }
-
- return 0;
-}
- * @endcode
- * @see tizen_core_clear_cpu_boosting()
- */
-int tizen_core_set_cpu_boosting(tizen_core_h core,
- tizen_core_cpu_boosting_level_e level);
-
-/**
- * @brief Clears cpu boosting of the tizen core.
- * @since_tizen 9.0
- *
- * @param[in] core The tizen core handle
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #TIZEN_CORE_ERROR_NONE Successful
- * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #TIZEN_CORE_ERROR_INVALID_CONTEXT The core is not running
- *
- * @code
-#include <tizen_core_internal.h>
-{
- tizen_core_h core = NULL;
- int ret;
-
- ret = tizen_core_find("main", &core);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- return -1;
- }
-
- ret = tizen_core_clear_cpu_boosting(core);
- if (ret != TIZEN_CORE_ERROR_NONE) {
- return -1;
- }
-
- return 0;
-}
- * @endcode
- * @see tizen_core_set_cpu_boosting()
- */
-int tizen_core_clear_cpu_boosting(tizen_core_h core);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __TIZEN_BASE_TIZEN_CORE_INTERNAL_H__ */
%__make %{?jobs:-j%jobs}
%check
-export LD_LIBRARY_PATH="../../tizen_base"
+export LD_LIBRARY_PATH="../../src/tizen-core"
ctest --verbose %{?_smp_mflags}
%if 0%{?gcov:1}
lcov -c --ignore-errors mismatch,graph,unused --no-external -b . -d . -o %{name}.info
--- /dev/null
+ADD_SUBDIRECTORY(tizen-core)
\ No newline at end of file
--- /dev/null
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} TIZEN_CORE_SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/channel TIZEN_CORE_CHANNEL_SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/event TIZEN_CORE_EVENT_SRCS)
+
+ADD_LIBRARY(${TARGET_TIZEN_CORE} SHARED
+ ${TIZEN_CORE_SRCS}
+ ${TIZEN_CORE_CHANNEL_SRCS}
+ ${TIZEN_CORE_EVENT_SRCS})
+
+SET_TARGET_PROPERTIES(${TARGET_TIZEN_CORE} PROPERTIES SOVERSION ${MAJORVER})
+SET_TARGET_PROPERTIES(${TARGET_TIZEN_CORE} PROPERTIES VERSION ${FULLVER})
+
+TARGET_INCLUDE_DIRECTORIES(${TARGET_TIZEN_CORE} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}/../
+ ${CMAKE_CURRENT_SOURCE_DIR}/channel/
+ ${CMAKE_CURRENT_SOURCE_DIR}/event/
+ ${CMAKE_CURRENT_SOURCE_DIR}/include/)
+
+APPLY_PKG_CONFIG(${TARGET_TIZEN_CORE} PUBLIC
+ DLOG_DEPS
+ GLIB_DEPS
+ CAPI_BASE_COMMON_DEPS
+ TIZEN_SHARED_QUEUE_DEPS
+ CAPI_SYSTEM_RESOURCE_DEPS
+)
+
+INSTALL(TARGETS ${TARGET_TIZEN_CORE} DESTINATION ${LIB_INSTALL_DIR})
+
+CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/${TARGET_TIZEN_CORE}.pc.in
+ ${CMAKE_CURRENT_SOURCE_DIR}/${TARGET_TIZEN_CORE}.pc @ONLY)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${TARGET_TIZEN_CORE}.pc
+ DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
+
+INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/
+ DESTINATION include/tizen-core
+ FILES_MATCHING
+ PATTERN "*_private.h" EXCLUDE
+ PATTERN "include/*.h*")
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef TIZEN_CORE_CHANNEL_CHANNEL_BROKER_H_
+#define TIZEN_CORE_CHANNEL_CHANNEL_BROKER_H_
+
+#include <memory>
+#include <utility>
+
+#include <shared-queue.hpp>
+
+#include "tizen-core/event_fd.h"
+#include "tizen-core/channel/channel_object.h"
+
+#undef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+
+namespace tizen_core {
+namespace channel {
+
+template <class T>
+class EXPORT_API ChannelBroker : public EventFd {
+ public:
+ ChannelBroker() = default;
+ virtual ~ChannelBroker() = default;
+
+ void Send(ChannelObject<T> object) {
+ queue_.Push(std::move(object));
+ Write(queue_.Size());
+ }
+
+ ChannelObject<T> Receive() {
+ uint64_t value = 0;
+ Read(&value);
+ return queue_.WaitAndPop();
+ }
+
+ bool Empty() const { return queue_.IsEmpty(); }
+
+ private:
+ tizen_base::SharedQueue<ChannelObject<T>> queue_;
+};
+
+} // namespace channel
+} // namespace tizen_core
+
+#endif // TIZEN_CORE_CHANNEL_CHANNEL_BROKER_H_
--- /dev/null
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef TIZEN_CORE_CHANNEL_CHANNEL_FACTORY_H_
+#define TIZEN_CORE_CHANNEL_CHANNEL_FACTORY_H_
+
+#include <memory>
+#include <utility>
+
+#include <shared-queue.hpp>
+
+#include "tizen-core/channel/channel_broker.h"
+#include "tizen-core/channel/receiver.h"
+#include "tizen-core/channel/sender.h"
+
+#undef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+
+namespace tizen_core {
+namespace channel {
+
+class EXPORT_API ChannelFactory {
+ public:
+ template <typename T>
+ static std::pair<std::shared_ptr<Sender<T>>, std::shared_ptr<Receiver<T>>>
+ MakePair() {
+ std::shared_ptr<ChannelBroker<T>> broker(new ChannelBroker<T>());
+ return {std::make_shared<Sender<T>>(broker),
+ std::make_shared<Receiver<T>>(broker)};
+ }
+};
+
+} // namespace channel
+} // namespace tizen_core
+
+#endif // TIZEN_CORE_CHANNEL_CHANNEL_FACTORY_H_
--- /dev/null
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef TIZEN_CORE_CHANNEL_CHANNEL_OBJECT_H_
+#define TIZEN_CORE_CHANNEL_CHANNEL_OBJECT_H_
+
+#include <string>
+#include <utility>
+
+#undef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+
+namespace tizen_core {
+namespace channel {
+
+template <typename T>
+class EXPORT_API ChannelObject {
+ public:
+ ChannelObject() : id_(0) {}
+ ChannelObject(int id, T data) : id_(id), data_(data) {}
+
+ void SetId(int id) {
+ id_ = id;
+ }
+
+ int GetId() const {
+ return id_;
+ }
+
+ void SetData(T data) {
+ data_ = data;
+ }
+
+ T GetData() const {
+ return data_;
+ }
+
+ void SetSender(std::string sender) {
+ sender_ = std::move(sender);
+ }
+
+ const std::string& GetSender() const {
+ return sender_;
+ }
+
+ private:
+ int id_;
+ T data_;
+ std::string sender_;
+};
+
+} // namespace channel
+} // namespace tizen_core
+
+#endif // TIZEN_CORE_CHANNEL_CHANNEL_OBJECT_H_
--- /dev/null
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef TIZEN_CORE_CHANNEL_RECEIVER_H_
+#define TIZEN_CORE_CHANNEL_RECEIVER_H_
+
+#include <functional>
+#include <memory>
+#include <utility>
+
+#include "tizen-core/context.h"
+#include "tizen-core/channel/channel_broker.h"
+
+#undef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+
+namespace tizen_core {
+namespace channel {
+
+template <typename T>
+class EXPORT_API Receiver : public std::enable_shared_from_this<Receiver<T>> {
+ public:
+ explicit Receiver(std::shared_ptr<ChannelBroker<T>> broker)
+ : broker_(std::move(broker)) {}
+
+ ChannelObject<T> Receive() { return broker_->Receive(); }
+
+ bool Empty() const { return broker_->Empty(); }
+
+ int GetFd() const { return broker_->GetFd(); }
+
+ void RefSelf() { self_ = this->shared_from_this(); }
+
+ void UnrefSelf() { self_.reset(); }
+
+ private:
+ std::shared_ptr<ChannelBroker<T>> broker_;
+ std::weak_ptr<Context> context_;
+ std::shared_ptr<Receiver<T>> self_;
+};
+
+} // namespace channel
+} // namespace tizen_core
+
+#endif // TIZEN_CORE_CHANNEL_RECEIVER_H_
--- /dev/null
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef TIZEN_CORE_CHANNEL_SENDER_H_
+#define TIZEN_CORE_CHANNEL_SENDER_H_
+
+#include <memory>
+#include <utility>
+
+#include "tizen-core/channel/channel_broker.h"
+#include "tizen-core/context_manager.h"
+
+#undef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+
+namespace tizen_core {
+namespace channel {
+
+template <typename T>
+class EXPORT_API Sender : public std::enable_shared_from_this<Sender<T>> {
+ public:
+ explicit Sender(std::shared_ptr<ChannelBroker<T>> broker)
+ : broker_(std::move(broker)) {}
+
+ void Send(ChannelObject<T> object) {
+ auto context = ContextManager::GetInst().FindFromThisThread();
+ if (context != nullptr)
+ object.SetSender(context->GetName());
+
+ broker_->Send(std::move(object));
+ }
+
+ void RefSelf() { self_ = this->shared_from_this(); }
+ void UnrefSelf() { self_.reset(); }
+
+ private:
+ std::shared_ptr<ChannelBroker<T>> broker_;
+ std::shared_ptr<Sender<T>> self_;
+};
+
+} // namespace channel
+} // namespace tizen_core
+
+#endif // TIZEN_CORE_CHANNEL_SENDER_H_
--- /dev/null
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "tizen-core/context.h"
+
+#include <utility>
+
+#include "tizen-core/log_private.h"
+
+namespace tizen_core {
+
+Context::Context(std::string name, bool use_thread)
+ : name_(std::move(name)),
+ handle_(use_thread ? g_main_context_new() : nullptr) {
+ if (handle_ == nullptr)
+ handle_ = g_main_context_ref(g_main_context_default());
+}
+
+Context::~Context() {
+ if (handle_ != nullptr)
+ g_main_context_unref(handle_);
+}
+
+// LCOV_EXCL_START
+Context::Context(const Context& ctx) {
+ name_ = ctx.name_;
+ loop_ = ctx.loop_;
+ handle_ = g_main_context_ref(ctx.handle_);
+}
+
+Context& Context::operator = (const Context& ctx) {
+ if (this != &ctx) {
+ name_ = ctx.name_;
+ loop_ = ctx.loop_;
+
+ if (handle_ != nullptr)
+ g_main_context_unref(handle_);
+
+ handle_ = g_main_context_ref(ctx.handle_);
+ }
+
+ return *this;
+}
+
+Context::Context(Context&& ctx) noexcept {
+ name_ = std::move(ctx.name_);
+ loop_ = std::move(ctx.loop_);
+ handle_ = ctx.handle_;
+ if (ctx.handle_ != nullptr)
+ ctx.handle_ = g_main_context_new();
+}
+
+Context& Context::operator = (Context&& ctx) noexcept {
+ if (this != &ctx) {
+ name_ = std::move(ctx.name_);
+ loop_ = std::move(ctx.loop_);
+ handle_ = ctx.handle_;
+ if (ctx.handle_ != nullptr)
+ ctx.handle_ = g_main_context_new();
+ }
+
+ return *this;
+}
+// LCOV_EXCL_STOP
+
+void Context::SetLoop(std::shared_ptr<ILoop> loop) {
+ loop_ = std::move(loop);
+}
+
+std::shared_ptr<ILoop> Context::GetLoop() const {
+ return loop_;
+}
+
+const std::string& Context::GetName() const {
+ return name_;
+}
+
+GMainContext* Context::GetHandle() const {
+ return handle_;
+}
+
+} // namespace tizen_core
--- /dev/null
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef TIZEN_CORE_CONTEXT_H_
+#define TIZEN_CORE_CONTEXT_H_
+
+#include <glib.h>
+
+#include <functional>
+#include <memory>
+#include <string>
+
+#include "tizen-core/interface_loop.h"
+
+#undef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+
+namespace tizen_core {
+
+class EXPORT_API Context {
+ public:
+ Context(std::string name, bool use_thread);
+ virtual ~Context();
+
+ Context(const Context& ctx);
+ Context& operator = (const Context& ctx);
+
+ Context(Context&& ctx) noexcept;
+ Context& operator = (Context&& ctx) noexcept;
+
+ void SetLoop(std::shared_ptr<ILoop> loop);
+ std::shared_ptr<ILoop> GetLoop() const;
+ const std::string& GetName() const;
+ GMainContext* GetHandle() const;
+
+ private:
+ std::string name_;
+ GMainContext* handle_ = nullptr;
+ std::shared_ptr<ILoop> loop_ = nullptr;
+};
+
+} // namespace tizen_core
+
+#endif // TIZEN_CORE_CONTEXT_H_
--- /dev/null
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "tizen-core/context_manager.h"
+
+#include <atomic>
+#include <utility>
+
+#include "tizen-core/log_private.h"
+
+namespace tizen_core {
+
+ContextManager& ContextManager::GetInst() {
+ static std::atomic<ContextManager*> inst_;
+ static std::mutex mutex_;
+ static ContextManager* inst = inst_.load(std::memory_order_acquire);
+ if (inst == nullptr) {
+ std::lock_guard<std::mutex> lock(mutex_);
+ inst = inst_.load(std::memory_order_relaxed);
+ if (inst == nullptr) {
+ inst = new ContextManager();
+ inst_.store(inst, std::memory_order_release);
+ }
+ }
+
+ return *inst;
+}
+
+std::shared_ptr<Context> ContextManager::Create(std::string name,
+ bool use_thread) {
+ auto context = std::make_shared<Context>(name, use_thread);
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ contexts_[std::move(name)] = context;
+ return context;
+}
+
+void ContextManager::Dispose(const std::string& name) {
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ auto found = contexts_.find(name);
+ if (found == contexts_.end())
+ return;
+
+ contexts_.erase(found);
+}
+
+std::shared_ptr<Context> ContextManager::Find(const std::string& name) {
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ auto found = contexts_.find(name);
+ if (found == contexts_.end())
+ return nullptr;
+
+ return found->second;
+}
+
+std::shared_ptr<Context> ContextManager::FindFromThisThread() {
+ auto handle = g_main_context_get_thread_default();
+ if (handle == nullptr) {
+ _W("Use default context");
+ handle = g_main_context_default();
+ }
+
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ for (const auto& iter : contexts_) {
+ auto& context = iter.second;
+ if (context->GetHandle() == handle)
+ return context;
+ }
+
+ return nullptr;
+}
+
+void ContextManager::DisposeAll() {
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ contexts_.clear();
+}
+
+} // namespace tizen_core
--- /dev/null
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef TIZEN_CORE_CONTEXT_MANAGER_H_
+#define TIZEN_CORE_CONTEXT_MANAGER_H_
+
+#include <functional>
+#include <memory>
+#include <mutex>
+#include <string>
+#include <unordered_map>
+
+#include "tizen-core/context.h"
+
+namespace tizen_core {
+
+class ContextManager {
+ public:
+ static ContextManager& GetInst();
+
+ std::shared_ptr<Context> Create(std::string name, bool use_thread = true);
+ void Dispose(const std::string& name);
+ std::shared_ptr<Context> Find(const std::string& name);
+ std::shared_ptr<Context> FindFromThisThread();
+ void DisposeAll();
+
+ private:
+ std::unordered_map<std::string, std::shared_ptr<Context>> contexts_;
+ mutable std::recursive_mutex mutex_;
+};
+
+} // namespace tizen_core
+
+#endif // TIZEN_CORE_CONTEXT_MANAGER_H_
--- /dev/null
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef TIZEN_CORE_EVENT_EVENT_BROKER_H_
+#define TIZEN_CORE_EVENT_EVENT_BROKER_H_
+
+#include <functional>
+#include <list>
+#include <memory>
+#include <unordered_map>
+#include <utility>
+
+#include <shared-queue.hpp>
+
+#include "tizen-core/event_fd.h"
+#include "tizen-core/event/event_object.h"
+#include "tizen-core/event/event_handler.h"
+
+#undef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+
+namespace tizen_core {
+namespace event {
+
+template <class T>
+class EXPORT_API EventBroker : public EventFd {
+ public:
+ EventBroker() = default;
+ virtual ~EventBroker() = default;
+
+ void AddHandler(std::shared_ptr<EventHandler<T>> handler) {
+ handlers_.push_back(std::move(handler));
+ }
+
+ void PrependHandler(std::shared_ptr<EventHandler<T>> handler) {
+ handlers_.push_front(std::move(handler));
+ }
+
+ void RemoveHandler(std::shared_ptr<EventHandler<T>> handler) {
+ handlers_.remove_if([&](const std::shared_ptr<EventHandler<T>>& event) {
+ return event == handler;
+ });
+ }
+
+ void Process() {
+ uint64_t value = 0;
+ Read(&value);
+ auto object = queue_.WaitAndPop();
+ if (!object)
+ return;
+
+ auto iter = handlers_.begin();
+ while (iter != handlers_.end()) {
+ auto handler = *iter;
+ iter++;
+ if (!handler->OnEventReceived(object.get()))
+ break;
+ }
+ }
+
+ void Emit(std::shared_ptr<EventObject<T>> object) {
+ queue_.Push(std::move(object));
+ Write(queue_.Size());
+ }
+
+ bool Empty() const { return queue_.IsEmpty(); }
+
+ void SetAttached(bool attached) { attached_ = attached; }
+
+ bool IsAttached() const { return attached_; }
+
+ private:
+ bool attached_ = false;
+ std::list<std::shared_ptr<EventHandler<T>>> handlers_;
+ tizen_base::SharedQueue<std::shared_ptr<EventObject<T>>> queue_;
+};
+
+} // namespace event
+} // namespace tizen_core
+
+#endif // TIZEN_CORE_EVENT_EVENT_BROKER_H_
--- /dev/null
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef TIZEN_CORE_EVENT_EVENT_HANDLER_H_
+#define TIZEN_CORE_EVENT_EVENT_HANDLER_H_
+
+#include "tizen-core/event/event_object.h"
+
+#undef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+
+namespace tizen_core {
+namespace event {
+
+template <class T>
+class EXPORT_API EventHandler {
+ public:
+ virtual ~EventHandler() = default;
+ virtual bool OnEventReceived(EventObject<T>* obj) = 0;
+};
+
+} // namespace event
+} // namespace tizen_core
+
+#endif // TIZEN_CORE_EVENT_EVENT_HANDLER_H_
--- /dev/null
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef TIZEN_CORE_EVENT_EVENT_OBJECT_H_
+#define TIZEN_CORE_EVENT_EVENT_OBJECT_H_
+
+#include <atomic>
+#include <memory>
+
+#undef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+
+namespace tizen_core {
+namespace event {
+
+template <typename T>
+class EXPORT_API EventObject
+ : public std::enable_shared_from_this<EventObject<T>> {
+ public:
+ EventObject() : id_(0) {}
+ EventObject(int id, T data) : id_(id), data_(data) {}
+ virtual ~EventObject() = default;
+
+ void SetId(int id) {
+ id_ = id;
+ }
+
+ int GetId() const {
+ return id_;
+ }
+
+ void SetData(T data) {
+ data_ = data;
+ }
+
+ T GetData() const {
+ return data_;
+ }
+
+ void Ref() {
+ if (++ref_count_ == 1)
+ self_ = this->shared_from_this();
+ }
+
+ void Unref() {
+ if (--ref_count_ == 0)
+ self_.reset();
+ }
+
+ private:
+ int id_;
+ T data_;
+ std::atomic<uint32_t> ref_count_ { 0 };
+ std::shared_ptr<EventObject<T>> self_;
+};
+
+} // namespace event
+} // namespace tizen_core
+
+#endif // TIZEN_CORE_EVENT_EVENT_OBJECT_H_
--- /dev/null
+/*
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "tizen-core/event_fd.h"
+
+#include <utility>
+
+#include "tizen-core/log_private.h"
+
+namespace tizen_core {
+
+EventFd::EventFd() {
+ fd_ = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
+ if (fd_ < 0) throw std::runtime_error("Failed to create eventfd");
+}
+
+EventFd::~EventFd() { Close(); }
+
+void EventFd::Close() {
+ if (fd_ > -1) {
+ close(fd_);
+ fd_ = -1;
+ }
+}
+
+int EventFd::GetFd() const { return fd_; }
+
+void EventFd::Write(uint64_t value) {
+ if (eventfd_write(fd_, static_cast<eventfd_t>(value)) < 0)
+ _E("Failed to write data. errno=%d", errno);
+}
+
+void EventFd::Read(uint64_t* value) {
+ if (eventfd_read(fd_, static_cast<eventfd_t*>(value)) < 0)
+ _E("Failed to read data. errno=%d", errno);
+}
+
+} // namespace tizen_core
--- /dev/null
+/*
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef TIZEN_CORE_EVENT_FD_H_
+#define TIZEN_CORE_EVENT_FD_H_
+
+#include <sys/eventfd.h>
+#include <unistd.h>
+
+#include <stdexcept>
+
+#undef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+
+namespace tizen_core {
+
+class EXPORT_API EventFd {
+ public:
+ EventFd();
+ virtual ~EventFd();
+
+ void Close();
+ int GetFd() const;
+ void Write(uint64_t value);
+ void Read(uint64_t* value);
+
+ private:
+ int fd_ = -1;
+};
+
+} // namespace tizen_core
+
+#endif // TIZEN_CORE_EVENT_FD_H_
--- /dev/null
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __TIZEN_BASE_TIZEN_CORE_H__
+#define __TIZEN_BASE_TIZEN_CORE_H__
+
+#include <stdbool.h>
+#include <stdint.h>
+#include <tizen_error.h>
+#include <poll.h>
+
+#include <tizen_core_channel.h>
+#include <tizen_core_event.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file tizen_core.h
+ */
+
+/**
+ * @addtogroup CAPI_TIZEN_CORE_MODULE
+ * @{
+ */
+
+/**
+ * @brief Enumeration for the tizen core result.
+ * @since_tizen 9.0
+ */
+typedef enum {
+ TIZEN_CORE_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
+ TIZEN_CORE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
+ TIZEN_CORE_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
+ TIZEN_CORE_ERROR_INVALID_CONTEXT = TIZEN_ERROR_APPLICATION | 0x01, /**< Invalid context */
+} tizen_core_error_e;
+
+/**
+ * @brief Enumeration for the priority of tizen core source.
+ * @since_tizen 9.0
+ */
+typedef enum {
+ TIZEN_CORE_PRIORITY_HIGH = -100, /**< High priority */
+ TIZEN_CORE_PRIORITY_DEFAULT = 0, /**< Default priority */
+ TIZEN_CORE_PRIORITY_HIGH_IDLE = 100, /**< High idle priority */
+ TIZEN_CORE_PRIORITY_DEFAULT_IDLE = 200, /**< Default idle priority */
+ TIZEN_CORE_PRIORITY_LOW = 300, /**< Low priority */
+} tizen_core_priority_e;
+
+/**
+ * @brief Enumeration for the event of tizen core poll fd.
+ * @since_tizen 9.0
+ * @see tizen_core_poll_fd_set_events()
+ * @see tizen_core_poll_fd_get_events()
+ * @see tizen_core_poll_fd_set_returned_events()
+ * @see tizen_core_poll_fd_get_returned_events()
+ */
+typedef enum {
+ TIZEN_CORE_POLL_EVENT_IN = POLLIN, /**< There is data to read */
+ TIZEN_CORE_POLL_EVENT_PRI = POLLPRI, /**< There is some exceptional condition on the file descriptor */
+ TIZEN_CORE_POLL_EVENT_OUT = POLLOUT, /**< Writing is now possible */
+ TIZEN_CORE_POLL_EVENT_ERR = POLLERR, /**< Error condition */
+ TIZEN_CORE_POLL_EVENT_HUP = POLLHUP, /**< Hang up */
+ TIZEN_CORE_POLL_EVENT_NVAL = POLLNVAL, /**< Invalid request: fd not open */
+} tizen_core_poll_event_e;
+
+/**
+ * @brief The tizen core handle.
+ * @since_tizen 9.0
+ */
+typedef void *tizen_core_h;
+
+
+/**
+ * @brief The tizen core task handle.
+ * @since_tizen 9.0
+ */
+typedef void *tizen_core_task_h;
+
+/**
+ * @brief The tizen core source handle.
+ * @since_tizen 9.0
+ */
+typedef void *tizen_core_source_h;
+
+/**
+ * @brief The tizen core poll fd handle.
+ * @since_tizen 9.0
+ */
+typedef void *tizen_core_poll_fd_h;
+
+/**
+ * @brief Called when the channel object is received.
+ * @since_tizen 9.0
+ * @remarks The @a object must not be deallocated by the application.
+ *
+ * @param[in] object The tizen core channel object handle
+ * @param[in] user_data The user data passed from the registration function
+ * @see tizen_core_add_channel()
+ */
+typedef void (*tizen_core_channel_receive_cb)(
+ tizen_core_channel_object_h object, void *user_data);
+
+/**
+ * @brief Called when the tizen core idle or timer event is emitted.
+ * @since_tizen 9.0
+ *
+ * @param[in] user_data The user data passed from the callback registration function
+ * @return @c true to repeat calling the callback function,
+ * otherwise @c false to remove the added source.
+ * @see tizen_core_add_idle_job()
+ * @see tizen_core_add_timer()
+ */
+typedef bool (*tizen_core_task_cb)(void *user_data);
+
+/**
+ * @brief Called before all file descriptors are polled.
+ * @details The @a source is the same object for which the callback was set.
+ * @details The function returns a timeout value to ensure that the poll()
+ * call doesn't block too long and miss the next timeout.
+ * The timeout value is -1 to indicate that it doesn't mind how long
+ * the poll() call blocks.
+ * @since_tizen 9.0
+ * @remarks The @a source should be released using tizen_core_source_destroy() when no longer needed.
+ * The @a timeout should not be released. The @a timeout can be used only in the callback.
+ *
+ * @param[in] source The tizen core source handle
+ * @param[out] timeout The timeout
+ * @param[in] user_data The user data passed from the callback registration function
+ * @return @c true to indicate that the source is always ready to be processed,
+ * otherwise @c false to wait until poll() has been called before it knows whether any events need to be processed.
+ * @see tizen_core_source_set_prepare_cb()
+ */
+typedef bool (*tizen_core_source_prepare_cb)(tizen_core_source_h source,
+ int *timeout, void *user_data);
+
+/**
+ * @brief Called when checks whether the source is ready to be processed or not.
+ * @details The @a source is the same object for which the callback was set.
+ * @details The function should return 'true' if it's ready to be dispatched.
+ * @since_tizen 9.0
+ * @remarks The @a source should be released using tizen_core_source_destroy() when no longer needed.
+ *
+ * @param[in] source The tizen core source handle
+ * @param[in] user_data The user data passed from the callback registration function
+ * @return @c true to indicate that the source is always ready to be processed,
+ * otherwise @c false to indicate that the source is not ready to be processed.
+ * @see tizen_core_source_set_check_cb()
+ */
+typedef bool (*tizen_core_source_check_cb)(tizen_core_source_h source,
+ void *user_data);
+
+/**
+ * @brief Called when dispatches events.
+ * @details The @a source is the same object for which the callback was set.
+ * @since_tizen 9.0
+ * @remarks The @a source should be released using tizen_core_source_destroy() when no longer needed.
+ *
+ * @param[in] source The tizen core source handle
+ * @param[in] user_data The user data passed from the callback registration function
+ * @return @c true to indicate that the process is ready to dispatch the event.
+ * @see tizen_core_source_set_dispatch_cb()
+ */
+typedef bool (*tizen_core_source_dispatch_cb)(tizen_core_source_h source,
+ void *user_data);
+
+/**
+ * @brief Called when the source is finalized.
+ * @details The @a source is the same object for which the callback was set.
+ * @since_tizen 9.0
+ * @remarks The @a source should not be released. The @a source is managed by the platform.
+ * @remarks The @a source is managed by the platform and will be released when the callback returns.
+ *
+ * @param[in] source The tizen core source handle
+ * @param[in] user_data The user data passed from the callback registration function
+ * @see tizen_core_source_set_finalize_cb()
+ */
+typedef void (*tizen_core_source_finalize_cb)(tizen_core_source_h source,
+ void *user_data);
+
+/**
+ * @brief Initializes the tizen core.
+ * @since_tizen 9.0
+ *
+ * @see tizen_core_shutdown()
+ * @see tizen_core_ready()
+ */
+void tizen_core_init(void);
+
+/**
+ * @brief Shutdowns the tizen core.
+ * @since_tizen 9.0
+ *
+ * @see tizen_core_init()
+ * @see tizen_core_ready()
+ */
+void tizen_core_shutdown(void);
+
+/**
+ * @brief Checks whether the tizen core is ready or not.
+ * @since_tizen 9.0
+ *
+ * @return @c true if the tizen core is ready, otherwise @c false.
+ *
+ * @see tizen_core_init()
+ * @see tizen_core_shutdown()
+ */
+bool tizen_core_ready(void);
+
+/**
+ * @brief Creates the tizen core task handle.
+ * @details If the @a name is "main", the @a use_thread should be set to 'false'.
+ * Otherwise, it returns #TIZEN_CORE_ERROR_INVALID_PARAMETER.
+ * @since_tizen 9.0
+ * @remarks The @a task should be released using tizen_core_task_destroy().
+ *
+ * @param[in] name The name of the task
+ * @param[in] use_thread true, if the task should be run in a separate thread, otherwise @c false
+ * @param[out] task The tizen core task handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #TIZEN_CORE_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #TIZEN_CORE_ERROR_INVALID_CONTEXT Invalid context
+ *
+ * @code
+#include <tizen_core.h>
+{
+ tizen_core_task_h task = NULL;
+ int ret;
+
+ tizen_core_init();
+ ret = tizen_core_task_create("main", false, &task);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ tizen_core_shutdown();
+ return -1;
+ }
+}
+ * @endcode
+ *
+ * @see tizen_core_task_destroy()
+ */
+int tizen_core_task_create(const char *name, bool use_thread,
+ tizen_core_task_h *task);
+
+/**
+ * @brief Destroys the tizen core task handle.
+ * @since_tizen 9.0
+ *
+ * @param[in] task The tizen core task handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @code
+#include <tizen_core.h>
+{
+ tizen_core_task_h task = NULL;
+ int ret;
+
+ tizen_core_init();
+ ret = tizen_core_task_create("main", false, &task);
+ if (ret != TIZEN_CORE_ERROR_NONE)
+ return ret;
+
+ ret = tizen_core_task_destroy(task);
+ if (ret != TIZEN_CORE_ERROR_NONE)
+ return ret;
+}
+ * @endcode
+ *
+ * @see tizen_core_task_create()
+ */
+int tizen_core_task_destroy(tizen_core_task_h task);
+
+/**
+ * @brief Runs the main loop of the tizen core task.
+ * @since_tizen 9.0
+ *
+ * @param[in] task The tizen core task handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #TIZEN_CORE_ERROR_INVALID_CONTEXT Invalid context
+ *
+ * @code
+#include <tizen_core.h>
+{
+ tizen_core_task_h task = NULL;
+ int ret;
+
+ tizen_core_init();
+ ret = tizen_core_task_create("worker", true, &task);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ tizen_core_shutdown();
+ return ret;
+ }
+
+ ret = tizen_core_task_run(task);
+ if (ret != TIZEN_CORE_ERROR_NONE)
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to run task");
+}
+ * @endcode
+ *
+ * @see tizen_core_task_quit()
+ */
+int tizen_core_task_run(tizen_core_task_h task);
+
+/**
+ * @brief Checks whether the tizen core task is running or not.
+ * @since_tizen 9.0
+ *
+ * @param[in] task The tizen core task handle
+ * @param[out] running @c true if the core task is running, \n
+ * otherwise @c false if not running
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @code
+#include <tizen_core.h>
+{
+ tizen_core_task_h task = NULL;
+ bool running = false;
+ int ret;
+
+ tizen_core_init();
+ ret = tizen_core_task_create("worker", true, &task);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ tizen_core_shutdown();
+ return ret;
+ }
+
+ ret = tizen_core_task_run(task);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to run task");
+ tizen_core_task_destroy(task);
+ tizen_core_shutdown();
+ return ret;
+ }
+
+ ret = tizen_core_task_is_running(task, &running);
+ if (ret != TIZEN_CORE_ERROR_NONE)
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to check whether the task is running or not");
+ else
+ dlog_print(DLOG_INFO, LOG_TAG, "worker task is %s", running ? "running" : "not running");
+}
+ * @endcode
+ *
+ * @see tizen_core_task_run()
+ * @see tizen_core_task_quit()
+ */
+int tizen_core_task_is_running(tizen_core_task_h task, bool *running);
+
+/**
+ * @brief Exits the main loop of the tizen core task.
+ * @since_tizen 9.0
+ *
+ * @param[in] task The tizen core task handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @code
+#include <tizen_core.h>
+{
+ tizen_core_task_h task = NULL;
+ int ret;
+
+ tizen_core_init();
+ tizen_core_task_create("worker", true, &task);
+ tizen_core_task_run(task);
+ ret = tizen_core_task_quit(task);
+ if (ret != TIZEN_CORE_ERROR_NONE)
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to exit the main loop");
+}
+ * @endcode
+ *
+ * @see tizen_core_task_run()
+ */
+int tizen_core_task_quit(tizen_core_task_h task);
+
+/**
+ * @brief Gets the tizen core from the tizen core task handle.
+ * @since_tizen 9.0
+ * @remarks The @a core should not be released.
+ * @remarks The @a core is available until the @a task is released.
+ *
+ * @param[in] task The tizen core task handle
+ * @param[out] core The tizen core handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @code
+#include <tizen_core.h>
+{
+ tizen_core_task_h task = NULL;
+ tizen_core_h core = NULL;
+ int ret;
+
+ tizen_core_init();
+ tizen_core_task_create("worker", true, &task);
+ ret = tizen_core_task_get_tizen_core(task, &core);
+ if (ret != TIZEN_CORE_ERROR_NONE)
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to get tizen core");
+}
+ * @endcode
+ */
+int tizen_core_task_get_tizen_core(tizen_core_task_h task, tizen_core_h *core);
+
+/**
+ * @brief Finds the tizen core from the name.
+ * @since_tizen 9.0
+ * @remarks The @a core should not be released.
+ * @remarks The @a core is available until #tizen_core_task_h of the @a core is released.
+ *
+ * @param[in] name The tizen core task name
+ * @param[out] core The tizen core handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #TIZEN_CORE_ERROR_INVALID_CONTEXT Invalid context
+ *
+ * @code
+#include <tizen_core.h>
+{
+ tizen_core_h core = NULL;
+ int ret;
+
+ ret = tizen_core_find("worker", &core);
+ if (ret != TIZEN_CORE_ERROR_NONE)
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to find tizen core");
+}
+ * @endcode
+ */
+int tizen_core_find(const char *name, tizen_core_h *core);
+
+/**
+ * @brief Finds the tizen core from this thread.
+ * @since_tizen 9.0
+ * @remarks The @a core should not be released.
+ * @remarks The @a core is available until #tizen_core_task_h of the @a core is released.
+ *
+ * @param[out] core The tizen core handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #TIZEN_CORE_ERROR_INVALID_CONTEXT Invalid context
+ *
+ * @code
+#include <tizen_core.h>
+{
+ tizen_core_h core = NULL;
+ int ret;
+
+ ret = tizen_core_find_from_this_thread(&core);
+ if (ret != TIZEN_CORE_ERROR_NONE)
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to find tizen core from this thread");
+}
+ * @endcode
+ */
+int tizen_core_find_from_this_thread(tizen_core_h *core);
+
+/**
+ * @brief Adds an idle job to the tizen core.
+ * @details The callback function will be called whenever there are
+ * no higher priority events pending to the tizen core.
+ * The given callback function is called repeatedly until it returns false,
+ * at which point the idler @a source is automatically destroyed and
+ * the callback function will not be called again.
+ * @since_tizen 9.0
+ * @remarks The @a source should be released using tizen_core_remove_source().
+ *
+ * @param[in] core The tizen core handle
+ * @param[in] callback The callback function to be invoked when the idle job is emitted
+ * @param[in] user_data The user data to be passed to the callback function
+ * @param[out] source The tizen core source handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #TIZEN_CORE_ERROR_OUT_OF_MEMORY Out of memory
+ *
+ * @code
+#include <tizen_core.h>
+static bool idle_cb(void *user_data)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "idler is invoked");
+ return true;
+}
+
+static tizen_core_source_h add_idle_job(void)
+{
+ tizen_core_source_h source = NULL;
+ tizen_core_h core = NULL;
+ int ret;
+
+ tizen_core_find("main", &core);
+ ret = tizen_core_add_idle_job(core, idle_cb, NULL, &source);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to add idle job");
+ return NULL;
+ }
+
+ return source;
+}
+ * @endcode
+ *
+ * @see tizen_core_remove_source()
+ * @see tizen_core_task_cb()
+ */
+int tizen_core_add_idle_job(tizen_core_h core, tizen_core_task_cb callback,
+ void *user_data, tizen_core_source_h *source);
+
+/**
+ * @brief Adds a timer to the tizen core.
+ * @details The callback function will be called at regular intervals.
+ * The given callback function is called repeatedly until it returns false,
+ * at which point the timer @a source is automatically destroyed and
+ * the callback function will not be called again.
+ * @since_tizen 9.0
+ * @remarks The @a source should be released using tizen_core_remove_source().
+ *
+ * @param[in] core The tizen core handle
+ * @param[in] interval The interval of the timer in milliseconds
+ * @param[in] callback The callback function to be invoked when the timer is expired
+ * @param[in] user_data The user data to be passed to the callback function
+ * @param[out] source The tizen core source handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #TIZEN_CORE_ERROR_OUT_OF_MEMORY Out of memory
+ *
+ * @code
+#include <tizen_core.h>
+
+static bool timeout_cb(void *user_data)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "timeout cb is invoked");
+ return true;
+}
+
+static tizen_core_source_h add_timer(unsigned int interval)
+{
+ tizen_core_source_h source = NULL;
+ tizen_core_h core = NULL;
+ int ret;
+
+ tizen_core_find("main", &core);
+ ret = tizen_core_add_timer(core, interval, timeout_cb, NULL, &source);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to add timer");
+ return NULL;
+ }
+
+ return source;
+}
+ * @endcode
+ *
+ * @see tizen_core_remove_source()
+ * @see tizen_core_task_cb()
+ */
+int tizen_core_add_timer(tizen_core_h core, unsigned int interval,
+ tizen_core_task_cb callback, void *user_data,
+ tizen_core_source_h *source);
+
+/**
+ * @brief Adds a channel receiver to the tizen core.
+ * @details The callback function will be called when the channel event is received.
+ * @since_tizen 9.0
+ * @remarks The @a source should be released using tizen_core_remove_source().
+ *
+ * @param[in] core The tizen core handle
+ * @param[in] receiver The channel receiver handle
+ * @param[in] callback The callback function to be invoked when the channel event is received
+ * @param[in] user_data The user data to be passed to the callback function
+ * @param[out] source The tizen core source handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #TIZEN_CORE_ERROR_OUT_OF_MEMORY Out of memory
+ *
+ * @code
+#include <tizen_core.h>
+static void channel_receiver_cb(tizen_core_channel_object_h object, void *user_data)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "channel object is received");
+}
+
+static tizen_core_source_h add_channel_event(tizen_core_channel_receiver_h receiver)
+{
+ tizen_core_source_h source = NULL;
+ tizen_core_h core = NULL;
+ int ret;
+
+ tizen_core_find("main", &core);
+ ret = tizen_core_add_channel(core, receiver, channel_receiver_cb, NULL, &source);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to add channel");
+ return NULL;
+ }
+
+ return source;
+}
+ * @endcode
+ *
+ * @see tizen_core_remove_source()
+ */
+int tizen_core_add_channel(tizen_core_h core,
+ tizen_core_channel_receiver_h receiver,
+ tizen_core_channel_receive_cb callback,
+ void *user_data, tizen_core_source_h *source);
+
+/**
+ * @brief Adds an event to the tizen core.
+ * @details The event handler added to the event handle is called
+ * using the corresponding core loop when the event emit occurs.
+ * When this function is called the ownership of the @a event is moved
+ * to the tizen core. The @a event will be released when the @a source
+ * is removed using tizen_core_remove_source().
+ * @since_tizen 9.0
+ * @remarks The @a source should be released using tizen_core_remove_source().
+ * @remarks The @a event MUST not be released using tizen_core_event_destroy()
+ * after adding to the tizen core using this function.
+ *
+ * @param[in] core The tizen core handle
+ * @param[in] event The tizen core event handle
+ * @param[out] source The tizen core source handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #TIZEN_CORE_ERROR_OUT_OF_MEMORY Out of memory
+ *
+ * @code
+#include <tizen_core.h>
+static tizen_core_source_h add_event_source(tizen_core_event_h event)
+{
+ tizen_core_source_h source = NULL;
+ tizen_core_h core = NULL;
+ int ret;
+
+ tizen_core_find("main", &core);
+ ret = tizen_core_add_event(core, event, &source);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to add event");
+ return NULL;
+ }
+
+ return source;
+}
+ * @endcode
+ *
+ * @see tizen_core_remove_source()
+ */
+int tizen_core_add_event(tizen_core_h core, tizen_core_event_h event,
+ tizen_core_source_h *source);
+
+/**
+ * @brief Emits the event to the tizen core.
+ * @details The event is emitted to the event handler registered in the corresponding tizen_core.
+ * @since_tizen 9.0
+ *
+ * @param[in] core The tizen core handle
+ * @param[in] object The tizen core event object handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @code
+#include <tizen_core.h>
+static int emit_event(tizen_core_event_object_h object)
+{
+ tizen_core_h core = NULL;
+ int ret;
+
+ tizen_core_find("main", &core);
+ ret = tizen_core_emit_event(core, object);
+ if (ret != TIZEN_CORE_ERROR_NONE)
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to emit event");
+
+ return ret;
+}
+ * @endcode
+ *
+ * @see tizen_core_add_event()
+ */
+int tizen_core_emit_event(tizen_core_h core, tizen_core_event_object_h object);
+
+/**
+ * @brief Adds a source to the tizen core.
+ * @since_tizen 9.0
+ * @remarks The @a source should be removed using tizen_core_remove_source().
+ *
+ * @param[in] core The tizen core handle
+ * @param[in] source The tizen core source handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @code
+#include <tizen_core.h>
+{
+ tizen_core_source_h source = NULL;
+ tizen_core_h core = NULL;
+ int ret;
+
+ tizen_core_source_create(&source);
+ tizen_core_find("main", &core);
+ ret = tizen_core_add_source(core, source);
+ if (ret != TIZEN_CORE_ERROR_NONE)
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to add source");
+}
+ * @endcode
+ *
+ * @see tizen_core_remove_source()
+ */
+int tizen_core_add_source(tizen_core_h core, tizen_core_source_h source);
+
+/**
+ * @brief Removes the source from the tizen core.
+ * @since_tizen 9.0
+ * @remarks If the source is not added to the tizen core, this function returns
+ * #TIZEN_CORE_ERROR_INVALID_CONTEXT.
+ *
+ * @param[in] core The tizen core handle
+ * @param[in] source The tizen core source handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #TIZEN_CORE_ERROR_INVALID_CONTEXT Invalid context
+ *
+ * @code
+#include <tizen_core.h>
+static void remove_source(tizen_core_source_h source)
+{
+ tizen_core_h core = NULL;
+ int ret;
+
+ tizen_core_find("main", &core);
+ ret = tizen_core_remove_source(core, source);
+ if (ret != TIZEN_CORE_ERROR_NONE)
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to remove source");
+ else
+ dlog_print(DLOG_INFO, LOG_TAG, "source is removed");
+}
+ * @endcode
+ *
+ * @see tizen_core_add_source()
+ */
+int tizen_core_remove_source(tizen_core_h core, tizen_core_source_h source);
+
+/**
+ * @brief Creates a tizen core source handle.
+ * @since_tizen 9.0
+ * @remarks The @a source should be released using tizen_core_source_destroy().
+ *
+ * @param[out] source The tizen core source handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #TIZEN_CORE_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #TIZEN_CORE_ERROR_INVALID_CONTEXT Invalid context
+ *
+ * @code
+#include <tizen_core.h>
+{
+ tizen_core_source_h source = NULL;
+ int ret;
+
+ ret = tizen_core_source_create(&source);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create source");
+ return ret;
+ }
+}
+ * @endcode
+ *
+ * @see tizen_core_add_source()
+ * @see tizen_core_remove_source()
+ * @see tizen_core_source_destroy()
+ */
+int tizen_core_source_create(tizen_core_source_h *source);
+
+/**
+ * @brief Destroys the tizen core source handle.
+ * @since_tizen 9.0
+ *
+ * @param[in] source The tizen core source handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @code
+#include <tizen_core.h>
+{
+ tizen_core_source_h source = NULL;
+ int ret;
+
+ ret = tizen_core_source_create(&source);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create source");
+ return ret;
+ }
+
+ ret = tizen_core_source_destroy(source);
+ if (ret != TIZEN_CORE_ERROR_NONE)
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to destroy source");
+}
+ * @endcode
+ * @see tizen_core_source_create()
+ * @see tizen_core_remove_source()
+ */
+int tizen_core_source_destroy(tizen_core_source_h source);
+
+/**
+ * @brief Waits for some events on the file descriptor.
+ * @details The tizen core source must be created using the tizen_core_source_create().
+ * @since_tizen 9.0
+ *
+ * @param[in] source The tizen core source handle
+ * @param[in] poll_fd The poll fd handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #TIZEN_CORE_ERROR_INVALID_CONTEXT Invalid context
+ *
+ * @code
+#include <tizen_core.h>
+static tizen_core_poll_fd_h add_poll_fd_to_source(tizen_core_source_h source, int fd)
+{
+ tizen_core_poll_fd_h poll_fd = NULL;
+ int ret;
+
+ tizen_core_poll_fd_create(&poll_fd);
+ tizen_core_poll_fd_set_fd(poll_fd, fd);
+ tizen_core_poll_fd_set_events(poll_fd, TIZEN_CORE_POLL_EVENT_IN);
+ ret = tizen_core_source_add_poll(source, poll_fd);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to add poll fd");
+ tizen_core_poll_fd_destroy(poll_fd);
+ return NULL;
+ }
+
+ return poll_fd;
+}
+ * @endcode
+ *
+ * @see tizen_core_source_create()
+ * @see tizen_core_source_set_prepare_cb()
+ * @see tizen_core_source_set_check_cb()
+ * @see tizen_core_source_set_dispatch_cb()
+ * @see tizen_core_source_set_finalize_cb()
+ * @see tizen_core_source_remove_poll()
+ */
+int tizen_core_source_add_poll(tizen_core_source_h source,
+ tizen_core_poll_fd_h poll_fd);
+
+/**
+ * @brief Removes to wait for some events on the file descriptor.
+ * @since_tizen 9.0
+ *
+ * @param[in] source The tizen core source handle
+ * @param[in] poll_fd The poll fd handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #TIZEN_CORE_ERROR_INVALID_CONTEXT Invalid context
+ *
+ * @code
+#include <tizen_core.h>
+static void remove_poll_from_source(tizen_core_source_h source, tizen_core_poll_fd_h poll_fd)
+{
+ int ret;
+
+ ret = tizen_core_source_remove_poll(source, poll_fd);
+ if (ret != TIZEN_CORE_ERROR_NONE)
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to remove poll fd");
+ else
+ dlog_print(DLOG_INFO, LOG_TAG, "Poll fd is removed");
+}
+ * @endcode
+ *
+ * @see tizen_core_source_create()
+ * @see tizen_core_source_add_poll()
+ */
+int tizen_core_source_remove_poll(tizen_core_source_h source,
+ tizen_core_poll_fd_h poll_fd);
+
+/**
+ * @brief Sets the prepare callback function to the tizen core source.
+ * @details This function is not mandatory.
+ * If you want to set a timeout value to ensure that the poll(),
+ * the @a callback function should be set.
+ * @since_tizen 9.0
+ *
+ * @param[in] source The tizen core source handle
+ * @param[in] callback The callback function to be invoked when the source is ready to be processed
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @code
+#include <tizen_core.h>
+static bool source_prepare_cb(tizen_core_source_h source, int *timeout, void *user_data)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "prepare callback is invoked");
+ return true;
+}
+
+static bool source_check_cb(tizen_core_source_h source, void *user_data)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "check callback is invoked");
+ return true;
+}
+
+static bool source_dispatch_cb(tizen_core_source_h source, void *user_data)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "dispatch callback is invoked");
+ return true;
+}
+
+static tizen_core_source_h create_source(void)
+{
+ tizen_core_source_h source = NULL;
+ int ret;
+
+ ret = tizen_core_source_create(&source);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create source");
+ return NULL;
+ }
+
+ ret = tizen_core_source_set_prepare_cb(source, source_prepare_cb, NULL);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to set prepare callback");
+ tizen_core_source_destroy(source);
+ return NULL;
+ }
+
+ tizen_core_source_set_check_cb(source, source_check_cb, NULL);
+ tizen_core_source_set_dispatch_cb(source, source_dispatch_cb, NULL);
+
+ return source;
+}
+ * @endcode
+ *
+ * @see tizen_core_source_create()
+ * @see tizen_core_source_prepare_cb()
+ * @see tizen_core_source_add_poll()
+ */
+int tizen_core_source_set_prepare_cb(
+ tizen_core_source_h source, tizen_core_source_prepare_cb callback,
+ void *user_data);
+
+/**
+ * @brief Sets the check callback function to the tizen core source.
+ * @details This function is not mandatory.
+ * If the @a callback function is not set, the tizen core source is processed.
+ * @since_tizen 9.0
+ *
+ * @param[in] source The tizen core source handle
+ * @param[in] callback The callback function to be invoked when the source is ready to be processed
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @code
+#include <tizen_core.h>
+static bool source_prepare_cb(tizen_core_source_h source, int *timeout, void *user_data)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "prepare callback is invoked");
+ return true;
+}
+
+static bool source_check_cb(tizen_core_source_h source, void *user_data)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "check callback is invoked");
+ return true;
+}
+
+static bool source_dispatch_cb(tizen_core_source_h source, void *user_data)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "dispatch callback is invoked");
+ return true;
+}
+
+static tizen_core_source_h create_source(void)
+{
+ tizen_core_source_h source = NULL;
+ int ret;
+
+ ret = tizen_core_source_create(&source);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create source");
+ return NULL;
+ }
+
+ tizen_core_source_set_prepare_cb(source, source_prepare_cb, NULL);
+ tizen_core_source_set_dispatch_cb(source, source_dispatch_cb, NULL);
+
+ ret = tizen_core_source_set_check_cb(source, source_check_cb, NULL);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to set check callback");
+ tizen_core_source_destroy(source);
+ return NULL;
+ }
+
+ return source;
+}
+ * @endcode
+ *
+ * @see tizen_core_source_create()
+ * @see tizen_core_source_check_cb()
+ */
+int tizen_core_source_set_check_cb(tizen_core_source_h source,
+ tizen_core_source_check_cb callback,
+ void *user_data);
+
+/**
+ * @brief Sets the dispatch callback function to the tizen core source.
+ * @details This function is mandatory. Before adding the @a source handle to
+ * the #tizen_core_h using tizen_core_add_source(),
+ * the @a callback function should be set.
+ * @since_tizen 9.0
+ *
+ * @param[in] source The tizen core source handle
+ * @param[in] callback The callback function to be dispatched events
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @code
+#include <tizen_core.h>
+static bool source_prepare_cb(tizen_core_source_h source, int *timeout, void *user_data)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "prepare callback is invoked");
+ return true;
+}
+
+static bool source_check_cb(tizen_core_source_h source, void *user_data)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "check callback is invoked");
+ return true;
+}
+
+static bool source_dispatch_cb(tizen_core_source_h source, void *user_data)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "dispatch callback is invoked");
+ return true;
+}
+
+static tizen_core_source_h create_source(void)
+{
+ tizen_core_source_h source = NULL;
+ int ret;
+
+ ret = tizen_core_source_create(&source);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create source");
+ return NULL;
+ }
+
+ tizen_core_source_set_prepare_cb(source, source_prepare_cb, NULL);
+ tizen_core_source_set_check_cb(source, source_check_cb, NULL);
+
+ ret = tizen_core_source_set_dispatch_cb(source, source_dispatch_cb, NULL);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to set dispatch callback");
+ tizen_core_source_destroy(source);
+ return NULL;
+ }
+
+ return source;
+}
+ * @endcode
+ *
+ * @see tizen_core_source_create()
+ * @see tizen_core_source_dispatch_cb()
+ */
+int tizen_core_source_set_dispatch_cb(
+ tizen_core_source_h source, tizen_core_source_dispatch_cb callback,
+ void *user_data);
+
+/**
+ * @brief Sets the finalize callback function to the tizen core source.
+ * @details This function is not mandatory.
+ * If there is anything you need to do when the source is removed,
+ * use this function to set the callback function.
+ * @since_tizen 9.0
+ *
+ * @param[in] source The tizen core source handle
+ * @param[in] callback The callback function to finalize the source
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @code
+#include <tizen_core.h>
+static bool source_prepare_cb(tizen_core_source_h source, int *timeout, void *user_data)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "prepare callback is invoked");
+ return true;
+}
+
+static bool source_check_cb(tizen_core_source_h source, void *user_data)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "check callback is invoked");
+ return true;
+}
+
+static bool source_dispatch_cb(tizen_core_source_h source, void *user_data)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "dispatch callback is invoked");
+ return true;
+}
+
+static void source_finalize_cb(tizen_core_source_h source, void *user_data)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "finalize callback is invoked");
+}
+
+static tizen_core_source_h create_source(void)
+{
+ tizen_core_source_h source = NULL;
+ int ret;
+
+ ret = tizen_core_source_create(&source);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create source");
+ return NULL;
+ }
+
+ tizen_core_source_set_prepare_cb(source, source_prepare_cb, NULL);
+ tizen_core_source_set_check_cb(source, source_check_cb, NULL);
+ tizen_core_source_set_dispatch_cb(source, source_dispatch_cb, NULL);
+
+ ret = tizen_core_source_set_finalize_cb(source, source_finalize_cb, NULL);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to set finalize callback");
+ tizen_core_source_destroy(source);
+ return NULL;
+ }
+
+ return source;
+}
+ * @endcode
+ *
+ * @see tizen_core_source_create()
+ * @see tizen_core_source_finalize_cb()
+ * @see tizen_core_remove_source()
+ * @see tizen_core_source_destroy()
+ */
+int tizen_core_source_set_finalize_cb(
+ tizen_core_source_h source, tizen_core_source_finalize_cb callback,
+ void *user_data);
+
+/**
+ * @brief Sets the priority to the tizen core source.
+ * @since_tizen 9.0
+ *
+ * @param[in] source The tizen core source handle
+ * @param[in] priority The priority value
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @code
+#include <tizen_core.h>
+static bool idle_job_cb(void *user_data)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "idler is invoked");
+ return true;
+}
+
+static tizen_core_source_h create_idle_source(void)
+{
+ tizen_core_source_h source = NULL;
+ tizen_core_h core = NULL;
+ int ret;
+
+ tizen_core_find("main", &core);
+ ret = tizen_core_add_idle_job(core, idle_job_cb, NULL, &source);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to add idle job");
+ return NULL;
+ }
+
+ ret = tizen_core_source_set_priority(source, TIZEN_CORE_PRIORITY_HIGH);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to set priority");
+ tizen_core_source_destroy(source);
+ return NULL;
+ }
+
+ return source;
+}
+ * @endcode
+ *
+ * @see tizen_core_priority_e
+ */
+int tizen_core_source_set_priority(tizen_core_source_h source,
+ tizen_core_priority_e priority);
+
+/**
+ * @brief Creates a tizen core poll fd handle.
+ * @since_tizen 9.0
+ * @remarks The @a poll_fd should be released using tizen_core_poll_fd_destroy().
+ *
+ * @param[out] poll_fd The tizen core poll fd handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #TIZEN_CORE_ERROR_OUT_OF_MEMORY Out of memory
+ *
+ * @code
+#include <tizen_core.h>
+{
+ tizen_core_poll_fd_h poll_fd = NULL;
+ int ret;
+
+ ret = tizen_core_poll_fd_create(&poll_fd);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create poll fd");
+ return;
+ }
+}
+ * @endcode
+ *
+ * @see tizen_core_poll_fd_destroy()
+ */
+int tizen_core_poll_fd_create(tizen_core_poll_fd_h *poll_fd);
+
+/**
+ * @brief Destroys the tizen core poll fd (file descriptor) handle.
+ * @since_tizen 9.0
+ * @remarks If the handle is already added to the source using the tizen_core_source_add_poll(),
+ * the handle will be removed from the source automatically after this function is called.
+ *
+ * @param[in] poll_fd The tizen core poll fd handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @code
+#include <tizen_core.h>
+{
+ tizen_core_poll_fd_h poll_fd = NULL;
+ int ret;
+
+ ret = tizen_core_poll_fd_create(&poll_fd);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create poll fd");
+ return;
+ }
+
+ ret = tizen_core_poll_fd_destroy(poll_fd);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to destroy poll fd");
+ }
+}
+ * @endcode
+ *
+ * @see tizen_core_poll_fd_create()
+ */
+int tizen_core_poll_fd_destroy(tizen_core_poll_fd_h poll_fd);
+
+/**
+ * @brief Sets the file descriptor to the poll fd handle.
+ * @since_tizen 9.0
+ *
+ * @param[in] poll_fd The tizen core poll fd handle
+ * @param[in] fd The file descriptor
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @code
+#include <tizen_core.h>
+{
+ tizen_core_poll_fd_h poll_fd = NULL;
+ int ret;
+
+ ret = tizen_core_poll_fd_create(&poll_fd);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create poll fd");
+ return;
+ }
+
+ ret = tizen_core_poll_fd_set_fd(poll_fd, 0);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to set fd to poll fd");
+ tizen_core_poll_fd_destroy(poll_fd);
+ return;
+ }
+}
+ * @endcode
+ *
+ * @see tizen_core_poll_fd_get_fd()
+ */
+int tizen_core_poll_fd_set_fd(tizen_core_poll_fd_h poll_fd, int fd);
+
+/**
+ * @brief Gets the file descriptor from the poll fd handle.
+ * @since_tizen 9.0
+ *
+ * @param[in] poll_fd The tizen core poll fd handle
+ * @param[out] fd The file descriptor
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @code
+#include <tizen_core.h>
+{
+ tizen_core_poll_fd_h poll_fd = NULL;
+ int fd = -1;
+ int ret;
+
+ ret = tizen_core_poll_fd_create(&poll_fd);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create poll fd");
+ return;
+ }
+
+ tizen_core_poll_fd_set_fd(poll_fd, 0);
+
+ ret = tizen_core_poll_fd_get_fd(poll_fd, &fd);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to get fd from poll fd");
+ tizen_core_poll_fd_destroy(poll_fd);
+ return;
+ }
+}
+ * @endcode
+ *
+ * @see tizen_core_poll_fd_set_fd()
+ */
+int tizen_core_poll_fd_get_fd(tizen_core_poll_fd_h poll_fd, int *fd);
+
+/**
+ * @brief Sets the requested events to the poll fd handle.
+ * @since_tizen 9.0
+ *
+ * @param[in] poll_fd The tizen core poll fd handle
+ * @param[in] events The requested events
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @code
+#include <tizen_core.h>
+{
+ tizen_core_poll_fd_h poll_fd = NULL;
+ int ret;
+
+ ret = tizen_core_poll_fd_create(&poll_fd);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create poll fd");
+ return;
+ }
+
+ tizen_core_poll_fd_set_fd(poll_fd, 0);
+
+ ret = tizen_core_poll_fd_set_events(poll_fd,
+ TIZEN_CORE_POLL_EVENT_IN | TIZEN_CORE_POLL_EVENT_OUT);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to set events");
+ tizen_core_poll_fd_destroy(poll_fd);
+ return;
+ }
+}
+ * @endcode
+ *
+ * @see tizen_core_poll_fd_get_events()
+ * @see tizen_core_poll_event_e
+ */
+int tizen_core_poll_fd_set_events(tizen_core_poll_fd_h poll_fd,
+ uint16_t events);
+
+/**
+ * @brief Gets the requested events from the poll fd handle.
+ * @since_tizen 9.0
+ *
+ * @param[in] poll_fd The tizen core poll fd handle
+ * @param[out] events The requested events
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @code
+#include <tizen_core.h>
+{
+ tizen_core_poll_fd_h poll_fd = NULL;
+ uint16_t events;
+ int ret;
+
+ ret = tizen_core_poll_fd_create(&poll_fd);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create poll fd");
+ return;
+ }
+
+ tizen_core_poll_fd_set_fd(poll_fd, 0);
+ tizen_core_poll_fd_set_events(poll_fd,
+ TIZEN_CORE_POLL_EVENT_IN | TIZEN_CORE_POLL_EVENT_HUP);
+
+ ret = tizen_core_poll_fd_get_events(poll_fd, &events);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to get events from poll fd");
+ tizen_core_poll_fd_destroy(poll_fd);
+ return;
+ }
+}
+ * @endcode
+ *
+ * @see tizen_core_poll_fd_set_events()
+ * @see tizen_core_poll_event_e
+ */
+int tizen_core_poll_fd_get_events(tizen_core_poll_fd_h poll_fd,
+ uint16_t *events);
+
+/**
+ * @brief Sets the returned events to the poll fd handle.
+ * @since_tizen 9.0
+ *
+ * @param[in] poll_fd The tizen core poll fd handle
+ * @param[in] returned_events The returned events
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @code
+#include <tizen_core.h>
+{
+ tizen_core_poll_fd_h poll_fd = NULL;
+ int ret;
+
+ ret = tizen_core_poll_fd_create(&poll_fd);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create poll fd");
+ return;
+ }
+
+ ret = tizen_core_poll_fd_set_returned_events(poll_fd,
+ TIZEN_CORE_POLL_EVENT_IN | TIZEN_CORE_POLL_EVENT_OUT);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to set returned events");
+ tizen_core_poll_fd_destroy(poll_fd);
+ return;
+ }
+}
+ * @endcode
+ *
+ * @see tizen_core_poll_fd_get_events()
+ * @see tizen_core_poll_event_e
+ */
+int tizen_core_poll_fd_set_returned_events(tizen_core_poll_fd_h poll_fd,
+ uint16_t returned_events);
+
+/**
+ * @brief Gets the returned events from the poll fd handle.
+ * @since_tizen 9.0
+ *
+ * @param[in] poll_fd The tizen core poll fd handle
+ * @param[out] returned_events The returned events
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @code
+#include <tizen_core.h>
+static bool source_prepare_cb(tizen_core_source_h source, int *timeout, void *user_data)
+{
+ *timeout = -1;
+ return true;
+}
+
+static bool source_check_cb(tizen_core_source_h source, void *user_data)
+{
+ tizen_core_poll_fd_h poll_fd = (tizen_core_poll_fd_h)user_data;
+ uint16_t returned_events = 0;
+
+ tizen_core_poll_fd_get_returned_events(poll_fd, &returned_events);
+ if (returned_events & TIZEN_CORE_POLL_EVENT_IN)
+ return true;
+
+ return false;
+}
+
+static bool source_dispatch_cb(tizen_core_source_h source, void *user_data)
+{
+ tizen_core_poll_fd_h poll_fd = (tizen_core_poll_fd_h)user_data;
+ ssize_t bytes;
+ int ret = 0;
+ int fd;
+
+ tizen_core_poll_fd_get_fd(poll_fd, &fd);
+ bytes = read(fd, (void *)&ret, sizeof(ret));
+ if (bytes < 0) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to read data. errno=%d", errno);
+ } else if (bytes == 0) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "socket was closed. fd=%d", fd);
+ tizen_core_source_destroy(source);
+ } else {
+ dlog_print(DLOG_INFO, LOG_TAG, "result=%d", ret);
+ }
+
+ return true;
+}
+
+static void source_finalize_cb(tizen_core_source_h source, void *user_data)
+{
+ tizen_core_poll_fd_h poll_fd = (tizen_core_poll_fd_h)user_data;
+
+ tizen_core_poll_fd_destroy(poll_fd);
+}
+
+static tizen_core_source_h create_io_source(int fd, uint16_t events)
+{
+ tizen_core_source_h source = NULL;
+ tizen_core_poll_fd_h poll_fd = NULL;
+ tizen_core_h core = NULL;
+
+ tizen_core_poll_fd_create(&poll_fd);
+ tizen_core_poll_fd_set_fd(poll_fd, fd);
+ tizen_core_poll_fd_set_events(poll_fd, events);
+
+ tizen_core_source_create(&source);
+ tizen_core_source_set_prepare_cb(source, source_prepare_cb, poll_fd);
+ tizen_core_source_set_check_cb(source, source_check_cb, poll_fd);
+ tizen_core_source_set_dispatch_cb(source, source_dispatch_cb, poll_fd);
+ tizen_core_source_set_finalize_cb(source, source_finalize_cb, poll_fd);
+
+ tizen_core_find("main", &core);
+ tizen_core_add_source(core, source);
+
+ return source;
+}
+ * @endcode
+ *
+ * @see tizen_core_poll_fd_set_events()
+ * @see tizen_core_poll_event_e
+ */
+int tizen_core_poll_fd_get_returned_events(tizen_core_poll_fd_h poll_fd,
+ uint16_t *returned_events);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_BASE_TIZEN_CORE_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __TIZEN_BASE_TIZEN_CORE_CHANNEL_H__
+#define __TIZEN_BASE_TIZEN_CORE_CHANNEL_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file tizen_core_channel.h
+ */
+
+/**
+ * @addtogroup CAPI_TIZEN_CORE_CHANNEL_MODULE
+ * @{
+ */
+
+/**
+ * @brief The tizen core channel sender handle.
+ * @since_tizen 9.0
+ */
+typedef void *tizen_core_channel_sender_h;
+
+/**
+ * @brief The tizen core channel receiver handle.
+ * @since_tizen 9.0
+ */
+typedef void *tizen_core_channel_receiver_h;
+
+/**
+ * @brief The tizen core channel object handle.
+ * @since_tizen 9.0
+ */
+typedef void *tizen_core_channel_object_h;
+
+/**
+ * @brief Called when the channel object is received.
+ * @since_tizen 9.0
+ * @remarks The @a object must not be deallocated by the application.
+ *
+ * @param[in] object The tizen core channel object handle
+ * @param[in] user_data The user data passed from the registration function
+ * @see tizen_core_add_channel()
+ */
+typedef void (*tizen_core_channel_receive_cb)(
+ tizen_core_channel_object_h object, void *user_data);
+
+/**
+ * @brief Makes a pair of channel sender and receiver.
+ * @since_tizen 9.0
+ * @remarks The @a sender should be released using tizen_core_channel_sender_destroy().
+ * @remarks The @a receiver should be released using tizen_core_channel_receiver_destroy().
+ *
+ * @param[out] sender The tizen core channel sender handle
+ * @param[out] receiver The tizen core channel receiver handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #TIZEN_CORE_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #TIZEN_CORE_ERROR_INVALID_CONTEXT Invalid context
+ *
+ * @code
+#include <tizen_core.h>
+{
+ tizen_core_channel_sender_h sender = NULL;
+ tizen_core_channel_receiver_h receiver = NULL;
+ int ret;
+
+ ret = tizen_core_channel_make_pair(&sender, &receiver);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to make channel pair");
+ return;
+ }
+}
+ * @endcode
+ *
+ * @see tizen_core_channel_sender_destroy()
+ * @see tizen_core_channel_receiver_destroy()
+ */
+int tizen_core_channel_make_pair(tizen_core_channel_sender_h *sender,
+ tizen_core_channel_receiver_h *receiver);
+
+/**
+ * @brief Sends the channel object to the receiver.
+ * @since_tizen 9.0
+ *
+ * @param[in] sender The tizen core channel sender handle
+ * @param[in] object The tizen core channel object handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @code
+#include <tizen_core.h>
+{
+ tizen_core_channel_sender_h sender = NULL;
+ tizen_core_channel_receiver_h receiver = NULL;
+ tizen_core_channel_object_h object = NULL;
+ int ret;
+
+ tizen_core_channel_make_pair(&sender, &receiver);
+ tizen_core_channel_object_create(&object);
+ tizen_core_channel_object_set_type(object, 22);
+ tizen_core_channel_object_set_data(object, strdup("22"));
+
+ int ret = tizen_core_channel_sender_send(sender, object);
+ if (ret != TIZEN_CORE_ERROR_NONE)
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to send object");
+
+ tizen_core_channel_object_destroy(object);
+}
+ * @endcode
+ *
+ * @see tizen_core_channel_object_create()
+ */
+int tizen_core_channel_sender_send(tizen_core_channel_sender_h sender,
+ tizen_core_channel_object_h object);
+
+/**
+ * @brief Destroys the channel sender handle.
+ * @since_tizen 9.0
+ *
+ * @param[in] sender The tizen core channel sender handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @code
+#include <tizen_core.h>
+{
+ tizen_core_channel_sender_h sender = NULL;
+ tizen_core_channel_receiver_h receiver = NULL;
+ int ret;
+
+ tizen_core_channel_make_pair(&sender, &receiver);
+ tizen_core_channel_receiver_destroy(receiver);
+
+ ret = tizen_core_channel_sender_destroy(sender);
+ if (ret != TIZEN_CORE_ERROR_NONE)
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to destroy channel sender");
+}
+ * @endcode
+ *
+ * @see tizen_core_channel_make_pair()
+ * @see tizen_core_channel_sender_clone()
+ */
+int tizen_core_channel_sender_destroy(tizen_core_channel_sender_h sender);
+
+/**
+ * @brief Creates and returns a copy of the given the @a sender handle.
+ * @since_tizen 9.0
+ * @remarks The @a cloned_sender should be released using tizen_core_channel_sender_destroy().
+ *
+ * @param[in] sender The tizen core channel sender handle
+ * @param[out] cloned_sender If successful, a newly created tizen core channel sender handle will be returned
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #TIZEN_CORE_ERROR_OUT_OF_MEMORY Out of memory
+ *
+ * @code
+#include <tizen_core.h>
+{
+ tizen_core_channel_sender_h sender = NULL;
+ tizen_core_channel_sender_h cloned_sender = NULL;
+ tizen_core_channel_receiver_h receiver = NULL;
+ int ret;
+
+ tizen_core_channel_make_pair(&sender, &receiver);
+
+ ret = tizen_core_channel_sender_clone(sender, &cloned_sender);
+ if (ret != TIZEN_CORE_ERROR_NONE)
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to clone channel sender");
+}
+ * @endcode
+ *
+ * @see tizen_core_channel_sender_destroy()
+ */
+int tizen_core_channel_sender_clone(tizen_core_channel_sender_h sender,
+ tizen_core_channel_sender_h *cloned_sender);
+
+/**
+ * @brief Receives the channel object from the sender.
+ * @since_tizen 9.0
+ * @remarks The @a object should be released using tizen_core_channel_object_destroy().
+ *
+ * @param[in] receiver The tizen core channel receiver handle
+ * @param[out] object The tizen core channel object handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #TIZEN_CORE_ERROR_OUT_OF_MEMORY Out of memory
+ *
+ * @code
+#include <tizen_core.h>
+{
+ tizen_core_channel_sender_h sender = NULL;
+ tizen_core_channel_receiver_h receiver = NULL;
+ tizen_core_channel_object_h object = NULL;
+ int id = -1;
+ char *data = NULL;
+ int ret;
+
+ tizen_core_channel_make_pair(&sender, &receiver);
+ tizen_core_channel_object_create(&object);
+ tizen_core_channel_object_set_id(object, 22);
+ tizen_core_channel_object_set_data(object, strdup("22"));
+
+ tizen_core_channel_sender_send(sender, object);
+ tizen_core_channel_object_destroy(object);
+ object = NULL;
+
+ ret = tizen_core_channel_receiver_receive(receiver, &object);
+ if (ret == TIZEN_CORE_ERROR_NONE) {
+ tizen_core_channel_object_get_id(object, &id);
+ tizen_core_channel_object_get_data(object, &data);
+ dlog_print(DLOG_INFO, LOG_TAG, "id=%d, data=%s", id, data);
+ free(data);
+ tizen_core_channel_object_destroy(object);
+ }
+
+ tizen_core_channel_sender_destroy(sender);
+ tizen_core_channel_receiver_destroy(receiver);
+}
+ * @endcode
+ *
+ * @see tizen_core_channel_object_destroy()
+ */
+int tizen_core_channel_receiver_receive(tizen_core_channel_receiver_h receiver,
+ tizen_core_channel_object_h *object);
+
+/**
+ * @brief Destroys the tizen core channel receiver handle.
+ * @since_tizen 9.0
+ *
+ * @param[in] receiver The tizen core channel receiver handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @code
+#include <tizen_core.h>
+{
+ tizen_core_channel_sender_h sender = NULL;
+ tizen_core_channel_receiver_h receiver = NULL;
+ int ret;
+
+ tizen_core_channel_make_pair(&sender, &receiver);
+ tizen_core_channel_sender_destroy(sender);
+
+ ret = tizen_core_channel_receiver_destroy(receiver);
+ if (ret != TIZEN_CORE_ERROR_NONE)
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to destroy channel receiver");
+}
+ * @endcode
+ *
+ * @see tizen_core_channel_make_pair()
+ */
+int tizen_core_channel_receiver_destroy(tizen_core_channel_receiver_h receiver);
+
+/**
+ * @brief Creates the tizen core channel object handle.
+ * @since_tizen 9.0
+ * @remarks The @a object should be released using tizen_core_channel_object_destroy().
+ *
+ * @param[out] object The tizen core channel object handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #TIZEN_CORE_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #TIZEN_CORE_ERROR_INVALID_CONTEXT Invalid context
+ *
+ * @code
+#include <tizen_core.h>
+{
+ tizen_core_channel_object_h object = NULL;
+ int ret;
+
+ ret = tizen_core_channel_object_create(&object);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create channel object");
+ return;
+ }
+
+ tizen_core_channel_object_destroy(object);
+}
+ * @endcode
+ *
+ * @see tizen_core_channel_object_destroy()
+ */
+int tizen_core_channel_object_create(tizen_core_channel_object_h *object);
+
+/**
+ * @brief Destroys the tizen core channel object handle.
+ * @since_tizen 9.0
+ *
+ * @param[in] object The tizen core channel object handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @code
+#include <tizen_core.h>
+{
+ tizen_core_channel_object_h object = NULL;
+ int ret;
+
+ tizen_core_channel_object_create(&object);
+
+ ret = tizen_core_channel_object_destroy(object);
+ if (ret != TIZEN_CORE_ERROR_NONE)
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to destroy channel object");
+}
+ * @endcode
+ *
+ * @see tizen_core_channel_object_create()
+ */
+int tizen_core_channel_object_destroy(tizen_core_channel_object_h object);
+
+/**
+ * @brief Sets the ID to the tizen core channel object handle.
+ * @since_tizen 9.0
+ *
+ * @param[in] object The tizen core channel object handle
+ * @param[in] id The channel ID
+ *
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @code
+#include <tizen_core.h>
+{
+ tizen_core_channel_object_h object = NULL;
+ int ret;
+
+ tizen_core_channel_object_create(&object);
+
+ ret = tizen_core_channel_object_set_id(object, 22);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to set channel type");
+ tizen_core_channel_object_destroy(object);
+ return;
+ }
+
+ tizen_core_channel_object_destroy(object);
+}
+ * @endcode
+ *
+ * @see tizen_core_channel_object_get_type()
+ */
+int tizen_core_channel_object_set_id(tizen_core_channel_object_h object,
+ int id);
+
+/**
+ * @brief Gets the ID from the tizen core channel object handle.
+ * @since_tizen 9.0
+ *
+ * @param[in] object The tizen core channel object handle
+ * @param[out] id The channel ID
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @code
+#include <tizen_core.h>
+{
+ tizen_core_channel_object_h object = NULL;
+ int id = 0;
+ int ret;
+
+ tizen_core_channel_object_create(&object);
+ tizen_core_channel_object_set_id(object, 22);
+
+ ret = tizen_core_channel_object_get_id(object, &id);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to get channel type");
+ return;
+ }
+
+ tizen_core_channel_object_destroy(object);
+}
+ * @endcode
+ *
+ * @see tizen_core_channel_object_set_id()
+ */
+int tizen_core_channel_object_get_id(tizen_core_channel_object_h object,
+ int *id);
+
+/**
+ * @brief Sets the data to the tizen core channel object handle.
+ * @since_tizen 9.0
+ * @remarks The @a data should be released using release function
+ * if the @a data is created by the memory allocation.
+ *
+ * @param[in] object The tizen core channel object handle
+ * @param[in] data The channel data
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @code
+#include <tizen_core.h>
+{
+ tizen_core_channel_object_h object = NULL;
+ char *data = NULL;
+ int ret;
+
+ tizen_core_channel_object_create(&object);
+
+ ret = tizen_core_channel_object_set_data(object, strdup("22"));
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to set channel data");
+ tizen_core_channel_object_destroy(object);
+ return;
+ }
+
+ tizen_core_channel_object_get_data(object, &data);
+ free(data);
+ tizen_core_channel_object_destroy(object);
+}
+ * @endcode
+ *
+ * @see tizen_core_channel_object_get_data()
+ */
+int tizen_core_channel_object_set_data(tizen_core_channel_object_h object,
+ void *data);
+
+/**
+ * @brief Gets the data from the tizen core channel object handle.
+ * @since_tizen 9.0
+ * @remarks The @a data should be released using release function.
+ *
+ * @param[in] object The tizen core channel object handle
+ * @param[out] data The channel data
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @code
+#include <tizen_core.h>
+{
+ tizen_core_channel_object_h object = NULL;
+ char *data = NULL;
+ int ret;
+
+ tizen_core_channel_object_create(&object);
+ tizen_core_channel_object_set_data(object, strdup("22"));
+
+ ret = tizen_core_channel_object_get_data(object, &data);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to get channel data");
+ tizen_core_channel_object_destroy(object);
+ return;
+ }
+
+ dlog_print(DLOG_INFO, LOG_TAG, "data=%s", data);
+ free(data);
+ tizen_core_channel_object_destroy(object);
+}
+ * @endcode
+ *
+ * @see tizen_core_channel_object_set_data()
+ */
+int tizen_core_channel_object_get_data(tizen_core_channel_object_h object,
+ void **data);
+
+/**
+ * @brief Gets the sender task name from the tizen core channel object handle.
+ * @since_tizen 9.0
+ * @remarks The @a task_name must not be deallocated by the application.
+ *
+ * @param[in] object The tizen core channel object handle
+ * @param[out] task_name The sender task name
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #TIZEN_CORE_ERROR_INVALID_CONTEXT Invalid context
+ *
+ * @code
+#include <tizen_core.h>
+
+static void print_task_name(tizen_core_channel_object_h object)
+{
+ const char *task_name = NULL;
+ int ret;
+
+ ret = tizen_core_channel_object_get_sender_task_name(object, &task_name);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to get sender task name");
+ return;
+ }
+
+ dlog_print(DLOG_INFO, LOG_TAG, "sender task=%s", task_name");
+}
+ * @endcode
+ *
+ * @see tizen_core_channel_sender_send()
+ * @see tizen_core_channel_receiver_receive()
+ */
+int tizen_core_channel_object_get_sender_task_name(
+ tizen_core_channel_object_h object, const char **task_name);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_BASE_TIZEN_CORE_CHANNEL_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __TIZEN_BASE_TIZEN_CORE_EVENT_H__
+#define __TIZEN_BASE_TIZEN_CORE_EVENT_H__
+
+#include <stdbool.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file tizen_core_event.h
+ */
+
+/**
+ * @addtogroup CAPI_TIZEN_CORE_EVENT_MODULE
+ * @{
+ */
+
+/**
+ * @brief The tizen core event handle.
+ * @since_tizen 9.0
+ */
+typedef void *tizen_core_event_h;
+
+/**
+ * @brief The tizen core event object handle.
+ * @since_tizen 9.0
+ */
+typedef void *tizen_core_event_object_h;
+
+/**
+ * @brief The tizen core event handler handle.
+ * @since_tizen 9.0
+ */
+typedef void *tizen_core_event_handler_h;
+
+/**
+ * @brief Called when the event is emitted.
+ * @since_tizen 9.0
+ * @remarks The @a object must not be deallocated by the application.
+ *
+ * @param[in] object The tizen core event object handle
+ * @param[in] user_data The user data passed from the callback registration function
+ * @return @c true to continue with the next iteration of the loop,
+ * otherwise @c false to break out of the loop
+ * @see tizen_core_event_add_handler()
+ */
+typedef bool (*tizen_core_event_handler_cb)(tizen_core_event_object_h object,
+ void *user_data);
+
+/**
+ * @brief Called when the event object is destroyed.
+ * @since_tizen 9.0
+ * @remarks The @a event_data should be released using release function if it's needed.
+ *
+ * @param[in] event_data The event data of the event object
+ * @param[in] user_data The user data passed from the callback registration function
+ * @see tizen_core_event_object_set_destroy_cb()
+ * @see tizen_core_event_object_destroy()
+ */
+typedef void (*tizen_core_event_object_destroy_cb)(void *event_data,
+ void *user_data);
+
+/**
+ * @brief Creates the tizen core event handle.
+ * @since_tizen 9.0
+ * @remarks The @a event should be released using tizen_core_event_destroy().
+ *
+ * @param[out] event The tizen core event handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #TIZEN_CORE_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #TIZEN_CORE_ERROR_INVALID_CONTEXT Invalid context
+ *
+ * @code
+#include <tizen_core.h>
+{
+ tizen_core_event_h event = NULL;
+ int ret;
+
+ ret = tizen_core_event_create(&event);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create event");
+ return;
+ }
+
+ tizen_core_event_destroy(event);
+}
+ * @endcode
+ *
+ * @see tizen_core_event_destroy()
+ */
+int tizen_core_event_create(tizen_core_event_h *event);
+
+/**
+ * @brief Destroys the tizen core event handle.
+ * @since_tizen 9.0
+ *
+ * @param[in] event The tizen core event handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @code
+#include <tizen_core.h>
+{
+ tizen_core_event_h event = NULL;
+ int ret;
+
+ tizen_core_event_create(&event);
+
+ ret = tizen_core_event_destroy(event);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to destroy event");
+ return;
+ }
+}
+ * @endcode
+ *
+ * @see tizen_core_event_create()
+ */
+int tizen_core_event_destroy(tizen_core_event_h event);
+
+/**
+ * @brief Adds the event handler to the tizen core event.
+ * @details The @a event_handler is added at the back of the handler list of the tizen core event.
+ * When tizen_core_emit_event() is called, the @a callback function of the @a event_handler is called first.
+ * @since_tizen 9.0
+ * @remarks The @a event_handler should be released using tizen_core_event_remove_handler().
+ *
+ * @param[in] event The tizen core event handle
+ * @param[in] callback The callback function to be invoked when the event is emitted
+ * @param[in] user_data The user data to be passed to the callback function
+ * @param[out] event_handler The tizen core event handler handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #TIZEN_CORE_ERROR_OUT_OF_MEMORY Out of memory
+ *
+ * @code
+#include <tizen_core.h>
+static void event_handler_cb(tizen_core_event_object_h object, void *user_data)
+{
+ int event_id = 0;
+ chat *event_data = NULL;
+
+ tizen_core_event_object_get_id(object, &event_id);
+ tizen_core_event_object_get_data(object, &event_data);
+
+ dlog_print(DLOG_INFO, LOG_TAG, "id=%d, data=%s", event_id, event_data);
+}
+
+static void add_event_handler(tizen_core_event_h event)
+{
+ tizen_core_event_handler_h event_handler = NULL;
+ int ret;
+
+ ret = tizen_core_event_add_handler(event, event_handler_cb, NULL, &event_handler);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to add event handler");
+ return;
+ }
+}
+ * @endcode
+ *
+ * @see tizen_core_event_emit()
+ * @see tizen_core_emit_event()
+ * @see tizen_core_event_remove_handler()
+ */
+int tizen_core_event_add_handler(
+ tizen_core_event_h event, tizen_core_event_handler_cb callback,
+ void *user_data, tizen_core_event_handler_h *event_handler);
+
+/**
+ * @brief Prepends the event handler to the tizen core event.
+ * @details The @a event_handler is added to the front of the handler list of the tizen core event.
+ * When tizen_core_emit_event() is called, the @a callback function of the @a event_handler is called first.
+ * @since_tizen 9.0
+ * @remarks The @a event_handler should be released using tizen_core_event_remove_handler().
+ *
+ * @param[in] event The tizen core event handle
+ * @param[in] callback The callback function to be invoked when the event is emitted
+ * @param[in] user_data The user data to be passed to the callback function
+ * @param[out] event_handler The tizen core event handler handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #TIZEN_CORE_ERROR_OUT_OF_MEMORY Out of memory
+ *
+ * @code
+#include <tizen_core.h>
+static void event_handler_cb(tizen_core_event_object_h object, void *user_data)
+{
+ int event_id = 0;
+ chat *event_data = NULL;
+
+ tizen_core_event_object_get_id(object, &event_id);
+ tizen_core_event_object_get_data(object, &event_data);
+
+ dlog_print(DLOG_INFO, LOG_TAG, "id=%d, data=%s", event_id, data);
+}
+
+static void prepend_event_handler(tizen_core_event_h event)
+{
+ tizen_core_event_handler_h event_handler = NULL;
+ int ret;
+
+ ret = tizen_core_event_prepend_handler(event, event_handler_cb, NULL, &event_handler);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to prepend event handler");
+ return;
+ }
+}
+ * @endcode
+ *
+ * @see tizen_core_event_emit()
+ * @see tizen_core_emit_event()
+ * @see tizen_core_event_remove_handler()
+ */
+int tizen_core_event_prepend_handler(
+ tizen_core_event_h event, tizen_core_event_handler_cb callback,
+ void *user_data, tizen_core_event_handler_h *event_handler);
+
+/**
+ * @brief Removes the event handler from the tizen core event.
+ * @since_tizen 9.0
+ *
+ * @param[in] event The tizen core event handle
+ * @param[in] event_handler The tizen core event handler handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @code
+#include <tizen_core.h>
+static void remove_event_handler(tizen_core_event_h event, tizen_core_event_handler_h handler)
+{
+ int ret;
+
+ ret = tizen_core_event_remove_handler(event, handler);
+ if (ret != TIZEN_CORE_ERROR_NONE)
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to remove event handler");
+}
+ * @endcode
+ *
+ * @see tizen_core_event_add_handler()
+ */
+int tizen_core_event_remove_handler(
+ tizen_core_event_h event, tizen_core_event_handler_h event_handler);
+
+/**
+ * @brief Emits the event to the tizen core event.
+ * @details The event is emitted to the tizen core event.
+ * @since_tizen 9.0
+ * @remarks The @a object will be released automatically.
+ * You MUST NOT release the @a object using tizen_core_event_object_destroy()
+ * when calling the function is successful.
+ * If this function returns an error, the @a object should be released
+ * using tizen_core_event_object_destroy().
+ *
+ * @param[in] event The tizen core event handle
+ * @param[in] object The tizen core event object handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @code
+#include <tizen_core.h>
+static void object_destroy_cb(void *event_data, void *user_data)
+{
+ char* value = (char *)event_data;
+
+ if (value)
+ free(value);
+}
+
+static void emit_event(tizen_core_event_h event)
+{
+ tizen_core_event_object_h object = NULL;
+ char buf[12];
+ int event_id = 99;
+ int ret;
+
+ snprintf(buf, sizeof(buf), "%d", event_id);
+ tizen_core_event_object_create(&object, event_id, strdup(buf));
+ tizen_core_event_object_set_destroy_cb(object, object_destroy_cb, NULL);
+
+ ret = tizen_core_event_emit(event, object);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to emit event");
+ tizen_core_event_object_destroy(object);
+ return;
+ }
+}
+ * @endcode
+ *
+ * @see tizen_core_event_add_handler()
+ */
+int tizen_core_event_emit(tizen_core_event_h event,
+ tizen_core_event_object_h object);
+
+/**
+ * @brief Creates the tizen core event object handle.
+ * @details The @a data can be nullptr.
+ * If the @a data is memory allocated, the @a data can be released
+ * using the tizen_core_event_object_set_destroy_cb() function.
+ * When tizen_core_event_object_destroy() calls, the callback function
+ * set in tizen_core_event_object_set_destroy_cb() is called.
+ * @since_tizen 9.0
+ * @remarks The @a object should be released using tizen_core_event_object_destroy().
+ * @remarks The @a object should not be released when the @a object is emitted
+ * using tizen_core_event_emit().
+ *
+ * @param[out] object The tizen core event object handle
+ * @param[in] id The event ID
+ * @param[in] data The event data
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #TIZEN_CORE_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #TIZEN_CORE_ERROR_INVALID_CONTEXT Invalid context
+ *
+ * @code
+#include <tizen_core.h>
+
+static void object_destroy_cb(void *event_data, void *user_data)
+{
+ char *value = (char *)event_data;
+
+ if (value)
+ free(value);
+}
+
+static tizen_core_event_object_h create_event_object(void)
+{
+ tizen_core_event_object_h object = NULL;
+ char buf[12];
+ int event_id = 99;
+ int ret;
+
+ snprintf(buf, sizeof(buf), "%d", event_id);
+ ret = tizen_core_event_object_create(&object, event_id, strdup(buf));
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create event object");
+ return NULL;
+ }
+
+ tizen_core_event_object_set_destroy_cb(object, object_destroy_cb, NULL);
+
+ return object;
+}
+ * @endcode
+ *
+ * @see tizen_core_event_object_set_destroy_cb()
+ * @see tizen_core_event_object_destroy()
+ * @see tizen_core_event_emit()
+ */
+int tizen_core_event_object_create(tizen_core_event_object_h *object,
+ int id, void *data);
+
+/**
+ * @brief Destroys the tizen core event object handle.
+ * @since_tizen 9.0
+ *
+ * @param[in] object The tizen core event object handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @code
+#include <tizen_core.h>
+{
+ tizen_core_event_object_h object = NULL;
+ int event_id = 99;
+ int ret;
+
+ tizen_core_event_object_create(&object, event_id, NULL);
+
+ ret = tizen_core_event_object_destroy(object);
+ if (ret != TIZEN_CORE_ERROR_NONE)
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to destroy event object");
+}
+ * @endcode
+ *
+ * @see tizen_core_event_object_create()
+ * @see tizen_core_event_object_set_destroy_cb()
+ */
+int tizen_core_event_object_destroy(tizen_core_event_object_h object);
+
+/**
+ * @brief Sets the destroy callback function to invoke when the event object is destroyed.
+ * @since_tizen 9.0
+ *
+ * @param[in] object The tizen core event object handle
+ * @param[in] callback The callback function to be invoked when the event object is destroyed
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @code
+#include <tizen_core.h>
+static void object_destroy_cb(void *data, void *user_data)
+{
+ char *str = (char *)data;
+
+ if (str)
+ free(str);
+}
+
+static tizen_core_event_object_h create_event_object(int id, char *str)
+{
+ tizen_core_event_object_h object = NULL;
+ int ret;
+
+ tizen_core_event_object_create(&object, id, str);
+
+ ret = tizen_core_event_object_set_destroy_cb(object, object_destroy_cb, NULL);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to set on_destroy callback");
+ tizen_core_event_object_destroy(object);
+ return NULL;
+ }
+
+ return object;
+}
+ * @endcode
+ *
+ * @see tizen_core_event_object_destroy()
+ */
+int tizen_core_event_object_set_destroy_cb(
+ tizen_core_event_object_h object,
+ tizen_core_event_object_destroy_cb callback, void *user_data);
+
+/**
+ * @brief Gets the event ID from the tizen core event object handle.
+ * @since_tizen 9.0
+ *
+ * @param[in] object The tizen core event object handle
+ * @param[out] id The event ID
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @code
+#include <tizen_core.h>
+{
+ tizen_core_event_object_h object = NULL;
+ int event_id;
+ int ret;
+
+ tizen_core_event_object_create(&object, 22, NULL);
+
+ ret = tizen_core_event_object_get_id(object, &event_id);
+ if (ret != TIZEN_CORE_ERROR_NONE)
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to get event id");
+
+ tizen_core_event_object_destroy(object);
+}
+ * @endcode
+ *
+ * @see tizen_core_event_object_create()
+ */
+int tizen_core_event_object_get_id(tizen_core_event_object_h object, int *id);
+
+/**
+ * @brief Gets the event data from the tizen core event object handle.
+ * @since_tizen 9.0
+ * @remarks The @a data should not be released if the @a object is emitted
+ * using tizen_core_event_emit().
+ * @remarks The @a data is available until the @a object is released.
+ *
+ * @param[in] object The tizen core event object handle
+ * @param[out] data The event data
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @code
+#include <tizen_core.h>
+static void event_object_destroy_cb(void *event_data, void *user_data)
+{
+ char *value = (char *)event_data;
+
+ if (value)
+ free(value);
+}
+
+static void create_and_destroy_event_object(void)
+{
+ tizen_core_event_object_h object = NULL;
+ char *event_data = strdup("22");
+ char *value = NULL;
+ int ret;
+
+ tizen_core_event_object_create(&object, 22, event_data);
+ tizen_core_event_object_set_destroy_cb(object, event_object_destroy_cb, NULL);
+
+ ret = tizen_core_event_object_get_data(object, &value);
+ if (ret != TIZEN_CORE_ERROR_NONE)
+ dlog_print(DLOG_ERROR, LOG_TAG, "Failed to get event data");
+
+ tizen_core_event_object_destroy(object);
+}
+ * @endcode
+ */
+int tizen_core_event_object_get_data(tizen_core_event_object_h object,
+ void **data);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_BASE_TIZEN_CORE_EVENT_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __TIZEN_BASE_TIZEN_CORE_EVENT_INTERNAL_H__
+#define __TIZEN_BASE_TIZEN_CORE_EVENT_INTERNAL_H__
+
+#include <tizen_core.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Generates the event ID.
+ * @since_tizen 9.0
+ *
+ * @return @c the generated event ID
+ *
+ * @code
+#include <tizen_core.h>
+{
+ tizen_core_event_object_h object = NULL;
+ int id;
+
+ id = tizen_core_event_generate_id();
+ tizen_core_event_object_create(&object, id, NULL);
+}
+ * @endcode
+ */
+int tizen_core_event_generate_id(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_BASE_TIZEN_CORE_EVENT_INTERNAL_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __TIZEN_BASE_TIZEN_CORE_INTERNAL_H__
+#define __TIZEN_BASE_TIZEN_CORE_INTERNAL_H__
+
+#include <tizen_core.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Enumeration for the tizen core cpu boosting level.
+ * @since_tizen 9.0
+ */
+typedef enum {
+ TIZEN_CORE_CPU_BOOSTING_LEVEL_NONE, /**< None level */
+ TIZEN_CORE_CPU_BOOSTING_LEVEL_STRONG, /**< Strong level */
+ TIZEN_CORE_CPU_BOOSTING_LEVEL_MEDIUM, /**< Medium level */
+ TIZEN_CORE_CPU_BOOSTING_LEVEL_WEAK, /**< Weak level */
+} tizen_core_cpu_boosting_level_e;
+
+/**
+ * @brief Gets the glib context from the tizen core handle.
+ * @since_tizen 9.0
+ *
+ * @param[in] core The tizen core handle
+ * @return @c the glib context on success,
+ * otherwise a nullptr
+ */
+void *tizen_core_get_glib_context(tizen_core_h core);
+
+/**
+ * @brief Sets cpu boosting of the tizen core.
+ * @since_tizen 9.0
+ *
+ * @param[in] core The tizen core handle
+ * @param[in] level The cpu boosting level
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #TIZEN_CORE_ERROR_INVALID_CONTEXT The core is not running
+ *
+ * @code
+#include <tizen_core_internal.h>
+{
+ tizen_core_h core = NULL;
+ int ret;
+
+ ret = tizen_core_find("main", &core);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ return -1;
+ }
+
+ ret = tizen_core_set_cpu_boosting(core, TIZEN_CORE_CPU_BOOSTING_LEVEL_STRONG);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ return -1;
+ }
+
+ return 0;
+}
+ * @endcode
+ * @see tizen_core_clear_cpu_boosting()
+ */
+int tizen_core_set_cpu_boosting(tizen_core_h core,
+ tizen_core_cpu_boosting_level_e level);
+
+/**
+ * @brief Clears cpu boosting of the tizen core.
+ * @since_tizen 9.0
+ *
+ * @param[in] core The tizen core handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #TIZEN_CORE_ERROR_INVALID_CONTEXT The core is not running
+ *
+ * @code
+#include <tizen_core_internal.h>
+{
+ tizen_core_h core = NULL;
+ int ret;
+
+ ret = tizen_core_find("main", &core);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ return -1;
+ }
+
+ ret = tizen_core_clear_cpu_boosting(core);
+ if (ret != TIZEN_CORE_ERROR_NONE) {
+ return -1;
+ }
+
+ return 0;
+}
+ * @endcode
+ * @see tizen_core_set_cpu_boosting()
+ */
+int tizen_core_clear_cpu_boosting(tizen_core_h core);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_BASE_TIZEN_CORE_INTERNAL_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef TIZEN_CORE_INTERFACE_LOOP_H_
+#define TIZEN_CORE_INTERFACE_LOOP_H_
+
+#include <functional>
+#include <memory>
+
+#include "tizen-core/interface_source.h"
+
+#undef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+
+namespace tizen_core {
+
+class EXPORT_API ILoop {
+ public:
+ virtual ~ILoop() = default;
+ virtual void Run() = 0;
+ virtual void Quit() = 0;
+ virtual bool IsRunning() const = 0;
+ virtual std::shared_ptr<ISource> AddIdleJob(std::function<bool()> cb) = 0;
+ virtual std::shared_ptr<ISource> AddTimer(unsigned int interval,
+ std::function<bool()> cb) = 0;
+ virtual void RemoveSource(std::shared_ptr<ISource> source) = 0;
+ virtual void AddSource(std::shared_ptr<ISource> source) = 0;
+};
+
+} // namespace tizen_core
+
+#endif // TIZEN_CORE_INTERFACE_LOOP_H_
--- /dev/null
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef TIZEN_CORE_INTERFACE_SOURCE_H_
+#define TIZEN_CORE_INTERFACE_SOURCE_H_
+
+#include <memory>
+
+#undef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+
+namespace tizen_core {
+
+class Context;
+class PollFd;
+
+class EXPORT_API ISource {
+ public:
+ virtual ~ISource() = default;
+ virtual void Attach(const std::shared_ptr<Context>& context) = 0;
+ virtual void AddPoll(std::shared_ptr<PollFd> poll_fd) = 0;
+ virtual void RemovePoll(const std::shared_ptr<PollFd>& poll_fd) = 0;
+ virtual void RefSelf() = 0;
+ virtual void UnrefSelf() = 0;
+};
+
+} // namespace tizen_core
+
+#endif // TIZEN_CORE_INTERFACE_SOURCE_H_
--- /dev/null
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef TIZEN_CORE_LOG_PRIVATE_H_
+#define TIZEN_CORE_LOG_PRIVATE_H_
+
+#include <dlog.h>
+
+#undef LOG_TAG
+#define LOG_TAG "TIZEN_CORE"
+
+#undef _E
+#define _E LOGE
+
+#undef _W
+#define _W LOGW
+
+#undef _I
+#define _I LOGI
+
+#undef _D
+#define _D LOGD
+
+#endif // TIZEN_CORE_LOG_PRIVATE_H_
--- /dev/null
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "tizen-core/poll_fd.h"
+
+#include "tizen-core/log_private.h"
+
+namespace tizen_core {
+
+PollFd::PollFd() { _D("PollFd=%p", this); }
+
+PollFd::~PollFd() { _D("PollFd=%p, fd=%d", this, gpollfd_.fd); }
+
+void PollFd::SetFd(int fd) { gpollfd_.fd = fd; }
+
+int PollFd::GetFd() const { return gpollfd_.fd; }
+
+void PollFd::SetEvents(uint16_t events) { gpollfd_.events = events; }
+
+uint16_t PollFd::GetEvents() const { return gpollfd_.events; }
+
+void PollFd::SetRevents(uint16_t revents) { gpollfd_.revents = revents; }
+
+uint16_t PollFd::GetRevents() const { return gpollfd_.revents; }
+
+const GPollFD* PollFd::GetGPollFD() const { return &gpollfd_; }
+
+void PollFd::RefSelf() { self_ = shared_from_this(); }
+
+void PollFd::UnrefSelf() {
+ if (!self_) return;
+
+ if (source_ != nullptr) {
+ source_->RemovePoll(self_);
+ source_ = nullptr;
+ }
+
+ self_.reset();
+}
+
+void PollFd::SetSource(ISource* source) { source_ = source; }
+
+ISource* PollFd::GetSource() const { return source_; }
+
+} // namespace tizen_core
--- /dev/null
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef TIZEN_CORE_POLL_FD_H_
+#define TIZEN_CORE_POLL_FD_H_
+
+#include <glib.h>
+
+#include <memory>
+
+#include "tizen-core/interface_source.h"
+
+#undef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+
+namespace tizen_core {
+
+class EXPORT_API PollFd : public std::enable_shared_from_this<PollFd> {
+ public:
+ PollFd();
+ ~PollFd();
+
+ void SetFd(int fd);
+ int GetFd() const;
+
+ void SetEvents(uint16_t events);
+ uint16_t GetEvents() const;
+
+ void SetRevents(uint16_t revents);
+ uint16_t GetRevents() const;
+
+ const GPollFD* GetGPollFD() const;
+
+ void RefSelf();
+ void UnrefSelf();
+
+ void SetSource(ISource* source);
+ ISource* GetSource() const;
+
+ private:
+ GPollFD gpollfd_ = { -1, 0, 0 };
+ std::shared_ptr<PollFd> self_;
+ ISource* source_ = nullptr;
+};
+
+} // namespace tizen_core
+
+#endif // TIZEN_CORE_POLL_FD_H_
--- /dev/null
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "tizen-core/source.h"
+
+#include <mutex>
+#include <stdexcept>
+#include <unordered_map>
+#include <utility>
+
+#include "tizen-core/log_private.h"
+
+namespace tizen_core {
+namespace {
+
+class SourceManager {
+ public:
+ void Insert(Source* source) {
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ auto* gsource = source->GetHandle();
+ map_[gsource] = source;
+ }
+
+ void Erase(GSource* gsource) {
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ map_.erase(gsource);
+ }
+
+ Source* Find(GSource* gsource) {
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ auto found = map_.find(gsource);
+ if (found == map_.end())
+ return nullptr;
+
+ return found->second;
+ }
+
+ private:
+ std::unordered_map<GSource*, Source*> map_;
+ mutable std::recursive_mutex mutex_;
+};
+
+SourceManager source_manager;
+
+} // namespace
+
+Source::Source(GSource* handle) : handle_(handle) {}
+
+Source::Source() {
+ static GSourceFuncs source_funcs = {
+ .prepare = SourcePrepareFunc,
+ .check = SourceCheckFunc,
+ .dispatch = SourceDispatchFunc,
+ .finalize = SourceFinalizeFunc,
+ .closure_callback = nullptr,
+ .closure_marshal = nullptr
+ };
+
+ handle_ = g_source_new(&source_funcs, sizeof(GSource));
+ if (handle_ == nullptr) {
+ _E("g_source_new() is failed"); // LCOV_EXCL_LINE
+ throw std::runtime_error("g_source_new() is failed"); // LCOV_EXCL_LINE
+ }
+ source_manager.Insert(this);
+}
+
+Source::~Source() {
+ if (handle_ != nullptr) {
+ // LCOV_EXCL_START
+ auto iter = poll_fds_.begin();
+ while (iter != poll_fds_.end()) {
+ auto& poll_fd = *iter;
+ poll_fd->SetSource(nullptr);
+ g_source_remove_poll(handle_,
+ const_cast<GPollFD*>(poll_fd->GetGPollFD()));
+ iter = poll_fds_.erase(iter);
+ }
+ // LCOV_EXCL_STOP
+
+ if (!g_source_is_destroyed(handle_)) g_source_destroy(handle_);
+ if (!attached_) g_source_unref(handle_);
+
+ source_manager.Erase(handle_);
+ }
+}
+
+void Source::AddPoll(std::shared_ptr<PollFd> poll_fd) {
+ _D("AddPoll(). PollFd=%p", poll_fd.get());
+ g_source_add_poll(handle_, const_cast<GPollFD*>(poll_fd->GetGPollFD()));
+ poll_fd->SetSource(this);
+ g_source_set_callback(handle_, nullptr, this, nullptr);
+ poll_fds_.push_back(std::move(poll_fd));
+}
+
+void Source::RemovePoll(const std::shared_ptr<PollFd>& poll_fd) {
+ _D("RemovePoll(). PollFd=%p", poll_fd.get());
+ poll_fd->SetSource(nullptr);
+ g_source_remove_poll(handle_, const_cast<GPollFD*>(poll_fd->GetGPollFD()));
+ poll_fds_.remove_if(
+ [=](const std::shared_ptr<PollFd>& pollfd) { return pollfd == poll_fd; });
+}
+
+void Source::Attach(const std::shared_ptr<Context>& context) {
+ if (handle_ == nullptr)
+ return;
+
+ if (attached_)
+ return;
+
+ g_source_attach(handle_, context->GetHandle());
+ g_source_unref(handle_);
+ attached_ = true;
+}
+
+bool Source::IsAttached() const { return attached_; }
+
+GSource* Source::GetHandle() const { return handle_; }
+
+void Source::RefSelf() { if (!self_) self_ = shared_from_this(); }
+
+void Source::UnrefSelf() { self_.reset(); }
+
+void Source::SetPriority(int priority) {
+ g_source_set_priority(handle_, priority);
+}
+
+// LCOV_EXCL_START
+bool Source::OnSourcePrepare(int* timeout) { return false; }
+
+bool Source::OnSourceCheck() { return false; }
+
+bool Source::OnSourceDispatch() { return false; }
+
+void Source::OnSourceFinalize() {}
+
+gboolean Source::SourcePrepareFunc(GSource* gsource, gint* timeout) {
+ auto source = source_manager.Find(gsource);
+ if (source == nullptr)
+ return FALSE;
+
+ return source->OnSourcePrepare(timeout);
+}
+
+gboolean Source::SourceCheckFunc(GSource* gsource) {
+ auto source = source_manager.Find(gsource);
+ if (source == nullptr)
+ return FALSE;
+
+ return source->OnSourceCheck();
+}
+
+gboolean Source::SourceDispatchFunc(GSource* gsource, GSourceFunc callback,
+ gpointer user_data) {
+ auto source = source_manager.Find(gsource);
+ if (source == nullptr)
+ return FALSE;
+
+ return source->OnSourceDispatch();
+}
+
+void Source::SourceFinalizeFunc(GSource* gsource) {
+ auto source = source_manager.Find(gsource);
+ if (source == nullptr)
+ return;
+
+ source->OnSourceFinalize();
+}
+// LCOV_EXCL_STOP
+
+} // namespace tizen_core
--- /dev/null
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef TIZEN_CORE_SOURCE_H_
+#define TIZEN_CORESOURCE_H_
+
+#include <glib.h>
+
+#include <list>
+#include <memory>
+
+#include "tizen-core/context.h"
+#include "tizen-core/interface_source.h"
+#include "tizen-core/poll_fd.h"
+
+#undef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+
+namespace tizen_core {
+
+class EXPORT_API Source : public ISource,
+ public std::enable_shared_from_this<Source> {
+ public:
+ Source();
+ explicit Source(GSource* handle);
+ virtual ~Source();
+
+ void AddPoll(std::shared_ptr<PollFd> poll_fd) override;
+ void RemovePoll(const std::shared_ptr<PollFd>& poll_fd) override;
+ void Attach(const std::shared_ptr<Context>& context) override;
+ bool IsAttached() const;
+ GSource* GetHandle() const;
+ void RefSelf() override;
+ void UnrefSelf() override;
+ void SetPriority(int priority);
+
+ virtual bool OnSourcePrepare(int* timeout);
+ virtual bool OnSourceCheck();
+ virtual bool OnSourceDispatch();
+ virtual void OnSourceFinalize();
+
+ private:
+ static gboolean SourcePrepareFunc(GSource* gsource, gint* timeout);
+ static gboolean SourceCheckFunc(GSource* gsource);
+ static gboolean SourceDispatchFunc(GSource* gsource, GSourceFunc callback,
+ gpointer user_data);
+ static void SourceFinalizeFunc(GSource* gsource);
+
+ private:
+ GSource* handle_ = nullptr;
+ bool attached_ = false;
+ std::shared_ptr<Source> self_;
+ std::list<std::shared_ptr<PollFd>> poll_fds_;
+};
+
+} // namespace tizen_core
+
+#endif // TIZEN_CORE_SOURCE_H_
--- /dev/null
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "tizen-core/include/tizen_core.h"
+
+#include <atomic>
+#include <stdexcept>
+
+#include "tizen-core/include/tizen_core_internal.h"
+#include "tizen-core/context_manager.h"
+#include "tizen-core/log_private.h"
+#include "tizen-core/task.h"
+#include "tizen-core/source.h"
+
+#undef EXPORT
+#define EXPORT __attribute__ ((visibility("default")))
+
+#undef API
+#define API extern "C" EXPORT
+
+namespace {
+
+std::atomic<int> tizen_core_ref(0);
+
+class SourceExt : public tizen_core::Source {
+ public:
+ SourceExt() {}
+
+ void SetPrepareCb(tizen_core_source_prepare_cb callback, void* user_data) {
+ prepare_cb_ = callback;
+ prepare_data_ = user_data;
+ }
+
+ void SetCheckCb(tizen_core_source_check_cb callback, void* user_data) {
+ check_cb_ = callback;
+ check_data_ = user_data;
+ }
+
+ void SetDispatchCb(tizen_core_source_dispatch_cb callback, void* user_data) {
+ dispatch_cb_ = callback;
+ dispatch_data_ = user_data;
+ }
+
+ void SetFinalizeCb(tizen_core_source_finalize_cb callback, void* user_data) {
+ finalize_cb_ = callback;
+ finalize_data_ = user_data;
+ }
+
+ private:
+ // LCOV_EXCL_START
+ bool OnSourcePrepare(int* timeout) override {
+ if (prepare_cb_ != nullptr)
+ return prepare_cb_(this, timeout, prepare_data_);
+
+ return false;
+ }
+
+ bool OnSourceCheck() override {
+ if (check_cb_ != nullptr)
+ return check_cb_(this, check_data_);
+
+ return false;
+ }
+
+ bool OnSourceDispatch() override {
+ if (dispatch_cb_ != nullptr)
+ return dispatch_cb_(this, dispatch_data_);
+
+ return false;
+ }
+
+ void OnSourceFinalize() override {
+ if (finalize_cb_ != nullptr)
+ finalize_cb_(this, finalize_data_);
+ }
+ // LCOV_EXCL_STOP
+
+ private:
+ tizen_core_source_prepare_cb prepare_cb_ = nullptr;
+ void* prepare_data_ = nullptr;
+ tizen_core_source_check_cb check_cb_ = nullptr;
+ void* check_data_ = nullptr;
+ tizen_core_source_dispatch_cb dispatch_cb_ = nullptr;
+ void* dispatch_data_ = nullptr;
+ tizen_core_source_finalize_cb finalize_cb_ = nullptr;
+ void* finalize_data_ = nullptr;
+};
+
+} // namespace
+
+API void tizen_core_init(void) {
+ ++tizen_core_ref;
+}
+
+API void tizen_core_shutdown(void) {
+ if (tizen_core_ref <= 0)
+ return;
+
+ if (tizen_core_ref == 1)
+ tizen_core::ContextManager::GetInst().DisposeAll();
+
+ --tizen_core_ref;
+}
+
+API bool tizen_core_ready(void) {
+ return tizen_core_ref > 0;
+}
+
+API int tizen_core_task_create(const char* name, bool use_thread,
+ tizen_core_task_h* task) {
+ if (name == nullptr || task == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (!tizen_core_ready())
+ return TIZEN_CORE_ERROR_INVALID_CONTEXT;
+
+ try {
+ auto handle = tizen_core::Task::Create(name, use_thread);
+ if (handle == nullptr) {
+ _E("Out of memory"); // LCOV_EXCL_LINE
+ return TIZEN_CORE_ERROR_OUT_OF_MEMORY; // LCOV_EXCL_LINE
+ }
+
+ handle->RefSelf();
+ *task = static_cast<tizen_core_task_h>(handle.get());
+ } catch (const std::invalid_argument& e) {
+ _E("Exception occurs. error(%s)", e.what());
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_task_destroy(tizen_core_task_h task) {
+ if (task == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* handle = static_cast<tizen_core::Task*>(task);
+ handle->Dispose();
+ handle->UnrefSelf();
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_task_run(tizen_core_task_h task) {
+ if (task == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* handle = static_cast<tizen_core::Task*>(task);
+ handle->Run();
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_task_is_running(tizen_core_task_h task, bool* running) {
+ if (task == nullptr || running == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* handle = static_cast<tizen_core::Task*>(task);
+ *running = handle->IsRunning();
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_task_quit(tizen_core_task_h task) {
+ if (task == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* handle = static_cast<tizen_core::Task*>(task);
+ handle->Quit();
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_task_get_tizen_core(tizen_core_task_h task,
+ tizen_core_h* core) {
+ if (task == nullptr || core == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ *core = static_cast<tizen_core_h>(task);
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_find(const char* name, tizen_core_h* core) {
+ if (name == nullptr || core == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (!tizen_core_ready())
+ return TIZEN_CORE_ERROR_INVALID_CONTEXT;
+
+ auto context = tizen_core::ContextManager::GetInst().Find(name);
+ if (context == nullptr) {
+ _E("Failed to find context. name(%s)", name);
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ *core = static_cast<tizen_core_h>(context->GetLoop().get());
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_find_from_this_thread(tizen_core_h* core) {
+ if (core == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (!tizen_core_ready())
+ return TIZEN_CORE_ERROR_INVALID_CONTEXT;
+
+ auto context = tizen_core::ContextManager::GetInst().FindFromThisThread();
+ if (context == nullptr) {
+ _E("Failed to find context"); // LCOV_EXCL_LINE
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER; // LCOV_EXCL_LINE
+ }
+
+ *core = static_cast<tizen_core_h>(context->GetLoop().get());
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_add_idle_job(tizen_core_h core, tizen_core_task_cb callback,
+ void* user_data, tizen_core_source_h* source) {
+ if (core == nullptr || callback == nullptr || source == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* task = static_cast<tizen_core::Task*>(core);
+ auto idle_source = task->AddIdleJob([=]() { return callback(user_data); });
+ if (idle_source == nullptr) {
+ _E("Failed to add idle job"); // LCOV_EXCL_LINE
+ return TIZEN_CORE_ERROR_OUT_OF_MEMORY; // LCOV_EXCL_LINE
+ }
+
+ *source = idle_source.get();
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_add_timer(tizen_core_h core, unsigned int interval,
+ tizen_core_task_cb callback, void* user_data,
+ tizen_core_source_h* source) {
+ if (core == nullptr || callback == nullptr || source == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* task = static_cast<tizen_core::Task*>(core);
+ auto timer_source =
+ task->AddTimer(interval, [=]() { return callback(user_data); });
+ if (timer_source == nullptr) {
+ _E("Failed to add timer"); // LCOV_EXCL_LINE
+ return TIZEN_CORE_ERROR_OUT_OF_MEMORY; // LCOV_EXCL_LINE
+ }
+
+ *source = timer_source.get();
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_add_channel(tizen_core_h core,
+ tizen_core_channel_receiver_h receiver,
+ tizen_core_channel_receive_cb callback,
+ void* user_data, tizen_core_source_h* source) {
+ if (core == nullptr || receiver == nullptr || callback == nullptr ||
+ source == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* task = static_cast<tizen_core::Task*>(core);
+ auto* channel_receiver =
+ static_cast<tizen_core::channel::Receiver<void*>*>(receiver);
+ auto channel_source = task->AddChannel<void*>(
+ channel_receiver->shared_from_this(),
+ [=](const tizen_core::channel::ChannelObject<void*>& object) {
+ callback(
+ &const_cast<tizen_core::channel::ChannelObject<void*>&>(object),
+ user_data);
+ });
+ if (channel_source == nullptr) {
+ _E("Failed to add channel"); // LCOV_EXCL_LINE
+ return TIZEN_CORE_ERROR_OUT_OF_MEMORY; // LCOV_EXCL_LINE
+ }
+
+ *source = channel_source.get();
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_add_event(tizen_core_h core, tizen_core_event_h event,
+ tizen_core_source_h* source) {
+ if (core == nullptr || event == nullptr || source == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* broker = static_cast<tizen_core::event::EventBroker<void*>*>(event);
+ if (broker->IsAttached()) {
+ _E("Already attached. event=%p", event);
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* task = static_cast<tizen_core::Task*>(core);
+ auto event_source = task->AddEvent(
+ std::shared_ptr<tizen_core::event::EventBroker<void*>>(broker));
+ if (event_source == nullptr) {
+ _E("Failed to add event"); // LCOV_EXCL_LINE
+ return TIZEN_CORE_ERROR_OUT_OF_MEMORY; // LCOV_EXCL_LINE
+ }
+
+ *source = event_source.get();
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_emit_event(tizen_core_h core,
+ tizen_core_event_object_h object) {
+ if (core == nullptr || object == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* task = static_cast<tizen_core::Task*>(core);
+ auto* event_object =
+ static_cast<tizen_core::event::EventObject<void*>*>(object);
+ task->EmitEvent(event_object->shared_from_this());
+ event_object->Unref();
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_add_source(tizen_core_h core, tizen_core_source_h source) {
+ if (core == nullptr || source == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* task = static_cast<tizen_core::Task*>(core);
+ auto* core_source = static_cast<tizen_core::Source*>(source);
+ task->AddSource(core_source->shared_from_this());
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_remove_source(tizen_core_h core,
+ tizen_core_source_h source) {
+ if (core == nullptr || source == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* core_source = static_cast<tizen_core::Source*>(source);
+ if (!core_source->IsAttached()) {
+ _E("Source(%p) is not attached", source);
+ return TIZEN_CORE_ERROR_INVALID_CONTEXT;
+ }
+
+ auto* task = static_cast<tizen_core::Task*>(core);
+ task->RemoveSource(core_source->shared_from_this());
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+// LCOV_EXCL_START
+API int tizen_core_set_cpu_boosting(
+ tizen_core_h core, tizen_core_cpu_boosting_level_e level) {
+ if (core == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* task = static_cast<tizen_core::Task*>(core);
+ if (!task->SetCpuBoosting(level))
+ return TIZEN_CORE_ERROR_INVALID_CONTEXT;
+
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_clear_cpu_boosting(tizen_core_h core) {
+ if (core == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* task = static_cast<tizen_core::Task*>(core);
+ if (!task->ClearCpuBoosting())
+ return TIZEN_CORE_ERROR_INVALID_CONTEXT;
+
+ return TIZEN_CORE_ERROR_NONE;
+}
+// LCOV_EXCL_STOP
+
+API int tizen_core_source_create(tizen_core_source_h* source) {
+ if (source == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (!tizen_core_ready())
+ return TIZEN_CORE_ERROR_INVALID_CONTEXT;
+
+ auto handle = std::make_shared<SourceExt>();
+ if (handle == nullptr) {
+ _E("Out of memory"); // LCOV_EXCL_LINE
+ return TIZEN_CORE_ERROR_OUT_OF_MEMORY; // LCOV_EXCL_STOP
+ }
+
+ handle->RefSelf();
+ *source = static_cast<tizen_core_source_h>(handle.get());
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_source_destroy(tizen_core_source_h source) {
+ if (source == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* handle = static_cast<SourceExt*>(source);
+ handle->UnrefSelf();
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_source_add_poll(tizen_core_source_h source,
+ tizen_core_poll_fd_h poll_fd) {
+ if (source == nullptr || poll_fd == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* handle = static_cast<SourceExt*>(source);
+ auto* pfd = static_cast<tizen_core::PollFd*>(poll_fd);
+ if (pfd->GetSource() != nullptr) {
+ _E("Invalid context"); // LCOV_EXCL_LINE
+ return TIZEN_CORE_ERROR_INVALID_CONTEXT; // LCOV_EXCL_LINE
+ }
+
+ handle->AddPoll(pfd->shared_from_this());
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_source_remove_poll(tizen_core_source_h source,
+ tizen_core_poll_fd_h poll_fd) {
+ if (source == nullptr || poll_fd == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* handle = static_cast<SourceExt*>(source);
+ auto* pfd = static_cast<tizen_core::PollFd*>(poll_fd);
+ if (pfd->GetSource() == nullptr) {
+ _E("Invalid context");
+ return TIZEN_CORE_ERROR_INVALID_CONTEXT;
+ }
+
+ handle->RemovePoll(pfd->shared_from_this());
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_source_set_prepare_cb(tizen_core_source_h source,
+ tizen_core_source_prepare_cb callback,
+ void* user_data) {
+ if (source == nullptr || callback == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* handle = static_cast<SourceExt*>(source);
+ handle->SetPrepareCb(callback, user_data);
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_source_set_check_cb(tizen_core_source_h source,
+ tizen_core_source_check_cb callback,
+ void* user_data) {
+ if (source == nullptr || callback == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* handle = static_cast<SourceExt*>(source);
+ handle->SetCheckCb(callback, user_data);
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_source_set_dispatch_cb(
+ tizen_core_source_h source, tizen_core_source_dispatch_cb callback,
+ void* user_data) {
+ if (source == nullptr || callback == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* handle = static_cast<SourceExt*>(source);
+ handle->SetDispatchCb(callback, user_data);
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_source_set_finalize_cb(
+ tizen_core_source_h source, tizen_core_source_finalize_cb callback,
+ void* user_data) {
+ if (source == nullptr || callback == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* handle = static_cast<SourceExt*>(source);
+ handle->SetFinalizeCb(callback, user_data);
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API void* tizen_core_get_glib_context(tizen_core_h core) {
+ if (core == nullptr) {
+ _E("Invalid parameter");
+ set_last_result(TIZEN_CORE_ERROR_INVALID_PARAMETER);
+ return nullptr;
+ }
+
+ auto* task = static_cast<tizen_core::Task*>(core);
+ set_last_result(TIZEN_CORE_ERROR_NONE);
+ return task->GetContext()->GetHandle();
+}
+
+API int tizen_core_source_set_priority(tizen_core_source_h source,
+ tizen_core_priority_e priority) {
+ if (source == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* handle = static_cast<SourceExt*>(source);
+ handle->SetPriority(static_cast<int>(priority));
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_poll_fd_create(tizen_core_poll_fd_h* poll_fd) {
+ if (poll_fd == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto handle = std::make_shared<tizen_core::PollFd>();
+ if (handle == nullptr) {
+ _E("Out of memory"); // LCOV_EXCL_LINE
+ return TIZEN_CORE_ERROR_OUT_OF_MEMORY; // LCOV_EXCL_LINE
+ }
+
+ handle->RefSelf();
+ *poll_fd = static_cast<tizen_core_poll_fd_h>(handle.get());
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_poll_fd_destroy(tizen_core_poll_fd_h poll_fd) {
+ if (poll_fd == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* handle = static_cast<tizen_core::PollFd*>(poll_fd);
+ handle->UnrefSelf();
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_poll_fd_set_fd(tizen_core_poll_fd_h poll_fd, int fd) {
+ if (poll_fd == nullptr || fd < 0) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* handle = static_cast<tizen_core::PollFd*>(poll_fd);
+ handle->SetFd(fd);
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_poll_fd_get_fd(tizen_core_poll_fd_h poll_fd, int* fd) {
+ if (poll_fd == nullptr || fd == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* handle = static_cast<tizen_core::PollFd*>(poll_fd);
+ *fd = handle->GetFd();
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_poll_fd_set_events(tizen_core_poll_fd_h poll_fd,
+ uint16_t events) {
+ if (poll_fd == nullptr || events == 0) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* handle = static_cast<tizen_core::PollFd*>(poll_fd);
+ handle->SetEvents(events);
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_poll_fd_get_events(tizen_core_poll_fd_h poll_fd,
+ uint16_t* events) {
+ if (poll_fd == nullptr || events == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* handle = static_cast<tizen_core::PollFd*>(poll_fd);
+ *events = handle->GetEvents();
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_poll_fd_set_returned_events(tizen_core_poll_fd_h poll_fd,
+ uint16_t returned_events) {
+ if (poll_fd == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* handle = static_cast<tizen_core::PollFd*>(poll_fd);
+ handle->SetRevents(returned_events);
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_poll_fd_get_returned_events(tizen_core_poll_fd_h poll_fd,
+ uint16_t* returned_events) {
+ if (poll_fd == nullptr || returned_events == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* handle = static_cast<tizen_core::PollFd*>(poll_fd);
+ *returned_events = handle->GetRevents();
+ return TIZEN_CORE_ERROR_NONE;
+}
--- /dev/null
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "tizen-core/include/tizen_core_channel.h"
+
+#include "tizen-core/include/tizen_core.h"
+#include "tizen-core/channel/channel_factory.h"
+#include "tizen-core/log_private.h"
+#include "tizen-core/task.h"
+#include "tizen-core/source.h"
+
+#undef EXPORT
+#define EXPORT __attribute__ ((visibility("default")))
+
+#undef API
+#define API extern "C" EXPORT
+
+namespace {
+
+} // namespace
+
+API int tizen_core_channel_make_pair(tizen_core_channel_sender_h* sender,
+ tizen_core_channel_receiver_h* receiver) {
+ if (sender == nullptr || receiver == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (!tizen_core_ready())
+ return TIZEN_CORE_ERROR_INVALID_CONTEXT;
+
+ auto [sender_ptr, receiver_ptr] =
+ tizen_core::channel::ChannelFactory::MakePair<void*>();
+ if (sender_ptr == nullptr || receiver_ptr == nullptr) {
+ _E("Out of memory"); // LCOV_EXCL_LINE
+ return TIZEN_CORE_ERROR_OUT_OF_MEMORY; // LCOV_EXCL_LINE
+ }
+
+ sender_ptr->RefSelf();
+ *sender = static_cast<tizen_core_channel_sender_h>(sender_ptr.get());
+
+ receiver_ptr->RefSelf();
+ *receiver = static_cast<tizen_core_channel_receiver_h>(receiver_ptr.get());
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_channel_sender_send(tizen_core_channel_sender_h sender,
+ tizen_core_channel_object_h object) {
+ if (sender == nullptr || object == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* channel_sender =
+ static_cast<tizen_core::channel::Sender<void*>*>(sender);
+ auto* channel_object =
+ static_cast<tizen_core::channel::ChannelObject<void*>*>(object);
+ channel_sender->Send(*channel_object);
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_channel_sender_destroy(tizen_core_channel_sender_h sender) {
+ if (sender == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* channel_sender =
+ static_cast<tizen_core::channel::Sender<void*>*>(sender);
+ channel_sender->UnrefSelf();
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_channel_sender_clone(
+ tizen_core_channel_sender_h sender,
+ tizen_core_channel_sender_h* cloned_sender) {
+ if (sender == nullptr || cloned_sender == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* channel_sender =
+ static_cast<tizen_core::channel::Sender<void*>*>(sender);
+ auto clone = std::shared_ptr<tizen_core::channel::Sender<void*>>(
+ new tizen_core::channel::Sender<void*>(*channel_sender));
+ clone->RefSelf();
+ *cloned_sender = static_cast<tizen_core_channel_sender_h>(clone.get());
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_channel_receiver_receive(
+ tizen_core_channel_receiver_h receiver,
+ tizen_core_channel_object_h* object) {
+ if (receiver == nullptr || object == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* channel_receiver =
+ static_cast<tizen_core::channel::Receiver<void*>*>(receiver);
+ auto channel_object = channel_receiver->Receive();
+ *object = static_cast<tizen_core_channel_object_h>(
+ new tizen_core::channel::ChannelObject<void*>(channel_object));
+ if (*object == nullptr) {
+ _E("Out of memory");
+ return TIZEN_CORE_ERROR_OUT_OF_MEMORY;
+ }
+
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_channel_receiver_destroy(
+ tizen_core_channel_receiver_h receiver) {
+ if (receiver == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* channel_receiver =
+ static_cast<tizen_core::channel::Receiver<void*>*>(receiver);
+ channel_receiver->UnrefSelf();
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_channel_object_create(tizen_core_channel_object_h* object) {
+ if (object == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (!tizen_core_ready())
+ return TIZEN_CORE_ERROR_INVALID_CONTEXT;
+
+ auto* channel_object =
+ new (std::nothrow) tizen_core::channel::ChannelObject<void*>();
+ if (channel_object == nullptr) {
+ _E("Out of memory"); // LCOV_EXCL_LINE
+ return TIZEN_CORE_ERROR_OUT_OF_MEMORY; // LCOV_EXCL_LINE
+ }
+
+ *object = static_cast<tizen_core_channel_object_h>(channel_object);
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_channel_object_destroy(tizen_core_channel_object_h object) {
+ if (object == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* channel_object =
+ static_cast<tizen_core::channel::ChannelObject<void*>*>(object);
+ delete channel_object;
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_channel_object_set_id(tizen_core_channel_object_h object,
+ int id) {
+ if (object == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* channel_object =
+ static_cast<tizen_core::channel::ChannelObject<void*>*>(object);
+ channel_object->SetId(id);
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_channel_object_get_id(tizen_core_channel_object_h object,
+ int* id) {
+ if (object == nullptr || id == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* channel_object =
+ static_cast<tizen_core::channel::ChannelObject<void*>*>(object);
+ *id = channel_object->GetId();
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_channel_object_set_data(tizen_core_channel_object_h object,
+ void* data) {
+ if (object == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* channel_object =
+ static_cast<tizen_core::channel::ChannelObject<void*>*>(object);
+ channel_object->SetData(data);
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_channel_object_get_data(tizen_core_channel_object_h object,
+ void** data) {
+ if (object == nullptr || data == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* channel_object =
+ static_cast<tizen_core::channel::ChannelObject<void*>*>(object);
+ *data = channel_object->GetData();
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_channel_object_get_sender_task_name(
+ tizen_core_channel_object_h object, const char** task_name) {
+ if (object == nullptr || task_name == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* channel_object =
+ static_cast<tizen_core::channel::ChannelObject<void*>*>(object);
+ auto& sender = channel_object->GetSender();
+ if (sender.empty()) {
+ _E("Invalid context"); // LCOV_EXCL_LINE
+ return TIZEN_CORE_ERROR_INVALID_CONTEXT; // LCOV_EXCL_LINE
+ }
+
+ *task_name = sender.c_str();
+ return TIZEN_CORE_ERROR_NONE;
+}
--- /dev/null
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "tizen-core/include/tizen_core_event.h"
+
+#include <atomic>
+#include <memory>
+#include <vector>
+
+#include "tizen-core/include/tizen_core.h"
+#include "tizen-core/include/tizen_core_event_internal.h"
+#include "tizen-core/event/event_broker.h"
+#include "tizen-core/log_private.h"
+#include "tizen-core/task.h"
+#include "tizen-core/source.h"
+
+#undef EXPORT
+#define EXPORT __attribute__ ((visibility("default")))
+
+#undef API
+#define API extern "C" EXPORT
+
+namespace {
+
+class EventObjectExt : public tizen_core::event::EventObject<void*> {
+ public:
+ EventObjectExt(int type, void* data) : EventObject<void*>(type, data) {}
+
+ ~EventObjectExt() {
+ if (destroy_cb_)
+ destroy_cb_(GetData(), destroy_data_);
+ }
+
+ void SetDestroyCb(tizen_core_event_object_destroy_cb callback,
+ void* data) {
+ destroy_cb_ = callback;
+ destroy_data_ = data;
+ }
+
+ private:
+ tizen_core_event_object_destroy_cb destroy_cb_ = nullptr;
+ void* destroy_data_ = nullptr;
+};
+
+class EventHandlerExt : public tizen_core::event::EventHandler<void*>,
+ public std::enable_shared_from_this<EventHandlerExt> {
+ public:
+ EventHandlerExt(tizen_core_event_handler_cb cb, void* user_data)
+ : tizen_core::event::EventHandler<void*>(),
+ cb_(cb),
+ user_data_(user_data) {}
+
+ private:
+ bool OnEventReceived(
+ tizen_core::event::EventObject<void*>* obj) override {
+ if (cb_)
+ return cb_(obj, user_data_);
+
+ return true;
+ }
+
+ private:
+ tizen_core_event_handler_cb cb_;
+ void* user_data_;
+};
+
+} // namespace
+
+API int tizen_core_event_create(tizen_core_event_h* event) {
+ if (event == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (!tizen_core_ready())
+ return TIZEN_CORE_ERROR_INVALID_CONTEXT;
+
+ auto* broker = new (std::nothrow) tizen_core::event::EventBroker<void*>();
+ if (broker == nullptr) {
+ _E("Out of memory"); // LCOV_EXCL_LINE
+ return TIZEN_CORE_ERROR_OUT_OF_MEMORY; // LCOV_EXCL_LINE
+ }
+
+ *event = static_cast<tizen_core_event_h>(broker);
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_event_destroy(tizen_core_event_h event) {
+ if (event == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* broker = static_cast<tizen_core::event::EventBroker<void*>*>(event);
+ if (broker->IsAttached()) {
+ _E("Event(%p) is attached to a source", event);
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ delete broker;
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_event_add_handler(
+ tizen_core_event_h event, tizen_core_event_handler_cb callback,
+ void* user_data, tizen_core_event_handler_h* event_handler) {
+ if (event == nullptr || callback == nullptr || event_handler == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto handler = std::make_shared<EventHandlerExt>(callback, user_data);
+ if (handler == nullptr) {
+ _E("Out of memory"); // LCOV_EXCL_LINE
+ return TIZEN_CORE_ERROR_OUT_OF_MEMORY; // LCOV_EXCL_LINE
+ }
+
+ auto* broker = static_cast<tizen_core::event::EventBroker<void*>*>(event);
+ broker->AddHandler(handler);
+ *event_handler = handler.get();
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_event_prepend_handler(
+ tizen_core_event_h event, tizen_core_event_handler_cb callback,
+ void* user_data, tizen_core_event_handler_h* event_handler) {
+ if (event == nullptr || callback == nullptr || event_handler == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto handler = std::make_shared<EventHandlerExt>(callback, user_data);
+ if (handler == nullptr) {
+ _E("Out of memory"); // LCOV_EXCL_LINE
+ return TIZEN_CORE_ERROR_OUT_OF_MEMORY; // LCOV_EXCL_LINE
+ }
+
+ auto* broker = static_cast<tizen_core::event::EventBroker<void*>*>(event);
+ broker->PrependHandler(handler);
+ *event_handler = handler.get();
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_event_remove_handler(
+ tizen_core_event_h event, tizen_core_event_handler_h event_handler) {
+ if (event == nullptr || event_handler == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* broker = static_cast<tizen_core::event::EventBroker<void*>*>(event);
+ auto* handler = static_cast<EventHandlerExt*>(event_handler);
+ broker->RemoveHandler(handler->shared_from_this());
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_event_emit(tizen_core_event_h event,
+ tizen_core_event_object_h object) {
+ if (event == nullptr || object == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* broker = static_cast<tizen_core::event::EventBroker<void*>*>(event);
+ auto* event_object = static_cast<EventObjectExt*>(object);
+ broker->Emit(event_object->shared_from_this());
+ event_object->Unref();
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_event_object_create(tizen_core_event_object_h* object,
+ int id, void* data) {
+ if (object == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (!tizen_core_ready())
+ return TIZEN_CORE_ERROR_INVALID_CONTEXT;
+
+ auto event_object = std::make_shared<EventObjectExt>(id, data);
+ if (event_object == nullptr) {
+ _E("Out of memory"); // LCOV_EXCL_LINE
+ return TIZEN_CORE_ERROR_OUT_OF_MEMORY; // LCOV_EXCL_LINE
+ }
+
+ event_object->Ref();
+ *object = static_cast<tizen_core_event_object_h>(event_object.get());
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_event_object_destroy(tizen_core_event_object_h object) {
+ if (object == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* event_object = static_cast<EventObjectExt*>(object);
+ event_object->SetId(-1);
+ event_object->Unref();
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_event_object_set_destroy_cb(
+ tizen_core_event_object_h object,
+ tizen_core_event_object_destroy_cb callback, void* user_data) {
+ if (object == nullptr || callback == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* event_object = static_cast<EventObjectExt*>(object);
+ event_object->SetDestroyCb(callback, user_data);
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_event_object_get_id(tizen_core_event_object_h object,
+ int* id) {
+ if (object == nullptr || id == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* event_object = static_cast<EventObjectExt*>(object);
+ *id = event_object->GetId();
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_event_object_get_data(tizen_core_event_object_h object,
+ void** data) {
+ if (object == nullptr || data == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* event_object = static_cast<EventObjectExt*>(object);
+ *data = event_object->GetData();
+ return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_event_generate_id(void) {
+ static std::atomic<int> id{0};
+ if ((id + 1) < 0) id = 0;
+ return id++;
+}
--- /dev/null
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "tizen-core/task.h"
+
+#include <cpu-boosting.h>
+#include <glib.h>
+#include <pthread.h>
+#include <unistd.h>
+
+#include <stdexcept>
+#include <utility>
+
+#include "tizen-core/context_manager.h"
+#include "tizen-core/log_private.h"
+#include "tizen-core/source.h"
+
+namespace tizen_core {
+namespace {
+
+class IdleSource : public Source {
+ public:
+ explicit IdleSource(std::function<bool()> cb)
+ : Source(g_idle_source_new()), cb_(std::move(cb)) {
+ g_source_set_callback(GetHandle(), IdleCb, this, nullptr);
+ }
+
+ private:
+ static gboolean IdleCb(gpointer user_data) {
+ auto* source = static_cast<IdleSource*>(user_data);
+ auto source_ptr = source->shared_from_this();
+ if (source->cb_())
+ return G_SOURCE_CONTINUE;
+
+ source->UnrefSelf();
+ return G_SOURCE_REMOVE;
+ }
+
+ private:
+ std::function<bool()> cb_;
+};
+
+class TimeoutSource : public Source {
+ public:
+ TimeoutSource(unsigned int interval, std::function<bool()> cb)
+ : Source(g_timeout_source_new(interval)), cb_(std::move(cb)) {
+ g_source_set_callback(GetHandle(), TimeoutCb, this, nullptr);
+ }
+
+ private:
+ static gboolean TimeoutCb(gpointer user_data) {
+ auto* source = static_cast<TimeoutSource*>(user_data);
+ auto source_ptr = source->shared_from_this();
+ if (source->cb_())
+ return G_SOURCE_CONTINUE;
+
+ source->UnrefSelf();
+ return G_SOURCE_REMOVE;
+ }
+
+ private:
+ std::function<bool()> cb_;
+};
+
+template <class T>
+class ChannelSource : public Source {
+ public:
+ ChannelSource(std::shared_ptr<Task> task,
+ std::shared_ptr<channel::Receiver<T>> receiver,
+ std::function<void(const channel::ChannelObject<T>&)> cb)
+ : task_(std::move(task)),
+ receiver_(std::move(receiver)),
+ cb_(std::move(cb)),
+ poll_fd_(new PollFd()) {
+ poll_fd_->SetFd(receiver_->GetFd());
+ poll_fd_->SetEvents(POLLIN);
+ AddPoll(poll_fd_);
+ }
+
+ private:
+ bool OnSourcePrepare(int* timeout) override {
+ *timeout = -1;
+ return false;
+ }
+
+ bool OnSourceCheck() override {
+ if (receiver_->Empty()) return false;
+ return true;
+ }
+
+ bool OnSourceDispatch() override {
+ while (!receiver_->Empty()) cb_(receiver_->Receive());
+ return true;
+ }
+
+ private:
+ std::shared_ptr<Task> task_;
+ std::shared_ptr<channel::Receiver<T>> receiver_;
+ std::function<void(const channel::ChannelObject<T>&)> cb_;
+ std::shared_ptr<PollFd> poll_fd_;
+};
+
+template <class T>
+class EventSource : public Source {
+ public:
+ EventSource(std::shared_ptr<Task> task,
+ std::shared_ptr<event::EventBroker<T>> broker)
+ : task_(std::move(task)),
+ broker_(std::move(broker)),
+ poll_fd_(new PollFd()) {
+ broker_->SetAttached(true);
+ poll_fd_->SetFd(broker_->GetFd());
+ poll_fd_->SetEvents(POLLIN);
+ AddPoll(poll_fd_);
+ }
+
+ void Emit(std::shared_ptr<event::EventObject<T>> object) {
+ broker_->Emit(std::move(object));
+ }
+
+ // LCOV_EXCL_START
+ void UnrefSelf() override {
+ task_->RemoveEventSource(shared_from_this());
+ Source::UnrefSelf();
+ }
+ // LCOV_EXCL_STOP
+ private:
+ bool OnSourcePrepare(int* timeout) override {
+ *timeout = -1;
+ return false;
+ }
+
+ bool OnSourceCheck() override {
+ if (broker_->Empty()) return false;
+ return true;
+ }
+
+ bool OnSourceDispatch() override {
+ while (!broker_->Empty()) broker_->Process();
+ return true;
+ }
+
+ private:
+ std::shared_ptr<Task> task_;
+ std::shared_ptr<event::EventBroker<T>> broker_;
+ std::shared_ptr<PollFd> poll_fd_;
+};
+
+// LCOV_EXCL_START
+resource_cpu_boosting_level ConvertCpuBoostingLevel(
+ tizen_core_cpu_boosting_level_e level) {
+ switch (level) {
+ case TIZEN_CORE_CPU_BOOSTING_LEVEL_NONE:
+ return CPU_BOOSTING_LEVEL_NONE;
+ case TIZEN_CORE_CPU_BOOSTING_LEVEL_STRONG:
+ return CPU_BOOSTING_LEVEL_STRONG;
+ case TIZEN_CORE_CPU_BOOSTING_LEVEL_MEDIUM:
+ return CPU_BOOSTING_LEVEL_MEDIUM;
+ case TIZEN_CORE_CPU_BOOSTING_LEVEL_WEAK:
+ return CPU_BOOSTING_LEVEL_WEAK;
+ default:
+ return CPU_BOOSTING_LEVEL_NONE;
+ }
+}
+
+const char* CpuBoostingLevelToStr(tizen_core_cpu_boosting_level_e level) {
+ switch (level) {
+ case TIZEN_CORE_CPU_BOOSTING_LEVEL_NONE:
+ return "NONE";
+ case TIZEN_CORE_CPU_BOOSTING_LEVEL_STRONG:
+ return "STRONG";
+ case TIZEN_CORE_CPU_BOOSTING_LEVEL_MEDIUM:
+ return "MEDIUM";
+ case TIZEN_CORE_CPU_BOOSTING_LEVEL_WEAK:
+ return "WEAK";
+ default:
+ return "NONE";
+ }
+}
+// LCOV_EXCL_STOP
+
+} // namespace
+
+Task::Task(std::string name, bool use_thread)
+ : name_(std::move(name)), use_thread_(use_thread) {
+ _W("Task: %s", name_.c_str());
+ if (name_ == "main" && use_thread_)
+ throw std::invalid_argument("main task must not use a thread");
+
+ context_ = ContextManager::GetInst().Create(name_, use_thread_);
+ loop_ = g_main_loop_new(context_->GetHandle(), FALSE);
+}
+
+Task::~Task() {
+ _W("~Task: %s", name_.c_str());
+ Quit();
+ if (use_thread_ && thread_.joinable())
+ thread_.join();
+
+ g_main_loop_unref(loop_);
+}
+
+std::shared_ptr<Task> Task::Create(std::string name, bool use_thread) {
+ auto task = std::make_shared<Task>(std::move(name), use_thread);
+ task->GetContext()->SetLoop(task);
+ return task;
+}
+
+void Task::Dispose() {
+ context_->SetLoop(nullptr);
+ ContextManager::GetInst().Dispose(name_);
+}
+
+std::shared_ptr<Context> Task::GetContext() const {
+ return context_;
+}
+
+void Task::Quit() {
+ if (g_main_loop_is_running(loop_))
+ g_main_loop_quit(loop_);
+}
+
+void Task::Run() {
+ if (use_thread_) {
+ std::unique_lock<std::mutex> lock(loop_mutex_);
+ idle_entered_ = false;
+ thread_ = std::thread([&]() -> void {
+ tid_ = gettid();
+ ThreadLoop();
+ tid_ = -1;
+ cpu_boosting_level_ = TIZEN_CORE_CPU_BOOSTING_LEVEL_NONE;
+ });
+ cond_var_.wait(lock, [this]() { return idle_entered_; });
+ } else {
+ tid_ = getpid();
+ g_main_loop_run(loop_);
+
+ while (g_main_context_pending(context_->GetHandle()))
+ g_main_context_dispatch(context_->GetHandle());
+
+ tid_ = -1;
+ }
+}
+
+bool Task::IsRunning() const {
+ return g_main_loop_is_running(loop_);
+}
+
+std::shared_ptr<ISource> Task::AddIdleJob(std::function<bool()> job) {
+ auto source = std::make_shared<IdleSource>(std::move(job));
+ AddSource(source);
+ return source;
+}
+
+std::shared_ptr<ISource> Task::AddTimer(unsigned int interval,
+ std::function<bool()> cb) {
+ auto source = std::make_shared<TimeoutSource>(interval, std::move(cb));
+ AddSource(source);
+ return source;
+}
+
+void Task::RemoveSource(std::shared_ptr<ISource> source) {
+ RemoveEventSource(source);
+ source->UnrefSelf();
+}
+
+void Task::AddSource(std::shared_ptr<ISource> source) {
+ source->Attach(context_);
+ source->RefSelf();
+}
+
+template <typename T>
+std::shared_ptr<ISource> Task::AddChannel(
+ std::shared_ptr<channel::Receiver<T>> receiver,
+ std::function<void(const channel::ChannelObject<T>&)> cb) {
+ auto source = std::make_shared<ChannelSource<T>>(
+ shared_from_this(), std::move(receiver), std::move(cb));
+ AddSource(source);
+ return source;
+}
+
+template <typename T>
+std::shared_ptr<ISource> Task::AddEvent(
+ std::shared_ptr<event::EventBroker<T>> broker) {
+ auto source =
+ std::make_shared<EventSource<T>>(shared_from_this(), std::move(broker));
+ AddSource(source);
+ AddEventSource(source);
+ return source;
+}
+
+template <typename T>
+void Task::EmitEvent(std::shared_ptr<event::EventObject<T>> object) {
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ for (auto& source : event_sources_) {
+ auto* event_source = dynamic_cast<EventSource<T>*>(source.get());
+ if (event_source == nullptr)
+ continue;
+
+ event_source->Emit(object);
+ }
+}
+
+// LCOV_EXCL_START
+bool Task::SetCpuBoosting(tizen_core_cpu_boosting_level_e level) {
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ if (tid_ == -1) {
+ _E("Not running yet.");
+ return false;
+ }
+
+ if (cpu_boosting_level_ == level)
+ return true;
+
+ resource_pid_t res_pid = {
+ .pid = 0,
+ .tid = &tid_,
+ .tid_count = 1,
+ };
+
+ resource_cpu_boosting_level native_level = ConvertCpuBoostingLevel(level);
+ int ret = resource_set_cpu_boosting(res_pid, native_level,
+ static_cast<cpu_boosting_flag_e>(0), -1);
+ if (ret != 0) {
+ _E("Failed to set cpu boosting. ret(%d)", ret);
+ return false;
+ }
+
+ _I("Set cpu boosting level(%s -> %s).",
+ CpuBoostingLevelToStr(cpu_boosting_level_), CpuBoostingLevelToStr(level));
+ cpu_boosting_level_ = level;
+ return true;
+}
+
+bool Task::ClearCpuBoosting() {
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ if (tid_ == -1) {
+ _E("Not running yet.");
+ return false;
+ }
+
+ resource_pid_t res_pid = {
+ .pid = 0,
+ .tid = &tid_,
+ .tid_count = 1,
+ };
+
+ int ret = resource_clear_cpu_boosting(res_pid);
+ if (ret != 0) {
+ _E("Failed to set cpu boosting. ret(%d)", ret);
+ return false;
+ }
+
+ _I("Clear cpu boosting");
+ cpu_boosting_level_ = TIZEN_CORE_CPU_BOOSTING_LEVEL_NONE;
+ return true;
+}
+// LCOV_EXCL_STOP
+
+void Task::ThreadLoop() {
+ {
+ std::unique_lock<std::mutex> lock(loop_mutex_);
+ GSource* source = g_idle_source_new();
+ g_source_set_callback(
+ source, [](gpointer user_data) {
+ auto* task = static_cast<Task*>(user_data);
+ std::unique_lock<std::mutex> idler_lock(task->loop_mutex_);
+ _W("thread loop is running");
+ task->idle_entered_ = true;
+ task->cond_var_.notify_one();
+ return G_SOURCE_REMOVE;
+ }, this,
+ nullptr);
+ g_source_set_priority(source, G_PRIORITY_HIGH);
+ g_source_attach(source, context_->GetHandle());
+ g_source_unref(source);
+
+ g_main_context_push_thread_default(context_->GetHandle());
+ }
+
+ pthread_setname_np(pthread_self(), name_.c_str());
+ g_main_loop_run(loop_);
+
+ while (g_main_context_pending(context_->GetHandle()))
+ g_main_context_dispatch(context_->GetHandle());
+
+ g_main_context_pop_thread_default(context_->GetHandle());
+}
+
+void Task::AddEventSource(std::shared_ptr<ISource> source) {
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ event_sources_.push_back(std::move(source));
+}
+
+void Task::RemoveEventSource(std::shared_ptr<ISource> source) {
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ event_sources_.remove(source);
+}
+
+void Task::RefSelf() { self_ = shared_from_this(); }
+
+void Task::UnrefSelf() { self_.reset(); }
+
+template std::shared_ptr<ISource> Task::AddChannel<void*>(
+ std::shared_ptr<channel::Receiver<void*>> receiver,
+ std::function<void(const channel::ChannelObject<void*>&)> cb);
+template std::shared_ptr<ISource> Task::AddEvent<void*>(
+ std::shared_ptr<event::EventBroker<void*>> broker);
+template void Task::EmitEvent<void*>(
+ std::shared_ptr<event::EventObject<void*>> object);
+
+} // namespace tizen_core
--- /dev/null
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef TIZEN_CORE_TASK_H_
+#define TIZEN_CORE_TASK_H_
+
+#include <glib.h>
+
+#include <functional>
+#include <list>
+#include <memory>
+#include <mutex>
+#include <string>
+#include <thread>
+
+#include "tizen-core/include/tizen_core_internal.h"
+#include "tizen-core/channel/receiver.h"
+#include "tizen-core/context.h"
+#include "tizen-core/event/event_broker.h"
+#include "tizen-core/interface_loop.h"
+#include "tizen-core/interface_source.h"
+
+#undef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+
+namespace tizen_core {
+
+class EXPORT_API Task : public ILoop,
+ public std::enable_shared_from_this<Task> {
+ public:
+ Task(std::string name, bool use_thread);
+ virtual ~Task();
+
+ Task(const Task& task) = delete;
+ Task& operator=(const Task& task) = delete;
+ Task(Task&& task) = delete;
+ Task& operator=(Task&& task) = delete;
+
+ static std::shared_ptr<Task> Create(std::string name, bool use_thread);
+ void Dispose();
+
+ std::shared_ptr<Context> GetContext() const;
+ void Quit() override;
+ void Run() override;
+ bool IsRunning() const override;
+
+ std::shared_ptr<ISource> AddIdleJob(std::function<bool()> cb) override;
+ std::shared_ptr<ISource> AddTimer(unsigned int interval,
+ std::function<bool()> cb) override;
+ void RemoveSource(std::shared_ptr<ISource> source) override;
+ void AddSource(std::shared_ptr<ISource> source) override;
+
+ template <typename T>
+ std::shared_ptr<ISource> AddChannel(
+ std::shared_ptr<channel::Receiver<T>> receiver,
+ std::function<void(const channel::ChannelObject<T>&)> cb);
+ template <typename T>
+ std::shared_ptr<ISource> AddEvent(
+ std::shared_ptr<event::EventBroker<T>> broker);
+ template <typename T>
+ void EmitEvent(std::shared_ptr<event::EventObject<T>> object);
+
+ bool SetCpuBoosting(tizen_core_cpu_boosting_level_e level);
+ bool ClearCpuBoosting();
+
+ void AddEventSource(std::shared_ptr<ISource> source);
+ void RemoveEventSource(std::shared_ptr<ISource> source);
+
+ void RefSelf();
+ void UnrefSelf();
+
+ private:
+ void ThreadLoop();
+
+ private:
+ pid_t tid_ = -1;
+ tizen_core_cpu_boosting_level_e cpu_boosting_level_ =
+ TIZEN_CORE_CPU_BOOSTING_LEVEL_NONE;
+ std::string name_;
+ bool use_thread_;
+ std::shared_ptr<Context> context_;
+ std::thread thread_;
+ std::condition_variable cond_var_;
+ mutable std::mutex loop_mutex_;
+ GMainLoop* loop_ = nullptr;
+ bool idle_entered_ = false;
+ std::list<std::shared_ptr<ISource>> event_sources_;
+ mutable std::recursive_mutex mutex_;
+ std::shared_ptr<Task> self_;
+};
+
+} // namespace tizen_core
+
+#endif // TIZEN_CORE_TASK_H_
--- /dev/null
+# Package Information for pkg-config
+
+prefix=@PREFIX@
+exec_prefix=/usr
+libdir=@LIB_INSTALL_DIR@
+includedir=@INCLUDE_INSTALL_DIR@/tizen-core
+
+Name: @PC_NAME@
+Description: @PC_DESCRIPTION@
+Version: @PC_VERSION@
+Requires: @PC_REQUIRED@
+Libs: -L${libdir} @PC_LDFLAGS@
+Cflags: -I${includedir}
${CMAKE_CURRENT_SOURCE_DIR}/mock/
${CMAKE_CURRENT_SOURCE_DIR}/../
${CMAKE_CURRENT_SOURCE_DIR}/../../
- ${CMAKE_CURRENT_SOURCE_DIR}/../../include/)
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../src/
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../src/tizen-core/
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../src/tizen-core/include/)
APPLY_PKG_CONFIG(${TARGET_TIZEN_CORE_UNITTESTS} PUBLIC
DLOG_DEPS
+++ /dev/null
-# Package Information for pkg-config
-
-prefix=@PREFIX@
-exec_prefix=/usr
-libdir=@LIB_INSTALL_DIR@
-includedir=@INCLUDE_INSTALL_DIR@/tizen-core
-
-Name: @PC_NAME@
-Description: @PC_DESCRIPTION@
-Version: @PC_VERSION@
-Requires: @PC_REQUIRED@
-Libs: -L${libdir} @PC_LDFLAGS@
-Cflags: -I${includedir}
+++ /dev/null
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} TIZEN_CORE_SRCS)
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/channel TIZEN_CORE_CHANNEL_SRCS)
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/event TIZEN_CORE_EVENT_SRCS)
-
-ADD_LIBRARY(${TARGET_TIZEN_CORE} SHARED
- ${TIZEN_CORE_SRCS}
- ${TIZEN_CORE_CHANNEL_SRCS}
- ${TIZEN_CORE_EVENT_SRCS})
-
-SET_TARGET_PROPERTIES(${TARGET_TIZEN_CORE} PROPERTIES SOVERSION ${MAJORVER})
-SET_TARGET_PROPERTIES(${TARGET_TIZEN_CORE} PROPERTIES VERSION ${FULLVER})
-
-TARGET_INCLUDE_DIRECTORIES(${TARGET_TIZEN_CORE} PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}
- ${CMAKE_CURRENT_SOURCE_DIR}/channel/
- ${CMAKE_CURRENT_SOURCE_DIR}/event/
- ${CMAKE_CURRENT_SOURCE_DIR}/../
- ${CMAKE_CURRENT_SOURCE_DIR}/../include/)
-
-APPLY_PKG_CONFIG(${TARGET_TIZEN_CORE} PUBLIC
- DLOG_DEPS
- GLIB_DEPS
- CAPI_BASE_COMMON_DEPS
- TIZEN_SHARED_QUEUE_DEPS
- CAPI_SYSTEM_RESOURCE_DEPS
-)
-
-INSTALL(TARGETS ${TARGET_TIZEN_CORE} DESTINATION ${LIB_INSTALL_DIR})
+++ /dev/null
-/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef TIZEN_CORE_TIZEN_BASE_CHANNEL_CHANNEL_BROKER_H_
-#define TIZEN_CORE_TIZEN_BASE_CHANNEL_CHANNEL_BROKER_H_
-
-#include <memory>
-#include <utility>
-
-#include <shared-queue.hpp>
-
-#include "tizen_base/event_fd.h"
-#include "tizen_base/channel/channel_object.h"
-
-#undef EXPORT_API
-#define EXPORT_API __attribute__((visibility("default")))
-
-namespace tizen_base {
-namespace tizen_core {
-namespace channel {
-
-template <class T>
-class EXPORT_API ChannelBroker : public EventFd {
- public:
- ChannelBroker() = default;
- virtual ~ChannelBroker() = default;
-
- void Send(ChannelObject<T> object) {
- queue_.Push(std::move(object));
- Write(queue_.Size());
- }
-
- ChannelObject<T> Receive() {
- uint64_t value = 0;
- Read(&value);
- return queue_.WaitAndPop();
- }
-
- bool Empty() const { return queue_.IsEmpty(); }
-
- private:
- SharedQueue<ChannelObject<T>> queue_;
-};
-
-} // namespace channel
-} // namespace tizen_core
-} // namespace tizen_base
-
-#endif // TIZEN_CORE_TIZEN_BASE_CHANNEL_CHANNEL_BROKER_H_
+++ /dev/null
-/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef TIZEN_CORE_TIZEN_BASE_CHANNEL_CHANNEL_FACTORY_H_
-#define TIZEN_CORE_TIZEN_BASE_CHANNEL_CHANNEL_FACTORY_H_
-
-#include <memory>
-#include <utility>
-
-#include <shared-queue.hpp>
-
-#include "tizen_base/channel/channel_broker.h"
-#include "tizen_base/channel/receiver.h"
-#include "tizen_base/channel/sender.h"
-
-#undef EXPORT_API
-#define EXPORT_API __attribute__((visibility("default")))
-
-namespace tizen_base {
-namespace tizen_core {
-namespace channel {
-
-class EXPORT_API ChannelFactory {
- public:
- template <typename T>
- static std::pair<std::shared_ptr<Sender<T>>, std::shared_ptr<Receiver<T>>>
- MakePair() {
- std::shared_ptr<ChannelBroker<T>> broker(new ChannelBroker<T>());
- return {std::make_shared<Sender<T>>(broker),
- std::make_shared<Receiver<T>>(broker)};
- }
-};
-
-} // namespace channel
-} // namespace tizen_core
-} // namespace tizen_base
-
-#endif // TIZEN_CORE_TIZEN_BASE_CHANNEL_CHANNEL_FACTORY_H_
+++ /dev/null
-/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef TIZEN_CORE_TIZEN_BASE_CHANNEL_CHANNEL_OBJECT_H_
-#define TIZEN_CORE_TIZEN_BASE_CHANNEL_CHANNEL_OBJECT_H_
-
-#include <string>
-#include <utility>
-
-#undef EXPORT_API
-#define EXPORT_API __attribute__((visibility("default")))
-
-namespace tizen_base {
-namespace tizen_core {
-namespace channel {
-
-template <typename T>
-class EXPORT_API ChannelObject {
- public:
- ChannelObject() : id_(0) {}
- ChannelObject(int id, T data) : id_(id), data_(data) {}
-
- void SetId(int id) {
- id_ = id;
- }
-
- int GetId() const {
- return id_;
- }
-
- void SetData(T data) {
- data_ = data;
- }
-
- T GetData() const {
- return data_;
- }
-
- void SetSender(std::string sender) {
- sender_ = std::move(sender);
- }
-
- const std::string& GetSender() const {
- return sender_;
- }
-
- private:
- int id_;
- T data_;
- std::string sender_;
-};
-
-} // namespace channel
-} // namespace tizen_core
-} // namespace tizen_base
-
-#endif // TIZEN_CORE_TIZEN_BASE_CHANNEL_CHANNEL_OBJECT_H_
+++ /dev/null
-/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef TIZEN_CORE_TIZEN_BASE_CHANNEL_RECEIVER_H_
-#define TIZEN_CORE_TIZEN_BASE_CHANNEL_RECEIVER_H_
-
-#include <functional>
-#include <memory>
-#include <utility>
-
-#include "tizen_base/context.h"
-#include "tizen_base/channel/channel_broker.h"
-
-#undef EXPORT_API
-#define EXPORT_API __attribute__((visibility("default")))
-
-namespace tizen_base {
-namespace tizen_core {
-namespace channel {
-
-template <typename T>
-class EXPORT_API Receiver : public std::enable_shared_from_this<Receiver<T>> {
- public:
- explicit Receiver(std::shared_ptr<ChannelBroker<T>> broker)
- : broker_(std::move(broker)) {}
-
- ChannelObject<T> Receive() { return broker_->Receive(); }
-
- bool Empty() const { return broker_->Empty(); }
-
- int GetFd() const { return broker_->GetFd(); }
-
- void RefSelf() { self_ = this->shared_from_this(); }
-
- void UnrefSelf() { self_.reset(); }
-
- private:
- std::shared_ptr<ChannelBroker<T>> broker_;
- std::weak_ptr<Context> context_;
- std::shared_ptr<Receiver<T>> self_;
-};
-
-} // namespace channel
-} // namespace tizen_core
-} // namespace tizen_base
-
-#endif // TIZEN_CORE_TIZEN_BASE_CHANNEL_RECEIVER_H_
+++ /dev/null
-/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef TIZEN_CORE_TIZEN_BASE_CHANNEL_SENDER_H_
-#define TIZEN_CORE_TIZEN_BASE_CHANNEL_SENDER_H_
-
-#include <memory>
-#include <utility>
-
-#include "tizen_base/channel/channel_broker.h"
-#include "tizen_base/context_manager.h"
-
-#undef EXPORT_API
-#define EXPORT_API __attribute__((visibility("default")))
-
-namespace tizen_base {
-namespace tizen_core {
-namespace channel {
-
-template <typename T>
-class EXPORT_API Sender : public std::enable_shared_from_this<Sender<T>> {
- public:
- explicit Sender(std::shared_ptr<ChannelBroker<T>> broker)
- : broker_(std::move(broker)) {}
-
- void Send(ChannelObject<T> object) {
- auto context = ContextManager::GetInst().FindFromThisThread();
- if (context != nullptr)
- object.SetSender(context->GetName());
-
- broker_->Send(std::move(object));
- }
-
- void RefSelf() { self_ = this->shared_from_this(); }
- void UnrefSelf() { self_.reset(); }
-
- private:
- std::shared_ptr<ChannelBroker<T>> broker_;
- std::shared_ptr<Sender<T>> self_;
-};
-
-} // namespace channel
-} // namespace tizen_core
-} // namespace tizen_base
-
-#endif // TIZEN_CORE_TIZEN_BASE_CHANNEL_SENDER_H_
+++ /dev/null
-/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "tizen_base/context.h"
-
-#include <utility>
-
-#include "tizen_base/log_private.h"
-
-namespace tizen_base {
-namespace tizen_core {
-
-Context::Context(std::string name, bool use_thread)
- : name_(std::move(name)),
- handle_(use_thread ? g_main_context_new() : nullptr) {
- if (handle_ == nullptr)
- handle_ = g_main_context_ref(g_main_context_default());
-}
-
-Context::~Context() {
- if (handle_ != nullptr)
- g_main_context_unref(handle_);
-}
-
-// LCOV_EXCL_START
-Context::Context(const Context& ctx) {
- name_ = ctx.name_;
- loop_ = ctx.loop_;
- handle_ = g_main_context_ref(ctx.handle_);
-}
-
-Context& Context::operator = (const Context& ctx) {
- if (this != &ctx) {
- name_ = ctx.name_;
- loop_ = ctx.loop_;
-
- if (handle_ != nullptr)
- g_main_context_unref(handle_);
-
- handle_ = g_main_context_ref(ctx.handle_);
- }
-
- return *this;
-}
-
-Context::Context(Context&& ctx) noexcept {
- name_ = std::move(ctx.name_);
- loop_ = std::move(ctx.loop_);
- handle_ = ctx.handle_;
- if (ctx.handle_ != nullptr)
- ctx.handle_ = g_main_context_new();
-}
-
-Context& Context::operator = (Context&& ctx) noexcept {
- if (this != &ctx) {
- name_ = std::move(ctx.name_);
- loop_ = std::move(ctx.loop_);
- handle_ = ctx.handle_;
- if (ctx.handle_ != nullptr)
- ctx.handle_ = g_main_context_new();
- }
-
- return *this;
-}
-// LCOV_EXCL_STOP
-
-void Context::SetLoop(std::shared_ptr<ILoop> loop) {
- loop_ = std::move(loop);
-}
-
-std::shared_ptr<ILoop> Context::GetLoop() const {
- return loop_;
-}
-
-const std::string& Context::GetName() const {
- return name_;
-}
-
-GMainContext* Context::GetHandle() const {
- return handle_;
-}
-
-} // namespace tizen_core
-} // namespace tizen_base
+++ /dev/null
-/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef TIZEN_CORE_TIZEN_BASE_CONTEXT_H_
-#define TIZEN_CORE_TIZEN_BASE_CONTEXT_H_
-
-#include <glib.h>
-
-#include <functional>
-#include <memory>
-#include <string>
-
-#include "tizen_base/interface_loop.h"
-
-#undef EXPORT_API
-#define EXPORT_API __attribute__((visibility("default")))
-
-namespace tizen_base {
-namespace tizen_core {
-
-class EXPORT_API Context {
- public:
- Context(std::string name, bool use_thread);
- virtual ~Context();
-
- Context(const Context& ctx);
- Context& operator = (const Context& ctx);
-
- Context(Context&& ctx) noexcept;
- Context& operator = (Context&& ctx) noexcept;
-
- void SetLoop(std::shared_ptr<ILoop> loop);
- std::shared_ptr<ILoop> GetLoop() const;
- const std::string& GetName() const;
- GMainContext* GetHandle() const;
-
- private:
- std::string name_;
- GMainContext* handle_ = nullptr;
- std::shared_ptr<ILoop> loop_ = nullptr;
-};
-
-} // namespace tizen_core
-} // namespace tizen_base
-
-#endif // TIZEN_CORE_TIZEN_BASE_CONTEXT_H_
+++ /dev/null
-/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "tizen_base/context_manager.h"
-
-#include <atomic>
-#include <utility>
-
-#include "tizen_base/log_private.h"
-
-namespace tizen_base {
-namespace tizen_core {
-
-ContextManager& ContextManager::GetInst() {
- static std::atomic<ContextManager*> inst_;
- static std::mutex mutex_;
- static ContextManager* inst = inst_.load(std::memory_order_acquire);
- if (inst == nullptr) {
- std::lock_guard<std::mutex> lock(mutex_);
- inst = inst_.load(std::memory_order_relaxed);
- if (inst == nullptr) {
- inst = new ContextManager();
- inst_.store(inst, std::memory_order_release);
- }
- }
-
- return *inst;
-}
-
-std::shared_ptr<Context> ContextManager::Create(std::string name,
- bool use_thread) {
- auto context = std::make_shared<Context>(name, use_thread);
- std::lock_guard<std::recursive_mutex> lock(mutex_);
- contexts_[std::move(name)] = context;
- return context;
-}
-
-void ContextManager::Dispose(const std::string& name) {
- std::lock_guard<std::recursive_mutex> lock(mutex_);
- auto found = contexts_.find(name);
- if (found == contexts_.end())
- return;
-
- contexts_.erase(found);
-}
-
-std::shared_ptr<Context> ContextManager::Find(const std::string& name) {
- std::lock_guard<std::recursive_mutex> lock(mutex_);
- auto found = contexts_.find(name);
- if (found == contexts_.end())
- return nullptr;
-
- return found->second;
-}
-
-std::shared_ptr<Context> ContextManager::FindFromThisThread() {
- auto handle = g_main_context_get_thread_default();
- if (handle == nullptr) {
- _W("Use default context");
- handle = g_main_context_default();
- }
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
- for (const auto& iter : contexts_) {
- auto& context = iter.second;
- if (context->GetHandle() == handle)
- return context;
- }
-
- return nullptr;
-}
-
-void ContextManager::DisposeAll() {
- std::lock_guard<std::recursive_mutex> lock(mutex_);
- contexts_.clear();
-}
-
-} // namespace tizen_core
-} // namespace tizen_base
+++ /dev/null
-/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef TIZEN_CORE_TIZEN_BASE_CONTEXT_MANAGER_H_
-#define TIZEN_CORE_TIZEN_BASE_CONTEXT_MANAGER_H_
-
-#include <functional>
-#include <memory>
-#include <mutex>
-#include <string>
-#include <unordered_map>
-
-#include "tizen_base/context.h"
-
-namespace tizen_base {
-namespace tizen_core {
-
-class ContextManager {
- public:
- static ContextManager& GetInst();
-
- std::shared_ptr<Context> Create(std::string name, bool use_thread = true);
- void Dispose(const std::string& name);
- std::shared_ptr<Context> Find(const std::string& name);
- std::shared_ptr<Context> FindFromThisThread();
- void DisposeAll();
-
- private:
- std::unordered_map<std::string, std::shared_ptr<Context>> contexts_;
- mutable std::recursive_mutex mutex_;
-};
-
-} // namespace tizen_core
-} // namespace tizen_base
-
-#endif // TIZEN_CORE_TIZEN_BASE_CONTEXT_MANAGER_H_
+++ /dev/null
-/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef TIZEN_CORE_TIZEN_BASE_EVENT_EVENT_BROKER_H_
-#define TIZEN_CORE_TIZEN_BASE_EVENT_EVENT_BROKER_H_
-
-#include <functional>
-#include <list>
-#include <memory>
-#include <unordered_map>
-#include <utility>
-
-#include <shared-queue.hpp>
-
-#include "tizen_base/event_fd.h"
-#include "tizen_base/event/event_object.h"
-#include "tizen_base/event/event_handler.h"
-
-#undef EXPORT_API
-#define EXPORT_API __attribute__((visibility("default")))
-
-namespace tizen_base {
-namespace tizen_core {
-namespace event {
-
-template <class T>
-class EXPORT_API EventBroker : public EventFd {
- public:
- EventBroker() = default;
- virtual ~EventBroker() = default;
-
- void AddHandler(std::shared_ptr<EventHandler<T>> handler) {
- handlers_.push_back(std::move(handler));
- }
-
- void PrependHandler(std::shared_ptr<EventHandler<T>> handler) {
- handlers_.push_front(std::move(handler));
- }
-
- void RemoveHandler(std::shared_ptr<EventHandler<T>> handler) {
- handlers_.remove_if([&](const std::shared_ptr<EventHandler<T>>& event) {
- return event == handler;
- });
- }
-
- void Process() {
- uint64_t value = 0;
- Read(&value);
- auto object = queue_.WaitAndPop();
- if (!object)
- return;
-
- auto iter = handlers_.begin();
- while (iter != handlers_.end()) {
- auto handler = *iter;
- iter++;
- if (!handler->OnEventReceived(object.get()))
- break;
- }
- }
-
- void Emit(std::shared_ptr<EventObject<T>> object) {
- queue_.Push(std::move(object));
- Write(queue_.Size());
- }
-
- bool Empty() const { return queue_.IsEmpty(); }
-
- void SetAttached(bool attached) { attached_ = attached; }
-
- bool IsAttached() const { return attached_; }
-
- private:
- bool attached_ = false;
- std::list<std::shared_ptr<EventHandler<T>>> handlers_;
- SharedQueue<std::shared_ptr<EventObject<T>>> queue_;
-};
-
-} // namespace event
-} // namespace tizen_core
-} // namespace tizen_base
-
-#endif // TIZEN_CORE_TIZEN_BASE_EVENT_EVENT_BROKER_H_
+++ /dev/null
-/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef TIZEN_CORE_TIZEN_BASE_EVENT_EVENT_HANDLER_H_
-#define TIZEN_CORE_TIZEN_BASE_EVENT_EVENT_HANDLER_H_
-
-#include "tizen_base/event/event_object.h"
-
-#undef EXPORT_API
-#define EXPORT_API __attribute__((visibility("default")))
-
-namespace tizen_base {
-namespace tizen_core {
-namespace event {
-
-template <class T>
-class EXPORT_API EventHandler {
- public:
- virtual ~EventHandler() = default;
- virtual bool OnEventReceived(EventObject<T>* obj) = 0;
-};
-
-} // namespace event
-} // namespace tizen_core
-} // namespace tizen_base
-
-#endif // TIZEN_CORE_TIZEN_BASE_EVENT_EVENT_HANDLER_H_
+++ /dev/null
-/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef TIZEN_CORE_TIZEN_BASE_EVENT_EVENT_OBJECT_H_
-#define TIZEN_CORE_TIZEN_BASE_EVENT_EVENT_OBJECT_H_
-
-#include <atomic>
-#include <memory>
-
-#undef EXPORT_API
-#define EXPORT_API __attribute__((visibility("default")))
-
-namespace tizen_base {
-namespace tizen_core {
-namespace event {
-
-template <typename T>
-class EXPORT_API EventObject
- : public std::enable_shared_from_this<EventObject<T>> {
- public:
- EventObject() : id_(0) {}
- EventObject(int id, T data) : id_(id), data_(data) {}
- virtual ~EventObject() = default;
-
- void SetId(int id) {
- id_ = id;
- }
-
- int GetId() const {
- return id_;
- }
-
- void SetData(T data) {
- data_ = data;
- }
-
- T GetData() const {
- return data_;
- }
-
- void Ref() {
- if (++ref_count_ == 1)
- self_ = this->shared_from_this();
- }
-
- void Unref() {
- if (--ref_count_ == 0)
- self_.reset();
- }
-
- private:
- int id_;
- T data_;
- std::atomic<uint32_t> ref_count_ { 0 };
- std::shared_ptr<EventObject<T>> self_;
-};
-
-} // namespace event
-} // namespace tizen_core
-} // namespace tizen_base
-
-#endif // TIZEN_CORE_TIZEN_BASE_EVENT_EVENT_OBJECT_H_
+++ /dev/null
-/*
- * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "tizen_base/event_fd.h"
-
-#include <utility>
-
-#include "tizen_base/log_private.h"
-
-namespace tizen_base {
-namespace tizen_core {
-
-EventFd::EventFd() {
- fd_ = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
- if (fd_ < 0) throw std::runtime_error("Failed to create eventfd");
-}
-
-EventFd::~EventFd() { Close(); }
-
-void EventFd::Close() {
- if (fd_ > -1) {
- close(fd_);
- fd_ = -1;
- }
-}
-
-int EventFd::GetFd() const { return fd_; }
-
-void EventFd::Write(uint64_t value) {
- if (eventfd_write(fd_, static_cast<eventfd_t>(value)) < 0)
- _E("Failed to write data. errno=%d", errno);
-}
-
-void EventFd::Read(uint64_t* value) {
- if (eventfd_read(fd_, static_cast<eventfd_t*>(value)) < 0)
- _E("Failed to read data. errno=%d", errno);
-}
-
-} // namespace tizen_core
-} // namespace tizen_base
+++ /dev/null
-/*
- * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef TIZEN_CORE_TIZEN_BASE_EVENT_FD_H_
-#define TIZEN_CORE_TIZEN_BASE_EVENT_FD_H_
-
-#include <sys/eventfd.h>
-#include <unistd.h>
-
-#include <stdexcept>
-
-#undef EXPORT_API
-#define EXPORT_API __attribute__((visibility("default")))
-
-namespace tizen_base {
-namespace tizen_core {
-
-class EXPORT_API EventFd {
- public:
- EventFd();
- virtual ~EventFd();
-
- void Close();
- int GetFd() const;
- void Write(uint64_t value);
- void Read(uint64_t* value);
-
- private:
- int fd_ = -1;
-};
-
-} // namespace tizen_core
-} // namespace tizen_base
-
-#endif // TIZEN_CORE_TIZEN_BASE_EVENT_FD_H_
+++ /dev/null
-/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef TIZEN_CORE_TIZEN_BASE_INTERFACE_LOOP_H_
-#define TIZEN_CORE_TIZEN_BASE_INTERFACE_LOOP_H_
-
-#include <functional>
-#include <memory>
-
-#include "tizen_base/interface_source.h"
-
-#undef EXPORT_API
-#define EXPORT_API __attribute__((visibility("default")))
-
-namespace tizen_base {
-namespace tizen_core {
-
-class EXPORT_API ILoop {
- public:
- virtual ~ILoop() = default;
- virtual void Run() = 0;
- virtual void Quit() = 0;
- virtual bool IsRunning() const = 0;
- virtual std::shared_ptr<ISource> AddIdleJob(std::function<bool()> cb) = 0;
- virtual std::shared_ptr<ISource> AddTimer(unsigned int interval,
- std::function<bool()> cb) = 0;
- virtual void RemoveSource(std::shared_ptr<ISource> source) = 0;
- virtual void AddSource(std::shared_ptr<ISource> source) = 0;
-};
-
-} // namespace tizen_core
-} // namespace tizen_base
-
-#endif // TIZEN_CORE_TIZEN_BASE_INTERFACE_LOOP_H_
+++ /dev/null
-/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef TIZEN_CORE_TIZEN_BASE_INTERFACE_SOURCE_H_
-#define TIZEN_CORE_TIZEN_BASE_INTERFACE_SOURCE_H_
-
-#include <memory>
-
-#undef EXPORT_API
-#define EXPORT_API __attribute__((visibility("default")))
-
-namespace tizen_base {
-namespace tizen_core {
-
-class Context;
-class PollFd;
-
-class EXPORT_API ISource {
- public:
- virtual ~ISource() = default;
- virtual void Attach(const std::shared_ptr<Context>& context) = 0;
- virtual void AddPoll(std::shared_ptr<PollFd> poll_fd) = 0;
- virtual void RemovePoll(const std::shared_ptr<PollFd>& poll_fd) = 0;
- virtual void RefSelf() = 0;
- virtual void UnrefSelf() = 0;
-};
-
-} // namespace tizen_core
-} // namespace tizen_base
-
-#endif // TIZEN_CORE_TIZEN_BASE_INTERFACE_SOURCE_H_
+++ /dev/null
-/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef TIZEN_CORE_TIZEN_BASE_LOG_PRIVATE_H_
-#define TIZEN_CORE_TIZEN_BASE_LOG_PRIVATE_H_
-
-#include <dlog.h>
-
-#undef LOG_TAG
-#define LOG_TAG "TIZEN_CORE"
-
-#undef _E
-#define _E LOGE
-
-#undef _W
-#define _W LOGW
-
-#undef _I
-#define _I LOGI
-
-#undef _D
-#define _D LOGD
-
-#endif // TIZEN_CORE_TIZEN_BASE_LOG_PRIVATE_H_
+++ /dev/null
-/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "tizen_base/poll_fd.h"
-
-#include "tizen_base/log_private.h"
-
-namespace tizen_base {
-namespace tizen_core {
-
-PollFd::PollFd() { _D("PollFd=%p", this); }
-
-PollFd::~PollFd() { _D("PollFd=%p, fd=%d", this, gpollfd_.fd); }
-
-void PollFd::SetFd(int fd) { gpollfd_.fd = fd; }
-
-int PollFd::GetFd() const { return gpollfd_.fd; }
-
-void PollFd::SetEvents(uint16_t events) { gpollfd_.events = events; }
-
-uint16_t PollFd::GetEvents() const { return gpollfd_.events; }
-
-void PollFd::SetRevents(uint16_t revents) { gpollfd_.revents = revents; }
-
-uint16_t PollFd::GetRevents() const { return gpollfd_.revents; }
-
-const GPollFD* PollFd::GetGPollFD() const { return &gpollfd_; }
-
-void PollFd::RefSelf() { self_ = shared_from_this(); }
-
-void PollFd::UnrefSelf() {
- if (!self_) return;
-
- if (source_ != nullptr) {
- source_->RemovePoll(self_);
- source_ = nullptr;
- }
-
- self_.reset();
-}
-
-void PollFd::SetSource(ISource* source) { source_ = source; }
-
-ISource* PollFd::GetSource() const { return source_; }
-
-} // namespace tizen_core
-} // namespace tizen_base
+++ /dev/null
-/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef TIZEN_CORE_TIZEN_BASE_POLL_FD_H_
-#define TIZEN_CORE_TIZEN_BASE_POLL_FD_H_
-
-#include <glib.h>
-
-#include <memory>
-
-#include "tizen_base/interface_source.h"
-
-#undef EXPORT_API
-#define EXPORT_API __attribute__((visibility("default")))
-
-namespace tizen_base {
-namespace tizen_core {
-
-class EXPORT_API PollFd : public std::enable_shared_from_this<PollFd> {
- public:
- PollFd();
- ~PollFd();
-
- void SetFd(int fd);
- int GetFd() const;
-
- void SetEvents(uint16_t events);
- uint16_t GetEvents() const;
-
- void SetRevents(uint16_t revents);
- uint16_t GetRevents() const;
-
- const GPollFD* GetGPollFD() const;
-
- void RefSelf();
- void UnrefSelf();
-
- void SetSource(ISource* source);
- ISource* GetSource() const;
-
- private:
- GPollFD gpollfd_ = { -1, 0, 0 };
- std::shared_ptr<PollFd> self_;
- ISource* source_ = nullptr;
-};
-
-} // namespace tizen_core
-} // namespace tizen_base
-
-#endif // TIZEN_CORE_TIZEN_BASE_POLL_FD_H_
+++ /dev/null
-/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "tizen_base/source.h"
-
-#include <mutex>
-#include <stdexcept>
-#include <unordered_map>
-#include <utility>
-
-#include "tizen_base/log_private.h"
-
-namespace tizen_base {
-namespace tizen_core {
-namespace {
-
-class SourceManager {
- public:
- void Insert(Source* source) {
- std::lock_guard<std::recursive_mutex> lock(mutex_);
- auto* gsource = source->GetHandle();
- map_[gsource] = source;
- }
-
- void Erase(GSource* gsource) {
- std::lock_guard<std::recursive_mutex> lock(mutex_);
- map_.erase(gsource);
- }
-
- Source* Find(GSource* gsource) {
- std::lock_guard<std::recursive_mutex> lock(mutex_);
- auto found = map_.find(gsource);
- if (found == map_.end())
- return nullptr;
-
- return found->second;
- }
-
- private:
- std::unordered_map<GSource*, Source*> map_;
- mutable std::recursive_mutex mutex_;
-};
-
-SourceManager source_manager;
-
-} // namespace
-
-Source::Source(GSource* handle) : handle_(handle) {}
-
-Source::Source() {
- static GSourceFuncs source_funcs = {
- .prepare = SourcePrepareFunc,
- .check = SourceCheckFunc,
- .dispatch = SourceDispatchFunc,
- .finalize = SourceFinalizeFunc,
- .closure_callback = nullptr,
- .closure_marshal = nullptr
- };
-
- handle_ = g_source_new(&source_funcs, sizeof(GSource));
- if (handle_ == nullptr) {
- _E("g_source_new() is failed"); // LCOV_EXCL_LINE
- throw std::runtime_error("g_source_new() is failed"); // LCOV_EXCL_LINE
- }
- source_manager.Insert(this);
-}
-
-Source::~Source() {
- if (handle_ != nullptr) {
- // LCOV_EXCL_START
- auto iter = poll_fds_.begin();
- while (iter != poll_fds_.end()) {
- auto& poll_fd = *iter;
- poll_fd->SetSource(nullptr);
- g_source_remove_poll(handle_,
- const_cast<GPollFD*>(poll_fd->GetGPollFD()));
- iter = poll_fds_.erase(iter);
- }
- // LCOV_EXCL_STOP
-
- if (!g_source_is_destroyed(handle_)) g_source_destroy(handle_);
- if (!attached_) g_source_unref(handle_);
-
- source_manager.Erase(handle_);
- }
-}
-
-void Source::AddPoll(std::shared_ptr<PollFd> poll_fd) {
- _D("AddPoll(). PollFd=%p", poll_fd.get());
- g_source_add_poll(handle_, const_cast<GPollFD*>(poll_fd->GetGPollFD()));
- poll_fd->SetSource(this);
- g_source_set_callback(handle_, nullptr, this, nullptr);
- poll_fds_.push_back(std::move(poll_fd));
-}
-
-void Source::RemovePoll(const std::shared_ptr<PollFd>& poll_fd) {
- _D("RemovePoll(). PollFd=%p", poll_fd.get());
- poll_fd->SetSource(nullptr);
- g_source_remove_poll(handle_, const_cast<GPollFD*>(poll_fd->GetGPollFD()));
- poll_fds_.remove_if(
- [=](const std::shared_ptr<PollFd>& pollfd) { return pollfd == poll_fd; });
-}
-
-void Source::Attach(const std::shared_ptr<Context>& context) {
- if (handle_ == nullptr)
- return;
-
- if (attached_)
- return;
-
- g_source_attach(handle_, context->GetHandle());
- g_source_unref(handle_);
- attached_ = true;
-}
-
-bool Source::IsAttached() const { return attached_; }
-
-GSource* Source::GetHandle() const { return handle_; }
-
-void Source::RefSelf() { if (!self_) self_ = shared_from_this(); }
-
-void Source::UnrefSelf() { self_.reset(); }
-
-void Source::SetPriority(int priority) {
- g_source_set_priority(handle_, priority);
-}
-
-// LCOV_EXCL_START
-bool Source::OnSourcePrepare(int* timeout) { return false; }
-
-bool Source::OnSourceCheck() { return false; }
-
-bool Source::OnSourceDispatch() { return false; }
-
-void Source::OnSourceFinalize() {}
-
-gboolean Source::SourcePrepareFunc(GSource* gsource, gint* timeout) {
- auto source = source_manager.Find(gsource);
- if (source == nullptr)
- return FALSE;
-
- return source->OnSourcePrepare(timeout);
-}
-
-gboolean Source::SourceCheckFunc(GSource* gsource) {
- auto source = source_manager.Find(gsource);
- if (source == nullptr)
- return FALSE;
-
- return source->OnSourceCheck();
-}
-
-gboolean Source::SourceDispatchFunc(GSource* gsource, GSourceFunc callback,
- gpointer user_data) {
- auto source = source_manager.Find(gsource);
- if (source == nullptr)
- return FALSE;
-
- return source->OnSourceDispatch();
-}
-
-void Source::SourceFinalizeFunc(GSource* gsource) {
- auto source = source_manager.Find(gsource);
- if (source == nullptr)
- return;
-
- source->OnSourceFinalize();
-}
-// LCOV_EXCL_STOP
-
-} // namespace tizen_core
-} // namespace tizen_base
+++ /dev/null
-/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef TCORE_TIZEN_BASE_SOURCE_H_
-#define TCORE_TIZEN_BASE_SOURCE_H_
-
-#include <glib.h>
-
-#include <list>
-#include <memory>
-
-#include "tizen_base/context.h"
-#include "tizen_base/interface_source.h"
-#include "tizen_base/poll_fd.h"
-
-#undef EXPORT_API
-#define EXPORT_API __attribute__((visibility("default")))
-
-namespace tizen_base {
-namespace tizen_core {
-
-class EXPORT_API Source : public ISource,
- public std::enable_shared_from_this<Source> {
- public:
- Source();
- explicit Source(GSource* handle);
- virtual ~Source();
-
- void AddPoll(std::shared_ptr<PollFd> poll_fd) override;
- void RemovePoll(const std::shared_ptr<PollFd>& poll_fd) override;
- void Attach(const std::shared_ptr<Context>& context) override;
- bool IsAttached() const;
- GSource* GetHandle() const;
- void RefSelf() override;
- void UnrefSelf() override;
- void SetPriority(int priority);
-
- virtual bool OnSourcePrepare(int* timeout);
- virtual bool OnSourceCheck();
- virtual bool OnSourceDispatch();
- virtual void OnSourceFinalize();
-
- private:
- static gboolean SourcePrepareFunc(GSource* gsource, gint* timeout);
- static gboolean SourceCheckFunc(GSource* gsource);
- static gboolean SourceDispatchFunc(GSource* gsource, GSourceFunc callback,
- gpointer user_data);
- static void SourceFinalizeFunc(GSource* gsource);
-
- private:
- GSource* handle_ = nullptr;
- bool attached_ = false;
- std::shared_ptr<Source> self_;
- std::list<std::shared_ptr<PollFd>> poll_fds_;
-};
-
-} // namespace tizen_core
-} // namespace tizen_base
-
-#endif // TCORE_TIZEN_BASE_SOURCE_H_
+++ /dev/null
-/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/tizen_core.h"
-
-#include <atomic>
-#include <stdexcept>
-
-#include "include/tizen_core_internal.h"
-#include "tizen_base/context_manager.h"
-#include "tizen_base/log_private.h"
-#include "tizen_base/task.h"
-#include "tizen_base/source.h"
-
-#undef EXPORT
-#define EXPORT __attribute__ ((visibility("default")))
-
-#undef API
-#define API extern "C" EXPORT
-
-namespace {
-
-std::atomic<int> tizen_core_ref(0);
-
-class SourceExt : public tizen_base::tizen_core::Source {
- public:
- SourceExt() {}
-
- void SetPrepareCb(tizen_core_source_prepare_cb callback, void* user_data) {
- prepare_cb_ = callback;
- prepare_data_ = user_data;
- }
-
- void SetCheckCb(tizen_core_source_check_cb callback, void* user_data) {
- check_cb_ = callback;
- check_data_ = user_data;
- }
-
- void SetDispatchCb(tizen_core_source_dispatch_cb callback, void* user_data) {
- dispatch_cb_ = callback;
- dispatch_data_ = user_data;
- }
-
- void SetFinalizeCb(tizen_core_source_finalize_cb callback, void* user_data) {
- finalize_cb_ = callback;
- finalize_data_ = user_data;
- }
-
- private:
- // LCOV_EXCL_START
- bool OnSourcePrepare(int* timeout) override {
- if (prepare_cb_ != nullptr)
- return prepare_cb_(this, timeout, prepare_data_);
-
- return false;
- }
-
- bool OnSourceCheck() override {
- if (check_cb_ != nullptr)
- return check_cb_(this, check_data_);
-
- return false;
- }
-
- bool OnSourceDispatch() override {
- if (dispatch_cb_ != nullptr)
- return dispatch_cb_(this, dispatch_data_);
-
- return false;
- }
-
- void OnSourceFinalize() override {
- if (finalize_cb_ != nullptr)
- finalize_cb_(this, finalize_data_);
- }
- // LCOV_EXCL_STOP
-
- private:
- tizen_core_source_prepare_cb prepare_cb_ = nullptr;
- void* prepare_data_ = nullptr;
- tizen_core_source_check_cb check_cb_ = nullptr;
- void* check_data_ = nullptr;
- tizen_core_source_dispatch_cb dispatch_cb_ = nullptr;
- void* dispatch_data_ = nullptr;
- tizen_core_source_finalize_cb finalize_cb_ = nullptr;
- void* finalize_data_ = nullptr;
-};
-
-} // namespace
-
-API void tizen_core_init(void) {
- ++tizen_core_ref;
-}
-
-API void tizen_core_shutdown(void) {
- if (tizen_core_ref <= 0)
- return;
-
- if (tizen_core_ref == 1)
- tizen_base::tizen_core::ContextManager::GetInst().DisposeAll();
-
- --tizen_core_ref;
-}
-
-API bool tizen_core_ready(void) {
- return tizen_core_ref > 0;
-}
-
-API int tizen_core_task_create(const char* name, bool use_thread,
- tizen_core_task_h* task) {
- if (name == nullptr || task == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- if (!tizen_core_ready())
- return TIZEN_CORE_ERROR_INVALID_CONTEXT;
-
- try {
- auto handle = tizen_base::tizen_core::Task::Create(name, use_thread);
- if (handle == nullptr) {
- _E("Out of memory"); // LCOV_EXCL_LINE
- return TIZEN_CORE_ERROR_OUT_OF_MEMORY; // LCOV_EXCL_LINE
- }
-
- handle->RefSelf();
- *task = static_cast<tizen_core_task_h>(handle.get());
- } catch (const std::invalid_argument& e) {
- _E("Exception occurs. error(%s)", e.what());
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_task_destroy(tizen_core_task_h task) {
- if (task == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* handle = static_cast<tizen_base::tizen_core::Task*>(task);
- handle->Dispose();
- handle->UnrefSelf();
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_task_run(tizen_core_task_h task) {
- if (task == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* handle = static_cast<tizen_base::tizen_core::Task*>(task);
- handle->Run();
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_task_is_running(tizen_core_task_h task, bool* running) {
- if (task == nullptr || running == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* handle = static_cast<tizen_base::tizen_core::Task*>(task);
- *running = handle->IsRunning();
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_task_quit(tizen_core_task_h task) {
- if (task == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* handle = static_cast<tizen_base::tizen_core::Task*>(task);
- handle->Quit();
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_task_get_tizen_core(tizen_core_task_h task,
- tizen_core_h* core) {
- if (task == nullptr || core == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- *core = static_cast<tizen_core_h>(task);
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_find(const char* name, tizen_core_h* core) {
- if (name == nullptr || core == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- if (!tizen_core_ready())
- return TIZEN_CORE_ERROR_INVALID_CONTEXT;
-
- auto context = tizen_base::tizen_core::ContextManager::GetInst().Find(name);
- if (context == nullptr) {
- _E("Failed to find context. name(%s)", name);
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- *core = static_cast<tizen_core_h>(context->GetLoop().get());
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_find_from_this_thread(tizen_core_h* core) {
- if (core == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- if (!tizen_core_ready())
- return TIZEN_CORE_ERROR_INVALID_CONTEXT;
-
- auto context =
- tizen_base::tizen_core::ContextManager::GetInst().FindFromThisThread();
- if (context == nullptr) {
- _E("Failed to find context"); // LCOV_EXCL_LINE
- return TIZEN_CORE_ERROR_INVALID_PARAMETER; // LCOV_EXCL_LINE
- }
-
- *core = static_cast<tizen_core_h>(context->GetLoop().get());
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_add_idle_job(tizen_core_h core, tizen_core_task_cb callback,
- void* user_data, tizen_core_source_h* source) {
- if (core == nullptr || callback == nullptr || source == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* task = static_cast<tizen_base::tizen_core::Task*>(core);
- auto idle_source = task->AddIdleJob([=]() { return callback(user_data); });
- if (idle_source == nullptr) {
- _E("Failed to add idle job"); // LCOV_EXCL_LINE
- return TIZEN_CORE_ERROR_OUT_OF_MEMORY; // LCOV_EXCL_LINE
- }
-
- *source = idle_source.get();
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_add_timer(tizen_core_h core, unsigned int interval,
- tizen_core_task_cb callback, void* user_data,
- tizen_core_source_h* source) {
- if (core == nullptr || callback == nullptr || source == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* task = static_cast<tizen_base::tizen_core::Task*>(core);
- auto timer_source =
- task->AddTimer(interval, [=]() { return callback(user_data); });
- if (timer_source == nullptr) {
- _E("Failed to add timer"); // LCOV_EXCL_LINE
- return TIZEN_CORE_ERROR_OUT_OF_MEMORY; // LCOV_EXCL_LINE
- }
-
- *source = timer_source.get();
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_add_channel(tizen_core_h core,
- tizen_core_channel_receiver_h receiver,
- tizen_core_channel_receive_cb callback,
- void* user_data, tizen_core_source_h* source) {
- if (core == nullptr || receiver == nullptr || callback == nullptr ||
- source == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* task = static_cast<tizen_base::tizen_core::Task*>(core);
- auto* channel_receiver =
- static_cast<tizen_base::tizen_core::channel::Receiver<void*>*>(receiver);
- auto channel_source = task->AddChannel<void*>(
- channel_receiver->shared_from_this(),
- [=](const tizen_base::tizen_core::channel::ChannelObject<void*>& object) {
- callback(
- &const_cast<tizen_base::tizen_core::channel::ChannelObject<void*>&>(
- object),
- user_data);
- });
- if (channel_source == nullptr) {
- _E("Failed to add channel"); // LCOV_EXCL_LINE
- return TIZEN_CORE_ERROR_OUT_OF_MEMORY; // LCOV_EXCL_LINE
- }
-
- *source = channel_source.get();
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_add_event(tizen_core_h core, tizen_core_event_h event,
- tizen_core_source_h* source) {
- if (core == nullptr || event == nullptr || source == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* broker =
- static_cast<tizen_base::tizen_core::event::EventBroker<void*>*>(event);
- if (broker->IsAttached()) {
- _E("Already attached. event=%p", event);
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* task = static_cast<tizen_base::tizen_core::Task*>(core);
- auto event_source = task->AddEvent(
- std::shared_ptr<tizen_base::tizen_core::event::EventBroker<void*>>(
- broker));
- if (event_source == nullptr) {
- _E("Failed to add event"); // LCOV_EXCL_LINE
- return TIZEN_CORE_ERROR_OUT_OF_MEMORY; // LCOV_EXCL_LINE
- }
-
- *source = event_source.get();
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_emit_event(tizen_core_h core,
- tizen_core_event_object_h object) {
- if (core == nullptr || object == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* task = static_cast<tizen_base::tizen_core::Task*>(core);
- auto* event_object =
- static_cast<tizen_base::tizen_core::event::EventObject<void*>*>(object);
- task->EmitEvent(event_object->shared_from_this());
- event_object->Unref();
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_add_source(tizen_core_h core, tizen_core_source_h source) {
- if (core == nullptr || source == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* task = static_cast<tizen_base::tizen_core::Task*>(core);
- auto* core_source = static_cast<tizen_base::tizen_core::Source*>(source);
- task->AddSource(core_source->shared_from_this());
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_remove_source(tizen_core_h core,
- tizen_core_source_h source) {
- if (core == nullptr || source == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* core_source = static_cast<tizen_base::tizen_core::Source*>(source);
- if (!core_source->IsAttached()) {
- _E("Source(%p) is not attached", source);
- return TIZEN_CORE_ERROR_INVALID_CONTEXT;
- }
-
- auto* task = static_cast<tizen_base::tizen_core::Task*>(core);
- task->RemoveSource(core_source->shared_from_this());
- return TIZEN_CORE_ERROR_NONE;
-}
-
-// LCOV_EXCL_START
-API int tizen_core_set_cpu_boosting(
- tizen_core_h core, tizen_core_cpu_boosting_level_e level) {
- if (core == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* task = static_cast<tizen_base::tizen_core::Task*>(core);
- if (!task->SetCpuBoosting(level))
- return TIZEN_CORE_ERROR_INVALID_CONTEXT;
-
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_clear_cpu_boosting(tizen_core_h core) {
- if (core == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* task = static_cast<tizen_base::tizen_core::Task*>(core);
- if (!task->ClearCpuBoosting())
- return TIZEN_CORE_ERROR_INVALID_CONTEXT;
-
- return TIZEN_CORE_ERROR_NONE;
-}
-// LCOV_EXCL_STOP
-
-API int tizen_core_source_create(tizen_core_source_h* source) {
- if (source == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- if (!tizen_core_ready())
- return TIZEN_CORE_ERROR_INVALID_CONTEXT;
-
- auto handle = std::make_shared<SourceExt>();
- if (handle == nullptr) {
- _E("Out of memory"); // LCOV_EXCL_LINE
- return TIZEN_CORE_ERROR_OUT_OF_MEMORY; // LCOV_EXCL_STOP
- }
-
- handle->RefSelf();
- *source = static_cast<tizen_core_source_h>(handle.get());
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_source_destroy(tizen_core_source_h source) {
- if (source == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* handle = static_cast<SourceExt*>(source);
- handle->UnrefSelf();
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_source_add_poll(tizen_core_source_h source,
- tizen_core_poll_fd_h poll_fd) {
- if (source == nullptr || poll_fd == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* handle = static_cast<SourceExt*>(source);
- auto* pfd = static_cast<tizen_base::tizen_core::PollFd*>(poll_fd);
- if (pfd->GetSource() != nullptr) {
- _E("Invalid context"); // LCOV_EXCL_LINE
- return TIZEN_CORE_ERROR_INVALID_CONTEXT; // LCOV_EXCL_LINE
- }
-
- handle->AddPoll(pfd->shared_from_this());
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_source_remove_poll(tizen_core_source_h source,
- tizen_core_poll_fd_h poll_fd) {
- if (source == nullptr || poll_fd == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* handle = static_cast<SourceExt*>(source);
- auto* pfd = static_cast<tizen_base::tizen_core::PollFd*>(poll_fd);
- if (pfd->GetSource() == nullptr) {
- _E("Invalid context");
- return TIZEN_CORE_ERROR_INVALID_CONTEXT;
- }
-
- handle->RemovePoll(pfd->shared_from_this());
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_source_set_prepare_cb(tizen_core_source_h source,
- tizen_core_source_prepare_cb callback,
- void* user_data) {
- if (source == nullptr || callback == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* handle = static_cast<SourceExt*>(source);
- handle->SetPrepareCb(callback, user_data);
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_source_set_check_cb(tizen_core_source_h source,
- tizen_core_source_check_cb callback,
- void* user_data) {
- if (source == nullptr || callback == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* handle = static_cast<SourceExt*>(source);
- handle->SetCheckCb(callback, user_data);
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_source_set_dispatch_cb(
- tizen_core_source_h source, tizen_core_source_dispatch_cb callback,
- void* user_data) {
- if (source == nullptr || callback == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* handle = static_cast<SourceExt*>(source);
- handle->SetDispatchCb(callback, user_data);
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_source_set_finalize_cb(
- tizen_core_source_h source, tizen_core_source_finalize_cb callback,
- void* user_data) {
- if (source == nullptr || callback == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* handle = static_cast<SourceExt*>(source);
- handle->SetFinalizeCb(callback, user_data);
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API void* tizen_core_get_glib_context(tizen_core_h core) {
- if (core == nullptr) {
- _E("Invalid parameter");
- set_last_result(TIZEN_CORE_ERROR_INVALID_PARAMETER);
- return nullptr;
- }
-
- auto* task = static_cast<tizen_base::tizen_core::Task*>(core);
- set_last_result(TIZEN_CORE_ERROR_NONE);
- return task->GetContext()->GetHandle();
-}
-
-API int tizen_core_source_set_priority(tizen_core_source_h source,
- tizen_core_priority_e priority) {
- if (source == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* handle = static_cast<SourceExt*>(source);
- handle->SetPriority(static_cast<int>(priority));
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_poll_fd_create(tizen_core_poll_fd_h* poll_fd) {
- if (poll_fd == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto handle = std::make_shared<tizen_base::tizen_core::PollFd>();
- if (handle == nullptr) {
- _E("Out of memory"); // LCOV_EXCL_LINE
- return TIZEN_CORE_ERROR_OUT_OF_MEMORY; // LCOV_EXCL_LINE
- }
-
- handle->RefSelf();
- *poll_fd = static_cast<tizen_core_poll_fd_h>(handle.get());
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_poll_fd_destroy(tizen_core_poll_fd_h poll_fd) {
- if (poll_fd == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* handle = static_cast<tizen_base::tizen_core::PollFd*>(poll_fd);
- handle->UnrefSelf();
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_poll_fd_set_fd(tizen_core_poll_fd_h poll_fd, int fd) {
- if (poll_fd == nullptr || fd < 0) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* handle = static_cast<tizen_base::tizen_core::PollFd*>(poll_fd);
- handle->SetFd(fd);
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_poll_fd_get_fd(tizen_core_poll_fd_h poll_fd, int* fd) {
- if (poll_fd == nullptr || fd == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* handle = static_cast<tizen_base::tizen_core::PollFd*>(poll_fd);
- *fd = handle->GetFd();
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_poll_fd_set_events(tizen_core_poll_fd_h poll_fd,
- uint16_t events) {
- if (poll_fd == nullptr || events == 0) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* handle = static_cast<tizen_base::tizen_core::PollFd*>(poll_fd);
- handle->SetEvents(events);
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_poll_fd_get_events(tizen_core_poll_fd_h poll_fd,
- uint16_t* events) {
- if (poll_fd == nullptr || events == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* handle = static_cast<tizen_base::tizen_core::PollFd*>(poll_fd);
- *events = handle->GetEvents();
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_poll_fd_set_returned_events(tizen_core_poll_fd_h poll_fd,
- uint16_t returned_events) {
- if (poll_fd == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* handle = static_cast<tizen_base::tizen_core::PollFd*>(poll_fd);
- handle->SetRevents(returned_events);
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_poll_fd_get_returned_events(tizen_core_poll_fd_h poll_fd,
- uint16_t* returned_events) {
- if (poll_fd == nullptr || returned_events == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* handle = static_cast<tizen_base::tizen_core::PollFd*>(poll_fd);
- *returned_events = handle->GetRevents();
- return TIZEN_CORE_ERROR_NONE;
-}
+++ /dev/null
-/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/tizen_core_channel.h"
-
-#include "include/tizen_core.h"
-#include "tizen_base/channel/channel_factory.h"
-#include "tizen_base/log_private.h"
-#include "tizen_base/task.h"
-#include "tizen_base/source.h"
-
-#undef EXPORT
-#define EXPORT __attribute__ ((visibility("default")))
-
-#undef API
-#define API extern "C" EXPORT
-
-namespace {
-
-} // namespace
-
-API int tizen_core_channel_make_pair(tizen_core_channel_sender_h* sender,
- tizen_core_channel_receiver_h* receiver) {
- if (sender == nullptr || receiver == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- if (!tizen_core_ready())
- return TIZEN_CORE_ERROR_INVALID_CONTEXT;
-
- auto [sender_ptr, receiver_ptr] =
- tizen_base::tizen_core::channel::ChannelFactory::MakePair<void *>();
- if (sender_ptr == nullptr || receiver_ptr == nullptr) {
- _E("Out of memory"); // LCOV_EXCL_LINE
- return TIZEN_CORE_ERROR_OUT_OF_MEMORY; // LCOV_EXCL_LINE
- }
-
- sender_ptr->RefSelf();
- *sender = static_cast<tizen_core_channel_sender_h>(sender_ptr.get());
-
- receiver_ptr->RefSelf();
- *receiver = static_cast<tizen_core_channel_receiver_h>(receiver_ptr.get());
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_channel_sender_send(tizen_core_channel_sender_h sender,
- tizen_core_channel_object_h object) {
- if (sender == nullptr || object == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* channel_sender =
- static_cast<tizen_base::tizen_core::channel::Sender<void*>*>(sender);
- auto* channel_object =
- static_cast<tizen_base::tizen_core::channel::ChannelObject<void*>*>(
- object);
- channel_sender->Send(*channel_object);
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_channel_sender_destroy(tizen_core_channel_sender_h sender) {
- if (sender == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* channel_sender =
- static_cast<tizen_base::tizen_core::channel::Sender<void*>*>(sender);
- channel_sender->UnrefSelf();
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_channel_sender_clone(
- tizen_core_channel_sender_h sender,
- tizen_core_channel_sender_h* cloned_sender) {
- if (sender == nullptr || cloned_sender == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* channel_sender =
- static_cast<tizen_base::tizen_core::channel::Sender<void*>*>(sender);
- auto clone = std::shared_ptr<tizen_base::tizen_core::channel::Sender<void*>>(
- new tizen_base::tizen_core::channel::Sender<void*>(*channel_sender));
- clone->RefSelf();
- *cloned_sender = static_cast<tizen_core_channel_sender_h>(clone.get());
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_channel_receiver_receive(
- tizen_core_channel_receiver_h receiver,
- tizen_core_channel_object_h* object) {
- if (receiver == nullptr || object == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* channel_receiver =
- static_cast<tizen_base::tizen_core::channel::Receiver<void*>*>(receiver);
- auto channel_object = channel_receiver->Receive();
- *object = static_cast<tizen_core_channel_object_h>(
- new tizen_base::tizen_core::channel::ChannelObject<void*>(
- channel_object));
- if (*object == nullptr) {
- _E("Out of memory");
- return TIZEN_CORE_ERROR_OUT_OF_MEMORY;
- }
-
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_channel_receiver_destroy(
- tizen_core_channel_receiver_h receiver) {
- if (receiver == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* channel_receiver =
- static_cast<tizen_base::tizen_core::channel::Receiver<void*>*>(receiver);
- channel_receiver->UnrefSelf();
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_channel_object_create(tizen_core_channel_object_h* object) {
- if (object == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- if (!tizen_core_ready())
- return TIZEN_CORE_ERROR_INVALID_CONTEXT;
-
- auto* channel_object = new (std::nothrow)
- tizen_base::tizen_core::channel::ChannelObject<void*>();
- if (channel_object == nullptr) {
- _E("Out of memory"); // LCOV_EXCL_LINE
- return TIZEN_CORE_ERROR_OUT_OF_MEMORY; // LCOV_EXCL_LINE
- }
-
- *object = static_cast<tizen_core_channel_object_h>(channel_object);
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_channel_object_destroy(tizen_core_channel_object_h object) {
- if (object == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* channel_object =
- static_cast<tizen_base::tizen_core::channel::ChannelObject<void*>*>(
- object);
- delete channel_object;
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_channel_object_set_id(tizen_core_channel_object_h object,
- int id) {
- if (object == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* channel_object =
- static_cast<tizen_base::tizen_core::channel::ChannelObject<void*>*>(
- object);
- channel_object->SetId(id);
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_channel_object_get_id(tizen_core_channel_object_h object,
- int* id) {
- if (object == nullptr || id == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* channel_object =
- static_cast<tizen_base::tizen_core::channel::ChannelObject<void*>*>(
- object);
- *id = channel_object->GetId();
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_channel_object_set_data(tizen_core_channel_object_h object,
- void* data) {
- if (object == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* channel_object =
- static_cast<tizen_base::tizen_core::channel::ChannelObject<void*>*>(
- object);
- channel_object->SetData(data);
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_channel_object_get_data(tizen_core_channel_object_h object,
- void** data) {
- if (object == nullptr || data == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* channel_object =
- static_cast<tizen_base::tizen_core::channel::ChannelObject<void*>*>(
- object);
- *data = channel_object->GetData();
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_channel_object_get_sender_task_name(
- tizen_core_channel_object_h object, const char** task_name) {
- if (object == nullptr || task_name == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* channel_object =
- static_cast<tizen_base::tizen_core::channel::ChannelObject<void*>*>(
- object);
- auto& sender = channel_object->GetSender();
- if (sender.empty()) {
- _E("Invalid context"); // LCOV_EXCL_LINE
- return TIZEN_CORE_ERROR_INVALID_CONTEXT; // LCOV_EXCL_LINE
- }
-
- *task_name = sender.c_str();
- return TIZEN_CORE_ERROR_NONE;
-}
+++ /dev/null
-/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "include/tizen_core_event.h"
-
-#include <atomic>
-#include <memory>
-#include <vector>
-
-#include "include/tizen_core.h"
-#include "include/tizen_core_event_internal.h"
-#include "tizen_base/event/event_broker.h"
-#include "tizen_base/log_private.h"
-#include "tizen_base/task.h"
-#include "tizen_base/source.h"
-
-#undef EXPORT
-#define EXPORT __attribute__ ((visibility("default")))
-
-#undef API
-#define API extern "C" EXPORT
-
-namespace {
-
-class EventObjectExt
- : public tizen_base::tizen_core::event::EventObject<void*> {
- public:
- EventObjectExt(int type, void* data) : EventObject<void*>(type, data) {}
-
- ~EventObjectExt() {
- if (destroy_cb_)
- destroy_cb_(GetData(), destroy_data_);
- }
-
- void SetDestroyCb(tizen_core_event_object_destroy_cb callback,
- void* data) {
- destroy_cb_ = callback;
- destroy_data_ = data;
- }
-
- private:
- tizen_core_event_object_destroy_cb destroy_cb_ = nullptr;
- void* destroy_data_ = nullptr;
-};
-
-class EventHandlerExt
- : public tizen_base::tizen_core::event::EventHandler<void*>,
- public std::enable_shared_from_this<EventHandlerExt> {
- public:
- EventHandlerExt(tizen_core_event_handler_cb cb, void* user_data)
- : tizen_base::tizen_core::event::EventHandler<void*>(),
- cb_(cb),
- user_data_(user_data) {}
-
- private:
- bool OnEventReceived(
- tizen_base::tizen_core::event::EventObject<void*>* obj) override {
- if (cb_)
- return cb_(obj, user_data_);
-
- return true;
- }
-
- private:
- tizen_core_event_handler_cb cb_;
- void* user_data_;
-};
-
-} // namespace
-
-API int tizen_core_event_create(tizen_core_event_h* event) {
- if (event == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- if (!tizen_core_ready())
- return TIZEN_CORE_ERROR_INVALID_CONTEXT;
-
- auto* broker =
- new (std::nothrow) tizen_base::tizen_core::event::EventBroker<void*>();
- if (broker == nullptr) {
- _E("Out of memory"); // LCOV_EXCL_LINE
- return TIZEN_CORE_ERROR_OUT_OF_MEMORY; // LCOV_EXCL_LINE
- }
-
- *event = static_cast<tizen_core_event_h>(broker);
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_event_destroy(tizen_core_event_h event) {
- if (event == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* broker =
- static_cast<tizen_base::tizen_core::event::EventBroker<void*>*>(event);
- if (broker->IsAttached()) {
- _E("Event(%p) is attached to a source", event);
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- delete broker;
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_event_add_handler(
- tizen_core_event_h event, tizen_core_event_handler_cb callback,
- void* user_data, tizen_core_event_handler_h* event_handler) {
- if (event == nullptr || callback == nullptr || event_handler == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto handler = std::make_shared<EventHandlerExt>(callback, user_data);
- if (handler == nullptr) {
- _E("Out of memory"); // LCOV_EXCL_LINE
- return TIZEN_CORE_ERROR_OUT_OF_MEMORY; // LCOV_EXCL_LINE
- }
-
- auto* broker =
- static_cast<tizen_base::tizen_core::event::EventBroker<void*>*>(event);
- broker->AddHandler(handler);
- *event_handler = handler.get();
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_event_prepend_handler(
- tizen_core_event_h event, tizen_core_event_handler_cb callback,
- void* user_data, tizen_core_event_handler_h* event_handler) {
- if (event == nullptr || callback == nullptr || event_handler == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto handler = std::make_shared<EventHandlerExt>(callback, user_data);
- if (handler == nullptr) {
- _E("Out of memory"); // LCOV_EXCL_LINE
- return TIZEN_CORE_ERROR_OUT_OF_MEMORY; // LCOV_EXCL_LINE
- }
-
- auto* broker =
- static_cast<tizen_base::tizen_core::event::EventBroker<void*>*>(event);
- broker->PrependHandler(handler);
- *event_handler = handler.get();
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_event_remove_handler(
- tizen_core_event_h event, tizen_core_event_handler_h event_handler) {
- if (event == nullptr || event_handler == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* broker =
- static_cast<tizen_base::tizen_core::event::EventBroker<void*>*>(event);
- auto* handler = static_cast<EventHandlerExt*>(event_handler);
- broker->RemoveHandler(handler->shared_from_this());
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_event_emit(tizen_core_event_h event,
- tizen_core_event_object_h object) {
- if (event == nullptr || object == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* broker =
- static_cast<tizen_base::tizen_core::event::EventBroker<void*>*>(event);
- auto* event_object = static_cast<EventObjectExt*>(object);
- broker->Emit(event_object->shared_from_this());
- event_object->Unref();
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_event_object_create(tizen_core_event_object_h* object,
- int id, void* data) {
- if (object == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- if (!tizen_core_ready())
- return TIZEN_CORE_ERROR_INVALID_CONTEXT;
-
- auto event_object = std::make_shared<EventObjectExt>(id, data);
- if (event_object == nullptr) {
- _E("Out of memory");
- return TIZEN_CORE_ERROR_OUT_OF_MEMORY;
- }
-
- event_object->Ref();
- *object = static_cast<tizen_core_event_object_h>(event_object.get());
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_event_object_destroy(tizen_core_event_object_h object) {
- if (object == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* event_object = static_cast<EventObjectExt*>(object);
- event_object->SetId(-1);
- event_object->Unref();
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_event_object_set_destroy_cb(
- tizen_core_event_object_h object,
- tizen_core_event_object_destroy_cb callback, void* user_data) {
- if (object == nullptr || callback == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* event_object = static_cast<EventObjectExt*>(object);
- event_object->SetDestroyCb(callback, user_data);
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_event_object_get_id(tizen_core_event_object_h object,
- int* id) {
- if (object == nullptr || id == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* event_object = static_cast<EventObjectExt*>(object);
- *id = event_object->GetId();
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_event_object_get_data(tizen_core_event_object_h object,
- void** data) {
- if (object == nullptr || data == nullptr) {
- _E("Invalid parameter");
- return TIZEN_CORE_ERROR_INVALID_PARAMETER;
- }
-
- auto* event_object = static_cast<EventObjectExt*>(object);
- *data = event_object->GetData();
- return TIZEN_CORE_ERROR_NONE;
-}
-
-API int tizen_core_event_generate_id(void) {
- static std::atomic<int> id{0};
- if ((id + 1) < 0) id = 0;
- return id++;
-}
+++ /dev/null
-/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "tizen_base/task.h"
-
-#include <cpu-boosting.h>
-#include <glib.h>
-#include <pthread.h>
-#include <unistd.h>
-
-#include <stdexcept>
-#include <utility>
-
-#include "tizen_base/context_manager.h"
-#include "tizen_base/log_private.h"
-#include "tizen_base/source.h"
-
-namespace tizen_base {
-namespace tizen_core {
-namespace {
-
-class IdleSource : public Source {
- public:
- explicit IdleSource(std::function<bool()> cb)
- : Source(g_idle_source_new()), cb_(std::move(cb)) {
- g_source_set_callback(GetHandle(), IdleCb, this, nullptr);
- }
-
- private:
- static gboolean IdleCb(gpointer user_data) {
- auto* source = static_cast<IdleSource*>(user_data);
- auto source_ptr = source->shared_from_this();
- if (source->cb_())
- return G_SOURCE_CONTINUE;
-
- source->UnrefSelf();
- return G_SOURCE_REMOVE;
- }
-
- private:
- std::function<bool()> cb_;
-};
-
-class TimeoutSource : public Source {
- public:
- TimeoutSource(unsigned int interval, std::function<bool()> cb)
- : Source(g_timeout_source_new(interval)), cb_(std::move(cb)) {
- g_source_set_callback(GetHandle(), TimeoutCb, this, nullptr);
- }
-
- private:
- static gboolean TimeoutCb(gpointer user_data) {
- auto* source = static_cast<TimeoutSource*>(user_data);
- auto source_ptr = source->shared_from_this();
- if (source->cb_())
- return G_SOURCE_CONTINUE;
-
- source->UnrefSelf();
- return G_SOURCE_REMOVE;
- }
-
- private:
- std::function<bool()> cb_;
-};
-
-template <class T>
-class ChannelSource : public Source {
- public:
- ChannelSource(std::shared_ptr<Task> task,
- std::shared_ptr<channel::Receiver<T>> receiver,
- std::function<void(const channel::ChannelObject<T>&)> cb)
- : task_(std::move(task)),
- receiver_(std::move(receiver)),
- cb_(std::move(cb)),
- poll_fd_(new PollFd()) {
- poll_fd_->SetFd(receiver_->GetFd());
- poll_fd_->SetEvents(POLLIN);
- AddPoll(poll_fd_);
- }
-
- private:
- bool OnSourcePrepare(int* timeout) override {
- *timeout = -1;
- return false;
- }
-
- bool OnSourceCheck() override {
- if (receiver_->Empty()) return false;
- return true;
- }
-
- bool OnSourceDispatch() override {
- while (!receiver_->Empty()) cb_(receiver_->Receive());
- return true;
- }
-
- private:
- std::shared_ptr<Task> task_;
- std::shared_ptr<channel::Receiver<T>> receiver_;
- std::function<void(const channel::ChannelObject<T>&)> cb_;
- std::shared_ptr<PollFd> poll_fd_;
-};
-
-template <class T>
-class EventSource : public Source {
- public:
- EventSource(std::shared_ptr<Task> task,
- std::shared_ptr<event::EventBroker<T>> broker)
- : task_(std::move(task)),
- broker_(std::move(broker)),
- poll_fd_(new PollFd()) {
- broker_->SetAttached(true);
- poll_fd_->SetFd(broker_->GetFd());
- poll_fd_->SetEvents(POLLIN);
- AddPoll(poll_fd_);
- }
-
- void Emit(std::shared_ptr<event::EventObject<T>> object) {
- broker_->Emit(std::move(object));
- }
-
- // LCOV_EXCL_START
- void UnrefSelf() override {
- task_->RemoveEventSource(shared_from_this());
- Source::UnrefSelf();
- }
- // LCOV_EXCL_STOP
- private:
- bool OnSourcePrepare(int* timeout) override {
- *timeout = -1;
- return false;
- }
-
- bool OnSourceCheck() override {
- if (broker_->Empty()) return false;
- return true;
- }
-
- bool OnSourceDispatch() override {
- while (!broker_->Empty()) broker_->Process();
- return true;
- }
-
- private:
- std::shared_ptr<Task> task_;
- std::shared_ptr<event::EventBroker<T>> broker_;
- std::shared_ptr<PollFd> poll_fd_;
-};
-
-// LCOV_EXCL_START
-resource_cpu_boosting_level ConvertCpuBoostingLevel(
- tizen_core_cpu_boosting_level_e level) {
- switch (level) {
- case TIZEN_CORE_CPU_BOOSTING_LEVEL_NONE:
- return CPU_BOOSTING_LEVEL_NONE;
- case TIZEN_CORE_CPU_BOOSTING_LEVEL_STRONG:
- return CPU_BOOSTING_LEVEL_STRONG;
- case TIZEN_CORE_CPU_BOOSTING_LEVEL_MEDIUM:
- return CPU_BOOSTING_LEVEL_MEDIUM;
- case TIZEN_CORE_CPU_BOOSTING_LEVEL_WEAK:
- return CPU_BOOSTING_LEVEL_WEAK;
- default:
- return CPU_BOOSTING_LEVEL_NONE;
- }
-}
-
-const char* CpuBoostingLevelToStr(tizen_core_cpu_boosting_level_e level) {
- switch (level) {
- case TIZEN_CORE_CPU_BOOSTING_LEVEL_NONE:
- return "NONE";
- case TIZEN_CORE_CPU_BOOSTING_LEVEL_STRONG:
- return "STRONG";
- case TIZEN_CORE_CPU_BOOSTING_LEVEL_MEDIUM:
- return "MEDIUM";
- case TIZEN_CORE_CPU_BOOSTING_LEVEL_WEAK:
- return "WEAK";
- default:
- return "NONE";
- }
-}
-// LCOV_EXCL_STOP
-
-} // namespace
-
-Task::Task(std::string name, bool use_thread)
- : name_(std::move(name)), use_thread_(use_thread) {
- _W("Task: %s", name_.c_str());
- if (name_ == "main" && use_thread_)
- throw std::invalid_argument("main task must not use a thread");
-
- context_ = ContextManager::GetInst().Create(name_, use_thread_);
- loop_ = g_main_loop_new(context_->GetHandle(), FALSE);
-}
-
-Task::~Task() {
- _W("~Task: %s", name_.c_str());
- Quit();
- if (use_thread_ && thread_.joinable())
- thread_.join();
-
- g_main_loop_unref(loop_);
-}
-
-std::shared_ptr<Task> Task::Create(std::string name, bool use_thread) {
- auto task = std::make_shared<Task>(std::move(name), use_thread);
- task->GetContext()->SetLoop(task);
- return task;
-}
-
-void Task::Dispose() {
- context_->SetLoop(nullptr);
- ContextManager::GetInst().Dispose(name_);
-}
-
-std::shared_ptr<Context> Task::GetContext() const {
- return context_;
-}
-
-void Task::Quit() {
- if (g_main_loop_is_running(loop_))
- g_main_loop_quit(loop_);
-}
-
-void Task::Run() {
- if (use_thread_) {
- std::unique_lock<std::mutex> lock(loop_mutex_);
- idle_entered_ = false;
- thread_ = std::thread([&]() -> void {
- tid_ = gettid();
- ThreadLoop();
- tid_ = -1;
- cpu_boosting_level_ = TIZEN_CORE_CPU_BOOSTING_LEVEL_NONE;
- });
- cond_var_.wait(lock, [this]() { return idle_entered_; });
- } else {
- tid_ = getpid();
- g_main_loop_run(loop_);
-
- while (g_main_context_pending(context_->GetHandle()))
- g_main_context_dispatch(context_->GetHandle());
-
- tid_ = -1;
- }
-}
-
-bool Task::IsRunning() const {
- return g_main_loop_is_running(loop_);
-}
-
-std::shared_ptr<ISource> Task::AddIdleJob(std::function<bool()> job) {
- auto source = std::make_shared<IdleSource>(std::move(job));
- AddSource(source);
- return source;
-}
-
-std::shared_ptr<ISource> Task::AddTimer(unsigned int interval,
- std::function<bool()> cb) {
- auto source = std::make_shared<TimeoutSource>(interval, std::move(cb));
- AddSource(source);
- return source;
-}
-
-void Task::RemoveSource(std::shared_ptr<ISource> source) {
- RemoveEventSource(source);
- source->UnrefSelf();
-}
-
-void Task::AddSource(std::shared_ptr<ISource> source) {
- source->Attach(context_);
- source->RefSelf();
-}
-
-template <typename T>
-std::shared_ptr<ISource> Task::AddChannel(
- std::shared_ptr<channel::Receiver<T>> receiver,
- std::function<void(const channel::ChannelObject<T>&)> cb) {
- auto source = std::make_shared<ChannelSource<T>>(
- shared_from_this(), std::move(receiver), std::move(cb));
- AddSource(source);
- return source;
-}
-
-template <typename T>
-std::shared_ptr<ISource> Task::AddEvent(
- std::shared_ptr<event::EventBroker<T>> broker) {
- auto source =
- std::make_shared<EventSource<T>>(shared_from_this(), std::move(broker));
- AddSource(source);
- AddEventSource(source);
- return source;
-}
-
-template <typename T>
-void Task::EmitEvent(std::shared_ptr<event::EventObject<T>> object) {
- std::lock_guard<std::recursive_mutex> lock(mutex_);
- for (auto& source : event_sources_) {
- auto* event_source = dynamic_cast<EventSource<T>*>(source.get());
- if (event_source == nullptr)
- continue;
-
- event_source->Emit(object);
- }
-}
-
-// LCOV_EXCL_START
-bool Task::SetCpuBoosting(tizen_core_cpu_boosting_level_e level) {
- std::lock_guard<std::recursive_mutex> lock(mutex_);
- if (tid_ == -1) {
- _E("Not running yet.");
- return false;
- }
-
- if (cpu_boosting_level_ == level)
- return true;
-
- resource_pid_t res_pid = {
- .pid = 0,
- .tid = &tid_,
- .tid_count = 1,
- };
-
- resource_cpu_boosting_level native_level = ConvertCpuBoostingLevel(level);
- int ret = resource_set_cpu_boosting(res_pid, native_level,
- static_cast<cpu_boosting_flag_e>(0), -1);
- if (ret != 0) {
- _E("Failed to set cpu boosting. ret(%d)", ret);
- return false;
- }
-
- _I("Set cpu boosting level(%s -> %s).",
- CpuBoostingLevelToStr(cpu_boosting_level_), CpuBoostingLevelToStr(level));
- cpu_boosting_level_ = level;
- return true;
-}
-
-bool Task::ClearCpuBoosting() {
- std::lock_guard<std::recursive_mutex> lock(mutex_);
- if (tid_ == -1) {
- _E("Not running yet.");
- return false;
- }
-
- resource_pid_t res_pid = {
- .pid = 0,
- .tid = &tid_,
- .tid_count = 1,
- };
-
- int ret = resource_clear_cpu_boosting(res_pid);
- if (ret != 0) {
- _E("Failed to set cpu boosting. ret(%d)", ret);
- return false;
- }
-
- _I("Clear cpu boosting");
- cpu_boosting_level_ = TIZEN_CORE_CPU_BOOSTING_LEVEL_NONE;
- return true;
-}
-// LCOV_EXCL_STOP
-
-void Task::ThreadLoop() {
- {
- std::unique_lock<std::mutex> lock(loop_mutex_);
- GSource* source = g_idle_source_new();
- g_source_set_callback(
- source, [](gpointer user_data) {
- auto* task = static_cast<Task*>(user_data);
- std::unique_lock<std::mutex> idler_lock(task->loop_mutex_);
- _W("thread loop is running");
- task->idle_entered_ = true;
- task->cond_var_.notify_one();
- return G_SOURCE_REMOVE;
- }, this,
- nullptr);
- g_source_set_priority(source, G_PRIORITY_HIGH);
- g_source_attach(source, context_->GetHandle());
- g_source_unref(source);
-
- g_main_context_push_thread_default(context_->GetHandle());
- }
-
- pthread_setname_np(pthread_self(), name_.c_str());
- g_main_loop_run(loop_);
-
- while (g_main_context_pending(context_->GetHandle()))
- g_main_context_dispatch(context_->GetHandle());
-
- g_main_context_pop_thread_default(context_->GetHandle());
-}
-
-void Task::AddEventSource(std::shared_ptr<ISource> source) {
- std::lock_guard<std::recursive_mutex> lock(mutex_);
- event_sources_.push_back(std::move(source));
-}
-
-void Task::RemoveEventSource(std::shared_ptr<ISource> source) {
- std::lock_guard<std::recursive_mutex> lock(mutex_);
- event_sources_.remove(source);
-}
-
-void Task::RefSelf() { self_ = shared_from_this(); }
-
-void Task::UnrefSelf() { self_.reset(); }
-
-template std::shared_ptr<ISource> Task::AddChannel<void*>(
- std::shared_ptr<channel::Receiver<void*>> receiver,
- std::function<void(const channel::ChannelObject<void*>&)> cb);
-template std::shared_ptr<ISource> Task::AddEvent<void*>(
- std::shared_ptr<event::EventBroker<void*>> broker);
-template void Task::EmitEvent<void*>(
- std::shared_ptr<event::EventObject<void*>> object);
-
-} // namespace tizen_core
-} // namespace tizen_base
+++ /dev/null
-/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef TIZEN_CORE_TIZEN_BASE_TASK_H_
-#define TIZEN_CORE_TIZEN_BASE_TASK_H_
-
-#include <glib.h>
-
-#include <functional>
-#include <list>
-#include <memory>
-#include <mutex>
-#include <string>
-#include <thread>
-
-#include "tizen_core_internal.h"
-#include "tizen_base/channel/receiver.h"
-#include "tizen_base/context.h"
-#include "tizen_base/event/event_broker.h"
-#include "tizen_base/interface_loop.h"
-#include "tizen_base/interface_source.h"
-
-#undef EXPORT_API
-#define EXPORT_API __attribute__((visibility("default")))
-
-namespace tizen_base {
-namespace tizen_core {
-
-class EXPORT_API Task : public ILoop,
- public std::enable_shared_from_this<Task> {
- public:
- Task(std::string name, bool use_thread);
- virtual ~Task();
-
- Task(const Task& task) = delete;
- Task& operator=(const Task& task) = delete;
- Task(Task&& task) = delete;
- Task& operator=(Task&& task) = delete;
-
- static std::shared_ptr<Task> Create(std::string name, bool use_thread);
- void Dispose();
-
- std::shared_ptr<Context> GetContext() const;
- void Quit() override;
- void Run() override;
- bool IsRunning() const override;
-
- std::shared_ptr<ISource> AddIdleJob(std::function<bool()> cb) override;
- std::shared_ptr<ISource> AddTimer(unsigned int interval,
- std::function<bool()> cb) override;
- void RemoveSource(std::shared_ptr<ISource> source) override;
- void AddSource(std::shared_ptr<ISource> source) override;
-
- template <typename T>
- std::shared_ptr<ISource> AddChannel(
- std::shared_ptr<channel::Receiver<T>> receiver,
- std::function<void(const channel::ChannelObject<T>&)> cb);
- template <typename T>
- std::shared_ptr<ISource> AddEvent(
- std::shared_ptr<event::EventBroker<T>> broker);
- template <typename T>
- void EmitEvent(std::shared_ptr<event::EventObject<T>> object);
-
- bool SetCpuBoosting(tizen_core_cpu_boosting_level_e level);
- bool ClearCpuBoosting();
-
- void AddEventSource(std::shared_ptr<ISource> source);
- void RemoveEventSource(std::shared_ptr<ISource> source);
-
- void RefSelf();
- void UnrefSelf();
-
- private:
- void ThreadLoop();
-
- private:
- pid_t tid_ = -1;
- tizen_core_cpu_boosting_level_e cpu_boosting_level_ =
- TIZEN_CORE_CPU_BOOSTING_LEVEL_NONE;
- std::string name_;
- bool use_thread_;
- std::shared_ptr<Context> context_;
- std::thread thread_;
- std::condition_variable cond_var_;
- mutable std::mutex loop_mutex_;
- GMainLoop* loop_ = nullptr;
- bool idle_entered_ = false;
- std::list<std::shared_ptr<ISource>> event_sources_;
- mutable std::recursive_mutex mutex_;
- std::shared_ptr<Task> self_;
-};
-
-} // namespace tizen_core
-} // namespace tizen_base
-
-#endif // TIZEN_CORE_TIZEN_BASE_TASK_H_