| 
    Tizen Native API
    10.0
    
   
   | 
  
  
  
 
The tizen core event API provides functions to add event handlers and transmit events.
Required Header
#include <tizen_core.h>
Overview
The tizen core event can transmit events to event handlers. It provides functions to add event handlers and emit events APIs.
Functions | |
| int | tizen_core_event_create (tizen_core_event_h *event) | 
| Creates the tizen core event handle.   | |
| int | tizen_core_event_destroy (tizen_core_event_h event) | 
| Destroys the tizen core event handle.   | |
| 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) | 
| Adds the event handler to the tizen core event.   | |
| 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) | 
| Prepends the event handler to the tizen core event.   | |
| int | tizen_core_event_remove_handler (tizen_core_event_h event, tizen_core_event_handler_h event_handler) | 
| Removes the event handler from the tizen core event.   | |
| int | tizen_core_event_emit (tizen_core_event_h event, tizen_core_event_object_h object) | 
| Emits the event to the tizen core event.   | |
| int | tizen_core_event_object_create (tizen_core_event_object_h *object, int id, void *data) | 
| Creates the tizen core event object handle.   | |
| int | tizen_core_event_object_destroy (tizen_core_event_object_h object) | 
| Destroys the tizen core event object handle.   | |
| int | tizen_core_event_object_set_destroy_cb (tizen_core_event_object_h object, tizen_core_event_object_destroy_cb callback, void *user_data) | 
| Sets the destroy callback function to invoke when the event object is destroyed.   | |
| int | tizen_core_event_object_get_id (tizen_core_event_object_h object, int *id) | 
| Gets the event ID from the tizen core event object handle.   | |
| int | tizen_core_event_object_get_data (tizen_core_event_object_h object, void **data) | 
| Gets the event data from the tizen core event object handle.   | |
Typedefs | |
| typedef void * | tizen_core_event_h | 
| The tizen core event handle.   | |
| typedef void * | tizen_core_event_object_h | 
| The tizen core event object handle.   | |
| typedef void * | tizen_core_event_handler_h | 
| The tizen core event handler handle.   | |
| typedef bool(* | tizen_core_event_handler_cb )(tizen_core_event_object_h object, void *user_data) | 
| Called when the event is emitted.   | |
| typedef void(* | tizen_core_event_object_destroy_cb )(void *event_data, void *user_data) | 
| Called when the event object is destroyed.   | |
Typedef Documentation
| typedef void* tizen_core_event_h | 
The tizen core event handle.
- Since :
 - 9.0
 
| typedef bool(* tizen_core_event_handler_cb)(tizen_core_event_object_h object, void *user_data) | 
Called when the event is emitted.
- Since :
 - 9.0
 
- Remarks:
 - The object must not be deallocated by the application.
 
- Parameters:
 - 
  
[in] object The tizen core event object handle [in] user_data The user data passed from the callback registration function  
- Returns:
 trueto continue with the next iteration of the loop, otherwisefalseto break out of the loop
- See also:
 - tizen_core_event_add_handler()
 
| typedef void* tizen_core_event_handler_h | 
The tizen core event handler handle.
- Since :
 - 9.0
 
| typedef void(* tizen_core_event_object_destroy_cb)(void *event_data, void *user_data) | 
Called when the event object is destroyed.
- Since :
 - 9.0
 
- Remarks:
 - The event_data should be released using release function if it's needed.
 
- Parameters:
 - 
  
[in] event_data The event data of the event object [in] user_data The user data passed from the callback registration function  
| typedef void* tizen_core_event_object_h | 
The tizen core event object handle.
- Since :
 - 9.0
 
Function Documentation
| 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 | ||
| ) | 
Adds the event handler to the tizen core event.
The event_handler is added at the back of the handler list of the tizen core event. When tizen_core_emit_event() is called, the callback function of the event_handler is called first.
- Since :
 - 9.0
 
- Remarks:
 - The event_handler should be released using tizen_core_event_remove_handler().
 
- Parameters:
 - 
  
[in] event The tizen core event handle [in] callback The callback function to be invoked when the event is emitted [in] user_data The user data to be passed to the callback function [out] event_handler The tizen core event handler handle  
- Returns:
 0on success, otherwise a negative error value
- Return values:
 - 
  
TIZEN_CORE_ERROR_NONE Successful TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter TIZEN_CORE_ERROR_OUT_OF_MEMORY Out of memory  
#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; } }
| int tizen_core_event_create | ( | tizen_core_event_h * | event | ) | 
Creates the tizen core event handle.
- Since :
 - 9.0
 
- Remarks:
 - The event should be released using tizen_core_event_destroy().
 
- Parameters:
 - 
  
[out] event The tizen core event handle  
- Returns:
 0on success, otherwise a negative error value
- Return values:
 - 
  
TIZEN_CORE_ERROR_NONE Successful TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter TIZEN_CORE_ERROR_OUT_OF_MEMORY Out of memory TIZEN_CORE_ERROR_INVALID_CONTEXT Invalid context  
#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); }
- See also:
 - tizen_core_event_destroy()
 
| int tizen_core_event_destroy | ( | tizen_core_event_h | event | ) | 
Destroys the tizen core event handle.
- Since :
 - 9.0
 
- Parameters:
 - 
  
[in] event The tizen core event handle  
- Returns:
 0on success, otherwise a negative error value
- Return values:
 - 
  
TIZEN_CORE_ERROR_NONE Successful TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter  
#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; } }
- See also:
 - tizen_core_event_create()
 
| int tizen_core_event_emit | ( | tizen_core_event_h | event, | 
| tizen_core_event_object_h | object | ||
| ) | 
Emits the event to the tizen core event.
The event is emitted to the tizen core event.
- Since :
 - 9.0
 
- Remarks:
 - The object will be released automatically. You MUST NOT release the object using tizen_core_event_object_destroy() when calling the function is successful. If this function returns an error, the object should be released using tizen_core_event_object_destroy().
 
- Parameters:
 - 
  
[in] event The tizen core event handle [in] object The tizen core event object handle  
- Returns:
 0on success, otherwise a negative error value
- Return values:
 - 
  
TIZEN_CORE_ERROR_NONE Successful TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter  
#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; } }
- See also:
 - tizen_core_event_add_handler()
 
| int tizen_core_event_object_create | ( | tizen_core_event_object_h * | object, | 
| int | id, | ||
| void * | data | ||
| ) | 
Creates the tizen core event object handle.
The data can be nullptr. If the data is memory allocated, the 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 :
 - 9.0
 
- Remarks:
 - The object should be released using tizen_core_event_object_destroy().
 - The object should not be released when the object is emitted using tizen_core_event_emit().
 
- Parameters:
 - 
  
[out] object The tizen core event object handle [in] id The event ID [in] data The event data  
- Returns:
 0on success, otherwise a negative error value
- Return values:
 - 
  
TIZEN_CORE_ERROR_NONE Successful TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter TIZEN_CORE_ERROR_OUT_OF_MEMORY Out of memory TIZEN_CORE_ERROR_INVALID_CONTEXT Invalid context  
#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; }
| int tizen_core_event_object_destroy | ( | tizen_core_event_object_h | object | ) | 
Destroys the tizen core event object handle.
- Since :
 - 9.0
 
- Parameters:
 - 
  
[in] object The tizen core event object handle  
- Returns:
 0on success, otherwise a negative error value
- Return values:
 - 
  
TIZEN_CORE_ERROR_NONE Successful TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter  
#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"); }
| int tizen_core_event_object_get_data | ( | tizen_core_event_object_h | object, | 
| void ** | data | ||
| ) | 
Gets the event data from the tizen core event object handle.
- Since :
 - 9.0
 
- Remarks:
 - The data should not be released if the object is emitted using tizen_core_event_emit().
 - The data is available until the object is released.
 
- Parameters:
 - 
  
[in] object The tizen core event object handle [out] data The event data  
- Returns:
 0on success, otherwise a negative error value
- Return values:
 - 
  
TIZEN_CORE_ERROR_NONE Successful TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter  
#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); }
| int tizen_core_event_object_get_id | ( | tizen_core_event_object_h | object, | 
| int * | id | ||
| ) | 
Gets the event ID from the tizen core event object handle.
- Since :
 - 9.0
 
- Parameters:
 - 
  
[in] object The tizen core event object handle [out] id The event ID  
- Returns:
 0on success, otherwise a negative error value
- Return values:
 - 
  
TIZEN_CORE_ERROR_NONE Successful TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter  
#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); }
- See also:
 - tizen_core_event_object_create()
 
| int tizen_core_event_object_set_destroy_cb | ( | tizen_core_event_object_h | object, | 
| tizen_core_event_object_destroy_cb | callback, | ||
| void * | user_data | ||
| ) | 
Sets the destroy callback function to invoke when the event object is destroyed.
- Since :
 - 9.0
 
- Parameters:
 - 
  
[in] object The tizen core event object handle [in] callback The callback function to be invoked when the event object is destroyed [in] user_data The user data to be passed to the callback function  
- Returns:
 0on success, otherwise a negative error value
- Return values:
 - 
  
TIZEN_CORE_ERROR_NONE Successful TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter  
#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; }
- See also:
 - tizen_core_event_object_destroy()
 
| 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 | ||
| ) | 
Prepends the event handler to the tizen core event.
The event_handler is added to the front of the handler list of the tizen core event. When tizen_core_emit_event() is called, the callback function of the event_handler is called first.
- Since :
 - 9.0
 
- Remarks:
 - The event_handler should be released using tizen_core_event_remove_handler().
 
- Parameters:
 - 
  
[in] event The tizen core event handle [in] callback The callback function to be invoked when the event is emitted [in] user_data The user data to be passed to the callback function [out] event_handler The tizen core event handler handle  
- Returns:
 0on success, otherwise a negative error value
- Return values:
 - 
  
TIZEN_CORE_ERROR_NONE Successful TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter TIZEN_CORE_ERROR_OUT_OF_MEMORY Out of memory  
#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; } }
| int tizen_core_event_remove_handler | ( | tizen_core_event_h | event, | 
| tizen_core_event_handler_h | event_handler | ||
| ) | 
Removes the event handler from the tizen core event.
- Since :
 - 9.0
 
- Parameters:
 - 
  
[in] event The tizen core event handle [in] event_handler The tizen core event handler handle  
- Returns:
 0on success, otherwise a negative error value
- Return values:
 - 
  
TIZEN_CORE_ERROR_NONE Successful TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter  
#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"); }
- See also:
 - tizen_core_event_add_handler()