MacAddressHandler::~MacAddressHandler()
{
    nfc_unregister_handover_listener();
    nfc_stop_events();
    unsubscribe(nfc_get_domain());
    bps_shutdown();
}
Beispiel #2
0
NfcSender::~NfcSender()
{
    nfc_unregister_snep_client();
    nfc_stop_events();
    unsubscribe(nfc_get_domain());
    bps_shutdown();
}
Beispiel #3
0
//! [0]
void NfcSender::initialize()
{
    bps_initialize();
    subscribe(nfc_get_domain());

    const int rc = nfc_request_events();
    if (rc == NFC_RESULT_SUCCESS) {
        qDebug() << "[INFO] Request NFC Events: NFC_RESULT_SUCCESS" << endl;
    } else {
        nfc_stop_events();
        unsubscribe(nfc_get_domain());
        bps_shutdown();
        qDebug() << "[ERRO] Request NFC Events: NFC_RESULT_FAILURE" << endl;
    }
    nfc_register_snep_client();
}
//! [0]
void MacAddressHandler::initialize()
{
    bps_initialize();
    subscribe(nfc_get_domain());

    const int rc = nfc_request_events();
    if (rc == NFC_RESULT_SUCCESS) {
        qDebug() << "[INFO] Request NFC Events: NFC_RESULT_SUCCESS" << endl;
    } else {
        nfc_stop_events();
        unsubscribe(nfc_get_domain());
        bps_shutdown();
        qDebug() << "[ERRO] Request NFC Events: NFC_RESULT_FAILURE" << endl;
    }

    nfc_register_handover_listener(BLUETOOTH_HANDOVER);
}
/*
 * This method encapsulated the main BPS event loop -- all the details needed to
 * set it in place have been done in the initialize() method
 */
void NfcWorker::listen() {
	qDebug() << "XXXX NfcWorker::listen() entered ...";

	int rc, domain;

	if (_failedToInitialize) {
		qDebug() << "XXXX NfcWorker::listen() terminating due to initialisation failure";
		emit message("Terminating due to initialisation failure");
		StateManager* state_mgr = StateManager::getInstance();
		state_mgr->setDefaultState();
		return;
	}

	_timeToDie = false;

	qDebug() << "XXXX NfcWorker::listen() entering event loop";

	while (!_timeToDie) {
		bps_event_t *event;

		qDebug() << "XXXX Time(ms) : " << getSysTimeMs() << ": bps_get_event() - entering";
		rc = bps_get_event(&event, BPS_EVENT_TIMEOUT);
		qDebug() << "XXXX Time(ms) : " << getSysTimeMs() << ": bps_get_event() - exited";

		if (!rc) {
			if (event) {
				domain = bps_event_get_domain(event);
				if (nfc_get_domain() == domain) {
					handleNfcEvent(event);

				} else if (navigator_get_domain() == domain) {
					handleNavigatorEvent(event);

				} else if (_bpsInterruptDomain == domain) {
					unsigned int code;
					code = bps_event_get_code(event);

					switch (code) {
					case NfcWorker::TERMINATE:
						_timeToDie = true;
						_taskToPerform = NONE_SET;
						emit message("Got a custom BPS event to terminate");
						qDebug() << "XXXX Got a custom BPS event to terminate.";
						break;

					case NfcWorker::WAKEUP:
						emit message("Got a custom BPS event to wake up");
						qDebug() << "XXXX Got a custom BPS event to wake up.";
						break;

					default:
						emit message("Unrecognised custom BPS event");
						qDebug() << "XXXX Unrecognised custom BPS event.";
						break;
					}

				} else {
					emit message("BPS event didn't match a wanted domain");
					qDebug() << "XXXX BPS event didn't match a wanted domain";
				}
			} else {
				qDebug() << "XXXX No events from BPS on this wakeup";
			}
		} else {
			qDebug() << "XXXX NfcWorker::listen() bps_get_event rc=" << rc;
			emit message("Error getting BPS event");
			qDebug() << "XXXX Error getting BPS event.";
		}
	}

	if (_navigatorExitReceived) {
		qDebug() << "XXXX Exiting listen() loop since got NAVIGATOR_EXIT event";
	}

	qDebug() << "XXXX - exited listen loop - changing state";
	StateManager* state_mgr = StateManager::getInstance();
	state_mgr->setDefaultState();

	//
	// NOTE: no need to call nfc_unregister_tag_readerwriter() since it gets
	//       called on our behalf automatically if needed.
	//
	qDebug() << "XXXX Time(ms) : " << getSysTimeMs() << ": nfc_stop_events() - entering";
	rc = nfc_stop_events();
	qDebug() << "XXXX Time(ms) : " << getSysTimeMs() << ": nfc_stop_events() - exited";

	qDebug() << "XXXX Time(ms) : " << getSysTimeMs() << ": navigator_stop_events() - entering";
	rc = navigator_stop_events(0);
	qDebug() << "XXXX Time(ms) : " << getSysTimeMs() << ": navigator_stop_events() - exited";

	qDebug() << "XXXX Time(ms) : " << getSysTimeMs() << ": bps_shutdown() - entering";
	bps_shutdown();
	qDebug() << "XXXX Time(ms) : " << getSysTimeMs() << ": bps_shutdown() - exited";

	qDebug() << "XXXX NfcWorker::listen() BPS shutdown. Exiting listen()";
}
Beispiel #6
0
/*
 * @param doWhat: 0 for reading, 1 for Writing
 * This method encapsulated the main BPS event loop -- all the details needed to
 * set it in place have been done in the initialize() method
 */
void NfcWorker::listen(int doWhat) {
	qDebug() << "XXXX NfcWorker::listen() entered ...";

	int rc, domain;

	if (_failedToInitialize) {
		qDebug()
				<< "XXXX NfcWorker::listen() terminating due to initialisation failure";
		emit message("Terminating due to initialisation failure");
		return;
	}

	_timeToDie = false;

	qDebug() << "XXXX NfcWorker::listen() entering event loop";

	while (!_timeToDie) {
		bps_event_t *event;

		qDebug() << ": bps_get_event() - entering";
		rc = bps_get_event(&event, BPS_EVENT_TIMEOUT);
		qDebug() << ": bps_get_event() - exited";

		if (!rc) {
			if (event) {
				domain = bps_event_get_domain(event);
				if (nfc_get_domain() == domain) {
					//Un-implemented portion
					handleNfcEvent(event,doWhat);
				} else if (_bpsInterruptDomain == domain) {
					unsigned int code;
					code = bps_event_get_code(event);

					switch (code) {
					case NfcWorker::TERMINATE:
						_timeToDie = true;
						emit message("Got a custom BPS event to terminate");
						qDebug() << "XXXX Got a custom BPS event to terminate.";
						break;

					case NfcWorker::WAKEUP:
						emit message("Got a custom BPS event to wake up");
						qDebug() << "XXXX Got a custom BPS event to wake up.";
						break;

					default:
						emit message("Unrecognised custom BPS event");
						qDebug() << "XXXX Unrecognised custom BPS event.";
						break;
					}

				} else {
					emit message("BPS event didn't match a wanted domain");
					qDebug() << "XXXX BPS event didn't match a wanted domain";
				}
			} else {
				qDebug() << "XXXX No events from BPS on this wakeup";
			}
		} else {
			qDebug() << "XXXX NfcWorker::listen() bps_get_event rc=" << rc;
			emit message("Error getting BPS event");
			qDebug() << "XXXX Error getting BPS event.";
		}
	}

	//
	// NOTE: no need to call nfc_unregister_tag_readerwriter() since it gets
	//       called on our behalf automatically if needed.
	//
	qDebug() << ": nfc_stop_events() - entering";
	rc = nfc_stop_events();
	qDebug() << ": nfc_stop_events() - exited";

	qDebug() << ": bps_shutdown() - entering";
	bps_shutdown();
	qDebug() << ": bps_shutdown() - exited";

	qDebug() << "XXXX NfcWorker::listen() BPS shutdown. Exiting listen()";
}