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
Highlighted
New Developer
Posts: 29
Registered: ‎08-03-2014
My Device: Q10
My Carrier: Vodafone

Trying to learn more about Geofencing

Hi all,

 

I have been readings the docs and trying to implement a way to be notified when the device enters into a region in my headless app. I don't want to post a notification in the hub but just do some background processing each time a region is entered.

 

I attempted to put the select while loop in a thread in my headless part (please tell me if this isn't the correct way to do this) but the loop doesn't seem to block, it just continously falls through the loop with no blocking.

 

There is very little reference to what I'm trying when I do a google search so can anybody tell me why my loop isn't blocking and also if I do get it to block how do I get the actual geomonitor event information in my loop?

 

Thanks for any help you can offer, I'm really at a loss with this.

 

Here's my attempt so far..

 

void RegionMonitor::run()
{
      geomonitor_service_t geomonitor = NULL;
      geomonitor_service_initialize(&geomonitor);
      int fd = 0;
      geomonitor_service_get_fd(geomonitor, &fd);
      geomonitor_region_t region = NULL;
      geomonitor_create_region(&region, "Home");
      geomonitor_region_set_circle_shape(region, 45.342102,-75.770581, 200.0);
      geomonitor_add(region);
      fd_set fds;
      FD_ZERO( &fds );
      FD_SET( fd, &fds );
      int flags = fcntl(fd, F_GETFL, 0);
      while (select( fd+1, &fds, NULL, NULL, NULL ) > 0)
      {
          qDebug() << "after while regionmonitor";
          if (FD_ISSET(fd, &fds)) {
              qDebug() << "after isset regionmonitor";
              // Read/parse the notifications, handle the event
              // and release it afterwards

          }
      }

      geomonitor_service_shutdown(&geomonitor);
}