Ejemplo n.º 1
0
int main(int argc, char *argv[])
{
	GDBusClient *client;
	int status;

	bt_shell_init(argc, argv, NULL);
	bt_shell_set_menu(&main_menu);
	bt_shell_set_prompt(PROMPT_OFF);

	dbus_conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, NULL, NULL);

	client = g_dbus_client_new(dbus_conn, "org.bluez", "/org/bluez");

	g_dbus_client_set_connect_watch(client, connect_handler, NULL);
	g_dbus_client_set_disconnect_watch(client, disconnect_handler, NULL);

	g_dbus_client_set_proxy_handlers(client, proxy_added, proxy_removed,
							property_changed, NULL);

	status = bt_shell_run();

	g_dbus_client_unref(client);

	dbus_connection_unref(dbus_conn);

	return status;
}
Ejemplo n.º 2
0
static void get_managed_objects_reply(DBusPendingCall *call, void *user_data)
{
	GDBusClient *client = user_data;
	DBusMessage *reply = dbus_pending_call_steal_reply(call);
	DBusError error;

	g_dbus_client_ref(client);

	dbus_error_init(&error);

	if (dbus_set_error_from_message(&error, reply) == TRUE) {
		dbus_error_free(&error);
		goto done;
	}

	parse_managed_objects(client, reply);

done:
	if (client->ready)
		client->ready(client, client->ready_data);

	dbus_message_unref(reply);

	dbus_pending_call_unref(client->get_objects_call);
	client->get_objects_call = NULL;

	g_dbus_client_unref(client);
}
Ejemplo n.º 3
0
int main(int argc, char *argv[])
{
	GDBusClient *client;
	guint signal;

	signal = setup_signalfd();
	if (signal == 0)
		return -errno;

	connection = g_dbus_setup_bus(DBUS_BUS_SYSTEM, NULL, NULL);

	main_loop = g_main_loop_new(NULL, FALSE);

	g_dbus_attach_object_manager(connection);

	printf("gatt-service unique name: %s\n",
				dbus_bus_get_unique_name(connection));

	create_services();

	client = g_dbus_client_new(connection, "org.bluez", "/org/bluez");

	g_dbus_client_set_connect_watch(client, connect_handler, NULL);

	g_main_loop_run(main_loop);

	g_dbus_client_unref(client);

	g_source_remove(signal);

	g_slist_free_full(services, g_free);
	dbus_connection_unref(connection);

	return 0;
}
Ejemplo n.º 4
0
static void get_all_properties_reply(DBusPendingCall *call, void *user_data)
{
	GDBusProxy *proxy = user_data;
	GDBusClient *client = proxy->client;
	DBusMessage *reply = dbus_pending_call_steal_reply(call);
	DBusMessageIter iter;
	DBusError error;

	dbus_error_init(&error);

	if (dbus_set_error_from_message(&error, reply) == TRUE) {
		dbus_error_free(&error);
		goto done;
	}

	dbus_message_iter_init(reply, &iter);

	update_properties(proxy, &iter, FALSE);

done:
	if (g_list_find(client->proxy_list, proxy) == NULL) {
		if (client->proxy_added)
			client->proxy_added(proxy, client->user_data);

		client->proxy_list = g_list_append(client->proxy_list, proxy);
	}

	dbus_message_unref(reply);

	g_dbus_client_unref(client);
}
Ejemplo n.º 5
0
static gboolean interfaces_removed(DBusConnection *conn, DBusMessage *msg,
							void *user_data)
{
	GDBusClient *client = user_data;
	DBusMessageIter iter, entry;
	const char *path;

	if (dbus_message_iter_init(msg, &iter) == FALSE)
		return TRUE;

	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_OBJECT_PATH)
		return TRUE;

	dbus_message_iter_get_basic(&iter, &path);
	dbus_message_iter_next(&iter);

	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY)
		return TRUE;

	dbus_message_iter_recurse(&iter, &entry);

	g_dbus_client_ref(client);

	while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
		const char *interface;

		dbus_message_iter_get_basic(&entry, &interface);
		proxy_remove(client, path, interface);
		dbus_message_iter_next(&entry);
	}

	g_dbus_client_unref(client);

	return TRUE;
}
Ejemplo n.º 6
0
static int bluetooth_init(void)
{
	connection = connman_dbus_get_connection();
	if (!connection)
		goto out;

	if (connman_technology_driver_register(&tech_driver) < 0) {
		connman_warn("Failed to initialize technology for Bluez 5");
		goto out;
	}

	devices = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
			device_free);

	if (connman_device_driver_register(&device_driver) < 0) {
		connman_warn("Failed to initialize device driver for "
				BLUEZ_SERVICE);
		connman_technology_driver_unregister(&tech_driver);
		goto out;
	}

	if (connman_network_driver_register(&network_driver) < 0) {
		connman_technology_driver_unregister(&tech_driver);
		connman_device_driver_unregister(&device_driver);
		goto out;
	}

	networks = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
			pan_free);

	client = g_dbus_client_new(connection, BLUEZ_SERVICE, BLUEZ_PATH);
	if (!client) {
		connman_warn("Failed to initialize D-Bus client for "
				BLUEZ_SERVICE);
		goto out;
	}

	g_dbus_client_set_proxy_handlers(client, object_added, object_removed,
			NULL, NULL);

	return 0;

out:
	if (networks)
		g_hash_table_destroy(networks);

	if (devices)
		g_hash_table_destroy(devices);

	if (client)
		g_dbus_client_unref(client);

	if (connection)
		dbus_connection_unref(connection);

	return -EIO;
}
Ejemplo n.º 7
0
static void service_connect(DBusConnection *conn, void *user_data)
{
	GDBusClient *client = user_data;

	g_dbus_client_ref(client);

	if (client->connect_func)
		client->connect_func(conn, client->connect_data);

	get_managed_objects(client);

	g_dbus_client_unref(client);
}
Ejemplo n.º 8
0
static void hfp_exit(void)
{
	DBusConnection *conn = ofono_dbus_get_connection();

	bt_unregister_profile(conn, HFP_EXT_PROFILE_PATH);
	g_dbus_unregister_interface(conn, HFP_EXT_PROFILE_PATH,
						BLUEZ_PROFILE_INTERFACE);

	ofono_handsfree_card_driver_unregister(&hfp16_hf_driver);

	ofono_modem_driver_unregister(&hfp_driver);
	g_dbus_client_unref(bluez);

	ofono_handsfree_audio_unref();
}
Ejemplo n.º 9
0
int main(int argc, char *argv[])
{
	GOptionContext *context;
	GError *error = NULL;
	DBusConnection *dbus_conn;
	GDBusClient *client;
	guint signal;

	context = g_option_context_new(NULL);
	g_option_context_add_main_entries(context, options, NULL);

	if (g_option_context_parse(context, &argc, &argv, &error) == FALSE) {
		if (error != NULL) {
			g_printerr("%s\n", error->message);
			g_error_free(error);
		} else
			g_printerr("An unknown error occurred\n");
		exit(1);
	}

	g_option_context_free(context);

	if (option_version == TRUE) {
		g_print("%s\n", VERSION);
		exit(0);
	}

	main_loop = g_main_loop_new(NULL, FALSE);
	dbus_conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, NULL, NULL);

	signal = setup_signalfd();

	client = g_dbus_client_new(dbus_conn, "org.bluez", "/org/bluez");

	g_dbus_client_set_connect_watch(client, connect_handler, client);
	g_dbus_client_set_disconnect_watch(client, disconnect_handler, NULL);

	g_main_loop_run(main_loop);

	g_dbus_client_unref(client);

	g_source_remove(signal);

	dbus_connection_unref(dbus_conn);
	g_main_loop_unref(main_loop);

	return 0;
}
Ejemplo n.º 10
0
static void external_app_watch_destroy(gpointer user_data)
{
	struct external_app *eapp = user_data;

	/* TODO: Remove from the database */

	external_apps = g_slist_remove(external_apps, eapp);

	g_dbus_client_unref(eapp->client);
	if (eapp->reg)
		dbus_message_unref(eapp->reg);

	g_free(eapp->owner);
	g_free(eapp->path);
	g_free(eapp);
}
Ejemplo n.º 11
0
static void bluetooth_exit(void)
{
	/*
	 * We unset the disabling of the Bluetooth device when shutting down
	 * so that non-PAN BT connections are not affected.
	 */
	device_driver.disable = NULL;

	g_dbus_client_unref(client);

	connman_network_driver_unregister(&network_driver);
	g_hash_table_destroy(networks);

	connman_device_driver_unregister(&device_driver);
	g_hash_table_destroy(devices);

	connman_technology_driver_unregister(&tech_driver);
	dbus_connection_unref(connection);
}
Ejemplo n.º 12
0
static void advertisement_free(void *data)
{
	struct advertisement *ad = data;

	if (ad->client) {
		g_dbus_client_set_disconnect_watch(ad->client, NULL, NULL);
		g_dbus_client_unref(ad->client);
	}

	bt_ad_unref(ad->data);

	g_dbus_proxy_unref(ad->proxy);

	if (ad->owner)
		g_free(ad->owner);

	if (ad->path)
		g_free(ad->path);

	free(ad);
}
Ejemplo n.º 13
0
static void qmi_exit(void)
{
	DBG("");

	/* Remove all watching signals */
	g_dbus_remove_watch(connection, watch_service);
	g_dbus_remove_watch(connection, watch_property_changed);
	g_dbus_remove_watch(connection, watch_state_changed);
	g_dbus_remove_watch(connection, watch_technology_changed);

	/* Close all opened qmi devices, do this before unref all D-Bus connections */
	if(qmi_hash) {

		g_hash_table_foreach(qmi_hash, close_modem, NULL);

	}

	qmi_service_connected = FALSE;

	/* Unregister all drivers */
	connman_device_driver_unregister(&qmi_driver);
	connman_network_driver_unregister(&network_driver);
	connman_technology_driver_unregister(&tech_driver);

	g_dbus_proxy_unref(qmi_proxy_manager);
	g_dbus_client_unref(qmi_client);
	dbus_connection_unref(connection);

	sem_post(&new_device_sem);
	pthread_join(init_modems_id, NULL);
	sem_destroy(&new_device_sem);

	/* Free all devices and its allocated memory */
	if(qmi_hash) {

		g_hash_table_destroy(qmi_hash);
		qmi_hash = NULL;
	}

}
Ejemplo n.º 14
0
static gboolean interfaces_added(DBusConnection *conn, DBusMessage *msg,
							void *user_data)
{
	GDBusClient *client = user_data;
	DBusMessageIter iter;
	const char *path;

	if (dbus_message_iter_init(msg, &iter) == FALSE)
		return TRUE;

	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_OBJECT_PATH)
		return TRUE;

	dbus_message_iter_get_basic(&iter, &path);
	dbus_message_iter_next(&iter);

	g_dbus_client_ref(client);

	parse_interfaces(client, path, &iter);

	g_dbus_client_unref(client);

	return TRUE;
}
Ejemplo n.º 15
0
static int qmi_init(void)
{
	int err = 0;

	DBG("");

	err = sem_init(&new_device_sem, 0, 0);
	if(err == -1) {

		connman_error("Failure init semaphore, error %d", errno);
		return -errno;
	}

	/* Create new hash table to store all connecting devices */
	qmi_hash = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, free_hash_values);
	if(qmi_hash == NULL) {

		connman_error("Hash table could not be created.");
		return -ENOMEM;
	}

	connection = connman_dbus_get_connection();
	if(connection == NULL) {

		connman_error("D-Bus connection failed");
		return -EIO;
	}

	/* Create new D-Bus client to address qmi-dbus server */
	qmi_client = g_dbus_client_new(	connection,
									QMI_SERVICE,
									QMI_PATH);
	if(qmi_client == NULL) {

		connman_error("D-Bus client not created");
		return -EIO;
	}

	/* Create new proxy client to address qmi-dbus manager interface */
	qmi_proxy_manager = g_dbus_proxy_new(	qmi_client,
											QMI_MANAGER_PATH,
											QMI_MANAGER_INTERFACE);

	if(qmi_proxy_manager == NULL) {

		connman_error("QMI proxy manager not created");
		g_dbus_client_unref(qmi_client);
		return -EIO;
	}

	/* Watch appearing qmi-dbus */
	watch_service = g_dbus_add_service_watch(	connection,
												QMI_SERVICE,
												on_handle_qmi_connect,
												on_handle_qmi_disconnect,
												NULL, NULL);

	/* Watching qmi-dbus signals */
	watch_property_changed = g_dbus_add_signal_watch(	connection,
														QMI_SERVICE, NULL,
														QMI_DEVICE_INTERFACE, PROPERTY_CHANGED,
														on_handle_property_changed,
														NULL, NULL);

	watch_state_changed = g_dbus_add_signal_watch(	connection,
													QMI_SERVICE, NULL,
													QMI_DEVICE_INTERFACE, STATE_CHANGED,
													on_handle_state_changed,
													NULL, NULL);

	watch_technology_changed = g_dbus_add_signal_watch(	connection,
														QMI_SERVICE, NULL,
														QMI_DEVICE_INTERFACE, TECHNOLOGY_CHANGED,
														on_handle_technology_changed,
														NULL, NULL);


	if((watch_service == 0) ||
		(watch_property_changed == 0) ||
		(watch_state_changed == 0) ||
		(watch_technology_changed == 0))	{

		connman_error("Adding service or signal watch");
		err = -EIO;
		goto remove;
	}

	err = connman_network_driver_register(&network_driver);
	if(err < 0) {

		connman_error("Register network driver");
		goto remove;
	}

	err = connman_device_driver_register(&qmi_driver);
	if(err < 0) {

		connman_error("Register device driver");
		connman_network_driver_unregister(&network_driver);
		goto remove;
	}

	err = connman_technology_driver_register(&tech_driver);
	if(err < 0) {

		connman_error("Register technology driver");
		connman_network_driver_unregister(&network_driver);
		connman_device_driver_unregister(&qmi_driver);
		goto remove;
	}

	return 0;

remove:

	g_dbus_remove_watch(connection, watch_service);
	g_dbus_remove_watch(connection, watch_property_changed);
	g_dbus_remove_watch(connection, watch_state_changed);
	g_dbus_remove_watch(connection, watch_technology_changed);
	g_dbus_proxy_unref(qmi_proxy_manager);
	g_dbus_client_unref(qmi_client);
	dbus_connection_unref(connection);

	return err;
}