remove build warning
[platform/core/pim/contacts-service.git] / client / ctsvc_client_activity_helper.c
1 /*
2  * Contacts Service
3  *
4  * Copyright (c) 2010 - 2015 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 <pims-ipc-data.h>
21
22 #include "contacts.h"
23 #include "ctsvc_internal.h"
24 #include "ctsvc_ipc_define.h"
25 #include "ctsvc_ipc_marshal.h"
26 #include "ctsvc_client_ipc.h"
27
28
29 int ctsvc_client_activity_delete_by_contact_id(contacts_h contact, int contact_id)
30 {
31         int ret = CONTACTS_ERROR_NONE;
32         pims_ipc_data_h indata = NULL;
33         pims_ipc_data_h outdata = NULL;
34
35         RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
36         RETVM_IF(contact_id <= 0, CONTACTS_ERROR_INVALID_PARAMETER,
37                         "id should be greater than 0");
38
39         /* make indata */
40         indata = pims_ipc_data_create(0);
41         if (indata == NULL) {
42                 /* LCOV_EXCL_START */
43                 ERR("pims_ipc_data_create() Fail");
44                 return CONTACTS_ERROR_OUT_OF_MEMORY;
45                 /* LCOV_EXCL_STOP */
46         }
47
48         ret = ctsvc_ipc_marshal_handle(contact, indata);
49         if (CONTACTS_ERROR_NONE != ret) {
50                 /* LCOV_EXCL_START */
51                 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
52                 pims_ipc_data_destroy(indata);
53                 return ret;
54                 /* LCOV_EXCL_STOP */
55         }
56
57         ret = ctsvc_ipc_marshal_int(contact_id, indata);
58         if (ret != CONTACTS_ERROR_NONE) {
59                 /* LCOV_EXCL_START */
60                 ERR("ctsvc_ipc_marshal_int() Fail(%d)", ret);
61                 pims_ipc_data_destroy(indata);
62                 return ret;
63                 /* LCOV_EXCL_STOP */
64         }
65
66         /* ipc call */
67         ret = ctsvc_ipc_call(CTSVC_IPC_ACTIVITY_MODULE,
68                         CTSVC_IPC_SERVER_ACTIVITY_DELETE_BY_CONTACT_ID, indata, &outdata);
69         if (0 != ret) {
70                 /* LCOV_EXCL_START */
71                 ERR("ctsvc_ipc_call() Fail(%d)", ret);
72                 pims_ipc_data_destroy(indata);
73                 return CONTACTS_ERROR_IPC;
74                 /* LCOV_EXCL_STOP */
75         }
76
77         pims_ipc_data_destroy(indata);
78
79         if (outdata) {
80                 int transaction_ver = 0;
81
82                 /* check result */
83                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
84                         /* LCOV_EXCL_START */
85                         ERR("ctsvc_ipc_unmarshal_int() Fail");
86                         pims_ipc_data_destroy(outdata);
87                         return CONTACTS_ERROR_IPC;
88                         /* LCOV_EXCL_STOP */
89                 }
90                 if (CONTACTS_ERROR_NONE == ret) {
91                         if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
92                                 /* LCOV_EXCL_START */
93                                 ERR("ctsvc_ipc_unmarshal_int() Fail");
94                                 pims_ipc_data_destroy(outdata);
95                                 return CONTACTS_ERROR_IPC;
96                                 /* LCOV_EXCL_STOP */
97                         }
98                         ctsvc_client_ipc_set_change_version(contact, transaction_ver);
99                 }
100                 pims_ipc_data_destroy(outdata);
101         }
102
103         return ret;
104 }
105
106 int ctsvc_client_activity_delete_by_account_id(contacts_h contact, int account_id)
107 {
108         int ret = CONTACTS_ERROR_NONE;
109         pims_ipc_data_h indata = NULL;
110         pims_ipc_data_h outdata = NULL;
111
112         RETV_IF(NULL == contact, CONTACTS_ERROR_INVALID_PARAMETER);
113         RETVM_IF(account_id <= 0, CONTACTS_ERROR_INVALID_PARAMETER,
114                         "id should be greater than 0");
115
116         /* make indata */
117         indata = pims_ipc_data_create(0);
118         if (indata == NULL) {
119                 /* LCOV_EXCL_START */
120                 ERR("pims_ipc_data_create() Fail");
121                 return CONTACTS_ERROR_OUT_OF_MEMORY;
122                 /* LCOV_EXCL_STOP */
123         }
124
125         ret = ctsvc_ipc_marshal_handle(contact, indata);
126         if (CONTACTS_ERROR_NONE != ret) {
127                 /* LCOV_EXCL_START */
128                 ERR("ctsvc_ipc_marshal_handle() Fail(%d)", ret);
129                 pims_ipc_data_destroy(indata);
130                 return ret;
131                 /* LCOV_EXCL_STOP */
132         }
133
134         ret = ctsvc_ipc_marshal_int(account_id, indata);
135         if (ret != CONTACTS_ERROR_NONE) {
136                 /* LCOV_EXCL_START */
137                 ERR("ctsvc_ipc_marshal_int() Fail");
138                 pims_ipc_data_destroy(indata);
139                 return ret;
140                 /* LCOV_EXCL_STOP */
141         }
142
143         /* ipc call */
144         ret = ctsvc_ipc_call(CTSVC_IPC_ACTIVITY_MODULE,
145                         CTSVC_IPC_SERVER_ACTIVITY_DELETE_BY_ACCOUNT_ID, indata, &outdata);
146         if (0 != ret) {
147                 /* LCOV_EXCL_START */
148                 ERR("ctsvc_ipc_call() Fail(%d)", ret);
149                 pims_ipc_data_destroy(indata);
150                 return CONTACTS_ERROR_IPC;
151                 /* LCOV_EXCL_STOP */
152         }
153
154         pims_ipc_data_destroy(indata);
155
156         if (outdata) {
157                 int transaction_ver = 0;
158                 if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &ret)) {
159                         /* LCOV_EXCL_START */
160                         ERR("ctsvc_ipc_unmarshal_int() Fail");
161                         pims_ipc_data_destroy(outdata);
162                         return CONTACTS_ERROR_IPC;
163                         /* LCOV_EXCL_STOP */
164                 }
165
166                 if (CONTACTS_ERROR_NONE == ret) {
167                         if (CONTACTS_ERROR_NONE != ctsvc_ipc_unmarshal_int(outdata, &transaction_ver)) {
168                                 /* LCOV_EXCL_START */
169                                 ERR("ctsvc_ipc_unmarshal_int() Fail");
170                                 pims_ipc_data_destroy(outdata);
171                                 return CONTACTS_ERROR_IPC;
172                                 /* LCOV_EXCL_STOP */
173                         }
174                         ctsvc_client_ipc_set_change_version(contact, transaction_ver);
175                 }
176                 pims_ipc_data_destroy(outdata);
177         }
178
179         return ret;
180 }
181