From c918efbda9795100fd2328d263b26f5eee4a64e0 Mon Sep 17 00:00:00 2001 From: Jongkyu Koo Date: Thu, 1 Sep 2016 16:53:44 +0900 Subject: [PATCH] change attribute of favorite_priority from sort only to read only Change-Id: I0105d7dcd0bce53274a9744d249e599fa6b9f9db Signed-off-by: Jongkyu Koo --- common/ctsvc_record_person.c | 19 ++++++++++++++++++- common/ctsvc_struct.h | 1 + common/ctsvc_view.c | 2 +- common/ipc/ctsvc_ipc_marshal.c | 27 +++++++++++++++++++++++++++ common/ipc/ctsvc_ipc_marshal.h | 2 ++ common/ipc/ctsvc_ipc_person.c | 4 ++++ include/contacts_views.h | 4 ++-- server/db/ctsvc_db_plugin_person.c | 9 +++++++-- server/db/ctsvc_db_plugin_person_helper.c | 8 ++------ 9 files changed, 64 insertions(+), 12 deletions(-) diff --git a/common/ctsvc_record_person.c b/common/ctsvc_record_person.c index f98e404..e061d8c 100644 --- a/common/ctsvc_record_person.c +++ b/common/ctsvc_record_person.c @@ -29,6 +29,7 @@ static int __ctsvc_person_get_int(contacts_record_h record, unsigned int propert static int __ctsvc_person_get_str_p(contacts_record_h record, unsigned int property_id, char **out_str); static int __ctsvc_person_get_str(contacts_record_h record, unsigned int property_id, char **out_str); static int __ctsvc_person_get_bool(contacts_record_h record, unsigned int property_id, bool *value); +static int __ctsvc_person_get_double(contacts_record_h record, unsigned int property_id, double *out); static int __ctsvc_person_set_int(contacts_record_h record, unsigned int property_id, int value, bool *is_dirty); static int __ctsvc_person_set_str(contacts_record_h record, unsigned int property_id, const char *str, bool *is_dirty); static int __ctsvc_person_set_bool(contacts_record_h record, unsigned int property_id, bool value, bool *is_dirty); @@ -42,7 +43,7 @@ ctsvc_record_plugin_cb_s person_plugin_cbs = { .get_int = __ctsvc_person_get_int, .get_bool = __ctsvc_person_get_bool, .get_lli = NULL, - .get_double = NULL, + .get_double = __ctsvc_person_get_double, .set_str = __ctsvc_person_set_str, .set_int = __ctsvc_person_set_int, .set_bool = __ctsvc_person_set_bool, @@ -148,6 +149,22 @@ static int __ctsvc_person_get_int(contacts_record_h record, unsigned int propert return CONTACTS_ERROR_NONE; } +static int __ctsvc_person_get_double(contacts_record_h record, unsigned int property_id, + double *out) +{ + ctsvc_person_s *person = (ctsvc_person_s*)record; + switch (property_id) { + case CTSVC_PROPERTY_PERSON_FAVORITE_PRIORITY: + *out = person->favorite_prio; + break; + + default: + ERR("This field(%d) is not supported in value(person)", property_id); + return CONTACTS_ERROR_INVALID_PARAMETER; + } + return CONTACTS_ERROR_NONE; +} + static int __ctsvc_person_get_str_real(contacts_record_h record, unsigned int property_id, char **out_str, bool copy) { diff --git a/common/ctsvc_struct.h b/common/ctsvc_struct.h index 1e6ce38..4fd07ad 100644 --- a/common/ctsvc_struct.h +++ b/common/ctsvc_struct.h @@ -254,6 +254,7 @@ typedef struct { char *addressbook_ids; int snippet_type; char *snippet_string; + double favorite_prio; } ctsvc_person_s; typedef struct { diff --git a/common/ctsvc_view.c b/common/ctsvc_view.c index ec2549b..4d32e67 100644 --- a/common/ctsvc_view.c +++ b/common/ctsvc_view.c @@ -715,7 +715,7 @@ const property_info_s __property_person[] = { {CTSVC_PROPERTY_PERSON_MESSAGE_ALERT, CTSVC_SEARCH_PROPERTY_ALL, "message_alert"}, {CTSVC_PROPERTY_PERSON_STATUS, CTSVC_SEARCH_PROPERTY_ALL, "status"}, {CTSVC_PROPERTY_PERSON_IS_FAVORITE, CTSVC_SEARCH_PROPERTY_ALL, "is_favorite"}, - {CTSVC_PROPERTY_PERSON_FAVORITE_PRIORITY, CTSVC_SEARCH_PROPERTY_FILTER, "favorite_prio"}, + {CTSVC_PROPERTY_PERSON_FAVORITE_PRIORITY, CTSVC_SEARCH_PROPERTY_ALL, "favorite_prio"}, {CTSVC_PROPERTY_PERSON_LINK_COUNT, CTSVC_SEARCH_PROPERTY_ALL, "link_count"}, {CTSVC_PROPERTY_PERSON_ADDRESSBOOK_IDS, CTSVC_SEARCH_PROPERTY_PROJECTION, "addressbook_ids"}, {CTSVC_PROPERTY_PERSON_HAS_PHONENUMBER, CTSVC_SEARCH_PROPERTY_ALL, "has_phonenumber"}, diff --git a/common/ipc/ctsvc_ipc_marshal.c b/common/ipc/ctsvc_ipc_marshal.c index 945abfd..45c309a 100644 --- a/common/ipc/ctsvc_ipc_marshal.c +++ b/common/ipc/ctsvc_ipc_marshal.c @@ -562,6 +562,23 @@ int ctsvc_ipc_unmarshal_unsigned_int(const pims_ipc_data_h data, unsigned int *p return CONTACTS_ERROR_NONE; } +int ctsvc_ipc_unmarshal_double(const pims_ipc_data_h data, double *pout) +{ + unsigned int size = 0; + + RETV_IF(NULL == data, CONTACTS_ERROR_INVALID_PARAMETER); + RETV_IF(NULL == pout, CONTACTS_ERROR_INVALID_PARAMETER); + + void *tmp = pims_ipc_data_get(data, &size); + if (tmp == NULL) { + ERR("pims_ipc_data_get() Fail"); + return CONTACTS_ERROR_NO_DATA; + } else { + *pout = *(double*)tmp; + } + return CONTACTS_ERROR_NONE; +} + int ctsvc_ipc_unmarshal_bool(const pims_ipc_data_h data, bool *pout) { unsigned int size = 0; @@ -674,6 +691,16 @@ int ctsvc_ipc_marshal_unsigned_int(const unsigned int in, pims_ipc_data_h ipc_da return CONTACTS_ERROR_NONE; } +int ctsvc_ipc_marshal_double(const double in, pims_ipc_data_h ipc_data) +{ + RETV_IF(NULL == ipc_data, CONTACTS_ERROR_INVALID_PARAMETER); + + if (pims_ipc_data_put(ipc_data, (void*)&in, sizeof(double)) != 0) + return CONTACTS_ERROR_OUT_OF_MEMORY; + + return CONTACTS_ERROR_NONE; +} + int ctsvc_ipc_marshal_bool(const bool in, pims_ipc_data_h ipc_data) { RETV_IF(NULL == ipc_data, CONTACTS_ERROR_INVALID_PARAMETER); diff --git a/common/ipc/ctsvc_ipc_marshal.h b/common/ipc/ctsvc_ipc_marshal.h index 7814547..60aff22 100644 --- a/common/ipc/ctsvc_ipc_marshal.h +++ b/common/ipc/ctsvc_ipc_marshal.h @@ -54,6 +54,7 @@ int ctsvc_ipc_unmarshal_bool(const pims_ipc_data_h data, bool *pout); int ctsvc_ipc_unmarshal_int(const pims_ipc_data_h data, int *pout); int ctsvc_ipc_unmarshal_unsigned_int(const pims_ipc_data_h data, unsigned int *pout); int ctsvc_ipc_unmarshal_record_common(const pims_ipc_data_h ipc_data, ctsvc_record_s *common); +int ctsvc_ipc_unmarshal_double(const pims_ipc_data_h data, double *pout); /* * NULL 이슈로 ctsvc_ipc_unmarshal_string / ctsvc_ipc_marshal_string 는 pair 를 이루어야함. @@ -63,6 +64,7 @@ int ctsvc_ipc_marshal_bool(const bool in, pims_ipc_data_h ipc_data); int ctsvc_ipc_marshal_int(const int in, pims_ipc_data_h ipc_data); int ctsvc_ipc_marshal_unsigned_int(const unsigned int in, pims_ipc_data_h ipc_data); int ctsvc_ipc_marshal_record_common(const ctsvc_record_s *common, pims_ipc_data_h ipc_data); +int ctsvc_ipc_marshal_double(const double in, pims_ipc_data_h ipc_data); /* * filter, query diff --git a/common/ipc/ctsvc_ipc_person.c b/common/ipc/ctsvc_ipc_person.c index f73c07d..ee27770 100644 --- a/common/ipc/ctsvc_ipc_person.c +++ b/common/ipc/ctsvc_ipc_person.c @@ -63,6 +63,8 @@ static int __ctsvc_ipc_unmarshal_person(pims_ipc_data_h ipc_data, const char *vi break; if (ctsvc_ipc_unmarshal_string(ipc_data, &person_p->snippet_string) != CONTACTS_ERROR_NONE) break; + if (ctsvc_ipc_unmarshal_double(ipc_data, &person_p->favorite_prio) != CONTACTS_ERROR_NONE) + break; return CONTACTS_ERROR_NONE; } while (0); @@ -113,6 +115,8 @@ static int __ctsvc_ipc_marshal_person(const contacts_record_h record, break; if (ctsvc_ipc_marshal_string((person_p->snippet_string), ipc_data) != CONTACTS_ERROR_NONE) break; + if (ctsvc_ipc_marshal_double((person_p->favorite_prio), ipc_data) != CONTACTS_ERROR_NONE) + break; return CONTACTS_ERROR_NONE; } while (0); diff --git a/include/contacts_views.h b/include/contacts_views.h index 43fbf88..180adf1 100644 --- a/include/contacts_views.h +++ b/include/contacts_views.h @@ -181,7 +181,7 @@ _CONTACTS_END_VIEW(_contacts_group) * string message_alert read, write Message alert path of the person * string status read only Status of social account * boolean is_favorite read, write The person is favorite or not - * double favorite_priority sort only The priority of favorite contacts. You cannot get/set the value but you can use it as sorting key, see the @ref contacts_query_set_sort + * double favorite_priority read only The priority of favorite contacts. it can be used as sorting key, see the @ref contacts_query_set_sort * integer link_count read only Link count of contact records (projection) * string addressbook_ids read only Addressbook IDs that the person belongs to (projection) * boolean has_phonenumber read only The person has phone number or not @@ -200,7 +200,7 @@ _CONTACTS_BEGIN_VIEW() _CONTACTS_PROPERTY_STR(vibration) /* read, write */ _CONTACTS_PROPERTY_STR(status) /* read only */ _CONTACTS_PROPERTY_BOOL(is_favorite) /* read, write */ - _CONTACTS_PROPERTY_DOUBLE(favorite_priority) /* sort only */ + _CONTACTS_PROPERTY_DOUBLE(favorite_priority) /* read only */ _CONTACTS_PROPERTY_INT(link_count) /* read only */ _CONTACTS_PROPERTY_STR(addressbook_ids) /* read only */ _CONTACTS_PROPERTY_BOOL(has_phonenumber) /* read only */ diff --git a/server/db/ctsvc_db_plugin_person.c b/server/db/ctsvc_db_plugin_person.c index f2c24f0..755abd1 100644 --- a/server/db/ctsvc_db_plugin_person.c +++ b/server/db/ctsvc_db_plugin_person.c @@ -67,7 +67,8 @@ static int __ctsvc_db_person_get_record(int id, contacts_record_h *out_record) "addressbook_ids, " "persons.has_phonenumber, " "persons.has_email, " - "EXISTS(SELECT person_id FROM "CTS_TABLE_FAVORITES" WHERE person_id=persons.person_id) is_favorite " + "EXISTS(SELECT person_id FROM "CTS_TABLE_FAVORITES" WHERE person_id=persons.person_id) is_favorite, " + "(SELECT favorite_prio FROM "CTS_TABLE_FAVORITES" WHERE person_id=persons.person_id) favorite_prio " "FROM "CTS_TABLE_PERSONS" " "LEFT JOIN "CTS_TABLE_CONTACTS" " "ON (name_contact_id = contacts.contact_id AND contacts.deleted = 0) " @@ -487,7 +488,8 @@ static int __ctsvc_db_person_get_all_records(int offset, int limit, contacts_lis "addressbook_ids, " "has_phonenumber, " "has_email, " - "is_favorite " + "is_favorite, " + "favorite_prio " "FROM "CTSVC_DB_VIEW_PERSON, ctsvc_get_display_column(), ctsvc_get_sort_name_column()); @@ -644,6 +646,9 @@ static int __ctsvc_db_person_get_records_with_query(contacts_query_h query, int free(person->message_alert); person->message_alert = SAFE_STRDUP(temp); break; + case CTSVC_PROPERTY_PERSON_FAVORITE_PRIORITY: + person->favorite_prio = ctsvc_stmt_get_dbl(stmt, i); + break; default: break; } diff --git a/server/db/ctsvc_db_plugin_person_helper.c b/server/db/ctsvc_db_plugin_person_helper.c index 5bb0fb7..71bd658 100644 --- a/server/db/ctsvc_db_plugin_person_helper.c +++ b/server/db/ctsvc_db_plugin_person_helper.c @@ -122,11 +122,7 @@ int ctsvc_db_person_create_record_from_stmt_with_projection(cts_stmt stmt, person->addressbook_ids = SAFE_STRDUP(temp); break; case CTSVC_PROPERTY_PERSON_FAVORITE_PRIORITY: - { - /* TODO: Fixme (BS) */ - int value = ctsvc_stmt_get_int(stmt, i); - value++; /* fix warning */ - } + person->favorite_prio = ctsvc_stmt_get_dbl(stmt, i); break; case CTSVC_PROPERTY_PERSON_SNIPPET_TYPE: person->snippet_type = ctsvc_stmt_get_int(stmt, i); @@ -222,7 +218,7 @@ int ctsvc_db_person_create_record_from_stmt(cts_stmt stmt, contacts_record_h *re person->has_phonenumber = ctsvc_stmt_get_int(stmt, i++); person->has_email = ctsvc_stmt_get_int(stmt, i++); person->is_favorite = ctsvc_stmt_get_int(stmt, i++); - + person->favorite_prio = ctsvc_stmt_get_dbl(stmt, i++); return CONTACTS_ERROR_NONE; } -- 2.7.4