void QBluetoothTransferReplyBluez::sessionStarted(QDBusPendingCallWatcher *watcher)
{
    QDBusPendingReply<QDBusObjectPath, QVariantMap> reply = *watcher;
    if (reply.isError()) {
        qCWarning(QT_BT_BLUEZ) << "Failed to start obex session:"
                               << reply.error().name() << reply.reply().errorMessage();

        m_errorStr = QBluetoothTransferReply::tr("Push session cannot be started");
        m_error = QBluetoothTransferReply::SessionError;
        m_finished = true;
        m_running = false;

        cleanupSession();

        emit QBluetoothTransferReply::error(m_error);
        emit finished(this);

        watcher->deleteLater();
        return;
    }

    const QDBusObjectPath path = reply.argumentAt<0>();
    const QVariantMap map = reply.argumentAt<1>();
    m_transfer_path = path.path();

    //watch the transfer
    OrgFreedesktopDBusPropertiesInterface *properties = new OrgFreedesktopDBusPropertiesInterface(
                            QStringLiteral("org.bluez.obex"), path.path(),
                            QDBusConnection::sessionBus(), this);
    connect(properties, SIGNAL(PropertiesChanged(QString,QVariantMap,QStringList)),
            SLOT(sessionChanged(QString,QVariantMap,QStringList)));

    watcher->deleteLater();
}
void UIMachine::cleanup()
{
    /* Preprocess all the meta-events: */
    QApplication::sendPostedEvents(0, QEvent::MetaCall);

    /* Cleanup machine-logic: */
    cleanupMachineLogic();

    /* Cleanup session UI: */
    cleanupSession();

    /* Quit application: */
    QApplication::quit();
}
void QBluetoothTransferReplyBluez::sessionChanged(const QString &interface,
                                                  const QVariantMap &changed_properties,
                                                  const QStringList &)
{
    if (changed_properties.contains(QStringLiteral("Transferred"))) {
        emit transferProgress(
            changed_properties.value(QStringLiteral("Transferred")).toULongLong(),
            m_size);
    }

    if (changed_properties.contains(QStringLiteral("Status"))) {
        const QString s = changed_properties.
                value(QStringLiteral("Status")).toString();
        if (s == QStringLiteral("complete")
            || s == QStringLiteral("error")) {

            m_transfer_path.clear();
            m_finished = true;
            m_running = false;

            if (s == QStringLiteral("error")) {
                m_error = QBluetoothTransferReply::UnknownError;
                m_errorStr = tr("Unknown Error");

                emit QBluetoothTransferReply::error(m_error);
            } else { // complete
                // allow progress bar to complete
                emit transferProgress(m_size, m_size);
            }

            cleanupSession();

            emit finished(this);
        } // ignore "active", "queued" & "suspended" status
    }
    qCDebug(QT_BT_BLUEZ) << "Transfer update:" << interface << changed_properties;
}
Exemple #4
0
__private_extern__
kern_return_t
_configopen(mach_port_t			server,
	    xmlData_t			nameRef,		/* raw XML bytes */
	    mach_msg_type_number_t	nameLen,
	    xmlData_t			optionsRef,		/* raw XML bytes */
	    mach_msg_type_number_t	optionsLen,
	    mach_port_t			*newServer,
	    int				*sc_status,
	    audit_token_t		audit_token)
{
	CFDictionaryRef			info;
	serverSessionRef		mySession;
	CFStringRef			name		= NULL;	/* name (un-serialized) */
	CFMutableDictionaryRef		newInfo;
	mach_port_t			oldNotify;
	CFDictionaryRef			options		= NULL;	/* options (un-serialized) */
	CFStringRef			sessionKey;
	kern_return_t 			status;
	SCDynamicStorePrivateRef	storePrivate;
	CFBooleanRef			useSessionKeys	= NULL;

	*sc_status = kSCStatusOK;

	/* un-serialize the name */
	if (!_SCUnserializeString(&name, NULL, (void *)nameRef, nameLen)) {
		*sc_status = kSCStatusFailed;
	}

	if ((optionsRef != NULL) && (optionsLen > 0)) {
		/* un-serialize the [session] options */
		if (!_SCUnserialize((CFPropertyListRef *)&options, NULL, (void *)optionsRef, optionsLen)) {
			*sc_status = kSCStatusFailed;
		}
	}

	if (*sc_status != kSCStatusOK) {
		goto done;
	}

	if (!isA_CFString(name)) {
		*sc_status = kSCStatusInvalidArgument;
		goto done;
	}

	if (options != NULL) {
		if (!isA_CFDictionary(options)) {
			*sc_status = kSCStatusInvalidArgument;
			goto done;
		}

		/*
		 * [pre-]process any provided options
		 */
		useSessionKeys = CFDictionaryGetValue(options, kSCDynamicStoreUseSessionKeys);
		if (useSessionKeys != NULL) {
			if (!isA_CFBoolean(useSessionKeys)) {
				*sc_status = kSCStatusInvalidArgument;
				goto done;
			}
		}
	}

	/*
	 * establish the new session
	 */
	mySession = addSession(server, openMPCopyDescription);
	if (mySession == NULL) {
#ifdef	DEBUG
		SCLog(TRUE, LOG_DEBUG, CFSTR("_configopen(): session is already open."));
#endif	/* DEBUG */
		*sc_status = kSCStatusFailed;	/* you can't re-open an "open" session */
		goto done;
	}

	*newServer = mySession->key;
	__MACH_PORT_DEBUG(TRUE, "*** _configopen (after addSession)", *newServer);

	/* save the audit_token in case we need to check the callers credentials */
	mySession->auditToken = audit_token;

	/* Create and add a run loop source for the port */
	mySession->serverRunLoopSource = CFMachPortCreateRunLoopSource(NULL, mySession->serverPort, 0);
	CFRunLoopAddSource(CFRunLoopGetCurrent(),
			   mySession->serverRunLoopSource,
			   kCFRunLoopDefaultMode);

	if (_configd_trace) {
		SCTrace(TRUE, _configd_trace,
			CFSTR("open    : %5d : %@\n"),
			*newServer,
			name);
	}

	*sc_status = __SCDynamicStoreOpen(&mySession->store, name);
	storePrivate = (SCDynamicStorePrivateRef)mySession->store;

	/*
	 * Make the server port accessible to the framework routines.
	 * ... and be sure to clear before calling CFRelease(store)
	 */
	storePrivate->server = *newServer;

	/*
	 * Process any provided [session] options
	 */
	if (useSessionKeys != NULL) {
		storePrivate->useSessionKeys = CFBooleanGetValue(useSessionKeys);
	}

	/* Request a notification when/if the client dies */
	status = mach_port_request_notification(mach_task_self(),
						*newServer,
						MACH_NOTIFY_NO_SENDERS,
						1,
						*newServer,
						MACH_MSG_TYPE_MAKE_SEND_ONCE,
						&oldNotify);
	if (status != KERN_SUCCESS) {
		SCLog(TRUE, LOG_ERR, CFSTR("_configopen() mach_port_request_notification() failed: %s"), mach_error_string(status));
		cleanupSession(*newServer);
		*newServer = MACH_PORT_NULL;
		*sc_status = kSCStatusFailed;
		goto done;
	}
	__MACH_PORT_DEBUG(TRUE, "*** _configopen (after mach_port_request_notification)", *newServer);

	if (oldNotify != MACH_PORT_NULL) {
		SCLog(TRUE, LOG_ERR, CFSTR("_configopen(): oldNotify != MACH_PORT_NULL"));
	}

	/*
	 * Save the name of the calling application / plug-in with the session data.
	 */
	sessionKey = CFStringCreateWithFormat(NULL, NULL, CFSTR("%d"), *newServer);
	info = CFDictionaryGetValue(sessionData, sessionKey);
	if (info != NULL) {
		newInfo = CFDictionaryCreateMutableCopy(NULL, 0, info);
	} else {
		newInfo = CFDictionaryCreateMutable(NULL,
						    0,
						    &kCFTypeDictionaryKeyCallBacks,
						    &kCFTypeDictionaryValueCallBacks);
	}
	CFDictionarySetValue(newInfo, kSCDName, name);
	CFDictionarySetValue(sessionData, sessionKey, newInfo);
	CFRelease(newInfo);
	CFRelease(sessionKey);

	/*
	 * Note: at this time we should be holding ONE send right and
	 *       ONE receive right to the server.  The send right is
	 *       moved to the caller.
	 */

    done :

	if (name != NULL)	CFRelease(name);
	if (options != NULL)	CFRelease(options);
	return KERN_SUCCESS;
}