*/
#include <map>
-#include <Types.h>
+#include <ContextTypes.h>
#include <Json.h>
-#include <DBusClient.h>
-#include <ProviderTypes.h>
+#include <Tuple.h>
+#include <app_history_internal.h>
+#include <app_history_types_internal.h>
+#include <AppHistoryTypes.h>
#include <context_history.h>
#define TYPE_NUMERIC 0
#define TYPE_STRING 1
#define FILTER_KEY_LIMIT 10
+#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")
+
// handles
typedef struct _context_history_handle_s {
/* At this point, this handle has no purpose.
} _cx_history_filter_handle;
typedef struct _context_history_list_handle_s {
- ctx::Json jlist;
- int current;
+ ctx_history_cursor_h cursor;
+
_context_history_list_handle_s() {
- current = 0;
+ cursor = NULL;
}
} _cx_history_list_handle;
typedef struct _context_history_record_handle_s {
- ctx::Json jrecord;
+ std::vector<std::string> keys;
+ std::shared_ptr<ctx::Tuple> tuple;
} _cx_history_record_handle;
static std::string convert_filter_to_string(context_history_filter_e filter_type);
static bool check_filter_data_int(context_history_filter_e filter_type, int val);
static bool check_filter_data_string(context_history_filter_e filter_type, const char* val);
static bool check_invalid_filter(context_history_data_e data_type, context_history_filter_h filter);
+static int __getIndexOf(context_history_record_h record, const std::string& key);
// life-cycle
-SO_EXPORT int context_history_create(context_history_h* handle)
+EXPORT_API int context_history_create(context_history_h* handle)
{
ASSERT_NOT_NULL(handle);
return CONTEXT_HISTORY_ERROR_NONE;
}
-SO_EXPORT int context_history_destroy(context_history_h handle)
+EXPORT_API int context_history_destroy(context_history_h handle)
{
ASSERT_NOT_NULL(handle);
delete handle;
}
// Read filter manipulation
-SO_EXPORT int context_history_filter_create(context_history_filter_h* filter)
+EXPORT_API int context_history_filter_create(context_history_filter_h* filter)
{
ASSERT_NOT_NULL(filter);
return CONTEXT_HISTORY_ERROR_NONE;
}
-SO_EXPORT int context_history_filter_destroy(context_history_filter_h filter)
+EXPORT_API int context_history_filter_destroy(context_history_filter_h filter)
{
ASSERT_NOT_NULL(filter);
delete filter;
return CONTEXT_HISTORY_ERROR_NONE;
}
-SO_EXPORT int context_history_filter_set_int(context_history_filter_h filter, context_history_filter_e filter_type, int val)
+EXPORT_API int context_history_filter_set_int(context_history_filter_h filter, context_history_filter_e filter_type, int val)
{
ASSERT_NOT_NULL(filter);
return CONTEXT_HISTORY_ERROR_NONE;
}
-SO_EXPORT int context_history_filter_set_string(context_history_filter_h filter, context_history_filter_e filter_type, const char* val)
+EXPORT_API int context_history_filter_set_string(context_history_filter_h filter, context_history_filter_e filter_type, const char* val)
{
ASSERT_NOT_NULL(filter);
ASSERT_NOT_NULL(val);
return CONTEXT_HISTORY_ERROR_NONE;
}
-SO_EXPORT 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)
+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)
{
ASSERT_NOT_NULL(handle);
ASSERT_NOT_NULL(list);
if (filter)
IF_FAIL_RETURN_TAG(check_invalid_filter(data_type, filter), CONTEXT_HISTORY_ERROR_INVALID_PARAMETER, _E, "Invalid filter key");
- int req_id;
- ctx::Json tmp_list;
- ctx::DBusClient dbusClient;
+ *list = new(std::nothrow) _cx_history_list_handle();
+ ASSERT_ALLOC(*list);
- int err = dbusClient.readSync(data_type_str, filter ? filter->jfilter : NULL, &req_id, &tmp_list);
+ int err = _ctx_history_query(data_type_str.c_str(), filter ? filter->jfilter.str().c_str() : "", &((*list)->cursor));
if (err == TIZEN_ERROR_NOT_SUPPORTED)
err = CONTEXT_HISTORY_ERROR_NO_DATA;
- IF_FAIL_RETURN_TAG(err == ERR_NONE, err, _E, "Getting list failed");
-
- _J("Read response", tmp_list);
-
- IF_FAIL_RETURN_TAG(tmp_list.getSize(NULL, KEY_QUERY_RESULT) > 0, CONTEXT_HISTORY_ERROR_NO_DATA, _D, "No data");
-
- *list = new(std::nothrow) _cx_history_list_handle();
- ASSERT_ALLOC(*list);
- (*list)->jlist = tmp_list;
- (*list)->current = 0;
+ IF_FAIL_RETURN_TAG(err == E_NONE, err, _E, "Query failed");
return CONTEXT_HISTORY_ERROR_NONE;
}
// Data object manipulation
-SO_EXPORT int context_history_list_get_count(context_history_list_h list, int* count)
+EXPORT_API int context_history_list_get_count(context_history_list_h list, int* count)
{
- ASSERT_NOT_NULL(list);
- ASSERT_NOT_NULL(count);
- *count = 0;
+ ASSERT_NOT_NULL(list && count);
- int result = list->jlist.getSize(NULL, KEY_QUERY_RESULT);
- IF_FAIL_RETURN(result > 0, CONTEXT_HISTORY_ERROR_OPERATION_FAILED);
+ unsigned int value;
- *count = result;
+ int err = ctx_history_cursor_get_count(list->cursor, &value);
+ IF_FAIL_RETURN_TAG(err == E_NONE, err, _E, "Get count failed");
- return CONTEXT_HISTORY_ERROR_NONE;
+ *count = value;
+ return E_NONE;
}
-SO_EXPORT int context_history_list_get_current(context_history_list_h list, context_history_record_h* record)
+EXPORT_API int context_history_list_get_current(context_history_list_h list, context_history_record_h* record)
{
ASSERT_NOT_NULL(list);
ASSERT_NOT_NULL(record);
*record = NULL;
- ctx::Json tmp_record;
- int error = list->jlist.getAt(NULL, KEY_QUERY_RESULT, list->current, &tmp_record);
- IF_FAIL_RETURN_TAG(error, CONTEXT_HISTORY_ERROR_OPERATION_FAILED, _E, "Record load failed");
+ unsigned int position = 0;
+ int err = ctx_history_cursor_get_position(list->cursor, &position);
+ IF_FAIL_RETURN_TAG(err == E_NONE, err, _E, "Get position failed");
*record = new(std::nothrow) _cx_history_record_handle();
ASSERT_ALLOC(*record);
- (*record)->jrecord = tmp_record;
+
+ (*record)->keys = list->cursor->keys;
+ (*record)->tuple = ctx::Tuple::duplicate(list->cursor->tuples[position]);
return CONTEXT_HISTORY_ERROR_NONE;
}
-
-SO_EXPORT int context_history_list_move_first(context_history_list_h list)
+EXPORT_API int context_history_list_move_first(context_history_list_h list)
{
ASSERT_NOT_NULL(list);
-
- list->current = 0;
-
- return CONTEXT_HISTORY_ERROR_NONE;
+ return ctx_history_cursor_first(list->cursor);
}
-SO_EXPORT int context_history_list_move_next(context_history_list_h list)
+EXPORT_API int context_history_list_move_next(context_history_list_h list)
{
ASSERT_NOT_NULL(list);
-
- IF_FAIL_RETURN_TAG(list->current+1 < list->jlist.getSize(NULL, KEY_QUERY_RESULT), CONTEXT_HISTORY_ERROR_NO_DATA, _D, "End of list");
-
- list->current++;
-
- return CONTEXT_HISTORY_ERROR_NONE;
+ return ctx_history_cursor_next(list->cursor);
}
-SO_EXPORT int context_history_list_destroy(context_history_list_h list)
+EXPORT_API int context_history_list_destroy(context_history_list_h list)
{
ASSERT_NOT_NULL(list);
-
+ ctx_history_cursor_destroy(list->cursor);
delete list;
return CONTEXT_HISTORY_ERROR_NONE;
}
-SO_EXPORT int context_history_record_get_int(context_history_record_h record, const char* key, int* val)
+EXPORT_API int context_history_record_get_int(context_history_record_h record, const char* key, int* 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<std::string> key_list;
- record->jrecord.getKeys(&key_list);
- IF_FAIL_RETURN_TAG(key_list.size() > 0, CONTEXT_HISTORY_ERROR_NO_DATA, _E, "No data");
+ int index = __getIndexOf(record, key);
+ IF_FAIL_RETURN_TAG(index >= 0, CONTEXT_HISTORY_ERROR_INVALID_PARAMETER, _E, "Invalid record key");
- // Check invalid record key
- IF_FAIL_RETURN_TAG(record->jrecord.get(NULL, key, val), CONTEXT_HISTORY_ERROR_INVALID_PARAMETER, _E, "Invalid record key");
+ int64_t value;
+ IF_FAIL_RETURN_TAG(record->tuple->getAt(index, &value), CONTEXT_HISTORY_ERROR_INVALID_PARAMETER, _E, "Invalid data");
+
+ *val = value;
return CONTEXT_HISTORY_ERROR_NONE;
}
-SO_EXPORT int context_history_record_get_double(context_history_record_h record, const char* key, double* val)
+EXPORT_API 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<std::string> key_list;
- record->jrecord.getKeys(&key_list);
- IF_FAIL_RETURN_TAG(key_list.size() > 0, CONTEXT_HISTORY_ERROR_NO_DATA, _E, "No data");
+ int index = __getIndexOf(record, key);
+ IF_FAIL_RETURN_TAG(index >= 0, CONTEXT_HISTORY_ERROR_INVALID_PARAMETER, _E, "Invalid record key");
- // Check invalid record key
- IF_FAIL_RETURN_TAG(record->jrecord.get(NULL, key, val), CONTEXT_HISTORY_ERROR_INVALID_PARAMETER, _E, "Invalid record key");
+ IF_FAIL_RETURN_TAG(record->tuple->getAt(index, val), CONTEXT_HISTORY_ERROR_INVALID_PARAMETER, _E, "Invalid data");
return CONTEXT_HISTORY_ERROR_NONE;
}
-SO_EXPORT int context_history_record_get_string(context_history_record_h record, const char* key, char** val)
+EXPORT_API int context_history_record_get_string(context_history_record_h record, const char* key, char** val)
{
ASSERT_NOT_NULL(record && val && key);
// Check key and data type
IF_FAIL_RETURN_TAG(check_record_key_data_type(TYPE_STRING, key), CONTEXT_HISTORY_ERROR_INVALID_PARAMETER, _E, "Data type mismatched");
- std::list<std::string> key_list;
- record->jrecord.getKeys(&key_list);
- IF_FAIL_RETURN_TAG(key_list.size() > 0, CONTEXT_HISTORY_ERROR_NO_DATA, _E, "No data");
+ int index = __getIndexOf(record, key);
+ IF_FAIL_RETURN_TAG(index >= 0, CONTEXT_HISTORY_ERROR_INVALID_PARAMETER, _E, "Invalid record key");
- // Check Invalid record key
std::string str;
- IF_FAIL_RETURN_TAG(record->jrecord.get(NULL, key, &str), CONTEXT_HISTORY_ERROR_INVALID_PARAMETER, _E, "Value load failed");
+ IF_FAIL_RETURN_TAG(record->tuple->getAt(index, &str), CONTEXT_HISTORY_ERROR_INVALID_PARAMETER, _E, "Invalid data");
*val = g_strdup(str.c_str());
ASSERT_ALLOC(*val);
return CONTEXT_HISTORY_ERROR_NONE;
}
-SO_EXPORT int context_history_record_destroy(context_history_record_h record)
+EXPORT_API int context_history_record_destroy(context_history_record_h record)
{
ASSERT_NOT_NULL(record);
delete record;
case CONTEXT_HISTORY_FILTER_RESULT_SIZE:
case CONTEXT_HISTORY_FILTER_START_TIME:
case CONTEXT_HISTORY_FILTER_END_TIME:
- if (val > 0 )
+ if (val > 0)
return true;
break;
case CONTEXT_HISTORY_FILTER_DAY_OF_WEEK:
return true;
}
+
+int __getIndexOf(context_history_record_h record, const std::string& key)
+{
+ unsigned int i = 0;
+
+ for (i = 0; i < record->keys.size(); ++i) {
+ if (record->keys[i] == key) {
+ return i;
+ }
+ }
+ return -1;
+}