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;
56 plugin_name = tcore_plugin_ref_plugin_name(p);
60 path = g_strdup_printf("%s/%s", MY_DBUS_PATH, plugin_name);
61 dbg("path = [%s]", path);
63 object = g_hash_table_lookup(ctx->objects, path);
65 dbg("dbus interface object already created. (object = %p)", object);
69 object = telephony_object_skeleton_new(path);
70 dbg("new dbus object created. (object = %p)", object);
71 g_hash_table_insert(ctx->objects, g_strdup(path), object);
74 dbus_plugin_setup_modem_interface(object, ctx);
76 if (tcore_plugin_ref_core_object(p, CORE_OBJECT_TYPE_CALL) != NULL)
77 dbus_plugin_setup_call_interface(object, ctx);
80 if (tcore_plugin_ref_core_object(p, CORE_OBJECT_TYPE_NETWORK) != NULL)
81 dbus_plugin_setup_network_interface(object, ctx);
83 if (tcore_plugin_ref_core_object(p, CORE_OBJECT_TYPE_SS) != NULL)
84 dbus_plugin_setup_ss_interface(object, ctx);
86 if (tcore_plugin_ref_core_object(p, CORE_OBJECT_TYPE_SMS) != NULL)
87 dbus_plugin_setup_sms_interface(object, ctx);
90 if (tcore_plugin_ref_core_object(p, CORE_OBJECT_TYPE_SAT) != NULL)
91 dbus_plugin_setup_sat_interface(object, ctx);
94 if (tcore_plugin_ref_core_object(p, CORE_OBJECT_TYPE_PHONEBOOK) != NULL)
95 dbus_plugin_setup_phonebook_interface(object, ctx);
97 if (tcore_plugin_ref_core_object(p, CORE_OBJECT_TYPE_SAP) != NULL)
98 dbus_plugin_setup_sap_interface(object, ctx);
100 if (tcore_plugin_ref_core_object(p, CORE_OBJECT_TYPE_SIM) != NULL)
101 dbus_plugin_setup_sim_interface(object, ctx);
103 if (tcore_plugin_ref_core_object(p, CORE_OBJECT_TYPE_GPS) != NULL)
104 dbus_plugin_setup_gps_interface(object, ctx);
106 g_dbus_object_manager_server_export (ctx->manager, G_DBUS_OBJECT_SKELETON (object));
113 static void refresh_object(struct custom_data *ctx)
125 plugins = tcore_server_ref_plugins(ctx->server);
130 for (cur = plugins; cur; cur = cur->next) {
135 co = tcore_plugin_ref_core_object(p, CORE_OBJECT_TYPE_MODEM);
139 if (!tcore_object_get_hal(co))
146 static TReturn send_response(Communicator *comm, UserRequest *ur, enum tcore_response_command command, unsigned int data_len, const void *data)
148 struct custom_data *ctx = NULL;
149 const struct tcore_user_info *ui;
151 dbg("Response Command = [0x%x], data_len = %d", command, data_len);
153 ctx = tcore_communicator_ref_user_data(comm);
155 dbg("user_data is NULL");
159 ui = tcore_user_request_ref_user_info(ur);
161 switch (command & (TCORE_RESPONSE | 0x0FF00000)) {
163 dbus_plugin_call_response(ctx, ur, ui->user_data, command, data_len, data);
167 dbus_plugin_ss_response(ctx, ur, ui->user_data, command, data_len, data);
174 dbus_plugin_sim_response(ctx, ur, ui->user_data, command, data_len, data);
178 dbus_plugin_sap_response(ctx, ur, ui->user_data, command, data_len, data);
181 case TRESP_PHONEBOOK:
182 dbus_plugin_phonebook_response(ctx, ur, ui->user_data, command, data_len, data);
186 dbus_plugin_modem_response(ctx, ur, ui->user_data, command, data_len, data);
190 dbus_plugin_sms_response(ctx, ur, ui->user_data, command, data_len, data);
194 dbus_plugin_sat_response(ctx, ur, ui->user_data, command, data_len, data);
200 dbus_plugin_network_response(ctx, ur, ui->user_data, command, data_len, data);
204 dbus_plugin_gps_response(ctx, ur, ui->user_data, command, data_len, data);
208 warn("unknown command (0x%x)", command);
215 static TReturn send_notification(Communicator *comm, CoreObject *source, enum tcore_notification_command command, unsigned int data_len, const void *data)
217 struct custom_data *ctx = NULL;
220 TelephonyObjectSkeleton *object;
222 dbg("notification !!! (command = 0x%x, data_len = %d)", command, data_len);
224 ctx = tcore_communicator_ref_user_data(comm);
226 dbg("user_data is NULL");
230 plugin_name = tcore_plugin_ref_plugin_name(tcore_object_ref_plugin(source));
232 path = g_strdup_printf("%s/%s", MY_DBUS_PATH, plugin_name);
235 path = g_strdup_printf("%s", MY_DBUS_PATH);
237 dbg("path = [%s]", path);
239 object = g_hash_table_lookup(ctx->objects, path);
240 dbg("dbus inteface object = %p", object);
242 switch (command & (TCORE_NOTIFICATION | 0x0FF00000)) {
244 dbus_plugin_call_notification(ctx, plugin_name, object, command, data_len, data);
248 dbus_plugin_ss_notification(ctx, plugin_name, object, command, data_len, data);
255 dbus_plugin_sim_notification(ctx, plugin_name, object, command, data_len, data);
259 dbus_plugin_sap_notification(ctx, plugin_name, object, command, data_len, data);
262 case TNOTI_PHONEBOOK:
263 dbus_plugin_phonebook_notification(ctx, plugin_name, object, command, data_len, data);
267 dbus_plugin_modem_notification(ctx, plugin_name, object, command, data_len, data);
271 dbus_plugin_sms_notification(ctx, plugin_name, object, command, data_len, data);
275 dbus_plugin_sat_notification(ctx, plugin_name, object, command, data_len, data);
281 dbus_plugin_network_notification(ctx, plugin_name, object, command, data_len, data);
285 dbus_plugin_gps_notification(ctx, plugin_name, object, command, data_len, data);
289 if (command == TNOTI_SERVER_RUN) {
295 warn("unknown command (0x%x)", command);
304 on_manager_getmodems (TelephonyManager *mgr,
305 GDBusMethodInvocation *invocation,
308 struct custom_data *ctx = user_data;
317 plugins = tcore_server_ref_plugins(ctx->server);
319 telephony_manager_complete_get_modems(mgr, invocation, NULL);
323 max_count = g_slist_length(plugins);
324 list = calloc(sizeof(gchar *) * max_count, 1);
328 for (cur = plugins; cur; cur = cur->next) {
333 co = tcore_plugin_ref_core_object(p, CORE_OBJECT_TYPE_MODEM);
337 if (!tcore_object_get_hal(co))
340 list[count] = g_strdup(tcore_plugin_get_description(p)->name);
344 telephony_manager_complete_get_modems(mgr, invocation, (const gchar **)list);
346 for (;count >= 0; count--) {
356 static void on_bus_acquired(GDBusConnection *conn, const gchar *name, gpointer user_data)
359 static Storage *strg;
360 struct custom_data *ctx = user_data;
361 TelephonyManager *mgr;
363 info("dbus registered");
367 /* Add interface to default object path */
368 mgr = telephony_manager_skeleton_new();
369 g_signal_connect (mgr,
371 G_CALLBACK (on_manager_getmodems),
372 ctx); /* user_data */
374 g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(mgr), conn, MY_DBUS_PATH, NULL);
376 g_dbus_object_manager_server_set_connection (ctx->manager, conn);
378 //set telephony ready registry
379 strg = tcore_server_find_storage(ctx->server, "vconf");
381 rv = tcore_storage_set_bool(strg, STORAGE_KEY_TELEPHONY_READY, TRUE);
383 dbg("fail to set the telephony status to registry");
386 dbg("done to acquire the dbus");
389 struct tcore_communitor_operations ops = {
390 .send_response = send_response,
391 .send_notification = send_notification,
394 static gboolean on_load()
401 static gboolean on_init(TcorePlugin *p)
404 struct custom_data *data;
412 data = calloc(sizeof(struct custom_data), 1);
419 comm = tcore_communicator_new(p, "dbus", &ops);
420 tcore_communicator_link_user_data(comm, data);
423 data->server = tcore_plugin_ref_server(p);
425 data->objects = g_hash_table_new(g_str_hash, g_str_equal);
426 data->cached_sat_main_menu = NULL;
428 dbg("data = %p", data);
430 id = g_bus_own_name (G_BUS_TYPE_SYSTEM,
432 G_BUS_NAME_OWNER_FLAGS_REPLACE,
438 data->manager = g_dbus_object_manager_server_new (MY_DBUS_PATH);
439 refresh_object(data);
444 static void on_unload(TcorePlugin *p)
446 struct custom_data *data;
454 comm = tcore_server_find_communicator(tcore_plugin_ref_server(p), "dbus");
458 data = tcore_communicator_ref_user_data(comm);
462 g_hash_table_destroy(data->objects);
467 struct tcore_plugin_define_desc plugin_define_desc =
469 .name = "NEW_DBUS_COMMUNICATOR",
470 .priority = TCORE_PLUGIN_PRIORITY_HIGH,
471 .version = PLUGIN_VERSION,