2 * Copyright (c) 2017-2020 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.
17 #include "sys_settings.h"
19 void clean_node(callback_node* node)
24 node->callback = NULL;
25 node->user_data = NULL;
29 callback_node* alloc_multi_callback_node()
31 callback_node* node = NULL;
32 node = (callback_node*)malloc(sizeof(callback_node));
35 SETTING_TRACE("Not enough node....");
44 void free_multi_callback_node(callback_node* node)
51 static gint _compare_cb(gconstpointer val, gconstpointer s_val)
53 if (NULL == val) return 1;
54 if (NULL == s_val) return 1;
56 callback_node* node = (callback_node*)val;
57 if (node->callback == s_val)
62 int delete_multi_callback(callback_list *handle, system_settings_changed_cb ptr)
66 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
68 GList *found = g_list_find_custom(handle->list, ptr, _compare_cb);
70 handle->list = g_list_remove_link(handle->list, found);
71 free_multi_callback_node((callback_node*)found->data);
76 return SYSTEM_SETTINGS_ERROR_NONE;
79 int add_multi_callback(callback_list *handle, system_settings_changed_cb ptr, void *user_data)
83 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
85 GList *found = g_list_find_custom(handle->list, ptr, _compare_cb);
87 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
89 callback_node* node = alloc_multi_callback_node();
92 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
95 node->user_data = user_data;
97 /* append the node to list. free_multi_callback_node will free the node */
98 handle->list = g_list_append(handle->list, node);
101 return SYSTEM_SETTINGS_ERROR_NONE;
104 int invoke_callback_list(callback_list *handle, system_settings_key_e key)
108 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
110 GList *itr = handle->list;
111 while (itr != NULL) {
112 callback_node* node = (callback_node*)itr->data;
114 node->callback(key, node->user_data);
115 itr = g_list_next(itr);
119 return SYSTEM_SETTINGS_ERROR_NONE;