Add 3.0 APIs and sync APIs same as 2.4
[platform/core/convergence/service-adaptor.git] / common / sal_ipc.c
1 /*
2  * Service Adaptor IPC
3  *
4  * Copyright (c) 2014 - 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 <glib.h>
21 #include <gio/gio.h>
22
23 #include "service_adaptor_errors.h"
24 #include "service_adaptor_internal.h"
25 #include "sal_ipc.h"
26
27 //******************************************************************************
28 //* Global variables and defines
29 //******************************************************************************
30
31 //******************************************************************************
32 //* Private interface
33 //******************************************************************************
34
35 //******************************************************************************
36 //* Private interface definition
37 //******************************************************************************
38
39 //******************************************************************************
40 //* Public interface definition
41 //******************************************************************************
42
43 API char *ipc_insure_g_variant_dup_string(GVariant *string)
44 {
45         char *ret = g_variant_dup_string(string, NULL);
46
47         if (0 == strcmp(ret, ""))
48         {
49                 SAL_FREE(ret);
50         }
51
52         return ret;
53 }
54
55 API void ipc_insure_g_variant_builder_add_array_string(GVariantBuilder *builder, const char *str)
56 {
57         if (NULL == str)
58         {
59                 g_variant_builder_add(builder, "(s)", "");
60         }
61         else
62         {
63                 g_variant_builder_add(builder, "(s)", str);
64         }
65 }
66
67 API char *ipc_make_return_type(const char *type)
68 {
69         return g_strdup_printf("(%sis)", SAL_IPC_STR(type));
70 }
71
72 API void ipc_create_error_msg(int code, char **ipc_msg)
73 {
74         switch (code)
75         {
76                 case SERVICE_ADAPTOR_ERROR_NONE:
77                 {
78                         *ipc_msg = NULL;
79                         break;
80                 }
81                 case SERVICE_ADAPTOR_ERROR_INTERNAL:
82                 {
83                         *ipc_msg = strdup("SERVICE_ADAPTOR_ERROR_INTERNAL");
84                         break;
85                 }
86                 default:
87                 {
88                         *ipc_msg = strdup("SERVICE_ADAPTOR_ERROR_UNKNOWN");
89                         break;
90                 }
91         }
92 }
93
94 API void ipc_create_variant_info(GVariant *parameters, int size, GVariant ***var_info)
95 {
96         for (size_t i = 0; i < size; i++)
97         {
98                 *(var_info +i) = (GVariant **) g_variant_get_child_value(parameters, i);
99         }
100 }
101
102 API void ipc_destroy_variant_info(GVariant **var_info, int size)
103 {
104         for (size_t i = 0; i < size; i++)
105         {
106                 g_variant_unref(var_info[i]);
107         }
108 }
109
110 API void ipc_free_reply_data(ipc_reply_data_h reply)
111 {
112         SAL_FN_CALL;
113
114         RET_IF(NULL == reply);
115
116         SAL_FREE(reply->type);
117         SAL_FREE(reply);
118
119         SAL_FN_END;
120 }