QBluetoothDeviceDiscoveryAgentPrivate::QBluetoothDeviceDiscoveryAgentPrivate(
    const QBluetoothAddress &deviceAdapter, QBluetoothDeviceDiscoveryAgent *parent) :
    lastError(QBluetoothDeviceDiscoveryAgent::NoError),
    m_adapterAddress(deviceAdapter),
    pendingCancel(false),
    pendingStart(false),
    manager(0),
    adapter(0),
    managerBluez5(0),
    adapterBluez5(0),
    discoveryTimer(0),
    useExtendedDiscovery(false),
    q_ptr(parent)
{
    Q_Q(QBluetoothDeviceDiscoveryAgent);
    if (isBluez5()) {
        managerBluez5 = new OrgFreedesktopDBusObjectManagerInterface(
                                           QStringLiteral("org.bluez"),
                                           QStringLiteral("/"),
                                           QDBusConnection::systemBus(), parent);
        QObject::connect(managerBluez5,
                         SIGNAL(InterfacesAdded(QDBusObjectPath,InterfaceList)),
                         q, SLOT(_q_InterfacesAdded(QDBusObjectPath,InterfaceList)));

    } else {
        manager = new OrgBluezManagerInterface(QStringLiteral("org.bluez"), QStringLiteral("/"),
                                           QDBusConnection::systemBus(), parent);
        QObject::connect(&extendedDiscoveryTimer,
                         SIGNAL(timeout()),
                         q, SLOT(_q_extendedDeviceDiscoveryTimeout()));
        extendedDiscoveryTimer.setInterval(10000);
        extendedDiscoveryTimer.setSingleShot(true);
    }
    inquiryType = QBluetoothDeviceDiscoveryAgent::GeneralUnlimitedInquiry;
}
QtBluezDiscoveryManager *QtBluezDiscoveryManager::instance()
{
    if (isBluez5())
        return discoveryManager();

    Q_ASSERT(false);
    return 0;
}
QBluetoothTransferReplyBluez::QBluetoothTransferReplyBluez(QIODevice *input, const QBluetoothTransferRequest &request,
                                                           QBluetoothTransferManager *parent)
:   QBluetoothTransferReply(parent),
    m_client(0), m_agent(0), m_clientBluez(0), m_objectPushBluez(0),
    m_tempfile(0), m_source(input),
    m_running(false), m_finished(false), m_size(0),
    m_error(QBluetoothTransferReply::NoError), m_errorStr(), m_transfer_path()
{
    setRequest(request);
    setManager(parent);

    if (!input) {
        qCWarning(QT_BT_BLUEZ) << "Invalid input device (null)";
        m_errorStr = QBluetoothTransferReply::tr("Invalid input device (null)");
        m_error = QBluetoothTransferReply::FileNotFoundError;
        m_finished = true;
        return;
    }

    if (isBluez5()) {
        m_clientBluez = new OrgBluezObexClient1Interface(QStringLiteral("org.bluez.obex"),
                                                        QStringLiteral("/org/bluez/obex"),
                                                        QDBusConnection::sessionBus(), this);


    } else {
        m_client = new OrgOpenobexClientInterface(QStringLiteral("org.openobex.client"),
                                                  QStringLiteral("/"),
                                                  QDBusConnection::sessionBus());

        m_agent_path = agentPath;
        m_agent_path.append(QStringLiteral("/%1%2/%3").
                            arg(QCoreApplication::applicationName()).
                            arg(QCoreApplication::applicationPid()).
                            arg(agentPathCounter.fetchAndAddOrdered(1)));

        m_agent = new AgentAdaptor(this);

        if (!QDBusConnection::sessionBus().registerObject(m_agent_path, this))
            qCWarning(QT_BT_BLUEZ) << "Failed creating obex agent dbus objects";
    }

    QMetaObject::invokeMethod(this, "start", Qt::QueuedConnection);
    m_running = true;
}