4 * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Ja-young Gu <jygu@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
32 #include "core_object.h"
36 struct tcore_plugin_type {
38 const struct tcore_plugin_define_desc *desc;
46 Server *parent_server;
49 TcorePlugin *tcore_plugin_new(Server *server,
50 const struct tcore_plugin_define_desc *desc,
51 const char *filename, void *handle)
55 p = calloc(1, sizeof(struct tcore_plugin_type));
60 p->filename = strdup(filename);
63 p->property = g_hash_table_new(g_str_hash, g_str_equal);
65 p->parent_server = server;
70 void tcore_plugin_free(TcorePlugin *plugin)
80 if (plugin->list_co) {
81 for (list = plugin->list_co; list; list = list->next) {
90 g_slist_free(plugin->list_co);
91 plugin->list_co = NULL;
94 if (plugin->filename) {
95 free(plugin->filename);
96 plugin->filename = NULL;
99 if (plugin->property) {
100 g_hash_table_destroy(plugin->property);
101 plugin->property = NULL;
106 if (plugin->handle) {
107 dlclose(plugin->handle);
108 plugin->handle = NULL;
114 const struct tcore_plugin_define_desc *tcore_plugin_get_description(TcorePlugin *plugin)
122 char *tcore_plugin_get_filename(TcorePlugin *plugin)
127 if (!plugin->filename)
130 return strdup(plugin->filename);
133 const char* tcore_plugin_ref_plugin_name(TcorePlugin *plugin)
138 if (!plugin->desc->name)
141 return plugin->desc->name;
144 Server *tcore_plugin_ref_server(TcorePlugin *plugin)
149 return plugin->parent_server;
152 TReturn tcore_plugin_link_user_data(TcorePlugin *plugin, void *user_data)
155 return TCORE_RETURN_EINVAL;
157 plugin->user_data = user_data;
159 return TCORE_RETURN_SUCCESS;
162 void *tcore_plugin_ref_user_data(TcorePlugin *plugin)
167 return plugin->user_data;
170 TReturn tcore_plugin_add_core_object(TcorePlugin *plugin, CoreObject *co)
173 return TCORE_RETURN_EINVAL;
175 dbg("add core_object! (name=%s)", tcore_object_ref_name(co));
177 plugin->list_co = g_slist_insert(plugin->list_co, co, 0);
179 return TCORE_RETURN_SUCCESS;
182 TReturn tcore_plugin_remove_core_object(TcorePlugin *plugin, CoreObject *co)
185 return TCORE_RETURN_EINVAL;
187 dbg("remove core_object! (name=%s)", tcore_object_ref_name(co));
189 plugin->list_co = g_slist_remove(plugin->list_co, co);
191 return TCORE_RETURN_SUCCESS;
194 CoreObject *tcore_plugin_ref_core_object(TcorePlugin *plugin, unsigned int type)
202 for (list = plugin->list_co; list; list = list->next) {
207 if (tcore_object_get_type(co) == type) {
215 GSList *tcore_plugin_get_core_objects(TcorePlugin *plugin)
217 GSList *list, *rlist = NULL;
223 for (list = plugin->list_co; list; list = list->next) {
228 rlist = g_slist_append(rlist, co);
234 GSList *tcore_plugin_get_core_objects_bytype(TcorePlugin *plugin, unsigned int type)
236 GSList *list, *rlist = NULL;
242 for (list = plugin->list_co; list; list = list->next) {
247 if ((CORE_OBJECT_TYPE_DEFAULT |(tcore_object_get_type(co) & 0x0FF00000)) == type)
248 rlist = g_slist_append(rlist, co);
254 TReturn tcore_plugin_core_object_event_emit(TcorePlugin *plugin, const char *event, const void *event_info)
260 return TCORE_RETURN_EINVAL;
262 dbg("event(%s) emit", event);
264 for (list = plugin->list_co; list; list = list->next) {
269 tcore_object_emit_callback(co, event, event_info);
272 return TCORE_RETURN_SUCCESS;
275 TReturn tcore_plugin_link_property(TcorePlugin *plugin, const char *key, void *data)
280 return TCORE_RETURN_EINVAL;
282 if (!plugin->property)
283 return TCORE_RETURN_EINVAL;
285 prev = g_hash_table_lookup(plugin->property, key);
288 g_hash_table_replace(plugin->property, (gpointer)key, data);
291 g_hash_table_insert(plugin->property, strdup(key), data);
294 return TCORE_RETURN_SUCCESS;
297 void *tcore_plugin_ref_property(TcorePlugin *plugin, const char *key)
302 if (!plugin->property)
305 return g_hash_table_lookup(plugin->property, key);