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 #include "generated-code.h"
46 static void add_modem(struct custom_data *ctx, TcorePlugin *p)
48 TelephonyObjectSkeleton *object;
49 char *plugin_name = NULL;
51 GSList *co_list = NULL;
53 plugin_name = tcore_plugin_ref_plugin_name(p);
57 path = g_strdup_printf("%s/%s", MY_DBUS_PATH, plugin_name);
58 dbg("path = [%s]", path);
60 object = g_hash_table_lookup(ctx->objects, path);
62 dbg("dbus interface object already created. (object = %p)", object);
66 object = telephony_object_skeleton_new(path);
67 dbg("new dbus object created. (object = %p)", object);
68 g_hash_table_insert(ctx->objects, g_strdup(path), object);
71 dbus_plugin_setup_modem_interface(object, ctx);
73 co_list = tcore_plugin_get_core_objects_bytype(p, CORE_OBJECT_TYPE_CALL);
75 g_slist_free(co_list);
76 dbus_plugin_setup_call_interface(object, ctx);
80 co_list = tcore_plugin_get_core_objects_bytype(p, CORE_OBJECT_TYPE_NETWORK);
82 g_slist_free(co_list);
83 dbus_plugin_setup_network_interface(object, ctx);
86 co_list = tcore_plugin_get_core_objects_bytype(p, CORE_OBJECT_TYPE_SS);
88 g_slist_free(co_list);
89 dbus_plugin_setup_ss_interface(object, ctx);
92 co_list = tcore_plugin_get_core_objects_bytype(p, CORE_OBJECT_TYPE_SMS);
94 g_slist_free(co_list);
95 dbus_plugin_setup_sms_interface(object, ctx);
98 co_list = tcore_plugin_get_core_objects_bytype(p, CORE_OBJECT_TYPE_SAT);
100 g_slist_free(co_list);
101 dbus_plugin_setup_sat_interface(object, ctx);
104 co_list = tcore_plugin_get_core_objects_bytype(p, CORE_OBJECT_TYPE_PHONEBOOK);
106 g_slist_free(co_list);
107 dbus_plugin_setup_phonebook_interface(object, ctx);
110 co_list = tcore_plugin_get_core_objects_bytype(p, CORE_OBJECT_TYPE_SAP);
112 g_slist_free(co_list);
113 dbus_plugin_setup_sap_interface(object, ctx);
116 co_list = tcore_plugin_get_core_objects_bytype(p, CORE_OBJECT_TYPE_SIM);
118 g_slist_free(co_list);
119 dbus_plugin_setup_sim_interface(object, ctx);
122 g_dbus_object_manager_server_export (ctx->manager, G_DBUS_OBJECT_SKELETON (object));
129 static void refresh_object(struct custom_data *ctx)
141 plugins = tcore_server_ref_plugins(ctx->server);
146 for (cur = plugins; cur; cur = cur->next) {
151 co_list = tcore_plugin_get_core_objects_bytype(p, CORE_OBJECT_TYPE_MODEM);
155 if (!tcore_object_get_hal(co_list->data)) {
156 g_slist_free(co_list);
160 g_slist_free(co_list);
166 static TReturn send_response(Communicator *comm, UserRequest *ur, enum tcore_response_command command, unsigned int data_len, const void *data)
168 struct custom_data *ctx = NULL;
169 const struct tcore_user_info *ui;
171 dbg("Response Command = [0x%x], data_len = %d", command, data_len);
173 ctx = tcore_communicator_ref_user_data(comm);
175 dbg("user_data is NULL");
179 ui = tcore_user_request_ref_user_info(ur);
181 switch (command & (TCORE_RESPONSE | 0x0FF00000)) {
183 dbus_plugin_call_response(ctx, ur, ui->user_data, command, data_len, data);
187 dbus_plugin_ss_response(ctx, ur, ui->user_data, command, data_len, data);
194 dbus_plugin_sim_response(ctx, ur, ui->user_data, command, data_len, data);
198 dbus_plugin_sap_response(ctx, ur, ui->user_data, command, data_len, data);
201 case TRESP_PHONEBOOK:
202 dbus_plugin_phonebook_response(ctx, ur, ui->user_data, command, data_len, data);
206 dbus_plugin_modem_response(ctx, ur, ui->user_data, command, data_len, data);
210 dbus_plugin_sms_response(ctx, ur, ui->user_data, command, data_len, data);
214 dbus_plugin_sat_response(ctx, ur, ui->user_data, command, data_len, data);
220 dbus_plugin_network_response(ctx, ur, ui->user_data, command, data_len, data);
224 warn("unknown command (0x%x)", command);
231 static TReturn send_notification(Communicator *comm, CoreObject *source, enum tcore_notification_command command, unsigned int data_len, const void *data)
233 struct custom_data *ctx = NULL;
236 TelephonyObjectSkeleton *object;
238 dbg("notification !!! (command = 0x%x, data_len = %d)", command, data_len);
240 ctx = tcore_communicator_ref_user_data(comm);
242 dbg("user_data is NULL");
246 plugin_name = tcore_plugin_ref_plugin_name(tcore_object_ref_plugin(source));
248 path = g_strdup_printf("%s/%s", MY_DBUS_PATH, plugin_name);
251 path = g_strdup_printf("%s", MY_DBUS_PATH);
253 dbg("path = [%s]", path);
255 object = g_hash_table_lookup(ctx->objects, path);
256 dbg("dbus inteface object = %p", object);
258 switch (command & (TCORE_NOTIFICATION | 0x0FF00000)) {
260 dbus_plugin_call_notification(ctx, plugin_name, object, command, data_len, data);
264 dbus_plugin_ss_notification(ctx, plugin_name, object, command, data_len, data);
271 dbus_plugin_sim_notification(ctx, plugin_name, object, command, data_len, data);
275 dbus_plugin_sap_notification(ctx, plugin_name, object, command, data_len, data);
278 case TNOTI_PHONEBOOK:
279 dbus_plugin_phonebook_notification(ctx, plugin_name, object, command, data_len, data);
283 dbus_plugin_modem_notification(ctx, plugin_name, object, command, data_len, data);
287 dbus_plugin_sms_notification(ctx, plugin_name, object, command, data_len, data);
291 dbus_plugin_sat_notification(ctx, plugin_name, object, command, data_len, data);
297 dbus_plugin_network_notification(ctx, plugin_name, object, command, data_len, data);
301 if (command == TNOTI_SERVER_RUN) {
307 warn("unknown command (0x%x)", command);
316 on_manager_getmodems (TelephonyManager *mgr,
317 GDBusMethodInvocation *invocation,
320 struct custom_data *ctx = user_data;
329 plugins = tcore_server_ref_plugins(ctx->server);
331 telephony_manager_complete_get_modems(mgr, invocation, NULL);
335 max_count = g_slist_length(plugins);
336 list = calloc(sizeof(gchar *) * max_count, 1);
340 for (cur = plugins; cur; cur = cur->next) {
345 co_list = tcore_plugin_get_core_objects_bytype(p, CORE_OBJECT_TYPE_MODEM);
349 if (!tcore_object_get_hal(co_list->data)) {
350 g_slist_free(co_list);
353 g_slist_free(co_list);
355 list[count] = g_strdup(tcore_plugin_get_description(p)->name);
359 telephony_manager_complete_get_modems(mgr, invocation, (const gchar **)list);
361 for (;count >= 0; count--) {
371 static void on_bus_acquired(GDBusConnection *conn, const gchar *name, gpointer user_data)
374 gpointer handle = NULL;
375 static Storage *strg;
376 struct custom_data *ctx = user_data;
377 TelephonyManager *mgr;
379 ctx->manager = g_dbus_object_manager_server_new (MY_DBUS_PATH);
383 /* Add interface to default object path */
384 mgr = telephony_manager_skeleton_new();
385 g_signal_connect (mgr,
387 G_CALLBACK (on_manager_getmodems),
388 ctx); /* user_data */
390 g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(mgr), conn, MY_DBUS_PATH, NULL);
392 g_dbus_object_manager_server_set_connection (ctx->manager, conn);
394 //set telephony ready registry
395 strg = tcore_server_find_storage(ctx->server, "vconf");
396 handle = tcore_storage_create_handle(strg, "vconf");
398 rv = tcore_storage_set_bool(strg, STORAGE_KEY_TELEPHONY_READY, TRUE);
400 dbg("fail to set the telephony status to registry");
403 dbg("done to acquire the dbus");
406 struct tcore_communitor_operations ops = {
407 .send_response = send_response,
408 .send_notification = send_notification,
411 static gboolean on_load()
418 static gboolean on_init(TcorePlugin *p)
421 struct custom_data *data;
429 data = calloc(sizeof(struct custom_data), 1);
436 comm = tcore_communicator_new(p, "dbus", &ops);
437 tcore_communicator_link_user_data(comm, data);
440 data->server = tcore_plugin_ref_server(p);
442 data->objects = g_hash_table_new(g_str_hash, g_str_equal);
443 data->cached_sat_main_menu = NULL;
445 dbg("data = %p", data);
447 id = g_bus_own_name (G_BUS_TYPE_SYSTEM,
449 G_BUS_NAME_OWNER_FLAGS_REPLACE,
458 static void on_unload(TcorePlugin *p)
460 struct custom_data *data;
468 comm = tcore_server_find_communicator(tcore_plugin_ref_server(p), "dbus");
472 data = tcore_communicator_ref_user_data(comm);
476 g_hash_table_destroy(data->objects);
481 struct tcore_plugin_define_desc plugin_define_desc =
483 .name = "NEW_DBUS_COMMUNICATOR",
484 .priority = TCORE_PLUGIN_PRIORITY_HIGH,