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.
28 #include <glib-object.h>
35 #include <communicator.h>
38 #include <user_request.h>
39 #include <co_network.h>
43 #ifndef PLUGIN_VERSION
44 #define PLUGIN_VERSION 1
47 #include "generated-code.h"
50 static void set_telephony_ready(Server *server)
55 strg = tcore_server_find_storage(server, "vconf");
56 rv = tcore_storage_set_bool(strg, STORAGE_KEY_TELEPHONY_READY, TRUE);
58 dbg("Set Telephony Ready (TRUE) to registry - %s", rv ? "SUCCESS"
62 static void add_modem(struct custom_data *ctx, TcorePlugin *p)
64 TelephonyObjectSkeleton *object;
71 cp_name = tcore_server_get_cp_name_by_plugin(p);
72 if (cp_name == NULL) {
73 err("CP Name is NULL");
77 path = g_strdup_printf("%s/%s", MY_DBUS_PATH, cp_name);
78 dbg("PATH: [%s]", path);
80 object = g_hash_table_lookup(ctx->objects, path);
82 /* Create new DBUS Interface object */
83 object = telephony_object_skeleton_new(path);
85 /* Insert the Object to DBUS interfaces HASH Table */
86 dbg("New DBUS Interface object created!!! (object = %p)", object);
90 g_hash_table_insert(ctx->objects, g_strdup(path), object);
92 dbg("DBUS Interface object already created!!! (object = %p)", object);
95 /* Add DBUS Interfaces for all Modules supported */
98 dbus_plugin_setup_modem_interface(object, ctx);
101 if (tcore_plugin_ref_core_object(p, CORE_OBJECT_TYPE_CALL) != NULL)
102 dbus_plugin_setup_call_interface(object, ctx);
105 if (tcore_plugin_ref_core_object(p, CORE_OBJECT_TYPE_NETWORK) != NULL)
106 dbus_plugin_setup_network_interface(object, ctx);
109 if (tcore_plugin_ref_core_object(p, CORE_OBJECT_TYPE_SS) != NULL)
110 dbus_plugin_setup_ss_interface(object, ctx);
113 if (tcore_plugin_ref_core_object(p, CORE_OBJECT_TYPE_SMS) != NULL)
114 dbus_plugin_setup_sms_interface(object, ctx);
117 co_sim = tcore_plugin_ref_core_object(p, CORE_OBJECT_TYPE_SIM);
119 dbus_plugin_setup_sim_interface(object, ctx);
122 if ((co_sim != NULL) && (tcore_sim_get_status(co_sim) >= SIM_STATUS_INITIALIZING))
123 if (tcore_plugin_ref_core_object(p, CORE_OBJECT_TYPE_SAT) != NULL)
124 dbus_plugin_setup_sat_interface(object, ctx);
127 if (tcore_plugin_ref_core_object(p, CORE_OBJECT_TYPE_PHONEBOOK) != NULL)
128 dbus_plugin_setup_phonebook_interface(object, ctx);
131 if (tcore_plugin_ref_core_object(p, CORE_OBJECT_TYPE_SAP) != NULL)
132 dbus_plugin_setup_sap_interface(object, ctx);
135 if (tcore_plugin_ref_core_object(p, CORE_OBJECT_TYPE_GPS) != NULL)
136 dbus_plugin_setup_gps_interface(object, ctx);
138 /* Export the Object to Manager */
139 g_dbus_object_manager_server_export(ctx->manager, G_DBUS_OBJECT_SKELETON(object));
141 if (g_dbus_object_manager_server_get_connection (ctx->manager) != NULL)
142 set_telephony_ready(ctx->server);
149 static gboolean refresh_object(gpointer user_data)
151 struct custom_data *ctx = user_data;
158 if (ctx->manager == NULL) {
163 plugins = tcore_server_ref_plugins(ctx->server);
168 for (cur = plugins; cur; cur = cur->next) {
170 /* AT Standard Plug-in is not considered */
172 || (strcmp(tcore_plugin_ref_plugin_name(p), "AT") == 0)) {
173 dbg("Plug-in Name: [%s]", tcore_plugin_ref_plugin_name(p));
177 co = tcore_plugin_ref_core_object(p, CORE_OBJECT_TYPE_MODEM);
188 static TReturn send_response(Communicator *comm, UserRequest *ur, enum tcore_response_command command, unsigned int data_len, const void *data)
190 struct custom_data *ctx = NULL;
191 const struct tcore_user_info *ui;
193 dbg("Response Command = [0x%x], data_len = %d", command, data_len);
195 ctx = tcore_communicator_ref_user_data(comm);
197 dbg("user_data is NULL");
201 ui = tcore_user_request_ref_user_info(ur);
203 switch (command & (TCORE_RESPONSE | 0x0FF00000)) {
205 dbus_plugin_call_response(ctx, ur, ui->user_data, command, data_len, data);
209 dbus_plugin_ss_response(ctx, ur, ui->user_data, command, data_len, data);
216 dbus_plugin_sim_response(ctx, ur, ui->user_data, command, data_len, data);
220 dbus_plugin_sap_response(ctx, ur, ui->user_data, command, data_len, data);
223 case TRESP_PHONEBOOK:
224 dbus_plugin_phonebook_response(ctx, ur, ui->user_data, command, data_len, data);
228 dbus_plugin_modem_response(ctx, ur, ui->user_data, command, data_len, data);
232 dbus_plugin_sms_response(ctx, ur, ui->user_data, command, data_len, data);
236 dbus_plugin_sat_response(ctx, ur, ui->user_data, command, data_len, data);
242 dbus_plugin_network_response(ctx, ur, ui->user_data, command, data_len, data);
246 dbus_plugin_gps_response(ctx, ur, ui->user_data, command, data_len, data);
250 warn("unknown command (0x%x)", command);
257 static TReturn send_notification(Communicator *comm, CoreObject *source, enum tcore_notification_command command, unsigned int data_len, const void *data)
259 struct custom_data *ctx = NULL;
260 TelephonyObjectSkeleton *object;
265 dbg("Notification!!! (command = 0x%x, data_len = %d)", command, data_len);
267 ctx = tcore_communicator_ref_user_data(comm);
269 dbg("user_data is NULL");
270 return TCORE_RETURN_FAILURE;
274 * Modem binary is not embedded in the platform. Telephony needs to
275 * be set to ready for pwlock. This is temporary solution for
277 * This problem needs to be addressed in pwlock in the future.
279 if (command == TNOTI_SERVER_MODEM_ERR) {
280 err("Modem interface plugin init failed");
281 set_telephony_ready(ctx->server);
283 return TCORE_RETURN_SUCCESS;
286 if (command == TNOTI_SERVER_ADDED_PLUGIN)
287 p = (TcorePlugin *)data;
289 p = tcore_object_ref_plugin(source);
291 cp_name = tcore_server_get_cp_name_by_plugin(p);
293 return TCORE_RETURN_FAILURE;
294 dbg("CP Name: [%s]", cp_name);
297 path = g_strdup_printf("%s/%s", MY_DBUS_PATH, cp_name);
300 path = g_strdup_printf("%s", MY_DBUS_PATH);
302 dbg("PATH: [%s]", path);
304 object = g_hash_table_lookup(ctx->objects, path);
305 dbg("DBUS interface Object = [0x%x]", object);
307 switch (command & (TCORE_NOTIFICATION | 0x0FF00000)) {
309 dbus_plugin_call_notification(ctx, cp_name, object, command, data_len, data);
313 dbus_plugin_ss_notification(ctx, cp_name, object, command, data_len, data);
320 dbus_plugin_sim_notification(ctx, cp_name, object, command, data_len, data);
324 dbus_plugin_sap_notification(ctx, cp_name, object, command, data_len, data);
327 case TNOTI_PHONEBOOK:
328 dbus_plugin_phonebook_notification(ctx, cp_name, object, command, data_len, data);
332 dbus_plugin_modem_notification(ctx, cp_name, object, command, data_len, data);
336 dbus_plugin_sms_notification(ctx, cp_name, object, command, data_len, data);
340 dbus_plugin_sat_notification(ctx, cp_name, object, command, data_len, data);
346 dbus_plugin_network_notification(ctx, cp_name, object, command, data_len, data);
350 dbus_plugin_gps_notification(ctx, cp_name, object, command, data_len, data);
354 dbg("Server Notification");
355 if (command == TNOTI_SERVER_ADDED_PLUGIN) {
356 dbg("Plug-in is added... Refresh the context");
357 g_idle_add(refresh_object, ctx);
362 warn("unknown command (0x%x)", command);
371 on_manager_getmodems (TelephonyManager *mgr,
372 GDBusMethodInvocation *invocation,
375 struct custom_data *ctx = user_data;
376 GSList *cp_name_list;
378 const char *name = NULL;
382 cp_name_list = tcore_server_get_cp_name_list(ctx->server);
383 if (cp_name_list == NULL) {
384 telephony_manager_complete_get_modems(mgr, invocation, &name);
388 count = g_slist_length(cp_name_list);
390 err("No Modems present");
391 telephony_manager_complete_get_modems(mgr, invocation, &name);
395 dbg("count: %d", count);
396 list = g_try_malloc0(sizeof(gchar *) * (count+1));
398 err("Failed to allocate memory");
399 g_slist_free_full(cp_name_list, g_free);
401 telephony_manager_complete_get_modems(mgr, invocation, &name);
406 for ( ; cp_name_list ; cp_name_list = cp_name_list->next) {
407 name = cp_name_list->data;
411 list[count] = g_strdup(name);
412 dbg("list[%d]: %s", count, list[count]);
416 telephony_manager_complete_get_modems(mgr, invocation, (const gchar **)list);
419 for (;count >= 0; count--)
424 /* Freeing the received list of CP names */
425 g_slist_free_full(cp_name_list, g_free);
430 static void on_bus_acquired(GDBusConnection *conn, const gchar *name, gpointer user_data)
432 struct custom_data *ctx = user_data;
433 TelephonyManager *mgr;
435 info("DBUS Registered");
437 /* Add interface to default object path */
438 mgr = telephony_manager_skeleton_new();
439 g_signal_connect (mgr,
441 G_CALLBACK (on_manager_getmodems),
442 ctx); /* user_data */
444 g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(mgr), conn, MY_DBUS_PATH, NULL);
446 g_dbus_object_manager_server_set_connection (ctx->manager, conn);
448 dbg("Aquire DBUS - COMPLETE");
451 g_idle_add(refresh_object, ctx);
454 struct tcore_communitor_operations ops = {
455 .send_response = send_response,
456 .send_notification = send_notification,
459 static gboolean on_load()
466 static gboolean on_init(TcorePlugin *p)
469 struct custom_data *data;
477 data = calloc(sizeof(struct custom_data), 1);
484 comm = tcore_communicator_new(p, "dbus", &ops);
485 tcore_communicator_link_user_data(comm, data);
488 data->server = tcore_plugin_ref_server(p);
490 data->objects = g_hash_table_new(g_str_hash, g_str_equal);
491 data->cached_sat_main_menu = NULL;
493 dbg("data = %p", data);
495 id = g_bus_own_name (G_BUS_TYPE_SYSTEM,
497 G_BUS_NAME_OWNER_FLAGS_REPLACE,
503 data->manager = g_dbus_object_manager_server_new (MY_DBUS_PATH);
505 g_idle_add(refresh_object, data);
510 static void on_unload(TcorePlugin *p)
512 struct custom_data *data;
520 comm = tcore_server_find_communicator(tcore_plugin_ref_server(p), "dbus");
524 data = tcore_communicator_ref_user_data(comm);
528 g_hash_table_destroy(data->objects);
533 struct tcore_plugin_define_desc plugin_define_desc =
535 .name = "NEW_DBUS_COMMUNICATOR",
536 .priority = TCORE_PLUGIN_PRIORITY_HIGH,
537 .version = PLUGIN_VERSION,