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"
32 #include "ps_context.h"
33 #include "ps_master.h"
36 * PS plugin Private information
39 GDBusConnection *conn; /* DBUS connection */
40 guint bus_id; /* Packet service BUS ID */
49 static void __packet_service_cleanup(PsPrivInfo *priv_info)
52 if (priv_info == NULL)
55 /* Cleaning up the master list */
56 g_slist_foreach(priv_info->master,
57 __remove_master, NULL);
59 /* Unowning the Gdbus */
60 g_bus_unown_name(priv_info->bus_id);
62 /* Free GDBusConnection */
63 g_object_unref(priv_info->conn);
66 * Freeing the memory allocated to the
67 * custom data for Packet Service
72 static void on_bus_acquired(GDBusConnection *conn,
73 const gchar *name, gpointer user_data)
76 ps_master_t *master = NULL;
78 TcorePlugin *p = user_data;
79 PsPrivInfo *priv_info = tcore_plugin_ref_user_data(p);
81 info("Bus is acquired: [%s]", name);
84 err("Failed to get 'plugin->user_data' Object for Packet Service");
91 master = _ps_master_create_master(conn, p);
93 err("Failed to create 'master' Object for Packet Service");
97 priv_info->master = g_slist_append(priv_info->master, master);
100 * Create and initialize 'modem(s)'
102 rv = _ps_master_create_modems(master, NULL);
104 err("Failure : Modem creation Failed ");
108 info("Packet Service plugin initialization: [Successful]");
117 * Packet service initializer
119 gboolean ps_main_init(TcorePlugin *p)
121 PsPrivInfo *priv_info = NULL;
122 GDBusConnection *conn = NULL;
123 gchar *address = NULL;
126 GError *error = NULL;
135 rv = _ps_context_initialize(p);
137 err("Failure : Initialize context global variable");
142 * Memory allocation for private information
144 priv_info = g_try_malloc0(sizeof(PsPrivInfo));
146 err("Failure :Memory allocation !!");
150 address = g_dbus_address_get_for_bus_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
151 g_assert_no_error(error);
153 conn = g_dbus_connection_new_for_address_sync(address,
154 G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT |
155 G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION,
159 g_assert_no_error(error);
161 err("Failure: G-dBus Connection failed"); /* TODO - Clean-up */
164 * Storing the G-dBus connection in Private information of PS Plugin
166 priv_info->conn = conn;
168 id = g_bus_own_name_on_connection(conn,
170 G_BUS_NAME_OWNER_FLAGS_REPLACE,
176 info("PacketService - dBus address: [%s] dBus connection ID: [%d]",
181 * Initializing custom data for Packet Service
183 priv_info->bus_id = id;
184 priv_info->master = NULL;
188 * Setting User data of PS plugin
190 tcore_plugin_link_user_data(p, (void *)priv_info);
196 * Packet service de-initializer
198 void ps_main_exit(TcorePlugin *p)
200 PsPrivInfo *priv_info = tcore_plugin_ref_user_data(p);
203 * Clean-up Packet Service
205 __packet_service_cleanup(priv_info);
206 tcore_plugin_link_user_data(p, NULL);
208 dbg("Packet Service exited!! ");