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
New Contributor
superfeeler
Posts: 8
Registered: ‎04-24-2012
My Device: bb9000
My Carrier: t-mobile
Accepted Solution

how to handle event from bps in Application

the given example only shows event handling in C, like dialog and others.

I want to handle these bps event in my mainApp.

I find all bps events are handled by BpsEventDispatcher::smileytongue:rocessBpsEvents().

these event willnot goto Application, anybody help?


int cascades_user_main(int argc, char **argv)
{
    // this is where the server is started etc
    Application app(argc, argv);

    App mainApp;
    QObject::connect(&app, SIGNAL(aboutToQuit()), &mainApp, SLOT(onUpdate()));

    return Application::exec(); // we complete the transaction started in the app constructor and start the client event loop here
    // when loop is exited the Application deletes the scene which deletes all its children (per qt rules for children)
    // not as nice of course
}

Please use plain text.
New Contributor
superfeeler
Posts: 8
Registered: ‎04-24-2012
My Device: bb9000
My Carrier: t-mobile

Re: how to handle event from bps in Application

some logs

startScreenEventThread(SUCCESS)
NavigatorPrivate::NavigatorPrivate - width=1024
NavigatorPrivate::NavigatorPrivate - height=600
NavigatorPrivate::NavigatorPrivate - angle=0
BpsEventDispatcher::smileytongue:rocessBpsEvents() - thread started
NavigatorPrivate::handleBpsEvent - window state
NavigatorPrivate::handleWindowStateEvent - thumbnail
NavigatorPrivate::handleBpsEvent - window state
NavigatorPrivate::handleWindowStateEvent - invisible
NavigatorPrivate::handleBpsEvent - exit
Enter App::smileysurprised:nUpdateSelected Index: 0, Label: OK, Context: n/a
### Server Thread: FINISHED
QNXApplicationEngineImpl::run(EXIT)

Please use plain text.
Developer
BikeAtor
Posts: 62
Registered: ‎03-31-2012
My Device: Playbook
My Carrier: None

Re: how to handle event from bps in Application

Write you own QThread and do the same as a NDK App.

Or use QTimer and poll the events. Thats the way I do for GPS. But be sure not to block the Gui-thread to long.

Please use plain text.
New Contributor
superfeeler
Posts: 8
Registered: ‎04-24-2012
My Device: bb9000
My Carrier: t-mobile

Re: how to handle event from bps in Application

:Balloon:

your reply is great.

a new thread to replace the NavigatorPrivate is really a good idea.

I check the ndk, and dont find information related to NavigatorPrivate.

I guess this class, or startScreenEventThread this thread isnot exposed yet.

that's make me quite compressed.

 

 

Please use plain text.
Developer
BikeAtor
Posts: 62
Registered: ‎03-31-2012
My Device: Playbook
My Carrier: None

Re: how to handle event from bps in Application

Here is some code from me to get GPS-Events. Should hopefully be the same for other events.

 

https://bdsc.webapps.blackberry.com/native/reference/com.qnx.doc.screen.lib_ref/topic/rscreen_get_ev...

 

    LOG_INFO << "use playbook GPS";
    this->screenOrientation = 0;
    bps_initialize();
    LOG_DEBUG << "initialized";
    if ( geolocation_request_events( 0 ) != BPS_SUCCESS )
    {
        LOG_WARNING << "could not request position: " << strerror( errno );
    }
    else
    {
        LOG_DEBUG << "request geolocation events";
        geolocation_set_period( 1 );
        LOG_INFO << "period 1 sec";

        LOG_DEBUG << "request orientation events";
        if ( orientation_request_events( 0 ) != BPS_SUCCESS )
        {
            LOG_WARNING << "could not request orientation: " << strerror( errno );
        }
        /*
           sensor_set_rate( SENSOR_TYPE_MAGNETOMETER, 1*1000*1000 );
           sensor_set_skip_duplicates( SENSOR_TYPE_MAGNETOMETER, true );
           sensor_request_events( SENSOR_TYPE_MAGNETOMETER );
         */

        if ( sensor_is_supported( SENSOR_TYPE_AZIMUTH_PITCH_ROLL ) == true )
        {
            // every 500 msec should be enough
            sensor_set_rate( SENSOR_TYPE_AZIMUTH_PITCH_ROLL, 500 * 1000 );
            sensor_set_skip_duplicates( SENSOR_TYPE_AZIMUTH_PITCH_ROLL, true );
            sensor_request_events( SENSOR_TYPE_AZIMUTH_PITCH_ROLL );
        }
        else
        {
            LOG_INFO << "SENSOR_TYPE_AZIMUTH_PITCH_ROLL not supported";
        }

        QTimer *playbookTimer = new QTimer();
        connect( playbookTimer, SIGNAL( timeout()), this, SLOT( pollPlaybookLocation()));
        playbookTimer->start( 100 );
        LOG_DEBUG << "playbook timer started";
    }

 

void GPS::pollPlaybookLocation()
{
    LOG_DEBUG;
    bps_event_t *event     = NULL;
    int         eventCount = 0;
    bps_get_event( &event, 0 );
    if ( event != NULL )
    {
        while ( event != NULL )
        {
            LOG_DEBUG << "event: " << QString::number( eventCount );
            eventCount++;
            if ( bps_event_get_domain( event ) == geolocation_get_domain())
            {

 

Please use plain text.
Developer
jheron
Posts: 188
Registered: ‎01-27-2012
My Device: playbook
My Carrier: ...

Re: how to handle event from bps in Application

FWIW, it appears that the bps event has been integrated into Qt's event loop. See commit a2dfb82

from yesterday. http://qt.gitorious.org/qt/qt/commits/4.8

Cheers,

Jon

Please use plain text.