Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Regular Contributor
0x29a
Posts: 68
Registered: ‎03-13-2012
My Device: Playbook

Ndk Bugg or current understanding on how events work is incorrect ?

At the entry point of my program I just call the class run method.

which should call

if (BPS_SUCCESS != screen_request_events(native_context))
      {
        fprintf(stderr, "screen_request_events failed\n");
        return EXIT_FAILURE;
      }
    return EXIT_SUCCESS;

The issue is that at no time when I touch the screen of the playbook it should produce a "Touch \n" in the console but it does not at all, but

the navigator does appear to work fine.

I have been debugging for hours and found that there are 3 threads created one for the graphics and one right after the screen_request_events call.

My question is what would cause

//Return the domain so what type of event it is.
int domain = bps_event_get_domain(event);

not to return a

domain == screen_get_domain ?

Below is my code that should be complete.

I think this maybe a bug with the most recent ndk ?

/* !
 * \file PlaybookNativeActivity.cpp
 * \brief This is a implementation of PlaybookNativeActivity it encapsulates Playbook
 *       functionality.
 * \date Mar 7, 2012
 * \author MichaelChung
 */

#include "BlackBerryPlatformNativeActivity.h"

namespace mobiusbear
{

  BlackBerryPlatformNativeActivity::BlackBerryPlatformNativeActivity()
  {
    opengl_es2_manager = OpenGLES2Manager();

  }

  BlackBerryPlatformNativeActivity::~BlackBerryPlatformNativeActivity()
  {

  }

  int
  BlackBerryPlatformNativeActivity::Run()
  {
    // Create the native window context.
    if (InitializeNativeWindow() == EXIT_FAILURE)
      {
        this->Exit();
        CleanUp();
        return EXIT_FAILURE;
      }
    // Initialize OpenGLES2.0.
    if (opengl_es2_manager.InitEGL() == EXIT_FAILURE)
      {
        this->Exit();
        CleanUp();
        return EXIT_FAILURE;
      }
    // Bind the OpenGLES2.0 to the native window.
    if (opengl_es2_manager.OpenGLES2Bind(native_window) == EXIT_FAILURE)
      {
        this->Exit();
        CleanUp();
        return EXIT_FAILURE;
      }
    // Start the screen request events from BPS.
    if (StartScreenRequestEvents() == EXIT_FAILURE)
      {
        this->Exit();
        CleanUp();
        return EXIT_FAILURE;
      }
    // Start the navigator events for BPS.
    if (StartNavigatorRequestEvents() == EXIT_FAILURE)
      {
        this->Exit();
        CleanUp();
        return EXIT_FAILURE;
      }
    // Start polling events for BPS.
    if (StartPollingEvents() == EXIT_FAILURE)
      {
        this->Exit();
        CleanUp();
        return EXIT_FAILURE;
      }
    // Cleanup the native activity.
    CleanUp();

    return EXIT_SUCCESS;
  }

  //TODO REMOVE THIS and implement observer pattern object using functor.
  void
  BlackBerryPlatformNativeActivity::Render()
  {
    //fprintf(stderr, "I am Rendering \n");
  }
  //TODO REMOVE THIS and implement observer pattern object using functor.
  void
  BlackBerryPlatformNativeActivity::smileyfrustrated:creenEventHandler(bps_event_t * event)
  {
    int screen_val;

    screen_event_t screen_event = screen_event_get_event(event);

    screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE,
        &screen_val);

    switch (screen_val)
    {
    case SCREEN_EVENT_MTOUCH_TOUCH:
      fprintf(stderr, "TOUCH \n");
      break;
    case SCREEN_EVENT_MTOUCH_MOVE:
      fprintf(stderr, "MOVE \n");
      break;
    case SCREEN_EVENT_MTOUCH_RELEASE:
      fprintf(stderr, "RELEASE \n");
      break;
    default:
      fprintf(stderr, "NOTHING \n");
      break;
      }
  }

  void
  BlackBerryPlatformNativeActivity::NavigatorEventHandler(bps_event_t * event)
  {
    switch (bps_event_get_code(event))
      {
    case NAVIGATOR_SWIPE_DOWN:
      fprintf(stderr, "Swipe down event \n");
      break;
    case NAVIGATOR_EXIT:
      fprintf(stderr, "Exit event \n");
      exit_application = true;
      break;
    default:
      break;
      }
  }

  int
  BlackBerryPlatformNativeActivity::InitializeNativeWindow()
  {

    /*
     * The context provides the setting for graphics operations within
     * a windowing environment. Using context specific API components
     * you gain access to objects on which you want to draw -
     * Windows, Groups, Displays, PixMap.
     * This allows access to their properties.
     *
     * A context encapsulates the connection to the windowing system.
     * You can use the context to set and return global properties and to get events.
     * The responsibility for this whole method is to create the context then
     * attach the context to the windowing system, then set window properties.
     */

    // Set up the Playbook attributes for the native window.
    int screen_usage = SCREEN_USAGE_OPENGL_ES2 | SCREEN_USAGE_ROTATION;
    // Set the screen color format.
    int screen_format = SCREEN_FORMAT_RGBX8888;
    // Set the number of buffers to be used for the native window.
    int number_of_buffers = 2;

    // Create a native context for the Playbook allows application to access the under laying windowing system.
    /*
     * The SCREEN_APPLICATION_CONTEXT
     * This context type enables a process to create its own windows and to control some of the window properties.
     * An application cannot modify a window that was created by another application and it cannot send an event outside of its own process space. An application's context is unaware of other top-level windows in the system.
     * An application context can parent another window, even if the window is created in another context within another processes.
     */
    return_code = screen_create_context(&native_context, 0);
    if(return_code)
      {
        perror("screen_create_context. \n");
        return EXIT_FAILURE;
      }

    // Playbook Native Window initialization.

    // BlackBerry Platform Services initialization
    bps_initialize();

    // Create a Native Window using the Native Context that can be used to
    // make graphical content visible on the display.
    // This creates the connection to the windowing system using the context.
    return_code = screen_create_window(&native_window, native_context);
    if (return_code)
      {
        perror("screen_create_window.\n");
        return EXIT_FAILURE;
      }

    // Set that windows properties using the screen format RGBA8888.
    return_code = screen_set_window_property_iv(native_window,
        SCREEN_PROPERTY_FORMAT, &screen_format);
    if (return_code)
      {
        perror("screen_set_window_property_iv.\n");
        return EXIT_FAILURE;
      }
    // Set the window property for screen usage rotation and OpenGL ES 2.0.
    return_code = screen_set_window_property_iv(native_window,
        SCREEN_PROPERTY_USAGE, &screen_usage);
    if (return_code)
      {
        perror("screen_set_window_property_iv.\n");
        return EXIT_FAILURE;
      }
    // Get the window screen property display.
    return_code = screen_get_window_property_pv(native_window,
        SCREEN_PROPERTY_DISPLAY, (void**) &native_display);
    if (return_code)
      {
        perror("screen_get_window_property_pv.\n");
        return EXIT_FAILURE;
      }

    int screen_resolution[2];
    // Get screen display property size for later use.
    return_code = screen_get_display_property_iv(native_display,
        SCREEN_PROPERTY_SIZE, screen_resolution);
    if (return_code)
      {
        perror("screen_get_display_property_iv.\n");
        return EXIT_FAILURE;
      }

    int angle = atoi(getenv("ORIENTATION"));

    // Get screen display property.
    // Pass the screen mode for use.
    screen_display_mode_t screen_mode;
    return_code = screen_get_display_property_pv(native_display,
        SCREEN_PROPERTY_MODE, (void **) &screen_mode);
    if (return_code)
      {
        perror("screen_get_display_property_pv.\n");
        return EXIT_FAILURE;
      }

    int size[2];

    // Get the screen buffer size.
    return_code = screen_get_window_property_iv(native_window,
        SCREEN_PROPERTY_BUFFER_SIZE, size);
    if (return_code)
      {
        perror("screen_get_window_property_iv.\n");
        return EXIT_FAILURE;

      }

    int buffer_size[2] =
      { size[0], size[1] };

    if ((angle == 0) || (angle == 180))
      {
        if (((screen_mode.width > screen_mode.height) && (size[0] < size[1]))
            || ((screen_mode.width < screen_mode.height) && (size[0] > size[1])))
          {
            buffer_size[1] = size[0];
            buffer_size[0] = size[1];
          }
      }
    else if ((angle == 90) || (angle == 270))
      {
        if (((screen_mode.width > screen_mode.height) && (size[0] > size[1]))
            || ((screen_mode.width < screen_mode.height && size[0] < size[1])))
          {
            buffer_size[1] = size[0];
            buffer_size[0] = size[1];
          }
      }
    else
      {
        fprintf(stderr,
            "Navigator returned an unexpected orientation angle.\n");
        return EXIT_FAILURE;
      }

    // Set buffer size
    return_code = screen_set_window_property_iv(native_window,
        SCREEN_PROPERTY_BUFFER_SIZE, buffer_size);
    if (return_code)
      {
        perror("screen_set_window_property_iv.\n");
        return EXIT_FAILURE;
      }
    // Set the native window angle.
    return_code = screen_set_window_property_iv(native_window,
        SCREEN_PROPERTY_ROTATION, &angle);
    if (return_code)
      {
        perror("screen_set_window_property_iv.\n");
        return EXIT_FAILURE;
      }
    // Set the native window buffer numbers.
    return_code = screen_create_window_buffers(native_window,
        number_of_buffers);
    if (return_code)
      {
        perror("screen_create_window_buffers.\n");
        return EXIT_FAILURE;
      }

    return EXIT_SUCCESS;

  }

  int
  BlackBerryPlatformNativeActivity::smileyfrustrated:tartScreenRequestEvents()
  {
    // The screen_request_events() function starts to deliver libscreen events to an application using BPS.
    // An application must not invoke libscreen's get_screen_event() function if it is receiving screen events through BPS.
    // The screen_request_events()
    // function should not be called multiple times before calling screen_stop_events().
    // An application may only request events for a single screen_context_t at one time.
    if (BPS_SUCCESS != screen_request_events(native_context))
      {
        fprintf(stderr, "screen_request_events failed\n");
        return EXIT_FAILURE;
      }
    return EXIT_SUCCESS;
  }

  int
  BlackBerryPlatformNativeActivity::smileyfrustrated:tartNavigatorRequestEvents()
  {
    // The navigator_request_events()
    // function starts to deliver navigator events to your application using BPS.
    // Events will be posted to the currently active channel.
    if (BPS_SUCCESS != navigator_request_events(0))
      {
        fprintf(stderr, "navigator_request_events failed \n");
        return EXIT_FAILURE;
      }
    // function specifies to the navigator whether your application's orientation.
    // is locked or not locked.
    if (BPS_SUCCESS != navigator_rotation_lock(false))
      {
        fprintf(stderr, "navigator_rotation_lock failed \n");
        return EXIT_FAILURE;
      }

    return EXIT_SUCCESS;

  }

  int
  BlackBerryPlatformNativeActivity::smileyfrustrated:tartPollingEvents()
  {

    // While this is not true grab events.
    while (!exit_application)
      {
        // This pointer will be destroyed after the while block is over
        // Should refactor this to allow memory manager management from memory pool.
        bps_event_t * event = NULL;

        for (;:smileywink:
          {
            // Get the event and pass it to the pointer.
            return_code = bps_get_event(&event, 50);

            // Ensure this returns success code.
            assert(return_code == BPS_SUCCESS);

            // If there is any event we will pull from domain otherwise it will crash the application.
            if (event)
              {
                //Return the domain so what type of event it is.
                int domain = bps_event_get_domain(event);

                // If it is a domain in which is screen related deal with it here.

                // If it is a screen event have it get the event for the screen.
                if (domain == screen_get_domain())
                  {
                    // Handle the event here.
                    fprintf(stderr, "The screen get domain event\n");
                    ScreenEventHandler(event);
                  } /* end if */

                // If it a navigator event handle it.
                if (domain == navigator_get_domain())
                  {
                    //  Handle the navigator.
                    fprintf(stderr, "The navigator get screen event\n");
                    NavigatorEventHandler(event);
                 }

              } /* end if */

            else
              {
                // Break the for loop to process other events.
                // fprintf(stderr,"else finish the if \n");
                break;
              } /* end else */

          } /* end for */

        // TODO replace this with a list that implements functors.
        Render();

      } /* While loop */

    return EXIT_SUCCESS;
  }

  int
  BlackBerryPlatformNativeActivity::CleanUp()
  {

    if (native_window != NULL)
      {
        screen_destroy_window(native_window);
        native_window = NULL;
      }
    screen_stop_events(native_context);
    native_context = NULL;
    bps_shutdown();
    screen_destroy_context(native_context);
    return EXIT_SUCCESS;
  }

  int
  BlackBerryPlatformNativeActivity::Exit()
  {
    opengl_es2_manager.CleanUp();
    this->CleanUp();
    return EXIT_SUCCESS;
  }

} /* namespace mobiusbear */


Please use plain text.
New Developer
PlayBookDave
Posts: 52
Registered: ‎01-09-2012
My Device: PlayBook

Re: Ndk Bugg or current understanding on how events work is incorrect ?

/*

* 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.

*/

rc =

bps_get_event(&event, -1);

Please use plain text.
Regular Contributor
0x29a
Posts: 68
Registered: ‎03-13-2012
My Device: Playbook

Re: Ndk Bugg or current understanding on how events work is incorrect ?

this does not work either ... changed and recompiled it still not luck =( it doesn't event enter that if statement
Please use plain text.
New Developer
PlayBookDave
Posts: 52
Registered: ‎01-09-2012
My Device: PlayBook

Re: Ndk Bugg or current understanding on how events work is incorrect ?

Well try Step filters and set break points...

Please use plain text.
Regular Contributor
0x29a
Posts: 68
Registered: ‎03-13-2012
My Device: Playbook

Re: Ndk Bugg or current understanding on how events work is incorrect ?

That was done essentially I have done the debugging when I tap the screen it should give me a certain code of around 1001 or 1002 or what ever that code number is I sometimes get code 12 which means screen idle but its rare an inconsistant which is odd.

Please use plain text.
Regular Contributor
0x29a
Posts: 68
Registered: ‎03-13-2012
My Device: Playbook

Re: Ndk Bugg or current understanding on how events work is incorrect ?

still at it no luck anyone else ever have this problem ?

Please use plain text.
Regular Contributor
0x29a
Posts: 68
Registered: ‎03-13-2012
My Device: Playbook

Re: Ndk Bugg or current understanding on how events work is incorrect ?

For using the filters and the step setups

 

What I have done is have it enter the event loop do a beizel down swipe run through the code then it will output it, then perform a touch and release then it appears to skip and not return a touch and release event :smileyfrustrated:. or any screen event for that matter.

Please use plain text.
BlackBerry Development Advisor
anhu
Posts: 54
Registered: ‎10-26-2011
My Device: Playbook

Re: Ndk Bugg or current understanding on how events work is incorrect ?

Hi, 

 

your code has the following line: 

  // Initialize OpenGLES2.0.

Which suggests you are using EGL and thus OpenGL. 

However, we can not find any calls to eglSwapBuffers() in your code. 

If you never call eglSwapBuffers() then there is no screen being displayed where touch events can happen. 

 

It might be worth trying to start with one of our NDK Samples at github and trying to modify the sample into the app you want. 


Please use plain text.
Regular Contributor
0x29a
Posts: 68
Registered: ‎03-13-2012
My Device: Playbook

Re: Ndk Bugg or current understanding on how events work is incorrect ?

Hey I will look into this, this is probably the reason
Please use plain text.