2 * tel-plugin-packetservice
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: DongHoo Park <donghoo.park@samsung.com>
7 * Arun Shukla <arun.shukla@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
31 #include <ps_common.h>
34 * PS plugin Private information
37 GDBusConnection *conn; /* DBUS connection */
38 guint bus_id; /* Packet service BUS ID */
47 static void __packet_service_cleanup(PsPrivInfo *priv_info)
50 if (priv_info == NULL)
53 /* Cleaning up the master list */
54 g_slist_foreach(priv_info->master,
55 __remove_master, NULL);
57 /* Unowning the Gdbus */
58 g_bus_unown_name(priv_info->bus_id);
60 /* Free GDBusConnection */
61 g_object_unref(priv_info->conn);
64 * Freeing the memory allocated to the
65 * custom data for Packet Service
70 static void on_bus_acquired(GDBusConnection *conn,
71 const gchar *name, gpointer user_data)
74 gpointer *master = NULL;
76 TcorePlugin *p = user_data;
77 PsPrivInfo *priv_info = tcore_plugin_ref_user_data(p);
79 dbg("Bus is acquired: [%s]", name);
84 master = _ps_master_create_master(conn, p);
86 err("Failed to create 'master' Object for Packet Service");
90 priv_info->master = g_slist_append(priv_info->master, master);
93 * Create and initialize 'modem(s)'
95 rv = _ps_master_create_modems(master, NULL);
97 dbg("Failure : Modem creation Failed ");
101 dbg("Packet Service plugin initialization: [Successful]");
110 * Packet service initializer
112 gboolean ps_main_init(TcorePlugin *p)
114 PsPrivInfo *priv_info = NULL;
115 GDBusConnection *conn = NULL;
116 gchar *address = NULL;
119 GError *error = NULL;
128 rv = _ps_context_initialize(p);
130 err("Failure : Initialize context global variable");
135 * Memory allocation for private information
137 priv_info = g_try_malloc0(sizeof(PsPrivInfo));
139 err("Failure :Memory allocation !!");
143 address = g_dbus_address_get_for_bus_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
144 g_assert_no_error(error);
146 conn = g_dbus_connection_new_for_address_sync(address,
147 G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT |
148 G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION,
152 g_assert_no_error(error);
154 dbg("Failure: G-dBus Connection failed"); /* TODO - Clean-up */
157 * Storing the G-dBus connection in Private information of PS Plugin
159 priv_info->conn = conn;
161 id = g_bus_own_name_on_connection(conn,
163 G_BUS_NAME_OWNER_FLAGS_REPLACE,
169 dbg("PacketService - dBus address: [%s] dBus connection ID: [%d]",
173 * Initializing custom data for Packet Service
175 priv_info->bus_id = id;
176 priv_info->master = NULL;
180 * Setting User data of PS plugin
182 tcore_plugin_link_user_data(p, (void *)priv_info);
188 * Packet service de-initializer
190 void ps_main_exit(TcorePlugin *p)
192 PsPrivInfo *priv_info = tcore_plugin_ref_user_data(p);
195 * Clean-up Packet Service
197 __packet_service_cleanup(priv_info);
198 tcore_plugin_link_user_data(p, NULL);
200 dbg("Packet Service exited!! ");