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>
33 static void __packet_service_cleanup(PsPrivInfo *priv_info)
36 if (priv_info == NULL)
39 /* Free cynara handle */
40 if (priv_info->p_cynara) {
41 cynara_finish(priv_info->p_cynara);
42 priv_info->p_cynara = NULL;
45 /* Cleaning up the master list */
46 g_slist_foreach(priv_info->master,
47 __remove_master, NULL);
49 /* Unowning the Gdbus */
50 g_bus_unown_name(priv_info->bus_id);
52 /* Free GDBusConnection */
53 g_object_unref(priv_info->conn);
56 * Freeing the memory allocated to the
57 * custom data for Packet Service
62 static void on_bus_acquired(GDBusConnection *conn,
63 const gchar *name, gpointer user_data)
66 gpointer *master = NULL;
68 TcorePlugin *p = user_data;
69 PsPrivInfo *priv_info = tcore_plugin_ref_user_data(p);
71 dbg("Bus is acquired: [%s]", name);
76 master = _ps_master_create_master(conn, p);
78 err("Failed to create 'master' Object for Packet Service");
82 priv_info->master = g_slist_append(priv_info->master, master);
85 * Create and initialize 'modem(s)'
87 rv = _ps_master_create_modems(master, NULL);
89 dbg("Failure : Modem creation Failed ");
93 dbg("Packet Service plugin initialization: [Successful]");
101 gboolean ps_main_init(TcorePlugin *p)
103 PsPrivInfo *priv_info = NULL;
104 GDBusConnection *conn = NULL;
105 gchar *address = NULL;
108 GError *error = NULL;
110 cynara *p_cynara = NULL;
118 rv = _ps_context_initialize(p);
120 err("Failure : Initialize context global variable");
125 * Memory allocation for private information
127 priv_info = g_try_malloc0(sizeof(PsPrivInfo));
129 err("Failure :Memory allocation !!");
133 /* Initialize cynara handle */
134 if (CYNARA_API_SUCCESS == cynara_initialize(&p_cynara, NULL)) {
135 dbg("cynara handle is successfully initialized.");
137 err("Failed to initialize cynara handle.");
141 address = g_dbus_address_get_for_bus_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
142 g_assert_no_error(error);
144 conn = g_dbus_connection_new_for_address_sync(address,
145 G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT |
146 G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION,
150 g_assert_no_error(error);
152 dbg("Failure: G-dBus Connection failed"); /* TODO - Clean-up */
155 * Storing the G-dBus connection in Private information of PS Plugin
157 priv_info->conn = conn;
159 id = g_bus_own_name_on_connection(conn,
161 G_BUS_NAME_OWNER_FLAGS_REPLACE,
167 dbg("PacketService - dBus address: [%s] dBus connection ID: [%d]",
171 * Initializing custom data for Packet Service
173 priv_info->bus_id = id;
174 priv_info->master = NULL;
176 priv_info->p_cynara = p_cynara;
179 * Setting User data of PS plugin
181 tcore_plugin_link_user_data(p, (void *)priv_info);
187 * Packet service de-initializer
189 void ps_main_exit(TcorePlugin *p)
191 PsPrivInfo *priv_info = tcore_plugin_ref_user_data(p);
194 * Clean-up Packet Service
196 __packet_service_cleanup(priv_info);
197 tcore_plugin_link_user_data(p, NULL);
199 dbg("Packet Service exited!! ");