From bdee5ea2bcf7e25ebe6b7e2636a5e01bb5c8a3e1 Mon Sep 17 00:00:00 2001 From: Somin Kim Date: Tue, 22 Aug 2017 23:28:50 +0900 Subject: [PATCH] [History] Add apphistory feature to Context History API Conflicts: CMakeLists.txt packaging/capi-context.spec Change-Id: Idab7265d8561297bfadbd22dd80c2ef27d0a5c40 --- CMakeLists.txt | 2 +- doc/context_history_doc.h | 5 +++-- include/context_history.h | 18 +++++++++++++++++- packaging/capi-context.spec | 1 + src/history/context_history.cpp | 30 ++++++++++++++++++++++++++++++ 5 files changed, 52 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 97e5d3f..4468749 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ INCLUDE(GNUInstallDirs) SET(target ${PROJECT_NAME}) # Dependencies -SET(DEPS "gio-2.0 jsoncpp bundle aul pkgmgr-info capi-base-common capi-appfw-app-control") +SET(DEPS "gio-2.0 jsoncpp bundle aul pkgmgr-info capi-base-common capi-appfw-app-control capi-system-info") SET(DEPS "${DEPS} cynara-creds-self cynara-session cynara-client") SET(DEPS "${DEPS} context-app-history-client context-job-scheduler-client") diff --git a/doc/context_history_doc.h b/doc/context_history_doc.h index c8f9095..4548a27 100644 --- a/doc/context_history_doc.h +++ b/doc/context_history_doc.h @@ -36,8 +36,9 @@ * * * @section CAPI_CONTEXT_HISTORY_MODULE_FEATURE Related Features - * - * Some of the statistic items in this API are related with one of the following features:@n + * This API is related with the following features:@n + * - http://tizen.org/feature/app_history + * And some of the statistic items in this API are related with one of the following features:@n * - http://tizen.org/feature/battery * * It is recommended to design feature related code in your application for reliability.@n diff --git a/include/context_history.h b/include/context_history.h index 9d82c2a..4a00f89 100644 --- a/include/context_history.h +++ b/include/context_history.h @@ -229,6 +229,7 @@ typedef struct _context_history_record_handle_s* context_history_record_h; * @return @c 0 on success, otherwise a negative error value * @retval #CONTEXT_HISTORY_ERROR_NONE Successful * @retval #CONTEXT_HISTORY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONTEXT_HISTORY_ERROR_NOT_SUPPORTED Not supported * @retval #CONTEXT_HISTORY_ERROR_OUT_OF_MEMORY Out of memory * * @see context_history_destroy() @@ -245,6 +246,7 @@ int context_history_create(context_history_h* handle); * * @return @c 0 on success, otherwise a negative error value * @retval #CONTEXT_HISTORY_ERROR_NONE Successful + * @retval #CONTEXT_HISTORY_ERROR_NOT_SUPPORTED Not supported * @retval #CONTEXT_HISTORY_ERROR_INVALID_PARAMETER Invalid parameter * * @pre context_history_create() @@ -261,6 +263,7 @@ int context_history_destroy(context_history_h handle); * @return @c 0 on success, otherwise a negative error value * @retval #CONTEXT_HISTORY_ERROR_NONE Successful * @retval #CONTEXT_HISTORY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONTEXT_HISTORY_ERROR_NOT_SUPPORTED Not supported * @retval #CONTEXT_HISTORY_ERROR_OUT_OF_MEMORY Memory allocation failed * * @see context_history_filter_destroy() @@ -277,6 +280,7 @@ int context_history_filter_create(context_history_filter_h* filter); * @return @c 0 on success, otherwise a negative error value * @retval #CONTEXT_HISTORY_ERROR_NONE Successful * @retval #CONTEXT_HISTORY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONTEXT_HISTORY_ERROR_NOT_SUPPORTED Not supported * * @pre context_history_filter_create() */ @@ -294,6 +298,7 @@ int context_history_filter_destroy(context_history_filter_h filter); * @return @c 0 on success, otherwise a negative error value * @retval #CONTEXT_HISTORY_ERROR_NONE Successful * @retval #CONTEXT_HISTORY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONTEXT_HISTORY_ERROR_NOT_SUPPORTED Not supported * * @pre context_history_filter_create() * @see context_history_filter_set_string() @@ -313,6 +318,7 @@ int context_history_filter_set_int(context_history_filter_h filter, context_hist * @return @c 0 on success, otherwise a negative error value * @retval #CONTEXT_HISTORY_ERROR_NONE Successful * @retval #CONTEXT_HISTORY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONTEXT_HISTORY_ERROR_NOT_SUPPORTED Not supported * * @pre context_history_filter_create() * @see context_history_filter_set_int() @@ -329,6 +335,7 @@ int context_history_filter_set_string(context_history_filter_h filter, context_h * @return @c 0 on success, otherwise a negative error value * @retval #CONTEXT_TRIGGER_ERROR_NONE Successful * @retval #CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONTEXT_HISTORY_ERROR_NOT_SUPPORTED Not supported * @retval #CONTEXT_TRIGGER_ERROR_OPERATION_FAILED Operation failed */ int context_history_is_supported(context_history_data_e data_type, bool* supported); @@ -353,7 +360,7 @@ int context_history_is_supported(context_history_data_e data_type, bool* support * @retval #CONTEXT_HISTORY_ERROR_NONE Successful * @retval #CONTEXT_HISTORY_ERROR_INVALID_PARAMETER Invalid parameter * @retval #CONTEXT_HISTORY_ERROR_PERMISSION_DENIED Permission denied - * @retval #CONTEXT_HISTORY_ERROR_NOT_SUPPORTED Unsupported history data + * @retval #CONTEXT_HISTORY_ERROR_NOT_SUPPORTED Not supported * @retval #CONTEXT_HISTORY_ERROR_OPERATION_FAILED Operation failed * @retval #CONTEXT_HISTORY_ERROR_OUT_OF_MEMORY Out of memory * @retval #CONTEXT_HISTORY_ERROR_NO_DATA Requested data does not exist @@ -373,6 +380,7 @@ int context_history_get_list(context_history_h handle, context_history_data_e da * @return @c 0 on success, otherwise a negative error value * @retval #CONTEXT_HISTORY_ERROR_NONE Successful * @retval #CONTEXT_HISTORY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONTEXT_HISTORY_ERROR_NOT_SUPPORTED Not supported * @retval #CONTEXT_HISTORY_ERROR_OPERATION_FAILED Operation failed * * @pre context_history_get_list() @@ -393,6 +401,7 @@ int context_history_list_get_count(context_history_list_h list, int* count); * @return @c 0 on success, otherwise a negative error value * @retval #CONTEXT_HISTORY_ERROR_NONE Successful * @retval #CONTEXT_HISTORY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONTEXT_HISTORY_ERROR_NOT_SUPPORTED Not supported * @retval #CONTEXT_HISTORY_ERROR_OPERATION_FAILED Operation failed * @retval #CONTEXT_HISTORY_ERROR_OUT_OF_MEMORY Out of memory * @@ -410,6 +419,7 @@ int context_history_list_get_current(context_history_list_h list, context_histor * @return @c 0 on success, otherwise a negative error value * @retval #CONTEXT_HISTORY_ERROR_NONE Successful * @retval #CONTEXT_HISTORY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONTEXT_HISTORY_ERROR_NOT_SUPPORTED Not supported * * @pre context_history_get_list() * @see context_history_list_get_count() @@ -426,6 +436,7 @@ int context_history_list_move_first(context_history_list_h list); * @return @c 0 on success, otherwise a negative error value * @retval #CONTEXT_HISTORY_ERROR_NONE Successful * @retval #CONTEXT_HISTORY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONTEXT_HISTORY_ERROR_NOT_SUPPORTED Not supported * @retval #CONTEXT_HISTORY_ERROR_NO_DATA Requested data does not exist * * @pre context_history_get_list() @@ -443,6 +454,7 @@ int context_history_list_move_next(context_history_list_h list); * @return @c 0 on success, otherwise a negative error value * @retval #CONTEXT_HISTORY_ERROR_NONE Successful * @retval #CONTEXT_HISTORY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONTEXT_HISTORY_ERROR_NOT_SUPPORTED Not supported * * @pre context_history_get_list() */ @@ -461,6 +473,7 @@ int context_history_list_destroy(context_history_list_h list); * @return @c 0 on success, otherwise a negative error value * @retval #CONTEXT_HISTORY_ERROR_NONE Successful * @retval #CONTEXT_HISTORY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONTEXT_HISTORY_ERROR_NOT_SUPPORTED Not supported * * @pre context_history_list_get_current() * @see context_history_record_get_double() @@ -482,6 +495,7 @@ int context_history_record_get_int(context_history_record_h record, const char* * @return @c 0 on success, otherwise a negative error value * @retval #CONTEXT_HISTORY_ERROR_NONE Successful * @retval #CONTEXT_HISTORY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONTEXT_HISTORY_ERROR_NOT_SUPPORTED Not supported * * @pre context_history_list_get_current() * @see context_history_record_get_int() @@ -502,6 +516,7 @@ int context_history_record_get_string(context_history_record_h record, const cha * @return @c 0 on success, otherwise a negative error value * @retval #CONTEXT_HISTORY_ERROR_NONE Successful * @retval #CONTEXT_HISTORY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONTEXT_HISTORY_ERROR_NOT_SUPPORTED Not supported * * @pre context_history_list_get_current() * @see context_history_record_get_int() @@ -518,6 +533,7 @@ int context_history_record_get_double(context_history_record_h record, const cha * @return @c 0 on success, otherwise a negative error value * @retval #CONTEXT_HISTORY_ERROR_NONE Successful * @retval #CONTEXT_HISTORY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONTEXT_HISTORY_ERROR_NOT_SUPPORTED Not supported * * @pre context_history_list_get_current() */ diff --git a/packaging/capi-context.spec b/packaging/capi-context.spec index e4dba6c..df2a19e 100644 --- a/packaging/capi-context.spec +++ b/packaging/capi-context.spec @@ -17,6 +17,7 @@ BuildRequires: pkgconfig(capi-appfw-app-control) BuildRequires: pkgconfig(cynara-creds-self) BuildRequires: pkgconfig(cynara-session) BuildRequires: pkgconfig(cynara-client) +BuildRequires: pkgconfig(capi-system-info) BuildRequires: pkgconfig(context-app-history-client) BuildRequires: pkgconfig(context-job-scheduler-client) diff --git a/src/history/context_history.cpp b/src/history/context_history.cpp index 3770d2f..2208e23 100644 --- a/src/history/context_history.cpp +++ b/src/history/context_history.cpp @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -32,6 +33,18 @@ #define ASSERT_ALLOC(X) IF_FAIL_RETURN_TAG(X, E_NO_MEM, _E, "Memory allocation failed") #define ASSERT_NOT_NULL(X) IF_FAIL_RETURN_TAG(X, E_PARAM, _E, "Parameter null") +#define APP_HISTORY_FEATURE "http://tizen.org/feature/app_history" +#define CHECK_APP_HISTORY_SUPPORTED(feature_name) \ + do { \ + bool is_supported = false; \ + if (!system_info_get_platform_bool(feature_name, &is_supported)) { \ + if (!is_supported) { \ + _E("[%s] feature is disabled", feature_name); \ + return CONTEXT_HISTORY_ERROR_NOT_SUPPORTED; \ + } \ + } \ + } while (0) + // handles typedef struct _context_history_handle_s { /* At this point, this handle has no purpose. @@ -70,6 +83,7 @@ static bool history_filter_is_deprecated(context_history_filter_e filter_type); // life-cycle EXPORT_API int context_history_create(context_history_h* handle) { + CHECK_APP_HISTORY_SUPPORTED(APP_HISTORY_FEATURE); ASSERT_NOT_NULL(handle); *handle = new(std::nothrow) _cx_history_handle(); @@ -80,6 +94,7 @@ EXPORT_API int context_history_create(context_history_h* handle) EXPORT_API int context_history_destroy(context_history_h handle) { + CHECK_APP_HISTORY_SUPPORTED(APP_HISTORY_FEATURE); ASSERT_NOT_NULL(handle); delete handle; return CONTEXT_HISTORY_ERROR_NONE; @@ -88,6 +103,7 @@ EXPORT_API int context_history_destroy(context_history_h handle) // Read filter manipulation EXPORT_API int context_history_filter_create(context_history_filter_h* filter) { + CHECK_APP_HISTORY_SUPPORTED(APP_HISTORY_FEATURE); ASSERT_NOT_NULL(filter); *filter = new(std::nothrow) _cx_history_filter_handle(); @@ -98,6 +114,7 @@ EXPORT_API int context_history_filter_create(context_history_filter_h* filter) EXPORT_API int context_history_filter_destroy(context_history_filter_h filter) { + CHECK_APP_HISTORY_SUPPORTED(APP_HISTORY_FEATURE); ASSERT_NOT_NULL(filter); delete filter; @@ -106,6 +123,7 @@ EXPORT_API int context_history_filter_destroy(context_history_filter_h filter) EXPORT_API int context_history_filter_set_int(context_history_filter_h filter, context_history_filter_e filter_type, int val) { + CHECK_APP_HISTORY_SUPPORTED(APP_HISTORY_FEATURE); ASSERT_NOT_NULL(filter); if (history_filter_is_deprecated(filter_type)) { @@ -127,6 +145,7 @@ EXPORT_API int context_history_filter_set_int(context_history_filter_h filter, c EXPORT_API int context_history_filter_set_string(context_history_filter_h filter, context_history_filter_e filter_type, const char* val) { + CHECK_APP_HISTORY_SUPPORTED(APP_HISTORY_FEATURE); ASSERT_NOT_NULL(filter); ASSERT_NOT_NULL(val); @@ -150,6 +169,7 @@ EXPORT_API int context_history_filter_set_string(context_history_filter_h filter EXPORT_API int context_history_is_supported(context_history_data_e data_type, bool* supported) { + CHECK_APP_HISTORY_SUPPORTED(APP_HISTORY_FEATURE); ASSERT_NOT_NULL(supported); if (history_is_deprecated(data_type)) { @@ -166,6 +186,7 @@ EXPORT_API int context_history_is_supported(context_history_data_e data_type, bo EXPORT_API int context_history_get_list(context_history_h handle, context_history_data_e data_type, context_history_filter_h filter, context_history_list_h* list) { + CHECK_APP_HISTORY_SUPPORTED(APP_HISTORY_FEATURE); ASSERT_NOT_NULL(handle); ASSERT_NOT_NULL(list); *list = NULL; @@ -203,6 +224,7 @@ EXPORT_API int context_history_get_list(context_history_h handle, context_histor // Data object manipulation EXPORT_API int context_history_list_get_count(context_history_list_h list, int* count) { + CHECK_APP_HISTORY_SUPPORTED(APP_HISTORY_FEATURE); ASSERT_NOT_NULL(list && count); unsigned int value; @@ -216,6 +238,7 @@ EXPORT_API int context_history_list_get_count(context_history_list_h list, int* EXPORT_API int context_history_list_get_current(context_history_list_h list, context_history_record_h* record) { + CHECK_APP_HISTORY_SUPPORTED(APP_HISTORY_FEATURE); ASSERT_NOT_NULL(list); ASSERT_NOT_NULL(record); *record = NULL; @@ -235,18 +258,21 @@ EXPORT_API int context_history_list_get_current(context_history_list_h list, con EXPORT_API int context_history_list_move_first(context_history_list_h list) { + CHECK_APP_HISTORY_SUPPORTED(APP_HISTORY_FEATURE); ASSERT_NOT_NULL(list); return ctx_history_cursor_first(list->cursor); } EXPORT_API int context_history_list_move_next(context_history_list_h list) { + CHECK_APP_HISTORY_SUPPORTED(APP_HISTORY_FEATURE); ASSERT_NOT_NULL(list); return ctx_history_cursor_next(list->cursor); } EXPORT_API int context_history_list_destroy(context_history_list_h list) { + CHECK_APP_HISTORY_SUPPORTED(APP_HISTORY_FEATURE); ASSERT_NOT_NULL(list); ctx_history_cursor_destroy(list->cursor); delete list; @@ -256,6 +282,7 @@ EXPORT_API int context_history_list_destroy(context_history_list_h list) EXPORT_API int context_history_record_get_int(context_history_record_h record, const char* key, int* val) { + CHECK_APP_HISTORY_SUPPORTED(APP_HISTORY_FEATURE); ASSERT_NOT_NULL(record && val && key); // Check key and data type @@ -274,6 +301,7 @@ EXPORT_API int context_history_record_get_int(context_history_record_h record, c EXPORT_API int context_history_record_get_double(context_history_record_h record, const char* key, double* val) { + CHECK_APP_HISTORY_SUPPORTED(APP_HISTORY_FEATURE); ASSERT_NOT_NULL(record && val && key); // Check key and data type @@ -289,6 +317,7 @@ EXPORT_API int context_history_record_get_double(context_history_record_h record EXPORT_API int context_history_record_get_string(context_history_record_h record, const char* key, char** val) { + CHECK_APP_HISTORY_SUPPORTED(APP_HISTORY_FEATURE); ASSERT_NOT_NULL(record && val && key); // Check key and data type @@ -308,6 +337,7 @@ EXPORT_API int context_history_record_get_string(context_history_record_h record EXPORT_API int context_history_record_destroy(context_history_record_h record) { + CHECK_APP_HISTORY_SUPPORTED(APP_HISTORY_FEATURE); ASSERT_NOT_NULL(record); delete record; -- 2.7.4