Skip to content

Support for responding to application object method calls #27

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

Closed
vjrantal opened this issue Mar 30, 2015 · 2 comments
Closed

Support for responding to application object method calls #27

vjrantal opened this issue Mar 30, 2015 · 2 comments

Comments

@vjrantal
Copy link
Contributor

Currently, one can define interfaces with methods and register them under application objects, but there is no way to respond to method calls after methods are invoked.

In ajtcl code, this is done with the AJ_MarshalReplyMsg function and an example can be found from https://git.allseenalliance.org/cgit/core/ajtcl.git/tree/samples/basic/basic_service.c#n84.

In terms of the API how this is exposed, alternatives include at least extending the addListener interface for returning values from the callbacks or defining a new interface like addMethodImplementation that has mechanism to handle returns.

See the comment at #26 (comment) for background information.

@vjrantal
Copy link
Contributor Author

vjrantal commented Apr 2, 2015

@garethsony and @christopherperry We now merged the first attempt of the iOS support for this feature.

If you are interested, you could try it out by adding the plugin directly from GitHub with something like:

cordova plugin add https://github.com/AllJoyn-Cordova/cordova-plugin-alljoyn.git

The documentation will be improved in the context of #26 but here is the basics of how it works.

Object setup:

var proxyObjects = [
      {
        path: "/chatService",
        interfaces: [
          [
            "org.alljoyn.bus.samples.dosomething",
            "!Signal str>s",
            "?DoSomething <s >s",
            null
          ],
          null
        ]
      },
      null
    ];

Listener (method implementaiton):

var doSomethingHandler = function(msgForReply) {
          // If needed, get the received message with msgForReply.message
          var getRandomInt = function() {
            return Math.floor(Math.random() * (100 - 0)) + 0;
          };
          var r = getRandomInt();
          if(r < 50) {
            msgForReply.replySuccess('s', ["A successful result argument"]);
          } else {
            msgForReply.replyError('bad luck my friend' + r);
          }
        };
bus.addListenerForReply([1,0,0,1], 's', doSomethingHandler);

You can also see this file https://github.com/AllJoyn-Cordova/cordova-plugin-alljoyn/blob/b2da906568030c311027f1d1ccc7fc3fea9bbd73/tests/methods.js that is a test using this feature and has been tested to work on iOS.

@garethsony
Copy link
Contributor

Awesome. Thank you for implementing this so quickly. We have tried it out and it seems to work well.

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

No branches or pull requests

3 participants