Пример #1
0
Pillow::HttpClient::HttpClient(QObject *parent)
	: QObject(parent), _responsePending(false), _error(NoError), _keepAliveTimeout(-1), _contentDecoder(0)
{
	_device = new QTcpSocket(this);
	connect(_device, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(device_error(QAbstractSocket::SocketError)));
	connect(_device, SIGNAL(connected()), this, SLOT(device_connected()));
	connect(_device, SIGNAL(readyRead()), this, SLOT(device_readyRead()));
	_requestWriter.setDevice(_device);
	_keepAliveTimeoutTimer.invalidate();
}
Пример #2
0
/**
 * Callback for org.bluez.HealthDevice.ChannelConnected signal
 * Reused by CreateChannel callback (channel initiation)
 */
static void channel_connected(DBusGProxy *proxy, const char *path, gpointer user_data)
{
	int fd;
	guint64 handle;
	device_object *dev;
	const char *device_path;

	channel_object *c = get_channel(path);
	if (c) {
		if (c->initiated_by_us && c->fd >= 0) {
			DEBUG("initiated channel already connected: %s", path);
			return;
		}
	}

	DEBUG("channel connected: %s", path);

	// Need to use non-GLib code here because GLib still does not have
	// the UNIX FD type.

	DBusMessage *msg, *reply;
	DBusError err;

	msg = dbus_message_new_method_call("org.bluez", path,
					   "org.bluez.HealthChannel", "Acquire");

	if (!msg) {
		ERROR(" network:dbus Can't allocate new method call");
		return;
	}

	dbus_error_init(&err);

	reply = dbus_connection_send_with_reply_and_block(
			dbus_g_connection_get_connection(conn),
			msg, -1, &err);

	dbus_message_unref(msg);

	if (!reply) {
		DEBUG(" network:dbus Can't acquire FD");

		if (dbus_error_is_set(&err)) {
			ERROR("%s", err.message);
			dbus_error_free(&err);
			return;
		}
	}

	if (!dbus_message_get_args(reply, &err,
				   DBUS_TYPE_UNIX_FD, &fd,
				   DBUS_TYPE_INVALID)) {
		DEBUG(" network:dbus Can't get reply arguments");

		if (dbus_error_is_set(&err)) {
			ERROR("%s", err.message);
			dbus_error_free(&err);
			dbus_message_unref(reply);
			return;
		}
	}

	dbus_message_unref(reply);

	// dbus_connection_flush(dbus_g_connection_get_connection(conn));
	DEBUG("File descriptor: %d", fd);

	device_path = dbus_g_proxy_get_path(proxy);
	handle = add_channel(path, device_path, fd, user_data != NULL);

	if (!handle) {
		// channel already known, reconnected
		// or channel is secondary
		return;
	}

	dev = get_device_object(device_path);

	if (dev) {
		device_connected(handle, dev->addr);
	} else {
		ERROR("Channel from unknown device: %s", device_path);
		device_connected(handle, device_path);
	}
}