[Utils] Interface for JavaScript <-> native communication.
authorRafal Galka <r.galka@samsung.com>
Fri, 12 Dec 2014 10:58:07 +0000 (11:58 +0100)
committerRafal Galka <r.galka@samsung.com>
Mon, 15 Dec 2014 08:18:08 +0000 (17:18 +0900)
commitbbc3816e3820b968db54bcf37effd60b67426341
tree0c12d7157fbe42fae4dc4710a0f16f2ca6458706
parent50caa0cc30196958e050ee5cf57ec5606777e8e1
[Utils] Interface for JavaScript <-> native communication.

[Message]
xwalk.utils.native prototype:
- callSync(cmd, args)
- call(cmd, args, callback)
- addListener(name, callback)
- removeListener(name)
and helpers to check/handle native response:
- isSuccess(result)
- isFailure(result)
- getResultObject(result)
- getErrorObject(result)

[Example]
var native_ = new xwalk.utils.NativeManager(extension);

SomeExtension.prototype.someAsyncMethod = function(id, onsuccess, onerror) {
  native_.call('SomeExtension.getElement', {
    id: id
  }, function(result) {
    if (native_.isFailure(result)) {
      onerror(native_.getErrorObject(result));
    } else {
      var data = native_.getResultObject();
      // conversion to appropriate API type
      var item = new tizen.SomeExtensionItem(data);
      onsuccess(item);
    }
  });
};

Change-Id: I867816be8ec78e5791c36dac0e6cced9f7567474
src/common/extension.cc
src/utils/utils_api.js