From: Mu-Woong Lee Date: Mon, 5 Sep 2016 02:03:02 +0000 (+0900) Subject: Add the double-precision attribute retrieving function context_history_record_get_dou... X-Git-Tag: submit/tizen/20160907.123648^2~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F88%2F86788%2F1;p=platform%2Fcore%2Fapi%2Fcontext.git Add the double-precision attribute retrieving function context_history_record_get_double() Change-Id: Ia3ce8a5b8fa649263b1c6515ac48590e2be39b18 Signed-off-by: Mu-Woong Lee --- diff --git a/include/context_history.h b/include/context_history.h index 3bc2b86..39e8327 100644 --- a/include/context_history.h +++ b/include/context_history.h @@ -407,6 +407,7 @@ int context_history_list_destroy(context_history_list_h list); * @retval #CONTEXT_HISTORY_ERROR_INVALID_PARAMETER Invalid parameter * * @pre context_history_list_get_current() + * @see context_history_record_get_double() * @see context_history_record_get_string() */ int context_history_record_get_int(context_history_record_h record, const char* key, int* value); @@ -426,9 +427,28 @@ int context_history_record_get_int(context_history_record_h record, const char* * * @pre context_history_list_get_current() * @see context_history_record_get_int() + * @see context_history_record_get_double() */ int context_history_record_get_string(context_history_record_h record, const char* key, char** value); +/** + * @brief Gets a double-precision value from a record. + * @since_tizen 3.0 + * + * @param[in] record The record handle + * @param[in] key The key of attribute to get + * @param[out] value The result value + * + * @return 0 on success, otherwise a negative error value + * @retval #CONTEXT_HISTORY_ERROR_NONE Successful + * @retval #CONTEXT_HISTORY_ERROR_INVALID_PARAMETER Invalid parameter + * + * @pre context_history_list_get_current() + * @see context_history_record_get_int() + * @see context_history_record_get_string() + */ +int context_history_record_get_double(context_history_record_h record, const char* key, double* value); + /** * @brief Destroys a record handle and releases all its resources. * @since_tizen 2.4 diff --git a/src/context_history.cpp b/src/context_history.cpp index ff04836..535c9ce 100644 --- a/src/context_history.cpp +++ b/src/context_history.cpp @@ -21,7 +21,7 @@ #include #include -#define TYPE_INT 0 +#define TYPE_NUMERIC 0 #define TYPE_STRING 1 #define FILTER_KEY_LIMIT 10 @@ -231,7 +231,24 @@ SO_EXPORT int context_history_record_get_int(context_history_record_h record, co ASSERT_NOT_NULL(record && val && key); // Check key and data type - IF_FAIL_RETURN_TAG(check_record_key_data_type(TYPE_INT, key), CONTEXT_HISTORY_ERROR_INVALID_PARAMETER, _E, "Data type mismatched"); + IF_FAIL_RETURN_TAG(check_record_key_data_type(TYPE_NUMERIC, key), CONTEXT_HISTORY_ERROR_INVALID_PARAMETER, _E, "Data type mismatched"); + + std::list key_list; + record->jrecord.getKeys(&key_list); + IF_FAIL_RETURN_TAG(key_list.size() > 0, CONTEXT_HISTORY_ERROR_NO_DATA, _E, "No data"); + + // Check invalid record key + IF_FAIL_RETURN_TAG(record->jrecord.get(NULL, key, val), CONTEXT_HISTORY_ERROR_INVALID_PARAMETER, _E, "Invalid record key"); + + return CONTEXT_HISTORY_ERROR_NONE; +} + +SO_EXPORT int context_history_record_get_double(context_history_record_h record, const char* key, double* val) +{ + ASSERT_NOT_NULL(record && val && key); + + // Check key and data type + IF_FAIL_RETURN_TAG(check_record_key_data_type(TYPE_NUMERIC, key), CONTEXT_HISTORY_ERROR_INVALID_PARAMETER, _E, "Data type mismatched"); std::list key_list; record->jrecord.getKeys(&key_list); @@ -363,7 +380,7 @@ bool check_record_key_data_type(int type, std::string key) key.compare(CONTEXT_HISTORY_AUDIO_JACK) == 0 || key.compare(CONTEXT_HISTORY_SYSTEM_VOLUME) == 0 || key.compare(CONTEXT_HISTORY_MEDIA_VOLUME) == 0) { - return (type == TYPE_INT); + return (type == TYPE_NUMERIC); } return false;