Update version 0.9.67
[platform/core/pim/contacts-service.git] / client / ctsvc_client_setting.c
1 /*\r
2  * Contacts Service\r
3  *\r
4  * Copyright (c) 2010 - 2012 Samsung Electronics Co., Ltd. All rights reserved.\r
5  *\r
6  * Licensed under the Apache License, Version 2.0 (the "License");\r
7  * you may not use this file except in compliance with the License.\r
8  * You may obtain a copy of the License at\r
9  *\r
10  * http://www.apache.org/licenses/LICENSE-2.0\r
11  *\r
12  * Unless required by applicable law or agreed to in writing, software\r
13  * distributed under the License is distributed on an "AS IS" BASIS,\r
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
15  * See the License for the specific language governing permissions and\r
16  * limitations under the License.\r
17  *\r
18  */\r
19 \r
20 #include <glib.h>\r
21 #include <pims-ipc-data.h>\r
22 \r
23 #include "contacts.h"\r
24 #include "ctsvc_internal.h"\r
25 #include "ctsvc_ipc_define.h"\r
26 #include "ctsvc_ipc_marshal.h"\r
27 #include "ctsvc_client_ipc.h"\r
28 \r
29 API int contacts_setting_get_name_display_order(contacts_name_display_order_e *name_display_order)\r
30 {\r
31         int ret = CONTACTS_ERROR_NONE;\r
32         pims_ipc_data_h outdata = NULL;\r
33 \r
34         RETVM_IF(name_display_order == NULL, CONTACTS_ERROR_INVALID_PARAMETER,"The out param is NULL");\r
35         *name_display_order = 0;\r
36         RETVM_IF(ctsvc_get_ipc_handle() == NULL,CONTACTS_ERROR_IPC,"contacts not connected");\r
37 \r
38         if (ctsvc_ipc_call(CTSVC_IPC_SETTING_MODULE, CTSVC_IPC_SERVER_SETTING_GET_NAME_DISPLAY_ORDER, NULL, &outdata) != 0) {\r
39                 CTS_ERR("ctsvc_ipc_call failed");\r
40                 return CONTACTS_ERROR_IPC;\r
41         }\r
42 \r
43         if (outdata) {\r
44                 unsigned int size = 0;\r
45                 ret = *(int*) pims_ipc_data_get(outdata, &size);\r
46                 if (CONTACTS_ERROR_NONE == ret) {\r
47                         *name_display_order = *(int*) pims_ipc_data_get(outdata, &size);\r
48                 }\r
49                 pims_ipc_data_destroy(outdata);\r
50         }\r
51 \r
52         return ret;\r
53 }\r
54 \r
55 API int contacts_setting_get_name_sorting_order(contacts_name_sorting_order_e *name_sorting_order)\r
56 {\r
57         int ret = CONTACTS_ERROR_NONE;\r
58         pims_ipc_data_h outdata = NULL;\r
59 \r
60         RETVM_IF(name_sorting_order == NULL, CONTACTS_ERROR_INVALID_PARAMETER, "The out param is NULL");\r
61         *name_sorting_order = 0;\r
62         RETVM_IF(ctsvc_get_ipc_handle() == NULL,CONTACTS_ERROR_IPC,"contacts not connected");\r
63 \r
64         if (ctsvc_ipc_call(CTSVC_IPC_SETTING_MODULE, CTSVC_IPC_SERVER_SETTING_GET_NAME_SORTING_ORDER, NULL, &outdata) != 0) {\r
65                 CTS_ERR("ctsvc_ipc_call failed");\r
66                 return CONTACTS_ERROR_IPC;\r
67         }\r
68 \r
69         if (outdata) {\r
70                 unsigned int size = 0;\r
71                 ret = *(int*) pims_ipc_data_get(outdata, &size);\r
72                 if (CONTACTS_ERROR_NONE == ret) {\r
73                         *name_sorting_order = *(int*) pims_ipc_data_get(outdata, &size);\r
74                 }\r
75                 pims_ipc_data_destroy(outdata);\r
76         }\r
77 \r
78         return ret;\r
79 }\r
80 \r
81 API int contacts_setting_set_name_display_order(contacts_name_display_order_e name_display_order)\r
82 {\r
83         int ret = CONTACTS_ERROR_NONE;\r
84         pims_ipc_data_h indata = NULL;\r
85         pims_ipc_data_h outdata = NULL;\r
86 \r
87         RETVM_IF(name_display_order != CONTACTS_NAME_DISPLAY_ORDER_FIRSTLAST\r
88                         && name_display_order != CONTACTS_NAME_DISPLAY_ORDER_LASTFIRST,\r
89                         CONTACTS_ERROR_INVALID_PARAMETER, "name display order is invalid : %d", name_display_order);\r
90         RETVM_IF(ctsvc_get_ipc_handle() == NULL,CONTACTS_ERROR_IPC,"contacts not connected");\r
91 \r
92         indata = pims_ipc_data_create(0);\r
93         if (indata == NULL) {\r
94                 CTS_ERR("ipc data created fail!");\r
95                 ret = CONTACTS_ERROR_OUT_OF_MEMORY;\r
96                 return ret;\r
97         }\r
98 \r
99         ret = ctsvc_ipc_marshal_int(name_display_order, indata);\r
100         if (ret != CONTACTS_ERROR_NONE) {\r
101                 CTS_ERR("marshal fail");\r
102                 pims_ipc_data_destroy(indata);\r
103                 return ret;\r
104         }\r
105 \r
106         if (ctsvc_ipc_call(CTSVC_IPC_SETTING_MODULE, CTSVC_IPC_SERVER_SETTING_SET_NAME_DISPLAY_ORDER, indata, &outdata) != 0) {\r
107                 CTS_ERR("ctsvc_ipc_call failed");\r
108                 pims_ipc_data_destroy(indata);\r
109                 return CONTACTS_ERROR_IPC;\r
110         }\r
111         pims_ipc_data_destroy(indata);\r
112 \r
113         if (outdata) {\r
114                 unsigned int size = 0;\r
115                 ret = *(int*) pims_ipc_data_get(outdata, &size);\r
116                 pims_ipc_data_destroy(outdata);\r
117         }\r
118 \r
119         return ret;\r
120 }\r
121 \r
122 API int contacts_setting_set_name_sorting_order(contacts_name_sorting_order_e name_sorint_order)\r
123 {\r
124         int ret = CONTACTS_ERROR_NONE;\r
125         pims_ipc_data_h indata = NULL;\r
126         pims_ipc_data_h outdata = NULL;\r
127 \r
128         RETVM_IF(name_sorint_order != CONTACTS_NAME_SORTING_ORDER_FIRSTLAST\r
129                         && name_sorint_order != CONTACTS_NAME_SORTING_ORDER_LASTFIRST,\r
130                         CONTACTS_ERROR_INVALID_PARAMETER, "name sorting order is invalid : %d", name_sorint_order);\r
131         RETVM_IF(ctsvc_get_ipc_handle() == NULL,CONTACTS_ERROR_IPC,"contacts not connected");\r
132 \r
133         indata = pims_ipc_data_create(0);\r
134         if (indata == NULL) {\r
135                 CTS_ERR("ipc data created fail!");\r
136                 ret = CONTACTS_ERROR_OUT_OF_MEMORY;\r
137                 return ret;\r
138         }\r
139 \r
140         ret = ctsvc_ipc_marshal_int(name_sorint_order, indata);\r
141         if (ret != CONTACTS_ERROR_NONE) {\r
142                 CTS_ERR("marshal fail");\r
143                 pims_ipc_data_destroy(indata);\r
144                 return ret;\r
145         }\r
146 \r
147         if (ctsvc_ipc_call(CTSVC_IPC_SETTING_MODULE, CTSVC_IPC_SERVER_SETTING_SET_NAME_SORTING_ORDER, indata, &outdata) != 0) {\r
148                 CTS_ERR("ctsvc_ipc_call failed");\r
149                 pims_ipc_data_destroy(indata);\r
150                 return CONTACTS_ERROR_IPC;\r
151         }\r
152         pims_ipc_data_destroy(indata);\r
153 \r
154         if (outdata) {\r
155                 unsigned int size = 0;\r
156                 ret = *(int*) pims_ipc_data_get(outdata, &size);\r
157                 pims_ipc_data_destroy(outdata);\r
158         }\r
159 \r
160         return ret;\r
161 }\r
162 \r