Beispiel #1
0
int main(int argc, char *argv[]) {

	int rc;
	int exit_application = 0;

	initBBSpecific();

	initOpenGL(screen_cxt);

	while (closeApplication == 0) {
		handleEvent();
		render();
	}

	//Stop requesting events from libscreen
	screen_stop_events(screen_cxt);

	//Shut down BPS library for this process
	bps_shutdown();

	//Use utility code to terminate EGL setup
	bbutil_terminate();

	//Destroy libscreen context
	screen_destroy_context(screen_cxt);
	return 0;
}
Beispiel #2
0
manager::manager() {
#if defined(__ANDROID__)
    // We're just going to open 1 joystick on android platform.
    int n = 0;
    {
#else
    for(int n = 0; n != SDL_NumJoysticks(); ++n) {
#endif
        SDL_Joystick* j = SDL_JoystickOpen(n);
        if(j) {
            joysticks.push_back(j);
        }
    }

    std::cerr << "initialized " << joysticks.size() << " joysticks\n";
}

manager::~manager() {
    foreach(SDL_Joystick* j, joysticks) {
        SDL_JoystickClose(j);
    }
    joysticks.clear();

#if defined(TARGET_BLACKBERRY)
    bps_shutdown();
#endif
}
Beispiel #3
0
void finalize()
{
    // Free allocated resources.
    if (_vertices) {
        free(_vertices);
        _vertices = NULL;
    }

    if (_indices) {
        free(_indices);
        _indices = NULL;
    }

    if (_textureCoords) {
        free(_textureCoords);
        _textureCoords = NULL;
    }

    // Destroy the font.
    bbutil_destroy_font(_font);

    // Stop requesting events from libscreen.
    SCREEN_API(screen_stop_events(_screen_ctx), "stop_events");

    // Shut down BPS library for this process.
    bps_shutdown();

    // Use utility code to terminate EGL setup.
    bbutil_terminate();

    // Destroy libscreen context.
    SCREEN_API(screen_destroy_context(_screen_ctx), "destroy_context");
}
Beispiel #4
0
int main(int argc, char *argv[]) {
    //Create a screen context that will be used to create an EGL surface to to receive libscreen events
    screen_create_context(&screen_cxt, 0);

    //Initialize BPS library
    bps_initialize();

    //Use utility code to initialize EGL for rendering with GL ES 1.1
    if (EXIT_SUCCESS != bbutil_init_egl(screen_cxt)) {
        fprintf(stderr, "bbutil_init_egl failed\n");
        bbutil_terminate();
        screen_destroy_context(screen_cxt);
        return 0;
    }

    //Initialize application logic
    if (EXIT_SUCCESS != initialize()) {
        fprintf(stderr, "initialize failed\n");
        bbutil_terminate();
        screen_destroy_context(screen_cxt);
        return 0;
    }

    //Signal BPS library that navigator and screen events will be requested
    if (BPS_SUCCESS != screen_request_events(screen_cxt)) {
        fprintf(stderr, "screen_request_events failed\n");
        bbutil_terminate();
        screen_destroy_context(screen_cxt);
        return 0;
    }

    if (BPS_SUCCESS != navigator_request_events(0)) {
        fprintf(stderr, "navigator_request_events failed\n");
        bbutil_terminate();
        screen_destroy_context(screen_cxt);
        return 0;
    }

    while (!shutdown) {
        // Handle user input and accelerometer
        handle_events();
        // Update scene contents
        update();
        // Draw Scene
        render();
    }

    //Stop requesting events from libscreen
    screen_stop_events(screen_cxt);

    //Use utility code to terminate EGL setup
    bbutil_terminate();

    //Shut down BPS library for this process
    bps_shutdown();

    //Destroy libscreen context
    screen_destroy_context(screen_cxt);
    return 0;
}
Beispiel #5
0
NfcSender::~NfcSender()
{
    nfc_unregister_snep_client();
    nfc_stop_events();
    unsubscribe(nfc_get_domain());
    bps_shutdown();
}
MacAddressHandler::~MacAddressHandler()
{
    nfc_unregister_handover_listener();
    nfc_stop_events();
    unsubscribe(nfc_get_domain());
    bps_shutdown();
}
Beispiel #7
0
void OSBB10::finalize() {

	if(main_loop)
		memdelete(main_loop);
	main_loop=NULL;

	/*
	if (debugger_connection_console) {
		memdelete(debugger_connection_console);
	}
	*/

	visual_server->finish();
	memdelete(visual_server);
	memdelete(rasterizer);

	physics_server->finish();
	memdelete(physics_server);

	physics_2d_server->finish();
	memdelete(physics_2d_server);

	#ifdef PAYMENT_SERVICE_ENABLED
	memdelete(payment_service);
	#endif

	memdelete(input);

	bbutil_terminate();
	screen_destroy_context(screen_cxt);

	bps_shutdown();
}
Beispiel #8
0
void QNXEnvironment::destroy()
{
	m_game = NULL;

	delete m_screen;
	delete m_audio;

	bps_shutdown();
}
QEventDispatcherBlackberryPrivate::~QEventDispatcherBlackberryPrivate()
{
    if ((holding_channel != -1) &&
        (bps_channel_destroy(holding_channel) != BPS_SUCCESS)) {
        qWarning("QEventDispatcherBlackberry: bps_channel_destroy failed");
    }

    // we're done using BPS
    bps_shutdown();
}
Beispiel #10
0
void BlackberryMain::endMain() {
	screen_stop_events(screen_cxt);
	bps_shutdown();
	NativeShutdownGraphics();
	delete audio;
	NativeShutdown();
	killDisplays();
	net::Shutdown();
	screen_destroy_context(screen_cxt);
}
Beispiel #11
0
int
main(int argc, char **argv)
{
    const int usage = SCREEN_USAGE_NATIVE;

    screen_window_t screen_win;
    screen_buffer_t screen_buf = NULL;
    int rect[4] = { 0, 0, 0, 0 };

    // create an application window which will just act as a background
    screen_create_context(&screen_ctx, 0);
    screen_create_window(&screen_win, screen_ctx);
    screen_create_window_group(screen_win, vf_group);
    screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_USAGE, &usage);
    screen_create_window_buffers(screen_win, 1);
    screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_RENDER_BUFFERS, (void **)&screen_buf);
    screen_get_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, rect+2);

    // fill the window with black
    int attribs[] = { SCREEN_BLIT_COLOR, 0x00000000, SCREEN_BLIT_END };
    screen_fill(screen_ctx, screen_buf, attribs);
    screen_post_window(screen_win, screen_buf, 1, rect, 0);
    // position the window at an arbitrary z-order
    int i = APP_ZORDER;
    screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_ZORDER, &i);

    // Signal bps library that navigator and screen events will be requested
    bps_initialize();
    screen_request_events(screen_ctx);
    navigator_request_events(0);

    // open camera and configure viewfinder
    if (init_camera() == EOK) {
        // our main loop just runs a state machine and handles input
        while (!shutdown) {
            run_state_machine();
            // Handle user input
            handle_event();
        }

        if (state == STATE_VIEWFINDER) {
            // clean up camera
            camera_stop_photo_viewfinder(handle);
            camera_close(handle);
        }
    }

    // Clean up
    screen_stop_events(screen_ctx);
    bps_shutdown();
    screen_destroy_window(screen_win);
    screen_destroy_context(screen_ctx);
    return 0;
}
Beispiel #12
0
void CCEGLView::release()
{
	screen_stop_events(m_screenContext);

	bps_shutdown();

    if (m_eglDisplay != EGL_NO_DISPLAY)
    {
        eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
    }

    if (m_eglSurface != EGL_NO_SURFACE)
    {
        eglDestroySurface(m_eglDisplay, m_eglSurface);
        m_eglSurface = EGL_NO_SURFACE;
    }

    if (m_eglContext != EGL_NO_CONTEXT)
    {
        eglDestroyContext(m_eglDisplay, m_eglContext);
        m_eglContext = EGL_NO_CONTEXT;
    }

    if (m_eglDisplay != EGL_NO_DISPLAY)
    {
        eglTerminate(m_eglDisplay);
        m_eglDisplay = EGL_NO_DISPLAY;
    }

    if (m_screenWindow)
    {
        screen_destroy_window(m_screenWindow);
        m_screenWindow = NULL;
    }

    if (m_screenEvent)
    {
    	screen_destroy_event(m_screenEvent);
    	m_screenEvent = NULL;
    }

    if (m_screenContext)
    {
        screen_destroy_context(m_screenContext);
        m_screenContext = NULL;
    }

	eglReleaseThread();

	m_isGLInitialized = false;

	exit(0);
}
void* eventLoop(void* data) {
	FREContext ctx = (FREContext) data;
	float x, y, z;
	bps_event_t *event = NULL;
	char buffer[256];

    // Initialize BPS
    bps_initialize();

	// Start the gyroscope
	if (sensor_request_events(SENSOR_TYPE_GYROSCOPE) != BPS_SUCCESS) {
		shutdown = true;
	}

	// Receive events through the event channel
	while (!shutdown) {
		event = NULL;

		if (bps_get_event(&event, 50) != BPS_SUCCESS)
			return NULL;

		if (event) {
			if (bps_event_get_domain(event) == sensor_get_domain()) {
				if (bps_event_get_code(event) == SENSOR_GYROSCOPE_READING) {
					if (sensor_event_get_xyz(event, &x, &y, &z) == BPS_SUCCESS) {
						sprintf(buffer, "%f&%f&%f", x, y, z);
						fprintf(stdout, "Sensor event: %f&%f&%f\n", x, y, z);
					    fflush(stdout);

						if(ctx != NULL) {
							FREDispatchStatusEventAsync(ctx, (uint8_t*)"CHANGE", (uint8_t*)buffer);
						}
					}
				}
			}
		}
	}

	if (sensor_stop_events(SENSOR_TYPE_GYROSCOPE) != BPS_SUCCESS) {
		fprintf(stdout, "Unable to stop sensor\n");
	    fflush(stdout);
	}

	// Stop BPS
	bps_shutdown();

	return NULL;
}
Beispiel #14
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();
}
/*
 * This method initialises the interface to BPS
 */
void NfcWorker::initialize() {

	qDebug() << "XXXX NfcWorker::initialize() starts...";

	int rc = BPS_FAILURE;

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

	if (rc) {
		_failedToInitialize = true;
		qDebug() << "XXXX Error: BPS failed to initialise. rc=" << rc;
		emit message(QString("BPS failed to initialise. rc=%1").arg(rc));
	} else {
		qDebug() << "XXXX BPS Initialised";
	}

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

	if (rc) {
		_failedToInitialize = true;
		qDebug() << "XXXX Error: Failed to request NFC BPS events. rc=" << rc;
		emit message("Failed to request NFC BPS events");
		bps_shutdown();
	} else {
		qDebug() << "XXXX Registered for NFC BPS events OK";
		emit message("Registered for NFC BPS events OK");
		_interruptMutex.lock();
		_bpsInterruptDomain = bps_register_domain();

		if (_bpsInterruptDomain == -1) {
			qDebug() << "XXXX Failed to register an interrupt domain.";
			emit message("Failed to register an interrupt domain");
		}

		_bpsChannel = bps_channel_get_active();
		_interruptMutex.unlock();

		qDebug() << "XXXX Time(ms) : " << getSysTimeMs() << ": navigator_request_events() - entering";
		CHECK(navigator_request_events(0));
		qDebug() << "XXXX Time(ms) : " << getSysTimeMs() << ": navigator_request_events() - exited";
	}
	qDebug() << "XXXX NfcWorker::initialize() ends...";
}
//! [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);
}
QString RegisterService::deviceModel() const
{
    QString deviceModel;

    if (bps_initialize() == BPS_SUCCESS) {
        qDebug() << "bps initialized";
        deviceinfo_details_t *deviceDetails = 0;

        if (deviceinfo_get_details(&deviceDetails) == BPS_SUCCESS) {
            deviceModel = deviceinfo_details_get_hardware_id(deviceDetails);
            deviceinfo_free_details(&deviceDetails);
        } else {
            qDebug() << "error retrieving device details";
        }

        bps_shutdown();
    } else {
        qDebug() << "error initializing bps";
    }

    return deviceModel;
}
Beispiel #18
0
int main(int argc, char **argv) {
    int rc;

    //Create a screen context that will be used to create an EGL surface to to receive libscreen events
    screen_create_context(&screen_cxt, 0);

    //Initialize BPS library
    bps_initialize();

    //Use utility code to initialize EGL for rendering with GL ES 1.1
    if (EXIT_SUCCESS != bbutil_init_egl(screen_cxt)) {
        fprintf(stderr, "Unable to initialize EGL\n");
        screen_destroy_context(screen_cxt);
        return 0;
    }

    //Initialize app data
    if (EXIT_SUCCESS != init()) {
        fprintf(stderr, "Unable to initialize app logic\n");
        bbutil_terminate();
        screen_destroy_context(screen_cxt);
        return 0;
    }

    //Signal BPS library that navigator orientation is to be locked
    if (BPS_SUCCESS != navigator_rotation_lock(true)) {
        fprintf(stderr, "navigator_rotation_lock failed\n");
        bbutil_terminate();
        screen_destroy_context(screen_cxt);
        return 0;
    }

    //Signal BPS library that navigator and screen events will be requested
    if (BPS_SUCCESS != screen_request_events(screen_cxt)) {
        fprintf(stderr, "screen_request_events failed\n");
        bbutil_terminate();
        screen_destroy_context(screen_cxt);
        return 0;
    }

    if (BPS_SUCCESS != navigator_request_events(0)) {
        fprintf(stderr, "navigator_request_events failed\n");
        bbutil_terminate();
        screen_destroy_context(screen_cxt);
        return 0;
    }

    for (;;) {
        //Request and process BPS next available event
        bps_event_t *event = NULL;
        rc = bps_get_event(&event, 0);
        assert(rc == BPS_SUCCESS);

        if ((event) && (bps_event_get_domain(event) == navigator_get_domain())
                && (NAVIGATOR_EXIT == bps_event_get_code(event))) {
            break;
        }

        render();
    }

    //Stop requesting events from libscreen
    screen_stop_events(screen_cxt);

    //Shut down BPS library for this process
    bps_shutdown();

    //Destroy the font
    bbutil_destroy_font(font);

    //Use utility code to terminate EGL setup
    bbutil_terminate();

    //Destroy libscreen context
    screen_destroy_context(screen_cxt);
    return 0;
}
Beispiel #19
0
/**
 * A sample application that demonstrates the BlackBerry Native APIs for
 * managing locale. The sample queries for the current locale and then listens
 * for locale update events.
 */
int
main(int argc, char *argv[])
{
    /*
     * Before we can listen for events from the BlackBerry Tablet OS platform
     * services, we need to initialize the BPS infrastructure
     */
    bps_initialize();

    if (setup_screen() != EXIT_SUCCESS) {
        printf("Unable to set up the screen. Exiting.");
        return 0;
    }

    /*
     * Once the BPS infrastructure has been initialized we can register for
     * events from the various BlackBerry Tablet OS platform services. The
     * Navigator service manages and delivers application life cycle and
     * visibility events.
     * For this sample, we request Navigator events so that we can track when
     * the system is terminating the application (NAVIGATOR_EXIT event) as well
     * as Locale events so we can be notified when the locale is updated
     */
    navigator_request_events(0);
    locale_request_events(0);
    dialog_request_events(0);

    /*
     * Create and display the dialog.
     */
    create_dialog();

    /*
     * Retrieve and display the current Locale using the locale_get(...) API
     */
    char* country = NULL;
    char* language = NULL;
    locale_get(&language, &country);
    display_locale(language, country);
    bps_free((char*)language);
    bps_free((char*)country);

   /*
    * Process Locale and Navigator events until we receive a NAVIGATOR_EXIT event.
    */
    int exit_application = 0;
    while (!exit_application) {
        /*
         * Using a negative timeout (-1) in the call to bps_get_event(...)
         * ensures that we don't busy wait by blocking until an event is
         * available.
         */
        bps_event_t *event = NULL;
        bps_get_event(&event, -1);

        if (event) {
            if (bps_event_get_domain(event) == locale_get_domain()) {
                /*
                 * If it is a LOCALE_INFO event then display the updated locale
                 * information
                 */
                if (LOCALE_INFO == bps_event_get_code(event)) {
                    /*
                     * The locale_event_get_language and locale_event_get_country
                     * calls return pointers to data within the event. When
                     * the event is destroyed below via the call to
                     * bps_event_destroy(event), the returned pointers would
                     * reference deallocated memory.
                     *
                     * To avoid potentially having pointers to dereferenced
                     * memory, we'll use local variables to store the pointers
                     * into the event data. This way, the pointers will go
                     * out of scope and thus cannot be used after the event
                     * is freed.
                     */
                    const char* language = locale_event_get_language(event);
                    const char* country = locale_event_get_country(event);
                    display_locale(language, country);
                }
            }

            /*
             * If it is a NAVIGATOR_EXIT event then set the exit_application
             * flag so the application will stop processing events, clean up
             * and exit
             */
            if (bps_event_get_domain(event) == navigator_get_domain()) {
                if (NAVIGATOR_EXIT == bps_event_get_code(event)) {
                    exit_application = 1;
                }
            }
        }
    }

    /*
     * Destroy the dialog, if it exists and cleanup screen resources.
     */
    destroy_dialog();
    cleanup_screen();

    /*
     * Clean up the BPS infrastructure and exit
     */
    bps_shutdown();
    return 0;
}
Beispiel #20
0
int main(int argc, char *argv[]) {
	int rc;
	int exit_application = 0;
	static screen_context_t screen_cxt;

	//Create a screen context that will be used to create an EGL surface to to receive libscreen events
	screen_create_context(&screen_cxt, 0);

	//Initialize BPS library
	bps_initialize();

	//Use utility code to initialize EGL in landscape orientation
	if (EXIT_SUCCESS != bbutil_init_egl(screen_cxt, GL_ES_1, LANDSCAPE)) {
		fprintf(stderr, "bbutil_init_egl failed\n");
		bbutil_terminate();
		screen_destroy_context(screen_cxt);
		return 0;
	}

	//Initialize application logic
	if (EXIT_SUCCESS != initialize()) {
		fprintf(stderr, "initialize failed\n");
		bbutil_terminate();
		screen_destroy_context(screen_cxt);
		return 0;
	}

	//Signal BPS library that navigator and screen events will be requested
	if (BPS_SUCCESS != screen_request_events(screen_cxt)) {
		fprintf(stderr, "screen_request_events failed\n");
		bbutil_terminate();
		screen_destroy_context(screen_cxt);
		return 0;
	}

	if (BPS_SUCCESS != navigator_request_events(0)) {
		fprintf(stderr, "navigator_request_events failed\n");
		bbutil_terminate();
		screen_destroy_context(screen_cxt);
		return 0;
	}

	//Signal BPS library that navigator orientation is not to be locked
	if (BPS_SUCCESS != navigator_rotation_lock(false)) {
		fprintf(stderr, "navigator_rotation_lock failed\n");
		bbutil_terminate();
		screen_destroy_context(screen_cxt);
		return 0;
	}

	while (!exit_application) {
		//Request and process BPS next available event
		bps_event_t *event = NULL;
		rc = bps_get_event(&event, 0);
		assert(rc == BPS_SUCCESS);

		if (event) {
			int domain = bps_event_get_domain(event);

			if (domain == screen_get_domain()) {
				handleScreenEvent(event);
			} else if ((domain == navigator_get_domain())
					&& (NAVIGATOR_EXIT == bps_event_get_code(event))) {
				exit_application = 1;
			}
		}

		render();
	}

	//Stop requesting events from libscreen
	screen_stop_events(screen_cxt);

	//Shut down BPS library for this process
	bps_shutdown();

	//Use utility code to terminate EGL setup
	bbutil_terminate();

	//Destroy libscreen context
	screen_destroy_context(screen_cxt);
	return 0;
}
void ScoreLoopThread::run() {
	qDebug() << "ScoreLoopThread run() started";

	AppData_t app;
	SC_InitData_t initData;
	SC_Error_t rc;
	char versionBuffer[0x100]; /* Thats 256 bytes */

	qDebug() << "Starting Scoreloop Sample...";

	/* Initialize the BPS event system */
	bps_initialize();
	bps_set_verbosity(0); /* Set to 1 or 2 for more output if you like */

	memset(&app, 0, sizeof(AppData_t));

	/* Initialize the Scoreloop platform dependent SC_InitData_t structure to default values. */
	SC_InitData_Init(&initData);

	/* What version of the Scoreloop library do we use? */
	if (SC_GetVersionInfo(&initData, versionBuffer, sizeof(versionBuffer))) {
		qDebug() << "Version-Info: " << versionBuffer;
	}

	/* Now, create the Scoreloop Client with the initialized SC_InitData_t structure
	 * as well as the game-id and game-secret as found on the developer portal.
	 */
	rc = SC_Client_New(&app.client, &initData, SCORELOOP_GAME_ID, SCORELOOP_GAME_SECRET, SCORELOOP_GAME_VERSION, SCORELOOP_GAME_CURRENCY, SCORELOOP_GAME_LANGUAGE);
	if (rc != SC_OK) {
		HandleError(&app, rc);
	} else {
		//InformUser(&app, "Note", "Scoreloop Sample started...");

		/* Request the user here just for demonstration purposes */
		RequestUser(&app);
	}

	while (!m_quit) {
		/* Get next BPS event */
		bps_event_t *event;
		bps_get_event(&event, -1);

		/* Scoreloop event handling  */
		if (bps_event_get_domain(event) == SC_GetBPSEventDomain(&initData)) {
			SC_HandleBPSEvent(&initData, event);
		}

		else if (bps_event_get_domain(event) == dialog_get_domain()) {
			dialog_destroy(dialog_event_get_dialog_instance(event));
			app.dialog = 0;
		}
		/* Add more BPS event handling here... */

	}

	/* Cleanup the Scoreloop client */
	SC_Client_Release(app.client);

	/* Shutdown BPS */
	bps_shutdown();
	qDebug() << "SensorsThread run() finished.";
}
/*
 * 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 #23
0
LocatoinData::~LocatoinData() {
  geolocation_stop_events(0);
  bps_shutdown();
  delete d;
}
StatusEventHandler::~StatusEventHandler()
{
    bps_shutdown();
}
Beispiel #25
0
/**
 * A sample application that demonstrates the BlackBerry(R) 10 Native SDK APIs
 * for geolocation.
 */
int
main(int argc, char *argv[])
{
    bool exit_application = false;

    /*
     * Before we can listen for events from the BlackBerry(R) 10 OS platform
     * services, we need to initialize the BPS infrastructure
     */
    bps_initialize();

    /*
     * Initialize the screen so that the window group Id is properly set, to allow
     * the dialogs to be displayed.
     */
    if (setup_screen() != EXIT_SUCCESS) {
        fprintf(stderr, "Unable to initialize screen.");
        exit(-1);
    }

    /*
     * Once the BPS infrastructure has been initialized we can register for
     * events from the various BlackBerry(R) 10 OS platform services. The
     * Navigator service manages and delivers application life cycle and
     * visibility events.
     *
     * For this sample, we request Navigator events so that we can track when
     * the system is terminating the application (NAVIGATOR_EXIT event).
     *
     * We request dialog events so we can be notified when the dialog service
     * responds to our requests/queries.
     *
     * We request geolocation events so that we can be notified of our current
     * geolocation.
     */
    if (BPS_SUCCESS != navigator_request_events(0)) {
        fprintf(stderr, "Error requesting navigator events: %s", strerror(errno));
        exit(-1);
    }
    if (BPS_SUCCESS != dialog_request_events(0)) {
        fprintf(stderr, "Error requesting dialog events: %s", strerror(errno));
        exit(-1);
    }
    if (BPS_SUCCESS != geolocation_request_events(0)) {
        fprintf(stderr, "Error requesting geolocation events: %s", strerror(errno));
        exit(-1);
    }

    /*
     * Get geolocation events once a second, which is the most often that they
     * are capable of being reported.
     */
    geolocation_set_period(1);

    /*
     * Create and display the dialog that will show the geolocation data.
     */
    create_dialog();
    show_dialog_message("Geolocation getting first fix");

    /*
     * Process Geolocation, Dialog and Navigator events until we receive a
     * NAVIGATOR_EXIT event.
     */
    while (!exit_application) {
        /*
         * Using a negative timeout (-1) in the call to bps_get_event(...)
         * ensures that we don't busy wait by blocking until an event is
         * available.
         */
        bps_event_t *event = NULL;
        bps_get_event(&event, -1);

        if (event) {
            /*
             * If it is a geolocation event, determine the response code and
             * handle the event accordingly.
             */
            if (bps_event_get_domain(event) == geolocation_get_domain()) {
                handle_geolocation_response(event);
            }

            /*
             * If it is a dialog event, determine the response code and handle
             * the event accordingly.
             */
            else if (bps_event_get_domain(event) == dialog_get_domain()) {
                /* We have no buttons so we don't need to do anything. */
                ;
            }

            /*
             * If it is a NAVIGATOR_EXIT event then set the exit_application
             * flag so the application will stop processing events, clean up and
             * exit.
             */
            else if (bps_event_get_domain(event) == navigator_get_domain()) {
                exit_application = handle_navigator_event(event);
            }
        }
    }

    /*
     * Stop geolocation events.
     */
    geolocation_stop_events(0);

    /*
     * Destroy the dialog, if it exists.
     */
    destroy_dialog();

    /*
     * Clean up the bps infrastructure and exit
     */
    bps_shutdown();
    cleanup_screen();
    return 0;
}
Beispiel #26
0
/**
 * Thread that handles accelerometer events and
 * sends relevant information to a dialog.
 *
 * @param p Unused.
 */
static void *
accel_main (void *p) {
    bool run = true;
    bps_event_t *event;
    float force_x, force_y, force_z;

    bps_initialize();

    /*
     * Each thread that calls bps_initialize() will have its
     * own unique channel ID.  Protect it inside a mutex and
     * condition variable to avoid race condition where main
     * thread tries to use it before we assign it.
     */
    pthread_mutex_lock(&chidMutex);
    accel_chid = bps_channel_get_active();
    pthread_cond_signal(&chidCond);
    pthread_mutex_unlock(&chidMutex);

    /*
     * Create and display a dialog that will show the data.
     */
    create_bottom_dialog();
    show_bottom_dialog_message("\n\nThis is the Accelerometer Dialog");

    if (BPS_SUCCESS != sensor_request_events(SENSOR_TYPE_ACCELEROMETER)) {
        fprintf(stderr, "Error requesting sensor's accelerometer events: %s", strerror(errno));
        bps_shutdown();
        return NULL;
    }

    sensor_set_rate(SENSOR_TYPE_ACCELEROMETER, ACCELEROMETER_RATE);
    sensor_set_skip_duplicates(SENSOR_TYPE_ACCELEROMETER, true);

    while (run) {
        /*
         * Block, at the very least we'll get the "STOP" event
         */
        bps_get_event(&event, -1);
        if (bps_event_get_domain(event) == local_event_domain) {
            if (bps_event_get_code(event) == STOP_REQUEST) {
                run = false;
            }
        }

        if (bps_event_get_domain(event) == sensor_get_domain()) {
            if (SENSOR_ACCELEROMETER_READING == bps_event_get_code(event)) {
                sensor_event_get_xyz(event, &force_x, &force_y, &force_z);
                display_accelerometer_reading(force_x, force_y, force_z);
            }
        }
    }

    sensor_stop_events(0);
    destroy_bottom_dialog();

    bps_shutdown();

    fprintf(stderr, "Exiting accelerometer thread\n");
    return NULL;


}
Beispiel #27
0
int main(int argc, char *argv[])
{
    int rc;
    int exit_application = 0;

    // Screen variables
    screen_context_t    screen_context = 0;
    screen_window_t     screen_window = 0;

    int screen_size[2] = {0,0};

    // Renderer variables
    mmr_connection_t*     mmr_connection = 0;
    mmr_context_t*        mmr_context = 0;
    strm_dict_t*          dict = NULL;

    // I/O variables
    int                    video_device_output_id = -1;
    int                    audio_device_output_id = -1;

    bps_initialize();

    /*
     * Create the window used for video output.
     */
    if (screen_create_context(&screen_context, SCREEN_APPLICATION_CONTEXT) != 0) {
        return EXIT_FAILURE;
    }

    if (screen_create_window(&screen_window, screen_context) != 0) {
        screen_destroy_context(screen_context);
        return EXIT_FAILURE;
    }

    if (screen_create_window_group(screen_window, window_group_name) != 0) {
        return EXIT_FAILURE;
    }

    int format = SCREEN_FORMAT_RGBA8888;
    if (screen_set_window_property_iv(screen_window, SCREEN_PROPERTY_FORMAT, &format) != 0) {
        return EXIT_FAILURE;
    }

    int usage = SCREEN_USAGE_NATIVE;
    if (screen_set_window_property_iv(screen_window, SCREEN_PROPERTY_USAGE, &usage) != 0) {
        return EXIT_FAILURE;
    }


    if (screen_create_window_buffers(screen_window, 1) != 0) {
        return EXIT_FAILURE;
    }

    /*
     * Configure mm-renderer.
     */
    mmr_connection = mmr_connect(NULL);
    if (mmr_connection == NULL) {
        return EXIT_FAILURE;
    }

    mmr_context = mmr_context_create(mmr_connection, video_context_name, 0, S_IRWXU|S_IRWXG|S_IRWXO);
    if (mmr_context == NULL) {
        return EXIT_FAILURE;
    }

    /*
     * Configure video and audio output.
     */
    video_device_output_id = mmr_output_attach(mmr_context, video_device_url, "video");
    if (video_device_output_id == -1) {
        return EXIT_FAILURE;
    }

    audio_device_output_id = mmr_output_attach(mmr_context, audio_device_url, "audio");
    if (audio_device_output_id == -1) {
        return EXIT_FAILURE;
    }

    // Get the render buffer
    screen_buffer_t temp_buffer[1];
    if (screen_get_window_property_pv( screen_window, SCREEN_PROPERTY_RENDER_BUFFERS, (void**)temp_buffer) != 0) {
        return EXIT_FAILURE;
    }

    // Fill the buffer with a solid color (black)
    int fill_attributes[3] = {SCREEN_BLIT_COLOR, 0x0, SCREEN_BLIT_END};
    if (screen_fill(screen_context, temp_buffer[0], fill_attributes) != 0) {
        return EXIT_FAILURE;
    }

    // Make the window visible
    if (screen_get_window_property_iv(screen_window, SCREEN_PROPERTY_SIZE, screen_size) != 0) {
        return EXIT_FAILURE;
    }

    int temp_rectangle[4] = {0, 0, screen_size[0], screen_size[1]};
    if (screen_post_window(screen_window, temp_buffer[0], 1, temp_rectangle, 0) != 0) {
        return EXIT_FAILURE;
    }

    // Prevent the backlight from going off
    int idle_mode = SCREEN_IDLE_MODE_KEEP_AWAKE;
    if (screen_set_window_property_iv(screen_window, SCREEN_PROPERTY_IDLE_MODE, &idle_mode) != 0) {
        return EXIT_FAILURE;
    }

    // Build up the path where our bundled resource is.
    char cwd[PATH_MAX];
    char media_file[PATH_MAX];
    getcwd(cwd,PATH_MAX);

    rc = snprintf(media_file, PATH_MAX, "file://%s/app/native/pb_sample.mp4", cwd);
    if ((rc == -1) || (rc >= PATH_MAX)) {
        return EXIT_FAILURE;
    }

    /*
     * Start the playback.
     */
    if (mmr_input_attach(mmr_context, media_file, "track") != 0) {
        return EXIT_FAILURE;
    }

    if (mmr_play(mmr_context) != 0) {
        return EXIT_FAILURE;
    }

    /* Do some work to make the aspect ratio correct.
     */
    dict = calculate_rect(screen_size[0], screen_size[1]);
    if (NULL == dict) {
        return EXIT_FAILURE;
    }

    if (mmr_output_parameters(mmr_context, video_device_output_id, dict) != 0) {
        return EXIT_FAILURE;
    }

     /* Note that we allocated memory for the dictionary, but the call to 
      * mmr_output_parameters() deallocates that memory even on failure.
      */  
    dict = NULL;

    screen_request_events(screen_context);
    navigator_request_events(0);

    /*
     * Handle keyboard events and stop playback upon user request.
     */
    for (;;) {
        bps_event_t *event = NULL;
        if (bps_get_event(&event, -1) != BPS_SUCCESS) {
            return EXIT_FAILURE;
        }

        if (event) {

            if (bps_event_get_domain(event) == navigator_get_domain() &&
                bps_event_get_code(event) == NAVIGATOR_EXIT) {

                exit_application = 1;
            }

            if (exit_application) {
                break;
            }
        }
    }

    screen_stop_events(screen_context);

    if (mmr_stop(mmr_context) != 0) {
        return EXIT_FAILURE;
    }

    if (mmr_output_detach(mmr_context, audio_device_output_id) != 0) {
        return EXIT_FAILURE;
    }

    if (mmr_output_detach(mmr_context, video_device_output_id) != 0) {
        return EXIT_FAILURE;
    }

    if (mmr_context_destroy(mmr_context) != 0) {
        return EXIT_FAILURE;
    }

    mmr_context = 0;
    video_device_output_id = -1;
    audio_device_output_id = -1;

    mmr_disconnect(mmr_connection);
    mmr_connection = 0;

    bps_shutdown();

    if (screen_destroy_window(screen_window) != 0) {
        return EXIT_FAILURE;
    }

    if (screen_destroy_context(screen_context) != 0) {
        return EXIT_FAILURE;
    }

    screen_context = 0;
    screen_window = 0;

    return EXIT_SUCCESS;
}
int main(int argc, char *argv[]) {
    int exit_application = 0;

    //Create a screen context that will be used to create an EGL surface to to receive libscreen events
    screen_create_context(&screen_ctx, 0);
	// Get display configuration (dimensions)
	int count = 0;
	screen_get_context_property_iv(screen_ctx, SCREEN_PROPERTY_DISPLAY_COUNT, &count);
	screen_display_t *screen_disps = (screen_display_t *)calloc(count, sizeof(screen_display_t));
	screen_get_context_property_pv(screen_ctx, SCREEN_PROPERTY_DISPLAYS, (void **)screen_disps);
	screen_display_t screen_disp = screen_disps[0];
	free(screen_disps);
	int dims[2] = { 0, 0 };
	screen_get_display_property_iv(screen_disp, SCREEN_PROPERTY_SIZE, dims);
	nScreenWidth = dims[0];
	nScreenHeight = dims[1];

    //Initialize BPS library
    bps_initialize();

    //Use utility code to initialize EGL for rendering with GL ES 2.0
    if (EXIT_SUCCESS != bbutil_init_egl(screen_ctx)) {
        fprintf(stderr, "bbutil_init_egl failed\n");
        bbutil_terminate();
        screen_destroy_context(screen_ctx);
        return 0;
    }

    //Initialize application logic
    if (EXIT_SUCCESS != initialize()) {
        fprintf(stderr, "initialize failed\n");
        bbutil_terminate();
        screen_destroy_context(screen_ctx);
        bps_shutdown();
        return 0;
    }

    while (!exit_application) {
        //Request and process all available BPS events
        bps_event_t *event = NULL;

        for(;;) {
            if (BPS_SUCCESS != bps_get_event(&event, 0)) {
                fprintf(stderr, "bps_get_event failed\n");
                break;
            }

            if (event) {
                int domain = bps_event_get_domain(event);

                if ((domain == navigator_get_domain())
                     && (NAVIGATOR_EXIT == bps_event_get_code(event))) {
                    exit_application = 1;
                }
            } else {
                break;
            }
        }
        render();
    }

    //Stop requesting events from libscreen
    screen_stop_events(screen_ctx);

    //Shut down BPS library for this process
    bps_shutdown();

    //Use utility code to terminate EGL setup
    bbutil_terminate();

    //Destroy libscreen context
    screen_destroy_context(screen_ctx);
    return 0;
}
Beispiel #29
0
/**
 * The main entry point.
 */
int
main(int argc, char *argv[])
{
    pthread_t accel_thread;

    bool exit_application = false;
    int rc;

    /*
     * Before we can listen for events from the BlackBerry Tablet OS platform
     * services, we need to initialize the BPS infrastructure
     */
    bps_initialize();

    /*
     * Initialize the screen so that the window group Id is properly set,
     * to allow the dialogs to be displayed.
     */
    if (setup_screen() != EXIT_SUCCESS) {
        fprintf(stderr, "Unable to initialize screen.");
        exit(-1);
    }

    /*
     * Once the BPS infrastructure has been initialized we can register for
     * events from the various BlackBerry Tablet OS platform services. The
     * Navigator service manages and delivers application life cycle and
     * visibility events.
     *
     * We register a custom event domain so that we can communicate with the
     * the accelerometer thread.  We will need to tell it to quit once we get
     * the NAVIGATOR_EXIT.
     *
     * We request Navigator events so that we can track when the system is
     * terminating the application (NAVIGATOR_EXIT event).
     *
     */
    local_event_domain = bps_register_domain();
    if (local_event_domain == -1) {
        fprintf(stderr, "Error registering custom event domain: %s", strerror(errno));
        exit(-1);
    }
    if (BPS_SUCCESS != navigator_request_events(0)) {
        fprintf(stderr, "Error requesting navigator events: %s", strerror(errno));
        exit(-1);
    }
    if (BPS_SUCCESS != dialog_request_events(0)) {
        fprintf(stderr, "Error requesting dialog events: %s", strerror(errno));
        exit(-1);
    }
    if (BPS_SUCCESS != geolocation_request_events(0)) {
        fprintf(stderr, "Error requesting geolocation events: %s", strerror(errno));
        exit(-1);
    }

    geolocation_set_period(1);

    /*
     * Create and display the dialogs that will show the data.
     */
    create_top_dialog();
    show_top_dialog_message("Geolocation getting first fix");

    /*
     * Before initializing the accelerometer service we must ensure the device
     * supports it.
     */
    if (!sensor_is_supported(SENSOR_TYPE_ACCELEROMETER)) {
        /**
         * If the device does not support accelerometer then notify the user,
         * clean up and exit
         */
        snprintf(msg, MSG_SIZE, "Accelerometer not supported by device!");
        show_top_dialog_message(msg);

        /*
         * Destroy the dialog, if it exists and cleanup screen resources.
         */
        destroy_top_dialog();
        cleanup_screen();
        bps_shutdown();
        return EXIT_FAILURE;
    }

    /*
     * Create the accelerometer event thread.
     */
    rc = pthread_create(&accel_thread, NULL, accel_main, NULL);
    if (rc != 0) {
        fprintf(stderr, "Error in pthread_create: %s", strerror(errno));
        exit(-1);
    }

    while (!exit_application) {
        /*
         * Using a negative timeout (-1) in the call to bps_get_event(...)
         * ensures that we don't busy wait by blocking until an event is
         * available.
         */
        bps_event_t *event = NULL;
        bps_get_event(&event, -1);

        if (event) {
            if (bps_event_get_domain(event) == geolocation_get_domain()) {
                handle_geolocation_response(event);
            }
            else if (bps_event_get_domain(event) == navigator_get_domain()) {
                exit_application = handle_navigator_event(event);
            }
        }
    }

    geolocation_stop_events(0);

    /*
     * Avoid a possible race condition where accel_chid has not yet
     * been assigned a valid channel ID.
     */
    pthread_mutex_lock(&chidMutex);
    while (accel_chid == -1) {
        pthread_cond_wait(&chidCond, &chidMutex);
    }
    pthread_mutex_unlock(&chidMutex);

    bps_event_t *stop_request_event = NULL;

    if (BPS_SUCCESS != bps_event_create(&stop_request_event, local_event_domain, STOP_REQUEST, NULL, NULL)) {
        fprintf(stderr, "Unable to create event: %s", strerror(errno));
        exit(-1);
    }

    if (BPS_SUCCESS != bps_channel_push_event(accel_chid, stop_request_event)) {
        fprintf(stderr, "Unable to push event: %s", strerror(errno));
    }

    pthread_join(accel_thread, NULL);

    /*
     * Destroy the dialog, if it exists.
     */
    destroy_top_dialog();

    bps_shutdown();
    cleanup_screen();

    return 0;
}
Beispiel #30
0
static void system_shutdown(void)
{
   bps_shutdown();
}