int OpenGLThread::initBPS() { //Initialize BPS library bps_initialize(); m_api = GL_ES_1; //Create a screen context that will be used to create an EGL surface to to receive libscreen events if (EXIT_SUCCESS != screen_create_context(&m_screen_ctx, 0)) { fprintf(stderr, "screen_request_events failed\n"); return EXIT_FAILURE; } // wait for rendering API to be set while (m_api == GL_UNKNOWN) { usleep(10); }; // initialize EGL if (EXIT_SUCCESS != initEGL()) { fprintf(stderr, "initialize EGL failed\n"); return EXIT_FAILURE; } //Signal BPS library that screen events will be requested if (BPS_SUCCESS != screen_request_events(m_screen_ctx)) { fprintf(stderr, "screen_request_events failed\n"); return EXIT_FAILURE; } setInitialized(true); return EXIT_SUCCESS; }
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; }
QT_BEGIN_NAMESPACE QQnxNavigatorBps::QQnxNavigatorBps(QObject *parent) : QQnxAbstractNavigator(parent) { bps_initialize(); }
ScreenWindow::ScreenWindow() : m_context(0) , m_window(0) , m_appWindow(0) { bps_initialize(); }
// Loops and runs the callback method void* KeyboardThread(void* parent) { Keyboard_NDK *pParent = static_cast<Keyboard_NDK *>(parent); sleep(1); // 1. Start the library bps_initialize(); // 2. Request events to flow into the event queue virtualkeyboard_request_events(0); sleep(3); // 3. Use any service at any time //virtualkeyboard_show(); // Show the virtual keyboard // 4. Listen for events for (;;) { // get an event bps_event_t *event; bps_get_event(&event, -1); // blocking // handle the event pParent->event(event); } return NULL; }
static void system_init(void) { /* FIXME - should this apply for both BB10 and PB? */ #if defined(__QNX__) && !defined(HAVE_BB10) bps_initialize(); #endif }
BPSEventListener::BPSEventListener() : _isKeyboardVisible(false) { subscribe(virtualkeyboard_get_domain()); subscribe(netstatus_get_domain()); bps_initialize(); virtualkeyboard_request_events(0); netstatus_request_events(0); }
LocatoinData::LocatoinData(QObject *object) : PlexyDesk::DataSource(object), d(new Private) { bps_initialize(); startGeoTracking(); startTimer(10000); Q_EMIT(ready()); }
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; }
int main(int argc, char **argv) { // Create a screen context that will be used to create an EGL surface to receive libscreen events. SCREEN_API(screen_create_context(&_screen_ctx, SCREEN_APPLICATION_CONTEXT), "create_context"); // 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_ctx)) { fprintf(stderr, "Unable to initialize EGL.\n"); screen_destroy_context(_screen_ctx); return 0; } // Initialize app data. if (EXIT_SUCCESS != init()) { fprintf(stderr, "Unable to initialize app logic.\n"); bbutil_terminate(); screen_destroy_context(_screen_ctx); return 0; } // Signal BPS library that navigator and screen events will be requested. if (BPS_SUCCESS != screen_request_events(_screen_ctx)) { fprintf(stderr, "screen_request_events failed\n"); bbutil_terminate(); screen_destroy_context(_screen_ctx); return 0; } if (BPS_SUCCESS != navigator_request_events(0)) { fprintf(stderr, "navigator_request_events failed\n"); bbutil_terminate(); screen_destroy_context(_screen_ctx); return 0; } // Look for attached gamepad and joystick devices. discoverControllers(); // Enter the event loop. while (!_shutdown) { update(); render(); } // Clean up resources and shut everything down. finalize(); return 0; }
ConnectionInfo::ConnectionInfo() : m_connected(false), m_interfaceName("Unknown"), m_interfaceType( ConnectionInfo::Unknown) { subscribe(netstatus_get_domain()); bps_initialize(); // Request all network status events. netstatus_request_events(0); info = NULL; }
StatusEventHandler::StatusEventHandler() { subscribe(netstatus_get_domain()); subscribe(locale_get_domain()); subscribe(geolocation_get_domain()); bps_initialize(); netstatus_request_events(0); locale_request_events(0); geolocation_request_events(0); geolocation_set_period(1); }
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; }
//! [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); }
Keyboard_NDK::Keyboard_NDK(Keyboard_JS *parent): m_pParent(parent), keyboardProperty(50), keyboardThreadCount(1), threadHalt(true), m_thread(0) { pthread_cond_t cond = PTHREAD_COND_INITIALIZER; pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; bps_initialize(); virtualkeyboard_request_events(0); virtualkeyboard_change_options(VIRTUALKEYBOARD_LAYOUT_EMAIL,VIRTUALKEYBOARD_ENTER_DEFAULT); m_pParent->getLog()->info("Keyboard Created"); }
int TitaniumRuntime::internalRun(int argc, char** argv) { bps_initialize(); // initialize the bps services TiRootObject* obj; obj = TiRootObject::createRootObject(); rootObject_.attachTiObject(obj); bb::cascades::Application app(argc, argv); TiCascadesApp mainApp; mainApp.initializeApp(); NativeObjectFactory objFactory(&mainApp); objectFactory_ = &objFactory; mainApp_ = &mainApp; int ret = obj->executeScript(&objFactory, javaScript_, messageLoop, this); // TODO: handle non-zero return code here obj->release(); return ret; }
//! constructor CIrrDeviceBB10::CIrrDeviceBB10(const SIrrlichtCreationParameters& param) : CIrrDeviceStub(param), bspScreenWindow((screen_window_t)param.WindowId), MouseX(0), MouseY(0), MouseButtonStates(0), Width(param.WindowSize.Width), Height(param.WindowSize.Height), Resizable(false), WindowHasFocus(true), WindowMinimized(false) { #ifdef _DEBUG setDebugName("CIrrDeviceBB10"); #endif // Initialize SDL... Timer for sleep, video for the obvious, and // noparachute prevents SDL from catching fatal errors. if (bps_initialize() !=BPS_SUCCESS) { os::Printer::log( "Unable to initialize BSP !"); Close = true; } //create screen context screen_create_context(&bspScreenCtx, 0); core::stringc devVersion = "BB10 Version "; Operator = new COSOperator(devVersion); os::Printer::log(devVersion.c_str(), ELL_INFORMATION); // create keymap createKeyMap(); // create window if (CreationParams.DriverType != video::EDT_NULL) { // create the window, only if we do not use the null device createWindow(); } // create cursor control CursorControl = new CCursorControl(this); // create driver createDriver(); if (VideoDriver) createGUIAndScene(); }
bool QNXEnvironment::init(Game *game) { Environment::init(game); openLogFile(); printLog("--------------------------------------------------------\n"); printLog(" %s - %s\n", m_game->getName(), m_game->getVersion()); printLog("--------------------------------------------------------\n"); bps_initialize(); screen_create_context(&screen_ctx, 0); if (BPS_SUCCESS != screen_request_events(screen_ctx)) { printLog("screen_request_events failed\n"); screen_destroy_context(screen_ctx); return false; } m_screen = new QNXScreen(screen_ctx); m_audio = emyl::manager::get_instance(); m_input = new QNXInput(screen_ctx); setFramesPerSecond(0, false, false); m_game->init(); if (!m_screen->init()) { printLog("ERROR: Couldn't init screen.\n"); return false; } //m_screen->setCaption(m_game->getName()); if (!m_audio-> init()) { printLog("ERROR: Couldn't run sound.\n"); } emyl::setErrorCallback(emylErrorCallback); m_game->load(); return true; }
void BlackberryMain::startMain(int argc, char *argv[]) { g_quitRequested = false; // Receive events from window manager screen_create_context(&screen_cxt, 0); // Initialise Blackberry Platform Services bps_initialize(); // TODO: Enable/disable based on setting sensor_set_rate(SENSOR_TYPE_ACCELEROMETER, 25000); sensor_request_events(SENSOR_TYPE_ACCELEROMETER); net::Init(); startDisplays(); screen_request_events(screen_cxt); navigator_request_events(0); dialog_request_events(0); vibration_request_events(0); NativeInit(argc, (const char **)argv, "/accounts/1000/shared/misc/", "app/native/assets/", "BADCOFFEE"); NativeInitGraphics(); audio = new BlackberryAudio(); runMain(); }
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; }
QEventDispatcherBlackberryPrivate::QEventDispatcherBlackberryPrivate() : loop_level(0) , ioData(new bpsIOHandlerData) { // prepare to use BPS int result = bps_initialize(); if (Q_UNLIKELY(result != BPS_SUCCESS)) qFatal("QEventDispatcherBlackberry: bps_initialize failed"); bps_channel = bps_channel_get_active(); if (bps_channel_create(&holding_channel, 0) != BPS_SUCCESS) { qWarning("QEventDispatcherBlackberry: bps_channel_create failed"); holding_channel = -1; } // get domain for IO ready and wake up events - ignoring race condition here for now if (bpsUnblockDomain == -1) { bpsUnblockDomain = bps_register_domain(); if (Q_UNLIKELY(bpsUnblockDomain == -1)) qWarning("QEventDispatcherBlackberry: bps_register_domain failed"); } }
CCEGLView::CCEGLView() { m_eglDisplay = EGL_NO_DISPLAY; m_eglContext = EGL_NO_CONTEXT; m_eglSurface = EGL_NO_SURFACE; m_screenEvent = 0; m_screenWindow = 0; strcpy(m_windowGroupID, ""); snprintf(m_windowGroupID, sizeof(m_windowGroupID), "%d", getpid()); bps_initialize(); navigator_request_events(0); static const int SENSOR_RATE = 25000; sensor_set_rate(SENSOR_TYPE_ACCELEROMETER, SENSOR_RATE); sensor_request_events(SENSOR_TYPE_ACCELEROMETER); navigator_rotation_lock(true); m_isGLInitialized = initGL(); if (m_isGLInitialized) initEGLFunctions(); }
QEventDispatcherBlackberryPrivate::QEventDispatcherBlackberryPrivate() : ioData(new bpsIOHandlerData) { // prepare to use BPS int result = bps_initialize(); if (result != BPS_SUCCESS) qFatal("QEventDispatcherBlackberryPrivate::QEventDispatcherBlackberry: bps_initialize() failed"); // get domain for IO ready events - ignoring race condition here for now if (bpsIOReadyDomain == -1) { bpsIOReadyDomain = bps_register_domain(); if (bpsIOReadyDomain == -1) qWarning("QEventDispatcherBlackberryPrivate::QEventDispatcherBlackberry: bps_register_domain() failed"); } // \TODO Reinstate this when bps is fixed. See comment in select() below. // Register thread_pipe[0] with bps /* int io_events = BPS_IO_INPUT; result = bps_add_fd(thread_pipe[0], io_events, &bpsIOHandler, ioData.data()); if (result != BPS_SUCCESS) qWarning() << Q_FUNC_INFO << "bps_add_fd() failed"; */ }
/** * 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; }
/** * 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; }
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; }
/** * 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; }
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; }