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.
30 #include "core_object.h"
37 #include "co_network.h"
43 #include "co_phonebook.h"
46 struct callback_type {
49 CoreObjectCallback callback;
53 struct tcore_object_type {
57 TcorePlugin *parent_plugin;
62 CoreObjectFreeHook free_hook;
63 CoreObjectCloneHook clone_hook;
64 CoreObjectDispatcher dispatcher;
73 struct tcore_object_mapping_tbl {
78 static void _util_print_mapping_tbl_entry(object_mapping_table_t *tbl_entry)
82 msg("------> Table Entry - HAL: [0x%x]", tbl_entry->hal);
84 co_list = tbl_entry->object_type;
85 if (co_list == NULL) {
86 err("No Core Objects defined for this Mapping Table Entry");
90 /* Search all the Table entries with matching 'type' */
91 for ( ; co_list ; co_list = co_list->next) {
92 if (co_list->data == NULL)
95 msg(" Core Object type: [0x%x]", co_list->data);
99 static void _free_tbl_entry(gpointer data)
101 object_mapping_table_t *tbl_entry;
108 dbg("Removing Mapping Table Entry - HAL: [0x%x]", tbl_entry->hal);
109 _util_print_mapping_tbl_entry(tbl_entry);
111 /* Free Core Object types list */
112 g_slist_free(tbl_entry->object_type);
114 /* Free Table entry */
117 static CoreObject *_object_new(TcorePlugin *plugin, unsigned int type)
121 co = calloc(1, sizeof(struct tcore_object_type));
125 co->parent_plugin = plugin;
128 co->property = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
133 static gboolean _on_at_event(TcoreAT *at, const GSList *lines, void *user_data)
137 struct callback_type *cb = user_data;
139 ret = cb->callback(cb->co, lines, cb->user_data);
147 static void _remove_at_callback(TcoreAT *at, struct callback_type *cb)
149 tcore_at_remove_notification_full(at, cb->event, _on_at_event, cb);
152 static object_mapping_table_t *_object_search_mapping_tbl_entry(GSList *mapping_tbl_list,
156 object_mapping_table_t *tbl_entry = NULL;
158 for (list = mapping_tbl_list; list ; list = list->next) {
159 tbl_entry = list->data;
160 if (tbl_entry == NULL)
163 /* Search for Table entry with matching 'hal' */
164 if (tbl_entry->hal == hal) {
172 static object_mapping_table_t *_object_search_mapping_tbl_entry_by_type(
173 GSList *mapping_tbl_list, unsigned int type)
177 object_mapping_table_t *tbl_entry = NULL;
179 for (list = mapping_tbl_list; list ; list = list->next) {
180 tbl_entry = list->data;
181 if (tbl_entry == NULL)
184 /* Search all the Table entries with matching 'type' */
185 for (co_list = tbl_entry->object_type ; co_list ; co_list = co_list->next) {
186 if (co_list->data == NULL)
189 if (type == (unsigned int)co_list->data) {
198 static CoreObject *_create_core_object_by_type(guint type,
199 TcorePlugin *plugin, TcoreHal *hal)
201 CoreObject *co = NULL;
204 case CORE_OBJECT_TYPE_MODEM:
205 /* Create Core Object */
206 co = tcore_modem_new(plugin, "modem", NULL, hal);
209 case CORE_OBJECT_TYPE_CALL:
210 /* Create Core Object */
211 co = tcore_call_new(plugin, "call", NULL, hal);
214 case CORE_OBJECT_TYPE_SS:
215 /* Create Core Object */
216 co = tcore_ss_new(plugin, "ss", NULL, hal);
219 case CORE_OBJECT_TYPE_NETWORK:
220 /* Create Core Object */
221 co = tcore_network_new(plugin, "network", NULL, hal);
224 case CORE_OBJECT_TYPE_PS:
225 /* Create Core Object */
226 co = tcore_ps_new(plugin, "ps", NULL, hal);
229 case CORE_OBJECT_TYPE_SIM:
230 /* Create Core Object */
231 co = tcore_sim_new(plugin, "sim", NULL, hal);
234 case CORE_OBJECT_TYPE_SAT:
235 /* Create Core Object */
236 co = tcore_sat_new(plugin, "sat", NULL, hal);
239 case CORE_OBJECT_TYPE_SAP:
240 /* Create Core Object */
241 co = tcore_sap_new(plugin, "sap", NULL, hal);
244 case CORE_OBJECT_TYPE_SMS:
245 /* Create Core Object */
246 co = tcore_sms_new(plugin, "sms", NULL, hal);
249 case CORE_OBJECT_TYPE_PHONEBOOK:
250 /* Create Core Object */
251 co = tcore_phonebook_new(plugin, "phonebook", NULL, hal);
254 case CORE_OBJECT_TYPE_GPS:
255 /* Create Core Object */
256 co = tcore_gps_new(plugin, "gps", NULL, hal);
259 case CORE_OBJECT_TYPE_CUSTOM: /* Fall through */
261 err("Unsupport/Invalid Core Object Type [0x%x]", type);
268 static gboolean _init_core_object_by_type(unsigned int type,
269 TcorePlugin *plugin, struct object_initializer *initializer_list)
271 gboolean ret = FALSE;
272 CoreObject *co = tcore_plugin_ref_core_object(plugin, type);
274 err("No Core Object of type: [0x%x]", type);
279 case CORE_OBJECT_TYPE_MODEM: {
280 /* Invoke initializer */
281 if (initializer_list->modem_init)
282 ret = initializer_list->modem_init(plugin, co);
285 case CORE_OBJECT_TYPE_CALL: {
286 /* Invoke initializer */
287 if (initializer_list->call_init)
288 ret = initializer_list->call_init(plugin, co);
291 case CORE_OBJECT_TYPE_SS: {
292 /* Invoke initializer */
293 if (initializer_list->ss_init)
294 ret = initializer_list->ss_init(plugin, co);
297 case CORE_OBJECT_TYPE_NETWORK: {
298 /* Invoke initializer */
299 if (initializer_list->network_init)
300 ret = initializer_list->network_init(plugin, co);
303 case CORE_OBJECT_TYPE_PS: {
304 /* Invoke initializer */
305 if (initializer_list->ps_init)
306 ret = initializer_list->ps_init(plugin, co);
309 case CORE_OBJECT_TYPE_SIM: {
310 /* Invoke initializer */
311 if (initializer_list->sim_init)
312 ret = initializer_list->sim_init(plugin, co);
315 case CORE_OBJECT_TYPE_SAT: {
316 /* Invoke initializer */
317 if (initializer_list->sat_init)
318 ret = initializer_list->sat_init(plugin, co);
321 case CORE_OBJECT_TYPE_SAP: {
322 /* Invoke initializer */
323 if (initializer_list->sap_init)
324 ret = initializer_list->sap_init(plugin, co);
327 case CORE_OBJECT_TYPE_SMS:{
328 /* Invoke initializer */
329 if (initializer_list->sms_init)
330 ret = initializer_list->sms_init(plugin, co);
333 case CORE_OBJECT_TYPE_PHONEBOOK: {
334 /* Invoke initializer */
335 if (initializer_list->phonebook_init)
336 ret = initializer_list->phonebook_init(plugin, co);
339 case CORE_OBJECT_TYPE_GPS:{
340 /* Invoke initializer */
341 if (initializer_list->gps_init)
342 ret = initializer_list->gps_init(plugin, co);
345 case CORE_OBJECT_TYPE_CUSTOM: /* Fall through */
347 dbg("Unsupport/Invalid Core Object Type [0x%x]", type);
354 static void _deinit_core_object_by_type(unsigned int type,
355 TcorePlugin *plugin, struct object_deinitializer *deinitializer_list)
359 co = tcore_plugin_ref_core_object(plugin, type);
361 err("No Core Object of type: [0x%x]", type);
366 case CORE_OBJECT_TYPE_MODEM: {
367 if (deinitializer_list->modem_deinit) {
368 /* Invoke deinitializer */
369 deinitializer_list->modem_deinit(plugin, co);
373 case CORE_OBJECT_TYPE_CALL: {
374 if (deinitializer_list->call_deinit) {
375 /* Invoke deinitializer */
376 deinitializer_list->call_deinit(plugin, co);
380 case CORE_OBJECT_TYPE_SS: {
381 if (deinitializer_list->ss_deinit) {
382 /* Invoke deinitializer */
383 deinitializer_list->ss_deinit(plugin, co);
387 case CORE_OBJECT_TYPE_NETWORK: {
388 if (deinitializer_list->network_deinit) {
389 /* Invoke deinitializer */
390 deinitializer_list->network_deinit(plugin, co);
394 case CORE_OBJECT_TYPE_PS: {
395 if (deinitializer_list->ps_deinit) {
396 /* Invoke deinitializer */
397 deinitializer_list->ps_deinit(plugin, co);
401 case CORE_OBJECT_TYPE_SIM: {
402 if (deinitializer_list->sim_deinit) {
403 /* Invoke deinitializer */
404 deinitializer_list->sim_deinit(plugin, co);
408 case CORE_OBJECT_TYPE_SAT: {
409 if (deinitializer_list->sat_deinit) {
410 /* Invoke deinitializer */
411 deinitializer_list->sat_deinit(plugin, co);
415 case CORE_OBJECT_TYPE_SAP: {
416 if (deinitializer_list->sap_deinit) {
417 /* Invoke deinitializer */
418 deinitializer_list->sap_deinit(plugin, co);
422 case CORE_OBJECT_TYPE_SMS:{
423 if (deinitializer_list->sms_deinit) {
424 /* Invoke deinitializer */
425 deinitializer_list->sms_deinit(plugin, co);
429 case CORE_OBJECT_TYPE_PHONEBOOK: {
430 if (deinitializer_list->phonebook_deinit) {
431 /* Invoke deinitializer */
432 deinitializer_list->phonebook_deinit(plugin, co);
436 case CORE_OBJECT_TYPE_GPS:{
437 if (deinitializer_list->gps_deinit) {
438 /* Invoke deinitializer */
439 deinitializer_list->gps_deinit(plugin, co);
443 case CORE_OBJECT_TYPE_CUSTOM: /* Fall through */
445 dbg("Unsupport/Invalid Core Object Type [0x%x]", type);
449 /* Free Core Object */
450 tcore_object_free(co);
454 CoreObject *tcore_object_new(TcorePlugin *plugin,
455 const char *name, TcoreHal *hal)
459 co = _object_new(plugin, CORE_OBJECT_TYPE_DEFAULT);
463 tcore_object_set_hal(co, hal);
464 tcore_object_set_name(co, name);
467 tcore_plugin_add_core_object(plugin, co);
472 void tcore_object_free(CoreObject *co)
475 struct callback_type *cb = NULL;
480 dbg("co_name=%s", co->name);
486 warn("free_hook is null, private-object couldn't be freed!!");
490 g_hash_table_destroy(co->property);
494 for (l = co->callbacks; l; l = l->next) {
505 g_slist_free(co->callbacks);
506 co->callbacks = NULL;
509 if (co->parent_plugin)
510 tcore_plugin_remove_core_object(co->parent_plugin, co);
515 memset(co, 0, sizeof(CoreObject));
519 CoreObject *tcore_object_clone(CoreObject *src, TcorePlugin *new_parent)
525 struct callback_type *cb = NULL;
533 p = src->parent_plugin;
535 dest = _object_new(p, src->type);
539 dest->object = src->object;
540 dest->user_data = src->user_data;
541 dest->free_hook = src->free_hook;
542 dest->clone_hook = src->clone_hook;
543 dest->dispatcher = src->dispatcher;
544 dest->hal = src->hal;
546 for (l = src->callbacks; l; l = l->next) {
551 tcore_object_add_callback(dest, cb->event, cb->callback, cb->user_data);
554 tcore_plugin_add_core_object(p, dest);
557 src->clone_hook(src, dest);
562 CoreObject *tcore_object_clone_template_object(TcorePlugin *p,
563 unsigned int co_type)
565 CoreObject *template_co;
567 template_co = tcore_server_find_template_object(tcore_plugin_ref_server(p), co_type);
568 if(template_co == NULL)
571 return tcore_object_clone(template_co, p);
575 const char *tcore_object_ref_name(CoreObject *co)
583 TReturn tcore_object_set_free_hook(CoreObject *co,
584 CoreObjectFreeHook free_hook)
587 return TCORE_RETURN_EINVAL;
589 co->free_hook = free_hook;
591 return TCORE_RETURN_SUCCESS;
595 TReturn tcore_object_set_clone_hook(CoreObject *co,
596 CoreObjectCloneHook clone_hook)
599 return TCORE_RETURN_EINVAL;
601 co->clone_hook = clone_hook;
603 return TCORE_RETURN_SUCCESS;
606 TReturn tcore_object_set_name(CoreObject *co, const char *name)
609 return TCORE_RETURN_EINVAL;
617 co->name = strdup(name);
619 return TCORE_RETURN_SUCCESS;
622 TcorePlugin *tcore_object_ref_plugin(CoreObject *co)
627 return co->parent_plugin;
630 TReturn tcore_object_link_object(CoreObject *co, void *object)
633 return TCORE_RETURN_EINVAL;
637 return TCORE_RETURN_SUCCESS;
640 void *tcore_object_ref_object(CoreObject *co)
648 TReturn tcore_object_set_type(CoreObject *co, unsigned int type)
651 return TCORE_RETURN_EINVAL;
655 return TCORE_RETURN_SUCCESS;
658 unsigned int tcore_object_get_type(CoreObject *co)
666 TReturn tcore_object_set_hal(CoreObject *co, TcoreHal *hal)
669 struct callback_type *cb = NULL;
673 return TCORE_RETURN_EINVAL;
676 // remove unsolicited callbacks
677 if (tcore_hal_get_mode(co->hal) == TCORE_HAL_MODE_AT) {
678 at = tcore_hal_get_at(co->hal);
679 for (l = co->callbacks; l; l = l->next) {
684 tcore_at_remove_notification_full(at, cb->event, _on_at_event, cb);
691 return TCORE_RETURN_SUCCESS;
693 // register unsolicited callbacks
694 if (tcore_hal_get_mode(hal) == TCORE_HAL_MODE_AT) {
695 at = tcore_hal_get_at(hal);
696 for (l = co->callbacks; l; l = l->next) {
701 if (cb->event[0] == 27)
702 tcore_at_add_notification(at, cb->event + 1, TRUE, _on_at_event, cb);
704 tcore_at_add_notification(at, cb->event, FALSE, _on_at_event, cb);
708 return TCORE_RETURN_SUCCESS;
711 TcoreHal *tcore_object_get_hal(CoreObject *co)
719 TReturn tcore_object_link_user_data(CoreObject *co,
723 return TCORE_RETURN_EINVAL;
725 co->user_data = user_data;
727 return TCORE_RETURN_SUCCESS;
730 void *tcore_object_ref_user_data(CoreObject *co)
735 return co->user_data;
738 TReturn tcore_object_dispatch_request(CoreObject *co,
742 return TCORE_RETURN_EINVAL;
745 return TCORE_RETURN_ENOSYS;
747 return co->dispatcher(co, ur);
750 TReturn tcore_object_set_dispatcher(CoreObject *co,
751 CoreObjectDispatcher func)
754 return TCORE_RETURN_EINVAL;
756 co->dispatcher = func;
758 return TCORE_RETURN_SUCCESS;
761 TReturn tcore_object_override_callback(CoreObject *co,
762 const char *event, tcore_object_callback callback, void *user_data)
764 struct callback_type *cb = NULL;
768 if ((co == NULL) || (event == NULL) || (callback == NULL))
769 return TCORE_RETURN_EINVAL;
771 if (strlen(event) < 1)
772 return TCORE_RETURN_EINVAL;
775 if (tcore_hal_get_mode(co->hal) == TCORE_HAL_MODE_AT)
776 at = tcore_hal_get_at(co->hal);
779 for (l = co->callbacks; l; l = l->next) {
784 if (g_strcmp0(cb->event, event) != 0)
788 _remove_at_callback(at, cb);
791 co->callbacks = g_slist_remove(co->callbacks, cb);
795 return tcore_object_add_callback(co, event, callback, user_data);
798 TReturn tcore_object_add_callback(CoreObject *co,
800 CoreObjectCallback callback, void *user_data)
802 struct callback_type *cb = NULL;
805 if (!co || !event || !callback)
806 return TCORE_RETURN_EINVAL;
808 if (strlen(event) < 1)
809 return TCORE_RETURN_EINVAL;
811 cb = calloc(1, sizeof(struct callback_type));
813 return TCORE_RETURN_ENOMEM;
816 cb->event = strdup(event);
817 cb->callback = callback;
818 cb->user_data = user_data;
820 co->callbacks = g_slist_append(co->callbacks, cb);
823 if (tcore_hal_get_mode(co->hal) == TCORE_HAL_MODE_AT) {
824 at = tcore_hal_get_at(co->hal);
826 tcore_at_add_notification(at, cb->event + 1, TRUE, _on_at_event, cb);
828 tcore_at_add_notification(at, cb->event, FALSE, _on_at_event, cb);
833 return TCORE_RETURN_SUCCESS;
836 TReturn tcore_object_del_callback(CoreObject *co,
837 const char *event, CoreObjectCallback callback)
839 struct callback_type *cb = NULL;
843 if (!co || !event || !callback || !co->callbacks)
844 return TCORE_RETURN_EINVAL;
846 if (strlen(event) == 0)
847 return TCORE_RETURN_EINVAL;
850 if (tcore_hal_get_mode(co->hal) == TCORE_HAL_MODE_AT)
851 at = tcore_hal_get_at(co->hal);
862 if (cb->callback != callback) {
867 if (g_strcmp0(cb->event, event) != 0) {
873 _remove_at_callback(at, cb);
876 co->callbacks = g_slist_remove(co->callbacks, cb);
881 return TCORE_RETURN_SUCCESS;
884 TReturn tcore_object_emit_callback(CoreObject *co,
885 const char *event, const void *event_info)
887 struct callback_type *cb = NULL;
892 return TCORE_RETURN_EINVAL;
902 if (g_strcmp0(cb->event, event) != 0) {
908 ret = cb->callback(co, event_info, cb->user_data);
911 co->callbacks = g_slist_remove(co->callbacks, cb);
919 return TCORE_RETURN_SUCCESS;
922 static GSList *_set_property_real (CoreObject *co, const char *key,
923 const char *value, GSList *list)
931 g_hash_table_remove (co->property, key);
932 return g_slist_append (list, (char *)key);
935 prev = g_hash_table_lookup(co->property, key);
938 * If same data, no change & no callback emit
940 if (strcmp (prev, value) == 0)
943 g_hash_table_replace(co->property, strdup(key), strdup(value));
946 g_hash_table_insert(co->property, strdup(key), strdup(value));
949 return g_slist_append (list, (char *)key);
952 TReturn tcore_object_set_property_full(CoreObject *co, const char *first_property, ...)
959 if (!co || !first_property)
960 return TCORE_RETURN_EINVAL;
962 va_start (argptr, first_property);
965 v = va_arg (argptr, char *);
966 list = _set_property_real (co, k, v, list);
969 k = va_arg (argptr, char *);
973 v = va_arg (argptr, char *);
974 list = _set_property_real (co, k, v, list);
980 return TCORE_RETURN_SUCCESS;
982 if (g_slist_length(list) > 0)
983 tcore_object_emit_callback (co,
984 CORE_OBJECT_EVENT_PROPERTY_CHANGED, list);
988 return TCORE_RETURN_SUCCESS;
991 const char *tcore_object_ref_property(CoreObject *co, const char *key)
996 return g_hash_table_lookup(co->property, key);
999 GHashTable *tcore_object_ref_property_hash(CoreObject *co)
1004 return co->property;
1006 void *tcore_object_add_mapping_tbl_entry(void *mapping_tbl,
1007 unsigned int object_type, TcoreHal *hal)
1009 GSList *mapping_tbl_list = mapping_tbl;
1010 object_mapping_table_t *tbl_entry;
1013 err("Mapping Table: [0x%x] HAL: [0x%x]", mapping_tbl, hal);
1018 * Search 'hal' across all the Table entries of the Mapping Table
1020 * Table entry MAY NOT be found as -
1021 * 1. Mapping Table is NOT yet created
1022 * 2. Table entry for corresponding 'hal' is NOT present
1024 * In each of the above cases, the new Mapping Table entry should be added
1025 * to the Mapping Table.
1027 tbl_entry = _object_search_mapping_tbl_entry(mapping_tbl_list, hal);
1028 if (tbl_entry == NULL) {
1029 dbg("Creating New Table entry for HAL: [0x%x]", hal);
1031 * If there is NO previously added Table entry for the 'hal' then
1032 * new Table entry is created
1035 tbl_entry = g_try_new0(object_mapping_table_t, 1);
1036 if (tbl_entry != NULL)
1037 tbl_entry->hal = hal;
1039 err("Failed to allocate memory");
1040 return mapping_tbl_list;
1043 /* Add the Mapping Table entry to Mapping Table */
1044 mapping_tbl_list = g_slist_append(mapping_tbl_list, tbl_entry);
1048 * Appending the Core Object type to the list of Core Objects types
1050 tbl_entry->object_type = g_slist_append(tbl_entry->object_type, (gpointer)object_type);
1051 dbg("Added Mapping Table entry - HAL: [0x%x] Object type: [0x%x]", hal, object_type);
1053 return mapping_tbl_list;
1056 void tcore_object_remove_mapping_tbl(void *mapping_tbl)
1058 GSList *mapping_tbl_list = mapping_tbl;
1060 if (mapping_tbl_list == NULL) {
1061 err("Mapping Table is NULL");
1065 /* Freeing Mapping Table */
1066 g_slist_free_full(mapping_tbl_list, _free_tbl_entry);
1069 void *tcore_object_remove_mapping_tbl_entry(void *mapping_tbl, TcoreHal *hal)
1071 GSList *mapping_tbl_list = mapping_tbl;
1072 object_mapping_table_t *tbl_entry;
1074 if (mapping_tbl_list == NULL) {
1075 err("Mapping Table is NULL");
1079 tbl_entry = _object_search_mapping_tbl_entry(mapping_tbl_list, hal);
1080 if (tbl_entry == NULL) {
1081 err("Table entry is NOT available");
1082 return mapping_tbl_list;
1085 dbg("Removing Mapping Table Entry - HAL: [0x%x]", hal);
1086 _util_print_mapping_tbl_entry(tbl_entry);
1088 /* Free Core Object types list */
1089 g_slist_free(tbl_entry->object_type);
1091 /* Remove mapping Table entry */
1092 mapping_tbl_list = g_slist_remove(mapping_tbl_list, tbl_entry);
1094 /* Free Table entry */
1097 return mapping_tbl_list;
1100 void tcore_object_remove_mapping_tbl_entry_by_type(void *mapping_tbl,
1101 unsigned int co_type)
1103 GSList *mapping_tbl_list;
1104 object_mapping_table_t *tbl_entry;
1106 if (mapping_tbl == NULL) {
1107 err("Mapping Table is NULL");
1111 mapping_tbl_list = mapping_tbl;
1114 _object_search_mapping_tbl_entry_by_type(mapping_tbl_list, co_type);
1115 if (tbl_entry == NULL) {
1116 err("Table entry is NOT available");
1120 /* Remove the Core Object type from the list */
1121 tbl_entry->object_type = g_slist_remove(tbl_entry->object_type, (gconstpointer)co_type);
1124 void tcore_object_print_mapping_tbl(void *mapping_tbl)
1126 GSList *mapping_tbl_list;
1127 object_mapping_table_t *tbl_entry = NULL;
1130 if (mapping_tbl == NULL) {
1131 err("Mapping Table is NULL");
1135 mapping_tbl_list = mapping_tbl;
1137 for ( ; mapping_tbl_list ; mapping_tbl_list = mapping_tbl_list->next) {
1138 tbl_entry = mapping_tbl_list->data;
1139 if (tbl_entry == NULL)
1142 _util_print_mapping_tbl_entry(tbl_entry);
1146 /* Initialize Core Objects */
1147 TReturn tcore_object_init_objects(TcorePlugin *plugin,
1148 struct object_initializer *initializer_list)
1150 GSList *mapping_tbl_list;
1151 gboolean ret = FALSE;
1153 /* Refer mapping_tbl from Server's Modem list */
1154 mapping_tbl_list = tcore_server_get_cp_mapping_tbl(plugin);
1157 * Mapping Table is a MUST
1158 * If Mapping Table is NOT NULL, then initialization would be guided by the
1159 * Mapping Table entries,
1160 * else, it is treated as a Failure.
1162 if (mapping_tbl_list != NULL) {
1163 object_mapping_table_t *tbl_entry;
1165 GSList *object_type_list;
1168 /* Create each Core Object based on the Mapping Table entries */
1169 mtbl_list = mapping_tbl_list;
1170 for ( ; mtbl_list ; mtbl_list = mtbl_list->next) {
1171 tbl_entry = mtbl_list->data;
1172 if (tbl_entry != NULL) {
1175 object_type_list = tbl_entry->object_type;
1176 for ( ; object_type_list ; object_type_list = object_type_list->next) {
1177 type = (guint)object_type_list->data;
1179 co = _create_core_object_by_type(type, plugin, tbl_entry->hal);
1181 err("Failed to create Core Object - Type: [0x%x]", type);
1182 return TCORE_RETURN_FAILURE;
1184 dbg("Created Core Object - Type: [0x%x]", type);
1190 /* Initialize each Core Object based on the Mapping Table entries */
1191 mtbl_list = mapping_tbl_list;
1192 for ( ; mtbl_list ; mtbl_list = mtbl_list->next) {
1193 tbl_entry = mtbl_list->data;
1194 if (tbl_entry != NULL) {
1195 /* To handle NULL 'init' function case */
1198 object_type_list = tbl_entry->object_type;
1200 for ( ; object_type_list ; object_type_list = object_type_list->next) {
1201 type = (unsigned int)object_type_list->data;
1202 dbg("Core Object type: [0x%x]", type);
1204 ret = _init_core_object_by_type(type, plugin, initializer_list);
1206 err("Failed to initialize Core Object Type [0x%x]", type);
1207 return TCORE_RETURN_FAILURE;
1209 dbg("Initialized Core Object - Type: [0x%x]", type);
1214 err("Mapping Table is NOT present");
1217 err("Failed to create/initialize Core Objects");
1218 return TCORE_RETURN_FAILURE;
1221 dbg("Successfully initialized Core Objects");
1222 return TCORE_RETURN_SUCCESS;
1225 /* De-initialize Core Objects */
1226 void tcore_object_deinit_objects(TcorePlugin *plugin,
1227 struct object_deinitializer *deinitializer_list)
1229 GSList *mapping_tbl_list;
1231 /* Refer mapping_tbl from Server's Modem list */
1232 mapping_tbl_list = tcore_server_get_cp_mapping_tbl(plugin);
1235 * Mapping Table is a MUST
1236 * If Mapping Table is NOT NULL, then de-initialization would be guided by the
1237 * Mapping Table entries,
1239 * just return with an Error log.
1241 if (mapping_tbl_list != NULL) {
1242 object_mapping_table_t *tbl_entry;
1243 GSList *object_type_list;
1246 /* De-initialize each Core Object based on the Mapping Table entries */
1247 for ( ; mapping_tbl_list ; mapping_tbl_list = mapping_tbl_list->next) {
1248 tbl_entry = mapping_tbl_list->data;
1249 if (tbl_entry == NULL)
1252 object_type_list = tbl_entry->object_type;
1254 for ( ; object_type_list ; object_type_list = object_type_list->next) {
1255 type = (unsigned int)object_type_list->data;
1256 dbg("Core Object type: [0x%x]", type);
1258 _deinit_core_object_by_type(type, plugin, deinitializer_list);
1261 dbg("Successfully de-initialized Core Objects");
1263 err("Mapping Table is NOT present");