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 add_modem(struct custom_data *ctx, TcorePlugin *p)
52 TelephonyObjectSkeleton *object;
61 cp_name = tcore_server_get_cp_name_by_plugin(p);
62 if (cp_name == NULL) {
63 err("CP Name is NULL");
67 path = g_strdup_printf("%s/%s", MY_DBUS_PATH, cp_name);
68 dbg("PATH: [%s]", path);
70 object = g_hash_table_lookup(ctx->objects, path);
72 /* Create new DBUS Interface object */
73 object = telephony_object_skeleton_new(path);
75 /* Insert the Object to DBUS interfaces HASH Table */
76 dbg("New DBUS Interface object created!!! (object = %p)", object);
80 g_hash_table_insert(ctx->objects, g_strdup(path), object);
82 dbg("DBUS Interface object already created!!! (object = %p)", object);
85 /* Add DBUS Interfaces for all Modules supported */
88 dbus_plugin_setup_modem_interface(object, ctx);
91 if (tcore_plugin_ref_core_object(p, CORE_OBJECT_TYPE_CALL) != NULL)
92 dbus_plugin_setup_call_interface(object, ctx);
95 if (tcore_plugin_ref_core_object(p, CORE_OBJECT_TYPE_NETWORK) != NULL)
96 dbus_plugin_setup_network_interface(object, ctx);
99 if (tcore_plugin_ref_core_object(p, CORE_OBJECT_TYPE_SS) != NULL)
100 dbus_plugin_setup_ss_interface(object, ctx);
103 if (tcore_plugin_ref_core_object(p, CORE_OBJECT_TYPE_SMS) != NULL)
104 dbus_plugin_setup_sms_interface(object, ctx);
107 co_sim = tcore_plugin_ref_core_object(p, CORE_OBJECT_TYPE_SIM);
109 dbus_plugin_setup_sim_interface(object, ctx);
112 if ((co_sim != NULL) && (tcore_sim_get_status(co_sim) >= SIM_STATUS_INITIALIZING))
113 if (tcore_plugin_ref_core_object(p, CORE_OBJECT_TYPE_SAT) != NULL)
114 dbus_plugin_setup_sat_interface(object, ctx);
117 if (tcore_plugin_ref_core_object(p, CORE_OBJECT_TYPE_PHONEBOOK) != NULL)
118 dbus_plugin_setup_phonebook_interface(object, ctx);
121 if (tcore_plugin_ref_core_object(p, CORE_OBJECT_TYPE_SAP) != NULL)
122 dbus_plugin_setup_sap_interface(object, ctx);
125 if (tcore_plugin_ref_core_object(p, CORE_OBJECT_TYPE_GPS) != NULL)
126 dbus_plugin_setup_gps_interface(object, ctx);
128 /* Export the Object to Manager */
129 g_dbus_object_manager_server_export(ctx->manager, G_DBUS_OBJECT_SKELETON(object));
132 * Set Telephony Ready registry
134 * At this point we can convey upper Layer that Telephony is Ready.
136 strg = tcore_server_find_storage(ctx->server, "vconf");
137 rv = tcore_storage_set_bool(strg, STORAGE_KEY_TELEPHONY_READY, TRUE);
139 err("Set Telephony Ready (TRUE) to registry - FAIL");
141 dbg("Set Telephony Ready (TRUE) to registry - SUCCESS");
149 static void refresh_object(struct custom_data *ctx)
157 if (ctx->manager == NULL) {
162 plugins = tcore_server_ref_plugins(ctx->server);
167 for (cur = plugins; cur; cur = cur->next) {
169 /* AT Standard Plug-in is not considered */
171 || (strcmp(tcore_plugin_ref_plugin_name(p), "AT") == 0)) {
172 dbg("Plug-in Name: [%s]", tcore_plugin_ref_plugin_name(p));
176 co = tcore_plugin_ref_core_object(p, CORE_OBJECT_TYPE_MODEM);
185 static TReturn send_response(Communicator *comm, UserRequest *ur, enum tcore_response_command command, unsigned int data_len, const void *data)
187 struct custom_data *ctx = NULL;
188 const struct tcore_user_info *ui;
190 dbg("Response Command = [0x%x], data_len = %d", command, data_len);
192 ctx = tcore_communicator_ref_user_data(comm);
194 dbg("user_data is NULL");
198 ui = tcore_user_request_ref_user_info(ur);
200 switch (command & (TCORE_RESPONSE | 0x0FF00000)) {
202 dbus_plugin_call_response(ctx, ur, ui->user_data, command, data_len, data);
206 dbus_plugin_ss_response(ctx, ur, ui->user_data, command, data_len, data);
213 dbus_plugin_sim_response(ctx, ur, ui->user_data, command, data_len, data);
217 dbus_plugin_sap_response(ctx, ur, ui->user_data, command, data_len, data);
220 case TRESP_PHONEBOOK:
221 dbus_plugin_phonebook_response(ctx, ur, ui->user_data, command, data_len, data);
225 dbus_plugin_modem_response(ctx, ur, ui->user_data, command, data_len, data);
229 dbus_plugin_sms_response(ctx, ur, ui->user_data, command, data_len, data);
233 dbus_plugin_sat_response(ctx, ur, ui->user_data, command, data_len, data);
239 dbus_plugin_network_response(ctx, ur, ui->user_data, command, data_len, data);
243 dbus_plugin_gps_response(ctx, ur, ui->user_data, command, data_len, data);
247 warn("unknown command (0x%x)", command);
254 static TReturn send_notification(Communicator *comm, CoreObject *source, enum tcore_notification_command command, unsigned int data_len, const void *data)
256 struct custom_data *ctx = NULL;
257 TelephonyObjectSkeleton *object;
262 dbg("Notification!!! (command = 0x%x, data_len = %d)", command, data_len);
264 if (command == TNOTI_SERVER_ADDED_PLUGIN)
265 p = (TcorePlugin *)data;
267 p = tcore_object_ref_plugin(source);
269 cp_name = tcore_server_get_cp_name_by_plugin(p);
271 return TCORE_RETURN_FAILURE;
272 dbg("CP Name: [%s]", cp_name);
274 ctx = tcore_communicator_ref_user_data(comm);
276 dbg("user_data is NULL");
277 return TCORE_RETURN_FAILURE;
281 path = g_strdup_printf("%s/%s", MY_DBUS_PATH, cp_name);
284 path = g_strdup_printf("%s", MY_DBUS_PATH);
286 dbg("PATH: [%s]", path);
288 object = g_hash_table_lookup(ctx->objects, path);
289 dbg("DBUS interface Object = [0x%x]", object);
291 switch (command & (TCORE_NOTIFICATION | 0x0FF00000)) {
293 dbus_plugin_call_notification(ctx, cp_name, object, command, data_len, data);
297 dbus_plugin_ss_notification(ctx, cp_name, object, command, data_len, data);
304 dbus_plugin_sim_notification(ctx, cp_name, object, command, data_len, data);
308 dbus_plugin_sap_notification(ctx, cp_name, object, command, data_len, data);
311 case TNOTI_PHONEBOOK:
312 dbus_plugin_phonebook_notification(ctx, cp_name, object, command, data_len, data);
316 dbus_plugin_modem_notification(ctx, cp_name, object, command, data_len, data);
320 dbus_plugin_sms_notification(ctx, cp_name, object, command, data_len, data);
324 dbus_plugin_sat_notification(ctx, cp_name, object, command, data_len, data);
330 dbus_plugin_network_notification(ctx, cp_name, object, command, data_len, data);
334 dbus_plugin_gps_notification(ctx, cp_name, object, command, data_len, data);
338 dbg("Server Notification");
339 if (command == TNOTI_SERVER_ADDED_PLUGIN) {
340 dbg("Plug-in is added... Refresh the context");
346 warn("unknown command (0x%x)", command);
355 on_manager_getmodems (TelephonyManager *mgr,
356 GDBusMethodInvocation *invocation,
359 struct custom_data *ctx = user_data;
360 GSList *cp_name_list;
366 cp_name_list = tcore_server_get_cp_name_list(ctx->server);
367 if (cp_name_list == NULL) {
368 telephony_manager_complete_get_modems(mgr, invocation, NULL);
372 count = g_slist_length(cp_name_list);
374 err("No Modems present");
375 telephony_manager_complete_get_modems(mgr, invocation, NULL);
379 dbg("count: %d", count);
380 list = g_try_malloc0(sizeof(gchar *) * (count+1));
382 err("Failed to allocate memory");
383 g_slist_free_full(cp_name_list, g_free);
385 telephony_manager_complete_get_modems(mgr, invocation, NULL);
390 for ( ; cp_name_list ; cp_name_list = cp_name_list->next) {
391 name = cp_name_list->data;
395 list[count] = g_strdup(name);
396 dbg("list[%d]: %s", count, list[count]);
400 telephony_manager_complete_get_modems(mgr, invocation, (const gchar **)list);
403 for (;count >= 0; count--)
408 /* Freeing the received list of CP names */
409 g_slist_free_full(cp_name_list, g_free);
414 static void on_bus_acquired(GDBusConnection *conn, const gchar *name, gpointer user_data)
416 struct custom_data *ctx = user_data;
417 TelephonyManager *mgr;
418 info("DBUS Registered");
420 /* Add interface to default object path */
421 mgr = telephony_manager_skeleton_new();
422 g_signal_connect (mgr,
424 G_CALLBACK (on_manager_getmodems),
425 ctx); /* user_data */
427 g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(mgr), conn, MY_DBUS_PATH, NULL);
429 g_dbus_object_manager_server_set_connection (ctx->manager, conn);
431 dbg("Aquire DBUS - COMPLETE");
437 struct tcore_communitor_operations ops = {
438 .send_response = send_response,
439 .send_notification = send_notification,
442 static gboolean on_load()
449 static gboolean on_init(TcorePlugin *p)
452 struct custom_data *data;
460 data = calloc(sizeof(struct custom_data), 1);
467 comm = tcore_communicator_new(p, "dbus", &ops);
468 tcore_communicator_link_user_data(comm, data);
471 data->server = tcore_plugin_ref_server(p);
473 data->objects = g_hash_table_new(g_str_hash, g_str_equal);
474 data->cached_sat_main_menu = NULL;
476 dbg("data = %p", data);
478 id = g_bus_own_name (G_BUS_TYPE_SYSTEM,
480 G_BUS_NAME_OWNER_FLAGS_REPLACE,
486 data->manager = g_dbus_object_manager_server_new (MY_DBUS_PATH);
488 refresh_object(data);
493 static void on_unload(TcorePlugin *p)
495 struct custom_data *data;
503 comm = tcore_server_find_communicator(tcore_plugin_ref_server(p), "dbus");
507 data = tcore_communicator_ref_user_data(comm);
511 g_hash_table_destroy(data->objects);
516 struct tcore_plugin_define_desc plugin_define_desc =
518 .name = "NEW_DBUS_COMMUNICATOR",
519 .priority = TCORE_PLUGIN_PRIORITY_HIGH,
520 .version = PLUGIN_VERSION,