//! runs the device. Returns false if device wants to be deleted
bool CIrrDeviceBB10::run()
{
	os::Timer::tick();
	
	//TODO: translate native event
	SEvent irrevent;
	bps_event_t *event = NULL;
	while ( !Close &&(bps_get_event(&event, 0) ==BPS_SUCCESS))
	{

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

                if ((event) && (bps_event_get_domain(event) == navigator_get_domain())
                        && (NAVIGATOR_WINDOW_INACTIVE == bps_event_get_code(event)))
                {
			WindowHasFocus =false;
                        break;
                }
                if ((event) && (bps_event_get_domain(event) == navigator_get_domain())
                        && (NAVIGATOR_WINDOW_ACTIVE == bps_event_get_code(event)))
                {
			WindowHasFocus =true;
                        break;
                }

                if ((event) && (bps_event_get_domain(event) == navigator_get_domain())
                        && (NAVIGATOR_WINDOW_STATE == bps_event_get_code(event)))
                {
			if(navigator_event_get_window_state(event) == NAVIGATOR_WINDOW_INVISIBLE)
				WindowHasFocus =false;
			else
				WindowHasFocus =true;
                        break;
                }
		
		//TODO: transfer bps event to irr event
		//postEventFromUser(irrevent);
		break;

	} // end while

	return !Close;
}
Exemple #2
0
static void handle_events() {
	int screen_domain = screen_get_domain();
	int navigator_domain = navigator_get_domain();
	int sensor_domain = sensor_get_domain();

	int rc;

	//Request and process available BPS events
	for(;;) {
		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_domain) {
				handleScreenEvent(event);
			} else if (domain == navigator_domain) {
				handleNavigatorEvent(event);
			} else if (domain == sensor_domain) {
				handleSensorEvent(event);
			}
		} else {
			//No more events in the queue
			break;
		}
	}
}
Exemple #3
0
static void handleNavigatorEvent(bps_event_t *event) {
    switch (bps_event_get_code(event)) {
    case NAVIGATOR_ORIENTATION_CHECK:
        //Signal navigator that we intend to resize
        navigator_orientation_check_response(event, true);
        break;
    case NAVIGATOR_ORIENTATION:
        if (EXIT_FAILURE == resize(event)) {
            shutdown = true;
        }
        break;
    case NAVIGATOR_EXIT:
        shutdown = true;
        break;
    case NAVIGATOR_WINDOW_INACTIVE:
        //Wait for NAVIGATOR_WINDOW_ACTIVE event
        for (;;) {
            if (BPS_SUCCESS != bps_get_event(&event, -1)) {
                fprintf(stderr, "bps_get_event failed\n");
                break;
            }

            if (event && (bps_event_get_domain(event) == navigator_get_domain())) {
                int code = bps_event_get_code(event);
                if (code == NAVIGATOR_EXIT) {
                    shutdown = true;
                    break;
                } else if (code == NAVIGATOR_WINDOW_ACTIVE) {
                    break;
                }
            }
        }
        break;
    }
}
void handleEvent() {
	//Request and process BPS next available event
	int rc, domain;

	for (;;) {
		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()) {
                handleNavigatorEvent(event);

			} else if (domain == dialog_get_domain()) {
                handle_dialog_response(event);
            }
		} else {
			break;
		}
	}

}
Exemple #5
0
bool ScreenWindow::pollEvent(WinEvent *event)
{
	bps_event_t *bpsEvent;
	bps_get_event(&bpsEvent, 0);
	if (bpsEvent) {
		int domain = bps_event_get_domain(bpsEvent);
		if (domain == navigator_get_domain()) {
			if (bps_event_get_code(bpsEvent) == NAVIGATOR_EXIT) {
				event->type = QUIT;
				return true;
			}
		} else if (domain == screen_get_domain()) {
			screen_event_t se = screen_event_get_event(bpsEvent);
			int type;
			screen_get_event_property_iv(se, SCREEN_PROPERTY_TYPE, &type);
			if (type == SCREEN_EVENT_CLOSE) {
				event->type = QUIT;
				return true;
			} else if (type == SCREEN_EVENT_MTOUCH_TOUCH) {
				event->type = MOUSEBUTTONDOWN;
				return true;
			}
		}
	}
	return false;
}
Exemple #6
0
static void handleEvents()
{
    int domain;

    // Get the first event in the queue.
    bps_event_t *event = NULL;
    if (BPS_SUCCESS != bps_get_event(&event, 0)) {
        fprintf(stderr, "bps_get_event() failed\n");
        return;
    }

    // Handle all events in the queue.
    // If we don't do this in a loop, we'll only handle one event per frame.
    // If many events are triggered quickly, e.g. by spinning the analog sticks,
    // the queue will grow and the user will see the analog sticks lag.
    while (event) {
        if (event) {
            domain = bps_event_get_domain(event);
            if (domain == navigator_get_domain()) {
                handleNavigatorEvent(event);
            } else if (domain == screen_get_domain()) {
                handleScreenEvent(event);
            }
        }

        if (BPS_SUCCESS != bps_get_event(&event, 0)) {
            fprintf(stderr, "bps_get_event() failed\n");
            return;
        }
    }
}
Exemple #7
0
static void qnx_input_poll(void *data)
{
   global_t *global = global_get_ptr();
   qnx_input_t *qnx = (qnx_input_t*)data;

   global->lifecycle_state &= ~(1ULL << RARCH_MENU_TOGGLE);

   /* Request and process all available BPS events. */

   while(true)
   {
      bps_event_t *event = NULL;
      int rc = bps_get_event(&event, 0);

      if(rc == BPS_SUCCESS)
      {
         int domain;

         if (!event)
            break;

         domain = bps_event_get_domain(event);
         if (domain == navigator_get_domain())
            qnx_handle_navigator_event(qnx, event);
         else if (domain == screen_get_domain())
            qnx_handle_screen_event(qnx, event);
      }
   }
}
Exemple #8
0
bool BbGuiHelper::nativeEventFilter(const QByteArray &eventType, void *message, long *result)
{
    Q_UNUSED(result);
    Q_UNUSED(eventType);

    bps_event_t * const event = static_cast<bps_event_t *>(message);
    if (event && bps_event_get_domain(event) == navigator_get_domain()) {
        const int code = bps_event_get_code(event);
        if (code == NAVIGATOR_ORIENTATION) {
            const int newOrientation = navigator_event_get_orientation_angle(event);
            if (newOrientation != m_currentOrientation) {
                m_currentOrientation = newOrientation;
                emit orientationChanged();
            }
        } else if (code == NAVIGATOR_WINDOW_STATE) {
            const bool appActive =
                    (navigator_event_get_window_state(event) == NAVIGATOR_WINDOW_FULLSCREEN);
            if (m_applicationActive != appActive) {
                m_applicationActive = appActive;
                emit applicationActiveChanged();
            }
        }
    }

    return false;
}
bool QQnxBpsEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, long *result)
{
    Q_UNUSED(eventType);
    Q_UNUSED(result);
    bps_event_t *event = static_cast<bps_event_t *>(message);
    const int eventDomain = bps_event_get_domain(event);
    qBpsEventFilterDebug() << Q_FUNC_INFO << "event=" << event << "domain=" << eventDomain;

    if (eventDomain == screen_get_domain()) {
        if (!m_screenEventHandler) {
            qWarning("QQNX: registered for screen events, but no handler provided.");
            return false;
        }

        screen_event_t screenEvent = screen_event_get_event(event);
        return m_screenEventHandler->handleEvent(screenEvent);
    }

    if (eventDomain == dialog_get_domain()) {
        dialog_instance_t nativeDialog = dialog_event_get_dialog_instance(event);
        QQnxFileDialogHelper *dialog = m_dialogMapper.value(nativeDialog, 0);
        if (dialog)
            return dialog->handleEvent(event);
    }

    if (eventDomain == navigator_get_domain())
        return handleNavigatorEvent(event);

    if (m_virtualKeyboard->handleEvent(event))
        return true;

    return false;
}
Exemple #10
0
static void qnx_input_poll(void *data)
{
   qnx_input_t *qnx = (qnx_input_t*)data;

   /* Request and process all available BPS events. */

   while(true)
   {
      bps_event_t *event = NULL;
      int rc = bps_get_event(&event, 0);

      if(rc == BPS_SUCCESS)
      {
         int domain;

         if (!event)
            break;

         domain = bps_event_get_domain(event);
         if (domain == navigator_get_domain())
            qnx_handle_navigator_event(qnx, event);
         else if (domain == screen_get_domain())
            qnx_handle_screen_event(qnx, event);
      }
   }
}
Exemple #11
0
static void qnx_input_poll(void *data)
{
   (void)data;
   //Request and process all available BPS events

   int rc, domain;

   g_extern.lifecycle_state &= ~(1ULL << RARCH_MENU_TOGGLE);

   while(true)
   {
      bps_event_t *event = NULL;
      rc = bps_get_event(&event, 0);
      if(rc == BPS_SUCCESS)
      {
         if (event)
         {
            domain = bps_event_get_domain(event);
            if (domain == navigator_get_domain())
               handle_navigator_event(event);
            else if (domain == screen_get_domain())
               handle_screen_event(event);
         }
         else
            break;
      }
   }
}
Exemple #12
0
static void gfx_ctx_check_window(bool *quit,
      bool *resize, unsigned *width, unsigned *height, unsigned frame_count)
{
   (void)frame_count;
   //Request and process all available BPS events
   bps_event_t *event = NULL;

   bps_get_event(&event, 0);

   *quit = false;

   unsigned new_width, new_height;
   gfx_ctx_get_video_size(&new_width, &new_height);
   if (new_width != *width || new_height != *height)
   {
      *width  = new_width;
      *height = new_height;
      *resize = true;
   }

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

      if (domain == screen_get_domain())
      {
         screen_event_t screen_event = screen_event_get_event(event);
         int screen_val;
         screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &screen_val);
         switch (screen_val) {

            case SCREEN_EVENT_MTOUCH_TOUCH:
            case SCREEN_EVENT_MTOUCH_MOVE:
            case SCREEN_EVENT_MTOUCH_RELEASE:

               break;
         }
      }
      else if ((domain == navigator_get_domain()) && (NAVIGATOR_EXIT == bps_event_get_code(event)))
         g_extern.lifecycle_state |= (1ULL << RARCH_QUIT_KEY);
   }

   // Check if we are exiting.
   if (g_extern.lifecycle_state & (1ULL << RARCH_QUIT_KEY))
      *quit = true;
}
static void
handle_event()
{
    int rc, domain;

    bps_event_t *event = NULL;
    rc = bps_get_event(&event, -1);
    assert(rc == BPS_SUCCESS);
    if (event) {
        domain = bps_event_get_domain(event);
        if (domain == navigator_get_domain()) {
            handle_navigator_event(event);
        } else if (domain == screen_get_domain()) {
            handle_screen_event(event);
        }
    }
}
 void ActionScreenLock::execute(ExecutionState* state)
 {
     DataModelLogger* RUNLOG = state->getLogger();
     state->getRuntimeResources()->bpsInitialize();
     navigator_request_events(NAVIGATOR_DEVICE_LOCK_STATE);
     bps_event_t* event = state->getRuntimeResources()->bpsGetEvent(navigator_get_domain(),
             NAVIGATOR_DEVICE_LOCK_STATE);
     navigator_stop_events(NAVIGATOR_DEVICE_LOCK_STATE);
     if (event) {
         RUNLOG->debug(SSTR("Retrieved lock state event"));
         state->setUserProperty("LOCK_STATE",
                 SSTR(
                         TriggerScreenLock::lockStateToString(
                                 navigator_event_get_device_lock_state(event))));
     } else {
         RUNLOG->error("Did not receive lock state information");
     }
 }
Exemple #15
0
void BbGuiHelper::handleBpsEvent(bps_event_t *event)
{
    if (event && bps_event_get_domain(event) == navigator_get_domain()) {
        const int code = bps_event_get_code(event);
        if (code == NAVIGATOR_ORIENTATION) {
            const int newOrientation = navigator_event_get_orientation_angle(event);
            if (newOrientation != m_currentOrientation) {
                m_currentOrientation = newOrientation;
                emit orientationChanged();
            }
        } else if (code == NAVIGATOR_WINDOW_STATE) {
            const bool appActive =
                    (navigator_event_get_window_state(event) == NAVIGATOR_WINDOW_FULLSCREEN);
            if (m_applicationActive != appActive) {
                m_applicationActive = appActive;
                emit applicationActiveChanged();
            }
        }
    }
}
Exemple #16
0
static void handle_events() {
    //Request and process available BPS events
    for(;;) {
        bps_event_t *event = NULL;
        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 == screen_get_domain()) {
                handleScreenEvent(event);
            } else if (domain == navigator_get_domain()) {
                handleNavigatorEvent(event);
            }
        } else {
            break;
        }
    }
}
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;
}
Exemple #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;
}
Exemple #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;
}
Exemple #20
0
int main(int argc, char *argv[])
{
    int rc;
    int exit_application = 0;

    bps_initialize();

    // Create and set up the app window.
    if (EXIT_FAILURE == setup_screen())
        return EXIT_FAILURE;

    bbads_set_log_verbosity(2);

    // Display Banner on screen
    load_ad(screen_window, WINDOW_GROUP_NAME);

    screen_request_events(screen_context);
    navigator_request_events(0);

    /**
     * Handle keyboard events and stop playback upon user request.
     */
    for (;;) {
        bps_event_t *event = 0;
        if (BPS_SUCCESS != bps_get_event(&event, -1)) {
            fprintf(stderr, "ERROR: Could not get BPS event!\n");
            return EXIT_FAILURE;
        }

        if (event) {
            if (navigator_get_domain() == bps_event_get_domain(event)) {
                int code = bps_event_get_code(event);

                if (NAVIGATOR_EXIT == code) {
                	if (BBADS_EOK != bbads_banner_destroy(ad_banner))
                	{
                	    fprintf(stderr, "cannot destroy banner");
                	}
                	else
                	{
                	   fprintf(stderr, "banner destroy");
                	}

                    exit_application = 1;
                }

            }
            else if (bbads_get_domain() == bps_event_get_domain(event)) {
                bbads_banner_t* event_banner;

                bbads_event_get_banner(event, &event_banner);
                bbads_banner_event_type_t event_type = (bbads_banner_event_type_t)bps_event_get_code(event);

                banner_event_handler(event_banner, event_type);
            }
            else if (screen_get_domain() == bps_event_get_domain(event)) {
            	int screen_val;
				char buf[1024];
				int pos[2];

				screen_event_t screen_event = screen_event_get_event(event);
				screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &screen_val);
				screen_get_event_property_cv(screen_event, SCREEN_PROPERTY_ID_STRING, sizeof(buf), buf);
				screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_POSITION, pos);

				switch (screen_val) {
				case SCREEN_EVENT_CREATE:
					fprintf(stderr, "create\n");
					if (BBADS_EOK != bbads_banner_is_visible(ad_banner, &ad_is_visible))
					{
						fprintf(stderr, "cannot get banner visibility");
					}
					if (!ad_is_visible)
					{
						if (BBADS_EOK != bbads_banner_set_window_visible(ad_banner))
							fprintf(stderr, "bbads_banner_set_window_visible has errors\n");

						if (BBADS_EOK != bbads_banner_display(ad_banner, screen_context, event))
							fprintf(stderr, "create cannot display banner\n");

					}
					break;
				}

            if (exit_application)
                break;
            }
        }
    }

    screen_stop_events(screen_context);

    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;
}
Exemple #21
0
int main( int argc, char **argv ) {
    const char *mmrname = NULL;
    const char *ctxtname = "testplayer";
    const char *audioout = NULL;
    const char *inputtype = "track";
    char cwd[PATH_MAX];
    char inputurl[PATH_MAX];
    int rc;
    int final_return_code = EXIT_FAILURE;
    int exit_application = 0;
    mmr_connection_t *connection = NULL;
    mmr_context_t *ctxt = NULL;

    /*
     * Before we can listen for events from the BlackBerry(R) 10 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(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 we can track when
     * the system is terminating the application (NAVIGATOR_EXIT event). 
     * This allows us to clean up application resources.
     */
    navigator_request_events(0);
    dialog_request_events(0);

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

    getcwd(cwd, PATH_MAX);
    rc = snprintf(inputurl, PATH_MAX, "file://%s%s", cwd, WAV_RELATIVE_PATH);
    if (rc > PATH_MAX - 1)
    {
          show_dialog_message("File name and path too long");
          goto fail;
    }

    mode_t mode = S_IRUSR | S_IXUSR;
    int audio_oid; // output ID
    strm_dict_t *aoparams = NULL; // output parameters

    audioout = DEFAULT_AUDIO_OUT;

    if ( ( connection = mmr_connect( mmrname ) ) == NULL ) {
        snprintf(msg, MSG_SIZE, "mmr_connect: %s", strerror(errno));
        show_dialog_message(msg);
    } else if ( ( ctxt = mmr_context_create( connection, ctxtname, 0, mode ) ) == NULL ) {
        snprintf(msg, MSG_SIZE, "%s: %s", ctxtname, strerror(errno));
        show_dialog_message(msg);
    } else if ( audioout && ( audio_oid = mmr_output_attach( ctxt, audioout, "audio" ) ) < 0 ) {
        mmrerror( ctxt, audioout );
    } else if ( aoparams && mmr_output_parameters( ctxt, audio_oid, aoparams ) ) {
        mmrerror( ctxt, "output parameters (audio)" );
    } else if ( mmr_input_attach( ctxt, inputurl, inputtype ) < 0 ) {
        mmrerror( ctxt, inputurl );
    } else if ( mmr_play( ctxt ) < 0 ) {
        mmrerror( ctxt, "mmr_play" );
    } else if (BPS_SUCCESS != bps_add_sigevent_handler( &mmr_sigevent, mmr_sigevent_handler, ctxt ) ) { 
        snprintf( msg, MSG_SIZE, "bps_add_sigevent_handler() failure %s", strerror( errno ) );
        show_dialog_message( msg );
    } else if ( drain_and_arm_mmr_events ( ctxt ) ) {
        snprintf( msg, MSG_SIZE, "drain_and_arm_mmr_events() failure %s", strerror( errno ) );
        show_dialog_message( msg );
    } else {
        show_dialog_message( "Playing Audio\n" );
        final_return_code = EXIT_SUCCESS;
    }

fail:
    /*
     * Process 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 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)) {
                    if (final_return_code == EXIT_SUCCESS) {
                        mmr_stop( ctxt );             // Not really necessary -- mmr_input_detach() would take care of this
                        mmr_input_detach( ctxt );     // Not really necessary -- mmr_context_destroy()  would take care of this
                        mmr_context_destroy( ctxt );  // Not really necessary -- mmr_disconnect() would take care of this
                        mmr_disconnect( connection ); // Not really necessary -- exiting would take care of this
                    }
                    exit_application = 1;
                }
            } else if (bps_event_get_domain(event) == dialog_get_domain()) {
                if (DIALOG_RESPONSE == bps_event_get_code(event)) {
                    handle_dialog_response_events(event);
                }
            }
        }
    }

    /*
     * Destroy the dialog, if it exists and cleanup screen resources.
     */
    destroy_dialog();
    cleanup_screen();
    /*
     * Clean up the BPS infrastructure and exit
     */
    bps_shutdown();

    return final_return_code;

}
void ConfigWindow::runEventLoop(TCOContext *emuContext)
{
	screen_buffer_t buffer = draw(emuContext);

	bool showingWindow = true;
	bps_initialize();
	screen_request_events(m_context);
	bps_event_t *event; /* FIXME: How do we verify they ran bps_initialize? */
	screen_event_t se;
	int eventType;
	int contactId;
	bool touching = false;
	bool releasedThisRound = false;
	int startPos[2] = {0,0};
	int endPos[2] = {0,0};
	bool scaling = false;

	while (showingWindow)
	{
		const int dirtyRects[4] = {0, 0, m_size[0], m_size[1]};

		releasedThisRound = false;
		bps_get_event(&event, 0);
		while (showingWindow && event)
		{
			int domain = bps_event_get_domain(event);
			if (domain == navigator_get_domain())
			{
				if (bps_event_get_code(event) == NAVIGATOR_SWIPE_DOWN)
					showingWindow = false;
				else if (bps_event_get_code(event) == NAVIGATOR_EXIT) {
					showingWindow = false;
				}
			} else if (domain == screen_get_domain()) {
				se = screen_event_get_event(event);
				screen_get_event_property_iv(se, SCREEN_PROPERTY_TYPE, &eventType);
				screen_get_event_property_iv(se, SCREEN_PROPERTY_TOUCH_ID, &contactId);
				switch (eventType)
				{
				case SCREEN_EVENT_MTOUCH_TOUCH:
					screen_get_event_property_iv(se, SCREEN_PROPERTY_TOUCH_ID, &contactId);
					if (contactId == 0 && !touching && !releasedThisRound) {
						touching = true;
						screen_get_event_property_iv(se, SCREEN_PROPERTY_SOURCE_POSITION, startPos);
						endPos[0] = startPos[0];
						endPos[1] = startPos[1];
					}
					break;
				case SCREEN_EVENT_MTOUCH_MOVE:
					screen_get_event_property_iv(se, SCREEN_PROPERTY_TOUCH_ID, &contactId);
					if (contactId == 0 && touching) {
						screen_get_event_property_iv(se, SCREEN_PROPERTY_SOURCE_POSITION, endPos);
					}
					break;
				case SCREEN_EVENT_MTOUCH_RELEASE:
					screen_get_event_property_iv(se, SCREEN_PROPERTY_TOUCH_ID, &contactId);
					if (contactId == 0 && touching) {
						touching = false;
						releasedThisRound = true;
						screen_get_event_property_iv(se, SCREEN_PROPERTY_SOURCE_POSITION, endPos);
					}
					break;
				case SCREEN_EVENT_PROPERTY:
					break;
				default:
#ifdef _DEBUG
					fprintf(stderr, "Unknown screen event: %d\n", eventType);
#endif
					break;
				}
			}

			bps_get_event(&event, 0);
		}

		if (releasedThisRound) {
			m_selected = 0;
		} else if (touching) {
			if (!m_selected)
				m_selected = emuContext->controlAt(startPos);
			if (m_selected && (endPos[0] != startPos[0] || endPos[1] != startPos[1])) {
				m_selected->move(endPos[0] - startPos[0], endPos[1] - startPos[1], (unsigned*)m_size);
				buffer = draw(emuContext);
				startPos[0] = endPos[0];
				startPos[1] = endPos[1];
			}
		}

		if (buffer)
			post(buffer);
	}
}
Exemple #23
0
void zaAppBase::dispatchevent(bps_event_t *event)
{
	int domain = bps_event_get_domain(event);
	if (domain == screen_get_domain())
	{
		int screen_val;
		int pair[2];
		int id;
		screen_event_t screen_event = screen_event_get_event(event);
		screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE,
				&screen_val);
		screen_get_event_property_iv(screen_event,
				SCREEN_PROPERTY_SOURCE_POSITION, pair);
		screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TOUCH_ID,
				&id);

		if (screen_val >= SCREEN_EVENT_MTOUCH_TOUCH
				&& screen_val <= SCREEN_EVENT_MTOUCH_RELEASE
				&& (id == 0 || m_multitouch))
		{
			e.m_id = id;
			e.m_type = screen_val;
			e.m_x = pair[0];
			e.m_y = m_height - pair[1];
			// e.m_obj
			m_active->processEvent(&e);
		}
		else if (screen_val == SCREEN_EVENT_KEYBOARD)
		{
			int key_status;
			screen_get_event_property_iv(screen_event,
					SCREEN_PROPERTY_KEY_FLAGS, &key_status);
			if (key_status & KEY_DOWN)
			{
				int key_code;
				screen_get_event_property_iv(screen_event,
						SCREEN_PROPERTY_KEY_SYM, &key_code);
				e.m_type = screen_val;
				e.m_keycode = key_code;
				m_active->processEvent(&e);
			}
		}
		else if (screen_val == SCREEN_EVENT_POINTER)
		{
			int buttons;
			static int mouse_pressed = false;
			screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_BUTTONS,
					&buttons);
			e.m_event = 0;
			e.m_x = pair[0];
			e.m_y = m_height - pair[1];
			e.m_id = id;

			if (buttons == SCREEN_LEFT_MOUSE_BUTTON && mouse_pressed == false)
			{
				mouse_pressed = true;
				e.m_type = 100; //down
			}
			else if (mouse_pressed && buttons == SCREEN_LEFT_MOUSE_BUTTON)
			{
				e.m_type = 101; //move
			}
			else if (mouse_pressed)
			{
				fprintf(stderr,"2222222  btn %d, x %d ,y  %d \n", buttons,e.m_x ,e.m_y );
				mouse_pressed = false;
				e.m_type = 102; //up
			}
			if (e.m_type >= 100 && e.m_type <= 102)
				m_active->processEvent(&e);
		}
	}
	else if (domain == navigator_get_domain())
	{
		int cod = bps_event_get_code(event);

		if (NAVIGATOR_WINDOW_INACTIVE == cod)
		{
			onInactive();
//				   ZaScreenFlash * l_flash = (ZaScreenFlash *)ZaResLib::getInstance()->getScreen("ZaScreenFlash");
//				   ZaScreenBase * l_src = (ZaScreenBase *)ZaResLib::getInstance()->getScreen("ZaScreenStart");
//				   string p= "";
//				   l_flash->changeScreen(l_src,l_src,l_src,p.c_str(),ZaScreenFlash::NONE);
		}
	}
}
Exemple #24
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;
}
Exemple #25
0
void BlackberryMain::runMain() {
	bool running = true;
	while (running && !g_quitRequested) {
		input_state.mouse_valid = false;
		input_state.accelerometer_valid = false;
		while (true) {
			// Handle Blackberry events
			bps_event_t *event = NULL;
			bps_get_event(&event, 0);
			if (event == NULL)
				break; // Ran out of events
			int domain = bps_event_get_domain(event);
			if (domain == screen_get_domain()) {
				handleInput(screen_event_get_event(event));
			} else if (domain == navigator_get_domain()) {
				switch(bps_event_get_code(event))
				{
				case NAVIGATOR_INVOKE_TARGET:
					{
						const navigator_invoke_invocation_t *invoke = navigator_invoke_event_get_invocation(event);
						if(invoke) {
							boot_filename = navigator_invoke_invocation_get_uri(invoke)+7; // Remove file://
						}
					}
					break;
				case NAVIGATOR_ORIENTATION:
					sensor_remap_coordinates(navigator_event_get_orientation_angle(event));
					break;
				case NAVIGATOR_BACK:
				case NAVIGATOR_SWIPE_DOWN:
					NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_ESCAPE, KEY_DOWN));
					break;
				case NAVIGATOR_EXIT:
					return;
				}
			} else if (domain == sensor_get_domain()) {
				if (SENSOR_ACCELEROMETER_READING == bps_event_get_code(event)) {
					sensor_event_get_xyz(event, &(input_state.acc.y), &(input_state.acc.x), &(input_state.acc.z));
					AxisInput axis;
					axis.deviceId = DEVICE_ID_ACCELEROMETER;
					axis.flags = 0;

					axis.axisId = JOYSTICK_AXIS_ACCELEROMETER_X;
					axis.value = input_state.acc.x;
					NativeAxis(axis);

					axis.axisId = JOYSTICK_AXIS_ACCELEROMETER_Y;
					axis.value = input_state.acc.y;
					NativeAxis(axis);

					axis.axisId = JOYSTICK_AXIS_ACCELEROMETER_Z;
					axis.value = input_state.acc.z;
					NativeAxis(axis);
				}
			}
		}
		UpdateInputState(&input_state);
		NativeUpdate(input_state);
		// Work in Progress
		// Currently: Render to HDMI port (eg. 1080p) when in game. Render to device when in menu.
		// Idea: Render to all displays. Controls go to internal, game goes to external(s).
		if (GetUIState() == UISTATE_INGAME && !emulating) {
			emulating = true;
			switchDisplay(screen_emu);
			if (g_Config.iShowFPSCounter == 4) {
				int options = SCREEN_DEBUG_STATISTICS;
				screen_set_window_property_iv(screen_win[0], SCREEN_PROPERTY_DEBUG, &options);
			}
		} else if (GetUIState() != UISTATE_INGAME && emulating) {
			emulating = false;
			switchDisplay(screen_ui);
		}
		NativeRender();
		EndInputState(&input_state);
		time_update();
		// This handles VSync
		if (emulating)
			eglSwapBuffers(egl_disp[screen_emu], egl_surf[screen_emu]);
		else
			eglSwapBuffers(egl_disp[screen_ui], egl_surf[screen_ui]);
	}
}
Exemple #26
0
void OSBB10::process_events() {

	handle_accelerometer();

	bps_event_t *event = NULL;

	do {
		int rc = bps_get_event(&event, 0);
		assert(rc == BPS_SUCCESS);

		if (!event) break;

		#ifdef BB10_SCORELOOP_ENABLED
		ScoreloopBB10* sc = Globals::get_singleton()->get_singleton_object("Scoreloop")->cast_to<ScoreloopBB10>();
		if (sc->handle_event(event))
			continue;
		#endif

		#ifdef PAYMENT_SERVICE_ENABLED
		if (payment_service->handle_event(event))
			continue;
		#endif

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

			handle_screen_event(event);

		} else if (domain == navigator_get_domain()) {

			if (NAVIGATOR_EXIT == bps_event_get_code(event)) {
				if (main_loop)
					main_loop->notification(MainLoop::NOTIFICATION_WM_QUIT_REQUEST);
				bps_event_destroy(event);
				exit(0);
				return;
			/*
			} else if (bps_event_get_code(event) == NAVIGATOR_ORIENTATION_CHECK) {

				int angle = navigator_event_get_orientation_angle(event);
				navigator_orientation_check_response(event, false);

			} else if (bps_event_get_code(event) == NAVIGATOR_ORIENTATION) {

				_resize(event);
			*/
			} else if (bps_event_get_code(event) == NAVIGATOR_WINDOW_STATE) {

				int state = navigator_event_get_window_state(event);
				bool was_fullscreen = fullscreen;
				minimized = state == NAVIGATOR_WINDOW_INVISIBLE;
				fullscreen = state == NAVIGATOR_WINDOW_FULLSCREEN;
				set_low_processor_usage_mode(!fullscreen);
				if (fullscreen != was_fullscreen) {
					if (fullscreen) {
						audio_server->set_fx_global_volume_scale(fullscreen_mixer_volume);
						audio_server->set_stream_global_volume_scale(fullscreen_stream_volume);
					} else {
						fullscreen_mixer_volume = audio_server->get_fx_global_volume_scale();
						fullscreen_stream_volume = audio_server->get_stream_global_volume_scale();
						audio_server->set_fx_global_volume_scale(0);
						audio_server->set_stream_global_volume_scale(0);
					};
				};
			};
		} else if (domain == audiodevice_get_domain()) {

			const char * audiodevice_path = audiodevice_event_get_path(event);
			printf("************* got audiodevice event, path %s\n", audiodevice_path);
			audio_driver->finish();
			audio_driver->init(audiodevice_path);
			audio_driver->start();
		};

		//bps_event_destroy(event);
	} while (event);
};
Exemple #27
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;
}
/*
 * 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()";
}
Exemple #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;
}
Exemple #30
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;
}