Remove async APIs same as 2.4
[platform/core/pim/contacts-service.git] / client / ctsvc_client_phonelog.c
1 /*
2  * Contacts Service
3  *
4  * Copyright (c) 2010 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #include <glib.h>
21 #include <pims-ipc-data.h>
22
23 #include "contacts.h"
24 #include "contacts_phone_log_internal.h"
25 #include "ctsvc_internal.h"
26 #include "ctsvc_ipc_define.h"
27 #include "ctsvc_client_ipc.h"
28 #include "ctsvc_ipc_marshal.h"
29
30 API int contacts_phone_log_reset_statistics(void)
31 {
32 #ifndef ENABLE_LOG_FEATURE
33         return CONTACTS_ERROR_NOT_SUPPORTED;
34 #endif // ENABLE_LOG_FEATURE
35
36         int ret = CONTACTS_ERROR_NONE;
37
38         pims_ipc_data_h indata = NULL;
39         pims_ipc_data_h outdata = NULL;
40
41         // make indata
42         indata = pims_ipc_data_create(0);
43         if (indata == NULL)
44         {
45                 CTS_ERR("ipc data created fail!");
46                 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
47                 return ret;
48         }
49
50         // ipc call
51         if (ctsvc_ipc_call(CTSVC_IPC_PHONELOG_MODULE, CTSVC_IPC_SERVER_PHONELOG_RESET_STATISTICS, indata, &outdata) != 0)
52         {
53                 CTS_ERR("ctsvc_ipc_call failed");
54                 pims_ipc_data_destroy(indata);
55                 return CONTACTS_ERROR_IPC;
56         }
57
58         pims_ipc_data_destroy(indata);
59
60         if (outdata)
61         {
62                 // check result
63                 unsigned int size = 0;
64                 ret = *(int*) pims_ipc_data_get(outdata, &size);
65
66                 if (CONTACTS_ERROR_NONE == ret) {
67                         int transaction_ver = 0;
68                         transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
69                         ctsvc_client_ipc_set_change_version(transaction_ver);
70                 }
71
72                 pims_ipc_data_destroy(outdata);
73         }
74
75         return ret;
76
77 }
78
79 API int contacts_phone_log_delete(contacts_phone_log_delete_e op, ...)
80 {
81 #ifndef ENABLE_LOG_FEATURE
82         return CONTACTS_ERROR_NOT_SUPPORTED;
83 #endif // ENABLE_LOG_FEATURE
84
85         int ret = CONTACTS_ERROR_NONE;
86
87         pims_ipc_data_h indata = NULL;
88         pims_ipc_data_h outdata = NULL;
89         char *number = NULL;
90         int extra_data1;
91
92         va_list args;
93
94         indata = pims_ipc_data_create(0);
95         if (indata == NULL) {
96                 CTS_ERR("ipc data created fail!");
97                 ret = CONTACTS_ERROR_OUT_OF_MEMORY;
98                 pims_ipc_data_destroy(indata);
99                 return ret;
100         }
101
102         ret = ctsvc_ipc_marshal_int( op, indata);
103         if (ret != CONTACTS_ERROR_NONE) {
104                 CTS_ERR("ctsvc_ipc_marshal_int fail");
105                 pims_ipc_data_destroy(indata);
106                 return ret;
107         }
108
109         switch(op) {
110         case CONTACTS_PHONE_LOG_DELETE_BY_ADDRESS:
111                 va_start(args, op);
112                 number = va_arg(args, char *);
113                 va_end(args);
114                 if (NULL == number) {
115                         pims_ipc_data_destroy(indata);
116                         return CONTACTS_ERROR_INVALID_PARAMETER;
117                 }
118                 ret = ctsvc_ipc_marshal_string(number, indata);
119                 if (ret != CONTACTS_ERROR_NONE) {
120                         CTS_ERR("ctsvc_ipc_marshal_string fail");
121                         pims_ipc_data_destroy(indata);
122                         return ret;
123                 }
124                 break;
125         case CONTACTS_PHONE_LOG_DELETE_BY_MESSAGE_EXTRA_DATA1:
126         case CONTACTS_PHONE_LOG_DELETE_BY_EMAIL_EXTRA_DATA1:
127                 va_start(args, op);
128                 extra_data1 = va_arg(args, int);
129                 va_end(args);
130                 ret = ctsvc_ipc_marshal_int(extra_data1, indata);
131                 if (ret != CONTACTS_ERROR_NONE) {
132                         CTS_ERR("ctsvc_ipc_marshal_int fail");
133                         pims_ipc_data_destroy(indata);
134                         return ret;
135                 }
136                 break;
137         default:
138                 CTS_ERR("Invalid parameter : operation is not proper (%d)", ret);
139                 pims_ipc_data_destroy(indata);
140                 return CONTACTS_ERROR_INVALID_PARAMETER;
141         }
142
143         if (ctsvc_ipc_call(CTSVC_IPC_PHONELOG_MODULE,
144                         CTSVC_IPC_SERVER_PHONELOG_DELETE, indata, &outdata) != 0) {
145                 CTS_ERR("ctsvc_ipc_call failed");
146                 pims_ipc_data_destroy(indata);
147                 return CONTACTS_ERROR_IPC;
148         }
149
150         pims_ipc_data_destroy(indata);
151
152         if (outdata) {
153                 unsigned int size = 0;
154                 ret = *(int*) pims_ipc_data_get(outdata, &size);
155
156                 if (CONTACTS_ERROR_NONE == ret) {
157                         int transaction_ver = 0;
158                         transaction_ver = *(int*)pims_ipc_data_get(outdata,&size);
159                         ctsvc_client_ipc_set_change_version(transaction_ver);
160                 }
161
162                 pims_ipc_data_destroy(outdata);
163         }
164
165         return ret;
166 }
167