Beispiel #1
0
static void create_modem(DBusConnection *conn,
				const char *path, DBusMessageIter *iter)
{
	struct modem_data *modem;
	DBusMessageIter dict;

	modem = g_try_new0(struct modem_data, 1);
	if (modem == NULL)
		return;

	modem->path = g_strdup(path);

	modem->format = AFMT_S16_LE;
	modem->channels = 1;
	modem->speed = 8000;
	modem->dsp_out = -1;

	modem->call_list = g_hash_table_new_full(g_str_hash, g_str_equal,
							NULL, destroy_call);

	modem->conn = conn;

	modem->call_added_watch = g_dbus_add_signal_watch(conn, NULL,
				modem->path, OFONO_CALLMANAGER_INTERFACE,
				"CallAdded", call_added, modem, NULL);
	modem->call_removed_watch = g_dbus_add_signal_watch(conn, NULL,
				modem->path, OFONO_CALLMANAGER_INTERFACE,
				"CallRemoved", call_removed, modem, NULL);
	modem->call_changed_watch = g_dbus_add_signal_watch(conn, NULL,
				NULL, OFONO_CALL_INTERFACE,
				"PropertyChanged", call_changed, modem, NULL);
	modem->audio_changed_watch = g_dbus_add_signal_watch(conn, NULL,
				NULL, OFONO_AUDIO_INTERFACE,
				"PropertyChanged", audio_changed, modem, NULL);

	g_hash_table_replace(modem_list, modem->path, modem);

	g_print("modem added (%s)\n", modem->path);

	dbus_message_iter_recurse(iter, &dict);

	while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
		DBusMessageIter entry, value;
		const char *key;

		dbus_message_iter_recurse(&dict, &entry);
		dbus_message_iter_get_basic(&entry, &key);

		dbus_message_iter_next(&entry);
		dbus_message_iter_recurse(&entry, &value);

		if (g_str_equal(key, "Interfaces") == TRUE)
			check_interfaces(modem, &value);
		else if (g_str_equal(key, "Manufacturer") == TRUE)
			check_manufacturer(modem, &value);

		dbus_message_iter_next(&dict);
	}
}
GDBusClient *g_dbus_client_new(DBusConnection *connection,
					const char *service, const char *path)
{
	GDBusClient *client;
	unsigned int i;

	if (connection == NULL)
		return NULL;

	client = g_try_new0(GDBusClient, 1);
	if (client == NULL)
		return NULL;

	if (dbus_connection_add_filter(connection, message_filter,
						client, NULL) == FALSE) {
		g_free(client);
		return NULL;
	}

	client->dbus_conn = dbus_connection_ref(connection);
	client->service_name = g_strdup(service);
	client->base_path = g_strdup(path);

	client->match_rules = g_ptr_array_sized_new(1);
	g_ptr_array_set_free_func(client->match_rules, g_free);

	client->watch = g_dbus_add_service_watch(connection, service,
						service_connect,
						service_disconnect,
						client, NULL);
	client->added_watch = g_dbus_add_signal_watch(connection, service,
						"/",
						DBUS_INTERFACE_OBJECT_MANAGER,
						"InterfacesAdded",
						interfaces_added,
						client, NULL);
	client->removed_watch = g_dbus_add_signal_watch(connection, service,
						"/",
						DBUS_INTERFACE_OBJECT_MANAGER,
						"InterfacesRemoved",
						interfaces_removed,
						client, NULL);
	g_ptr_array_add(client->match_rules, g_strdup_printf("type='signal',"
				"sender='%s',path_namespace='%s'",
				client->service_name, client->base_path));

	for (i = 0; i < client->match_rules->len; i++) {
		modify_match(client->dbus_conn, "AddMatch",
				g_ptr_array_index(client->match_rules, i));
	}

	return g_dbus_client_ref(client);
}
Beispiel #3
0
static int mce_probe(struct btd_adapter *adapter)
{
	DBusMessage *msg;
	DBusPendingCall *call;

	DBG("path %s", adapter_get_path(adapter));

	msg = dbus_message_new_method_call(MCE_SERVICE, MCE_REQUEST_PATH,
					MCE_REQUEST_IF, MCE_RADIO_STATES_GET);

	if (!dbus_connection_send_with_reply(conn, msg, &call, -1)) {
		error("calling %s failed", MCE_RADIO_STATES_GET);
		dbus_message_unref(msg);
		return -1;
	}

	dbus_pending_call_set_notify(call, read_radio_states_cb, adapter, NULL);
	dbus_pending_call_unref(call);
	dbus_message_unref(msg);

	watch_id = g_dbus_add_signal_watch(conn, NULL, MCE_SIGNAL_PATH,
					MCE_SIGNAL_IF, MCE_RADIO_STATES_SIG,
					mce_signal_callback, adapter, NULL);
	return 0;
}
static void update_or_create_service(const char *obj_path,
					DBusMessageIter *dict)
{
	struct connman_service *service;

	if (service_if == NULL)
		return;

	service = get_service(obj_path);
	if (service == NULL) {
		service = g_try_malloc0(sizeof(struct connman_service));
		if (service == NULL)
			return;

		service->path = g_strdup(obj_path);

		g_hash_table_insert(service_if->services,
					service->path, service);

		service->property_changed_wid = g_dbus_add_signal_watch(
						service_if->dbus_cnx,
						CONNMAN_DBUS_NAME,
						service->path,
						CONNMAN_SERVICE_INTERFACE,
						"PropertyChanged",
						property_changed_signal_cb,
						service, NULL);
	}

	service_if->ordered_services = g_slist_append(
				service_if->ordered_services, service->path);

	cui_dbus_foreach_dict_entry(dict, update_service_property, service);
}
Beispiel #5
0
static int jolla_gps_init()
{
    DBG("");

    connection = connman_dbus_get_connection();
    if (connection == NULL) {
        connman_warn("Failed to get dbus connection");
        return -EIO;
    }

    watch = g_dbus_add_service_watch(connection, JOLLA_SERVICE, jolla_gps_connect,
                                     jolla_gps_disconnect, NULL, NULL);
    if (watch == 0) {
        connman_warn("Failed to add jolla service watcher");
        dbus_connection_unref(connection);
        return -EIO;
    }

    device_watch = g_dbus_add_signal_watch(connection, JOLLA_SERVICE, JOLLA_DEVICE_PATH,
                                           JOLLA_DEVICE_INTERFACE, PROPERTY_CHANGED,
                                           device_changed, NULL, NULL);
    if (device_watch == 0) {
        connman_warn("Failed to add jolla device property changed signal watcher");
        g_dbus_remove_watch(connection, watch);
        dbus_connection_unref(connection);
        return -EIO;
    }

    if (connman_technology_driver_register(&tech_driver) < 0) {
        connman_warn("Failed to initialize technology for Jolla GPS");
        g_dbus_remove_watch(connection, device_watch);
        g_dbus_remove_watch(connection, watch);
        dbus_connection_unref(connection);
        return -EIO;
    }

    if (connman_device_driver_register(&device_driver) < 0) {
        connman_warn("Failed to initialize device driver for " JOLLA_SERVICE);
        connman_technology_driver_unregister(&tech_driver);
        g_dbus_remove_watch(connection, device_watch);
        g_dbus_remove_watch(connection, watch);
        dbus_connection_unref(connection);
        return -EIO;
    }

    jolla_gps_device = connman_device_create("gps", CONNMAN_DEVICE_TYPE_GPS);
    if (jolla_gps_device == NULL) {
        connman_warn("Failed to creat GPS device");
        return -ENODEV;
    }

    if (connman_device_register(jolla_gps_device) < 0) {
        connman_warn("Failed to register GPS device");
        connman_device_unref(jolla_gps_device);
        jolla_gps_device = NULL;
        return -EIO;
    }

    return 0;
}
Beispiel #6
0
static void mce_connect(DBusConnection *conn, void *user_data)
{
	DBG("");
	signal_watch = g_dbus_add_signal_watch(conn,
						MCE_SERVICE, NULL,
						MCE_SIGNAL_IF,
						MCE_DISPLAY_SIG,
						display_changed,
						user_data, NULL);
}
Beispiel #7
0
static void ofono_connect(DBusConnection *conn, void *user_data)
{
	g_print("starting telephony interface\n");

	ofono_running = TRUE;

	modem_list = g_hash_table_new_full(g_str_hash, g_str_equal,
						NULL, destroy_modem);

	modem_added_watch = g_dbus_add_signal_watch(conn, NULL, NULL,
				OFONO_MANAGER_INTERFACE, "ModemAdded",
						modem_added, NULL, NULL);
	modem_removed_watch = g_dbus_add_signal_watch(conn, NULL, NULL,
				OFONO_MANAGER_INTERFACE, "ModemRemoved",
						modem_removed, NULL, NULL);
	modem_changed_watch = g_dbus_add_signal_watch(conn, NULL, NULL,
				OFONO_MODEM_INTERFACE, "PropertyChanged",
						modem_changed, NULL, NULL);

	get_modems(conn);
}
Beispiel #8
0
static void *usb_start(struct obex_server *server, int *err)
{
    guint id;

    id = g_dbus_add_signal_watch(connection, NULL, NULL,
                                 "com.meego.usb_moded",
                                 "sig_usb_state_ind",
                                 handle_signal, server, NULL);
    if (err != NULL)
        *err = 0;

    return GUINT_TO_POINTER(id);
}
Beispiel #9
0
static void connect_cb(DBusPendingCall *call, void *user_data)
{
	struct synce_context *context = user_data;
	DBusConnection *conn;
	DBusMessage *reply;
	DBusError err;
	char *path;

	conn = context->dbus_conn;

	reply = dbus_pending_call_steal_reply(call);

	dbus_error_init(&err);
	if (dbus_message_get_args(reply, &err, DBUS_TYPE_OBJECT_PATH, &path,
						DBUS_TYPE_INVALID) == FALSE) {
		error("%s", err.message);
		dbus_error_free(&err);
		goto failed;
	}

	DBG("Got conn object %s from syncevolution", path);
	context->conn_obj = g_strdup(path);

	context->reply_watch = g_dbus_add_signal_watch(conn, NULL, path,
						SYNCE_CONN_INTERFACE, "Reply",
						reply_signal, context, NULL);

	context->abort_watch = g_dbus_add_signal_watch(conn, NULL, path,
						SYNCE_CONN_INTERFACE, "Abort",
						abort_signal, context, NULL);

	dbus_message_unref(reply);

	return;

failed:
	obex_object_set_io_flags(context, G_IO_ERR, -EPERM);
	context->lasterr = -EPERM;
}
Beispiel #10
0
static struct media_player *media_player_create(struct media_adapter *adapter,
						const char *sender,
						const char *path,
						int *err)
{
	DBusConnection *conn = btd_get_dbus_connection();
	struct media_player *mp;

	mp = g_new0(struct media_player, 1);
	mp->adapter = adapter;
	mp->sender = g_strdup(sender);
	mp->path = g_strdup(path);
	mp->timer = g_timer_new();

	mp->watch = g_dbus_add_disconnect_watch(conn, sender,
						media_player_exit, mp,
						NULL);
	mp->properties_watch = g_dbus_add_properties_watch(conn, sender,
						path, MEDIA_PLAYER_INTERFACE,
						properties_changed,
						mp, NULL);
	mp->seek_watch = g_dbus_add_signal_watch(conn, sender,
						path, MEDIA_PLAYER_INTERFACE,
						"Seeked", position_changed,
						mp, NULL);
	mp->player = avrcp_register_player(adapter->btd_adapter, &player_cb,
							mp, media_player_free);
	if (!mp->player) {
		if (err)
			*err = -EPROTONOSUPPORT;
		media_player_destroy(mp);
		return NULL;
	}

	mp->settings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
								g_free);

	adapter->players = g_slist_append(adapter->players, mp);

	info("Player registered: sender=%s path=%s", sender, path);

	if (err)
		*err = 0;

	return mp;
}
Beispiel #11
0
static int tapi_init(void)
{
	int err;

	DBG("");

	connection = near_dbus_get_connection();
	if (connection == NULL)
		return -EIO;

	watch = g_dbus_add_service_watch(connection, TELEPHONY_SERVICE,
					tapi_connect, tapi_disconnect,
					NULL, NULL);

	sim_watch = g_dbus_add_signal_watch(connection, TELEPHONY_SERVICE,
					NULL, SIM_INTERFACE, SIM_STATUS,
					sim_changed, NULL, NULL);

	if (watch == 0 || sim_watch == 0) {
		err = -EIO;
		goto remove;
	}

	err = seel_io_driver_register(&tizen_io_driver);
	if (err < 0)
		goto remove;

	err = seel_cert_driver_register(&tizen_cert_driver);
	if (err < 0) {
		seel_io_driver_unregister(&tizen_io_driver);
		goto remove;
	}

	return 0;

remove:
	g_dbus_remove_watch(connection, watch);
	g_dbus_remove_watch(connection, sim_watch);

	dbus_connection_unref(connection);

	return err;
}
Beispiel #12
0
static void *usb_start(struct obex_server *server, int *err)
{
	guint id;
	DBusMessage *msg;
	DBusPendingCall *call;

	msg = dbus_message_new_method_call("com.meego.usb_moded",
						"/com/meego/usb_moded",
						"com.meego.usb_moded",
						"mode_request");

	if (dbus_connection_send_with_reply(connection,
					msg, &call, -1) == FALSE) {
		error("usb: unable to send mode_request");
		dbus_message_unref(msg);
		goto fail;
	}

	dbus_pending_call_set_notify(call, mode_request_reply, server, NULL);
	dbus_pending_call_unref(call);
	dbus_message_unref(msg);

	id = g_dbus_add_signal_watch(connection, NULL, NULL,
					"com.meego.usb_moded",
					"sig_usb_state_ind",
					handle_signal, server, NULL);

	if (err != NULL)
		*err = 0;

	return GUINT_TO_POINTER(id);

fail:
	if (err != NULL)
		*err = -1;

	return NULL;
}
gboolean g_dbus_set_disconnect_function(DBusConnection *connection,
				GDBusWatchFunction function,
				void *user_data, DBusFreeFunction destroy)
{
	struct disconnect_data *dc_data;

	dc_data = g_new0(struct disconnect_data, 1);

	dc_data->function = function;
	dc_data->user_data = user_data;

	dbus_connection_set_exit_on_disconnect(connection, FALSE);

	if (g_dbus_add_signal_watch(connection, NULL, NULL,
				DBUS_INTERFACE_LOCAL, "Disconnected",
				disconnected_signal, dc_data, g_free) == 0) {
		error("Failed to add watch for D-Bus Disconnected signal");
		g_free(dc_data);
		return FALSE;
	}

	return TRUE;
}
static void get_user_settings(struct accounts_data *accounts)
{
	DBusConnection *conn = ofono_dbus_get_connection();
	size_t i;

	snprintf(accounts->uid_path, sizeof(accounts->uid_path),
			ACCOUNTS_PATH"%u", (unsigned) accounts->current_uid);

	/*
	 * Register for property changes. Note that AccountsService is D-Bus,
	 * initiated, so there is no risk for race conditions on start.
	 */
	accounts->prop_change_watch =
		g_dbus_add_signal_watch(conn, ACCOUNTS_SERVICE,
						accounts->uid_path,
						DBUS_INTERFACE_PROPERTIES,
						"PropertiesChanged",
						property_changed,
						accounts, NULL);

	/* Retrieve AccountService properties */
	for (i = 0; i < NUM_SETTINGS; ++i)
		get_property(accounts, i);
}
Beispiel #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;
}
Beispiel #16
0
static int bluetooth_init(void)
{
	int err;

	connection = connman_dbus_get_connection();
	if (connection == NULL)
		return -EIO;

	watch = g_dbus_add_service_watch(connection, BLUEZ_SERVICE,
			bluetooth_connect, bluetooth_disconnect, NULL, NULL);

	added_watch = g_dbus_add_signal_watch(connection, BLUEZ_SERVICE, NULL,
						BLUEZ_MANAGER_INTERFACE,
						ADAPTER_ADDED, adapter_added,
						NULL, NULL);

	removed_watch = g_dbus_add_signal_watch(connection, BLUEZ_SERVICE, NULL,
						BLUEZ_MANAGER_INTERFACE,
						ADAPTER_REMOVED, adapter_removed,
						NULL, NULL);

	adapter_watch = g_dbus_add_signal_watch(connection, BLUEZ_SERVICE,
						NULL, BLUEZ_ADAPTER_INTERFACE,
						PROPERTY_CHANGED, adapter_changed,
						NULL, NULL);

	device_removed_watch = g_dbus_add_signal_watch(connection,
						BLUEZ_SERVICE, NULL,
						BLUEZ_ADAPTER_INTERFACE,
						DEVICE_REMOVED, device_removed,
						NULL, NULL);

	device_watch = g_dbus_add_signal_watch(connection, BLUEZ_SERVICE, NULL,
						BLUEZ_DEVICE_INTERFACE,
						PROPERTY_CHANGED, device_changed,
						NULL, NULL);

	network_watch = g_dbus_add_signal_watch(connection, BLUEZ_SERVICE,
						NULL, BLUEZ_NETWORK_INTERFACE,
						PROPERTY_CHANGED, network_changed,
						NULL, NULL);

	if (watch == 0 || added_watch == 0 || removed_watch == 0
			|| adapter_watch == 0 || network_watch == 0
				|| device_watch == 0
					|| device_removed_watch == 0) {
		err = -EIO;
		goto remove;
	}

	err = connman_network_driver_register(&pan_driver);
	if (err < 0)
		goto remove;

	err = connman_device_driver_register(&bluetooth_driver);
	if (err < 0) {
		connman_network_driver_unregister(&pan_driver);
		goto remove;
	}

	err = connman_technology_driver_register(&tech_driver);
	if (err < 0) {
		connman_device_driver_unregister(&bluetooth_driver);
		connman_network_driver_unregister(&pan_driver);
		goto remove;
	}

	return 0;

remove:
	g_dbus_remove_watch(connection, watch);
	g_dbus_remove_watch(connection, added_watch);
	g_dbus_remove_watch(connection, removed_watch);
	g_dbus_remove_watch(connection, adapter_watch);
	g_dbus_remove_watch(connection, device_removed_watch);
	g_dbus_remove_watch(connection, device_watch);
	g_dbus_remove_watch(connection, network_watch);

	dbus_connection_unref(connection);

	return err;
}