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;
53 char *plugin_name = NULL;
55 GSList *co_list = NULL;
57 plugin_name = tcore_plugin_ref_plugin_name(p);
61 path = g_strdup_printf("%s/%s", MY_DBUS_PATH, plugin_name);
62 dbg("path = [%s]", path);
64 object = g_hash_table_lookup(ctx->objects, path);
66 dbg("dbus interface object already created. (object = %p)", object);
70 object = telephony_object_skeleton_new(path);
71 dbg("new dbus object created. (object = %p)", object);
72 g_hash_table_insert(ctx->objects, g_strdup(path), object);
75 dbus_plugin_setup_modem_interface(object, ctx);
77 co_list = tcore_plugin_get_core_objects_bytype(p, CORE_OBJECT_TYPE_CALL);
79 g_slist_free(co_list);
80 dbus_plugin_setup_call_interface(object, ctx);
83 co_list = tcore_plugin_get_core_objects_bytype(p, CORE_OBJECT_TYPE_NETWORK);
85 g_slist_free(co_list);
86 dbus_plugin_setup_network_interface(object, ctx);
89 co_list = tcore_plugin_get_core_objects_bytype(p, CORE_OBJECT_TYPE_SS);
91 g_slist_free(co_list);
92 dbus_plugin_setup_ss_interface(object, ctx);
95 co_list = tcore_plugin_get_core_objects_bytype(p, CORE_OBJECT_TYPE_SMS);
97 g_slist_free(co_list);
98 dbus_plugin_setup_sms_interface(object, ctx);
101 co_list = tcore_plugin_get_core_objects_bytype(p, CORE_OBJECT_TYPE_SAT);
103 g_slist_free(co_list);
104 dbus_plugin_setup_sat_interface(object, ctx);
107 co_list = tcore_plugin_get_core_objects_bytype(p, CORE_OBJECT_TYPE_PHONEBOOK);
109 g_slist_free(co_list);
110 dbus_plugin_setup_phonebook_interface(object, ctx);
113 co_list = tcore_plugin_get_core_objects_bytype(p, CORE_OBJECT_TYPE_SAP);
115 g_slist_free(co_list);
116 dbus_plugin_setup_sap_interface(object, ctx);
119 co_list = tcore_plugin_get_core_objects_bytype(p, CORE_OBJECT_TYPE_SIM);
121 g_slist_free(co_list);
122 dbus_plugin_setup_sim_interface(object, ctx);
125 g_dbus_object_manager_server_export (ctx->manager, G_DBUS_OBJECT_SKELETON (object));
132 static void refresh_object(struct custom_data *ctx)
144 plugins = tcore_server_ref_plugins(ctx->server);
149 for (cur = plugins; cur; cur = cur->next) {
154 co_list = tcore_plugin_get_core_objects_bytype(p, CORE_OBJECT_TYPE_MODEM);
158 if (!tcore_object_get_hal(co_list->data)) {
159 g_slist_free(co_list);
163 g_slist_free(co_list);
169 static TReturn send_response(Communicator *comm, UserRequest *ur, enum tcore_response_command command, unsigned int data_len, const void *data)
171 struct custom_data *ctx = NULL;
172 const struct tcore_user_info *ui;
174 dbg("Response Command = [0x%x], data_len = %d", command, data_len);
176 ctx = tcore_communicator_ref_user_data(comm);
178 dbg("user_data is NULL");
182 ui = tcore_user_request_ref_user_info(ur);
184 switch (command & (TCORE_RESPONSE | 0x0FF00000)) {
186 dbus_plugin_call_response(ctx, ur, ui->user_data, command, data_len, data);
190 dbus_plugin_ss_response(ctx, ur, ui->user_data, command, data_len, data);
197 dbus_plugin_sim_response(ctx, ur, ui->user_data, command, data_len, data);
201 dbus_plugin_sap_response(ctx, ur, ui->user_data, command, data_len, data);
204 case TRESP_PHONEBOOK:
205 dbus_plugin_phonebook_response(ctx, ur, ui->user_data, command, data_len, data);
209 dbus_plugin_modem_response(ctx, ur, ui->user_data, command, data_len, data);
213 dbus_plugin_sms_response(ctx, ur, ui->user_data, command, data_len, data);
217 dbus_plugin_sat_response(ctx, ur, ui->user_data, command, data_len, data);
223 dbus_plugin_network_response(ctx, ur, ui->user_data, command, data_len, data);
227 warn("unknown command (0x%x)", command);
234 static TReturn send_notification(Communicator *comm, CoreObject *source, enum tcore_notification_command command, unsigned int data_len, const void *data)
236 struct custom_data *ctx = NULL;
239 TelephonyObjectSkeleton *object;
241 dbg("notification !!! (command = 0x%x, data_len = %d)", command, data_len);
243 ctx = tcore_communicator_ref_user_data(comm);
245 dbg("user_data is NULL");
249 plugin_name = tcore_plugin_ref_plugin_name(tcore_object_ref_plugin(source));
251 path = g_strdup_printf("%s/%s", MY_DBUS_PATH, plugin_name);
254 path = g_strdup_printf("%s", MY_DBUS_PATH);
256 dbg("path = [%s]", path);
258 object = g_hash_table_lookup(ctx->objects, path);
259 dbg("dbus inteface object = %p", object);
261 switch (command & (TCORE_NOTIFICATION | 0x0FF00000)) {
263 dbus_plugin_call_notification(ctx, plugin_name, object, command, data_len, data);
267 dbus_plugin_ss_notification(ctx, plugin_name, object, command, data_len, data);
274 dbus_plugin_sim_notification(ctx, plugin_name, object, command, data_len, data);
278 dbus_plugin_sap_notification(ctx, plugin_name, object, command, data_len, data);
281 case TNOTI_PHONEBOOK:
282 dbus_plugin_phonebook_notification(ctx, plugin_name, object, command, data_len, data);
286 dbus_plugin_modem_notification(ctx, plugin_name, object, command, data_len, data);
290 dbus_plugin_sms_notification(ctx, plugin_name, object, command, data_len, data);
294 dbus_plugin_sat_notification(ctx, plugin_name, object, command, data_len, data);
300 dbus_plugin_network_notification(ctx, plugin_name, object, command, data_len, data);
304 if (command == TNOTI_SERVER_RUN) {
310 warn("unknown command (0x%x)", command);
319 on_manager_getmodems (TelephonyManager *mgr,
320 GDBusMethodInvocation *invocation,
323 struct custom_data *ctx = user_data;
332 plugins = tcore_server_ref_plugins(ctx->server);
334 telephony_manager_complete_get_modems(mgr, invocation, NULL);
338 max_count = g_slist_length(plugins);
339 list = calloc(sizeof(gchar *) * max_count, 1);
343 for (cur = plugins; cur; cur = cur->next) {
348 co_list = tcore_plugin_get_core_objects_bytype(p, CORE_OBJECT_TYPE_MODEM);
352 if (!tcore_object_get_hal(co_list->data)) {
353 g_slist_free(co_list);
356 g_slist_free(co_list);
358 list[count] = g_strdup(tcore_plugin_get_description(p)->name);
362 telephony_manager_complete_get_modems(mgr, invocation, (const gchar **)list);
364 for (;count >= 0; count--) {
374 static void on_bus_acquired(GDBusConnection *conn, const gchar *name, gpointer user_data)
377 gpointer handle = NULL;
378 static Storage *strg;
379 struct custom_data *ctx = user_data;
380 TelephonyManager *mgr;
382 info("dbus registered");
384 ctx->manager = g_dbus_object_manager_server_new (MY_DBUS_PATH);
388 /* Add interface to default object path */
389 mgr = telephony_manager_skeleton_new();
390 g_signal_connect (mgr,
392 G_CALLBACK (on_manager_getmodems),
393 ctx); /* user_data */
395 g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(mgr), conn, MY_DBUS_PATH, NULL);
397 g_dbus_object_manager_server_set_connection (ctx->manager, conn);
399 //set telephony ready registry
400 strg = tcore_server_find_storage(ctx->server, "vconf");
401 handle = tcore_storage_create_handle(strg, "vconf");
403 rv = tcore_storage_set_bool(strg, STORAGE_KEY_TELEPHONY_READY, TRUE);
405 dbg("fail to set the telephony status to registry");
408 dbg("done to acquire the dbus");
411 struct tcore_communitor_operations ops = {
412 .send_response = send_response,
413 .send_notification = send_notification,
416 static gboolean on_load()
423 static gboolean on_init(TcorePlugin *p)
426 struct custom_data *data;
434 data = calloc(sizeof(struct custom_data), 1);
441 comm = tcore_communicator_new(p, "dbus", &ops);
442 tcore_communicator_link_user_data(comm, data);
445 data->server = tcore_plugin_ref_server(p);
447 data->objects = g_hash_table_new(g_str_hash, g_str_equal);
448 data->cached_sat_main_menu = NULL;
450 dbg("data = %p", data);
452 id = g_bus_own_name (G_BUS_TYPE_SYSTEM,
454 G_BUS_NAME_OWNER_FLAGS_REPLACE,
463 static void on_unload(TcorePlugin *p)
465 struct custom_data *data;
473 comm = tcore_server_find_communicator(tcore_plugin_ref_server(p), "dbus");
477 data = tcore_communicator_ref_user_data(comm);
481 g_hash_table_destroy(data->objects);
486 struct tcore_plugin_define_desc plugin_define_desc =
488 .name = "NEW_DBUS_COMMUNICATOR",
489 .priority = TCORE_PLUGIN_PRIORITY_HIGH,
490 .version = PLUGIN_VERSION,