diff --git a/profiles/sap/main.c b/profiles/sap/main.c
index c9c90bd..4894f2e 100644
--- a/profiles/sap/main.c
+++ b/profiles/sap/main.c
#include "plugin.h"
#include "manager.h"
-static DBusConnection *connection;
-
static int sap_init(void)
{
- connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
-
- if (!connection)
- return -EIO;
-
- if (sap_manager_init(connection) < 0) {
- dbus_connection_unref(connection);
- return -EIO;
- }
-
- return 0;
+ return sap_manager_init();
}
static void sap_exit(void)
{
sap_manager_exit();
-
- dbus_connection_unref(connection);
}
BLUETOOTH_PLUGIN_DEFINE(sap, VERSION,
diff --git a/profiles/sap/manager.c b/profiles/sap/manager.c
index ecf672e..ebfe266 100644
--- a/profiles/sap/manager.c
+++ b/profiles/sap/manager.c
#include "manager.h"
#include "server.h"
-static DBusConnection *connection = NULL;
-
static int sap_server_probe(struct btd_adapter *adapter)
{
const char *path = adapter_get_path(adapter);
.adapter_remove = sap_server_remove,
};
-int sap_manager_init(DBusConnection *conn)
+int sap_manager_init(void)
{
- connection = dbus_connection_ref(conn);
-
- if (sap_server_init(connection) < 0) {
- error("Can't init SAP server");
- dbus_connection_unref(conn);
- return -1;
- }
-
btd_profile_register(&sap_profile);
return 0;
void sap_manager_exit(void)
{
btd_profile_unregister(&sap_profile);
-
- dbus_connection_unref(connection);
- connection = NULL;
-
- sap_server_exit();
}
diff --git a/profiles/sap/manager.h b/profiles/sap/manager.h
index e08c882..6601a03 100644
--- a/profiles/sap/manager.h
+++ b/profiles/sap/manager.h
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-int sap_manager_init(DBusConnection *conn);
+int sap_manager_init(void);
void sap_manager_exit(void);
diff --git a/profiles/sap/sap-dummy.c b/profiles/sap/sap-dummy.c
index dab5acc..36354b8 100644
--- a/profiles/sap/sap-dummy.c
+++ b/profiles/sap/sap-dummy.c
#include <glib.h>
#include <gdbus.h>
+#include <stdint.h>
+#include "dbus-common.h"
#include "log.h"
#include "sap.h"
SIM_MISSING = 0x03
};
-static DBusConnection *connection = NULL;
static unsigned int init_cnt = 0;
static int sim_card_conn_status = SIM_DISCONNECTED;
if (init_cnt++)
return 0;
- connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
-
- if (g_dbus_register_interface(connection, SAP_DUMMY_PATH,
+ if (g_dbus_register_interface(btd_get_dbus_connection(), SAP_DUMMY_PATH,
SAP_DUMMY_IFACE, dummy_methods, NULL, NULL,
NULL, NULL) == FALSE) {
error("sap-dummy interface %s init failed on path %s",
SAP_DUMMY_IFACE, SAP_DUMMY_PATH);
- if (init_cnt--) {
- dbus_connection_unref(connection);
- connection = NULL;
- }
+ init_cnt--;
return -1;
}
if (--init_cnt)
return;
- g_dbus_unregister_interface(connection, SAP_DUMMY_PATH,
- SAP_DUMMY_IFACE);
-
- dbus_connection_unref(connection);
- connection = NULL;
+ g_dbus_unregister_interface(btd_get_dbus_connection(),
+ SAP_DUMMY_PATH, SAP_DUMMY_IFACE);
}
diff --git a/profiles/sap/server.c b/profiles/sap/server.c
index fc3d83c..6c5aa21 100644
--- a/profiles/sap/server.c
+++ b/profiles/sap/server.c
struct sap_connection *conn;
};
-static DBusConnection *connection;
-
static void start_guard_timer(struct sap_server *server, guint interval);
static void stop_guard_timer(struct sap_server *server);
static gboolean guard_timeout(gpointer data);
}
server->listen_io = io;
- if (!g_dbus_register_interface(connection, server->path,
- SAP_SERVER_INTERFACE,
+ if (!g_dbus_register_interface(btd_get_dbus_connection(),
+ server->path, SAP_SERVER_INTERFACE,
server_methods, server_signals, NULL,
server, destroy_sap_interface)) {
error("D-Bus failed to register %s interface",
void sap_server_unregister(const char *path)
{
- g_dbus_unregister_interface(connection, path, SAP_SERVER_INTERFACE);
+ g_dbus_unregister_interface(btd_get_dbus_connection(),
+ path, SAP_SERVER_INTERFACE);
sap_exit();
}
-
-int sap_server_init(DBusConnection *conn)
-{
- connection = dbus_connection_ref(conn);
- return 0;
-}
-
-void sap_server_exit(void)
-{
- dbus_connection_unref(connection);
- connection = NULL;
-}
diff --git a/profiles/sap/server.h b/profiles/sap/server.h
index 6d2f5e9..9ea9a78 100644
--- a/profiles/sap/server.h
+++ b/profiles/sap/server.h
#include <gdbus.h>
-int sap_server_init(DBusConnection *conn);
-void sap_server_exit(void);
int sap_server_register(const char *path, bdaddr_t *src);
void sap_server_unregister(const char *path);