2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include "iotcon-constant.h"
22 #include "ic-common.h"
26 char* ic_utils_strdup(const char *src)
30 RETV_IF(NULL == src, NULL);
35 ERR("strdup() Fail(%d)", errno);
43 const char* ic_utils_dbus_encode_str(const char *src)
45 return (src) ? src : IC_STR_NULL;
49 char* ic_utils_dbus_decode_str(char *src)
51 RETV_IF(NULL == src, NULL);
53 if (IC_STR_EQUAL == strcmp(IC_STR_NULL, src))
60 int ic_utils_convert_interface_flag(iotcon_interface_e src, char **dest)
63 case IOTCON_INTERFACE_DEFAULT:
64 *dest = IC_INTERFACE_DEFAULT;
66 case IOTCON_INTERFACE_LINK:
67 *dest = IC_INTERFACE_LINK;
69 case IOTCON_INTERFACE_BATCH:
70 *dest = IC_INTERFACE_BATCH;
72 case IOTCON_INTERFACE_GROUP:
73 *dest = IC_INTERFACE_GROUP;
75 case IOTCON_INTERFACE_NONE:
77 ERR("Invalid interface(%d)", src);
78 return IOTCON_ERROR_INVALID_PARAMETER;
80 return IOTCON_ERROR_NONE;
84 int ic_utils_convert_interface_string(const char *src, iotcon_interface_e *dest)
86 RETV_IF(NULL == src, IOTCON_ERROR_INVALID_PARAMETER);
87 RETV_IF(NULL == dest, IOTCON_ERROR_INVALID_PARAMETER);
89 if (IC_STR_EQUAL == strcmp(IC_INTERFACE_DEFAULT, src)) {
90 *dest = IOTCON_INTERFACE_DEFAULT;
91 } else if (IC_STR_EQUAL == strcmp(IC_INTERFACE_LINK, src)) {
92 *dest = IOTCON_INTERFACE_LINK;
93 } else if (IC_STR_EQUAL == strcmp(IC_INTERFACE_BATCH, src)) {
94 *dest = IOTCON_INTERFACE_BATCH;
95 } else if (IC_STR_EQUAL == strcmp(IC_INTERFACE_GROUP, src)) {
96 *dest = IOTCON_INTERFACE_GROUP;
98 ERR("Invalid Interface");
99 return IOTCON_ERROR_INVALID_PARAMETER;
102 return IOTCON_ERROR_NONE;
106 void ic_utils_gvariant_array_free(GVariant **value)
110 for (i = 0; value[i]; i++)
111 g_variant_unref(value[i]);