From: Mu-Woong Lee Date: Mon, 3 Jul 2017 03:06:06 +0000 (+0900) Subject: Replace the glib-json wrapper CtxJson with jsoncpp X-Git-Tag: submit/tizen/20170705.022841^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e9dc8cbe0b10cded2af1c5edc87f9f97ac8e6723;p=platform%2Fcore%2Fapi%2Fcontext.git Replace the glib-json wrapper CtxJson with jsoncpp Change-Id: I9f77aa8aadaa01c3fd703b861b52092b17eb8b53 Signed-off-by: Mu-Woong Lee (cherry picked from commit 955735862175b3b18c9e74c3d15f9c6412537525) --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 49d5907..430be88 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ FILE(GLOB_RECURSE SRCS src/*.cpp) MESSAGE("Sources: ${SRCS}") # Dependencies -SET(DEPS "gio-2.0 context-common-legacy aul bundle capi-appfw-app-control pkgmgr-info context-app-history-client") +SET(DEPS "gio-2.0 jsoncpp context-common-legacy aul bundle capi-appfw-app-control pkgmgr-info context-app-history-client") # Common Options INCLUDE(FindPkgConfig) diff --git a/packaging/capi-context.spec b/packaging/capi-context.spec index b792a50..6eecaf9 100644 --- a/packaging/capi-context.spec +++ b/packaging/capi-context.spec @@ -8,6 +8,7 @@ Source0: %{name}-%{version}.tar.gz BuildRequires: cmake BuildRequires: pkgconfig(gio-2.0) +BuildRequires: pkgconfig(jsoncpp) BuildRequires: pkgconfig(aul) BuildRequires: pkgconfig(bundle) BuildRequires: pkgconfig(capi-appfw-app-control) diff --git a/src/context_history.cpp b/src/context_history.cpp index 8895ad4..3770d2f 100644 --- a/src/context_history.cpp +++ b/src/context_history.cpp @@ -15,8 +15,8 @@ */ #include +#include #include -#include #include #include #include @@ -41,7 +41,7 @@ typedef struct _context_history_handle_s { } _cx_history_handle; typedef struct _context_history_filter_handle_s { - ctx::CtxJson jfilter; + Json::Value jfilter; } _cx_history_filter_handle; typedef struct _context_history_list_handle_s { @@ -120,7 +120,7 @@ EXPORT_API int context_history_filter_set_int(context_history_filter_h filter, c // Check filter and its data type IF_FAIL_RETURN_TAG(check_filter_data_int(filter_type, val), CONTEXT_HISTORY_ERROR_INVALID_PARAMETER, _E, "Filter type mismatched"); - filter->jfilter.set(NULL, filter_str.c_str(), val); + filter->jfilter[filter_str] = val; return CONTEXT_HISTORY_ERROR_NONE; } @@ -143,7 +143,7 @@ EXPORT_API int context_history_filter_set_string(context_history_filter_h filter // Check filter and its data type IF_FAIL_RETURN_TAG(check_filter_data_string(filter_type, val), CONTEXT_HISTORY_ERROR_INVALID_PARAMETER, _E, "Filter type mismatched"); - filter->jfilter.set(NULL, filter_str.c_str(), val); + filter->jfilter[filter_str] = val; return CONTEXT_HISTORY_ERROR_NONE; } @@ -187,7 +187,14 @@ EXPORT_API int context_history_get_list(context_history_h handle, context_histor *list = new(std::nothrow) _cx_history_list_handle(); ASSERT_ALLOC(*list); - int err = _ctx_history_query(data_type_str.c_str(), filter ? filter->jfilter.str().c_str() : "", &((*list)->cursor)); + std::string filterStr; + if (filter) { + Json::FastWriter fw; + fw.omitEndingLineFeed(); + filterStr = fw.write(filter->jfilter); + } + + int err = _ctx_history_query(data_type_str.c_str(), filterStr.c_str(), &((*list)->cursor)); IF_FAIL_RETURN_TAG(err == E_NONE, err, _E, "Query failed"); return CONTEXT_HISTORY_ERROR_NONE; @@ -530,11 +537,9 @@ bool check_invalid_filter(context_history_data_e data_type, context_history_filt } bool found = true; - std::list keys; - filter->jfilter.getKeys(&keys); + std::vector keys = filter->jfilter.getMemberNames(); - for (std::list::iterator it = keys.begin(); it != keys.end(); ++it) { - std::string key = (*it); + for (auto& key : keys) { found = false; for (int i = 1; i < FILTER_KEY_LIMIT; ++i) { if (allowed[i] && key == filter_key[i]) {