Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to use custom receive handler #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

PanicMan
Copy link

@PanicMan PanicMan commented May 8, 2015

Added ability to use custom receive handler to receive custom messages in own app, in this case all messages other than the download messages will be forwarded to own receive handler

Added ability to use custom receive handler to receive custom messages in own app
added ability for an error callback, so we can act if an error occurs
@sarfata
Copy link
Contributor

sarfata commented May 19, 2015

Thanks for sharing this. This is a nice addition but I am not sure we want to add this in the example at the moment, just to keep things as simple as possible.

I will keep your PR open and I will discuss this with my colleague to see what would be the best way to share that with everyone.

@PanicMan
Copy link
Author

ok, cool! I think it's very useful as otherwise you are not able to receive any messages from JS...

@cpfair
Copy link

cpfair commented May 19, 2015

I did this the other way around: don't touch the netDL code, instead use the fact that app_message_set_x_handler returns the old callback to chain in additional ones (which defer to that old callback if the message is uninteresting). Much cleaner IMO.

@PanicMan
Copy link
Author

Ok, that sounds interesting! Do you have an example to look at? I've seen nothing about that in the documentation...

@cpfair
Copy link

cpfair commented May 19, 2015

It's documented -
https://developer.getpebble.com/docs/c/Foundation/AppMessage/#app_message_register_inbox_received and could work something like this:

static AppMessageInboxReceived netdl_received_handler;
// ...
static void in_received_handler(DictionaryIterator *iter, void *ctx) {
  if (dict_find(iter, ...)) {
    // Do things
  } else {
    // Pass to netDL
    netdl_received_handler(iter, ctx);
  }
}
// ...
static void init(void) {
  netdownload_initialize(...);
  netdl_received_handler = app_message_register_inbox_received(in_received_handler);
}

@PanicMan
Copy link
Author

Hmm, not bad, that could also be a solution for ntDL itself... What about the error handler? Is there also an better solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants