0

I want to get the timerID for a time based trigger headless app. I get the trigger to fire and invoke the headless portion of my app, but the problem is that I cannot fetch the timerID.

Is there any way to get the timerID from the request? I've tried the following(generally):

void Service::handleInvoke(const bb::system::InvokeRequest &request) {
    if (request.action().compare("bb.action.system.TIMER_FIRED") == 0) {
        // I've tried the following things and looked at their results in a saved setting 
        // but none give the timerID

        QString yo(request.data());
        settingzs.setValue("wheresthetimerid",yo);

        // and
        QVVariantMap metmet = request.metadata();    
        QString whatid = metmet["timerID"]; //also tried metmet[0] to no avail
        settingzs.setValue("wheresthetimerid",whatid);

        // and 
        request.uri()
        // and 
        request.listID() 
   }
}
nonesuchnick
  • 627
  • 4
  • 17
Dave
  • 17
  • 4

1 Answers1

0

No, it doesn't seem that it is possible to get the timerID of the original InvokeTimerRequest when handling an invocation in the Cascades APIs. Initially, I thought it might be possible to simply cast the InvokeRequest to an InvokeTimerRequest, but looking closely at the API definitions, these are separate classes and an InvokeTimerRequest is fundamentally different than an InvokeRequest.

An InvokeTimerRequest basically registers a timer for generating an invocation to a specific target, and when/each time the timer fires, a new distinct InvokeRequest object is created and sent. It is recommended to store the timerID when creating and registering the InvokeTimerRequest, since the timerID must be used to de-register the invoke timer if it is recurring.

If you really need to get the ID of the request, and you are willing to go lower level, this might be possible using the BlackBerry Platform Services (BPS) API to handle invoke events. You would need to implement a BPS event loop in your service, and register to receive and handle navigator events. From the event you can retrieve the navigator_invoke_invocation_t structure describing the invocation, and you should be able to call navigator_invoke_invocation_get_id() to retrieve the ID of the InvokeRequest.

switch (bps_event_get_code(event)) {
  case NAVIGATOR_INVOKE_TARGET: {
    const navigator_invoke_invocation_t *invoke = 
        navigator_invoke_event_get_invocation(event);
    // an invocation has been received
    if(invoke) {
      // retrieve invocation action
      QString action = navigator_invoke_invocation_get_action(invoke);
      if (action.compare("bb.action.system.TIMER_FIRED") == 0) {
        QString id = navigator_invoke_invocation_get_id(invoke);
      }
    }
  }
  break;
} 

For a more C++ approach, you could create your own subclass of AbstractBpsEventHandler to handle this instead.

However, in the end the ID retrieved is most likely only the ID of the generated InvokeRequest, and not the timerID you specified when creating and registering the InvokeTimerRequest.

nonesuchnick
  • 627
  • 4
  • 17