[Utils] remove Native Bridge from utils_api.js 85/164485/1
authorLukasz Bardeli <l.bardeli@samsung.com>
Tue, 19 Dec 2017 08:46:05 +0000 (09:46 +0100)
committerLukasz Bardeli <l.bardeli@samsung.com>
Tue, 19 Dec 2017 08:46:05 +0000 (09:46 +0100)
        Remove NativeBridge from code. Native Bridge is not used anymore in
        webapi plugins.

[Verification] Code compiles without error. TCT passrate alarm, filesystem, archive and
        systeminfo 100%

Change-Id: Ia2da038df334b08425739bc3e18f0d3a3fc688ab
Signed-off-by: Lukasz Bardeli <l.bardeli@samsung.com>
src/utils/utils_api.js

index 07dfedb3326c75a0a609082a58c876773095406c..a651ab53b41196d0756a8a1ef7d0e36353a48fec 100644 (file)
@@ -1161,255 +1161,6 @@ NativeManager.prototype.callIfPossible = function(callback) {
   }
 };
 
-/*
- *bridge is a two way communication interface
- *Example usage:
- *var bridge = new NativeBridge(extension);
- *    To send sync method:
- *    var result = bridge.sync({
- *        cmd: 'my_cpp_function_symbol',
- *        args: {
- *            name: 'My name',
- *            age: 28
- *        }
- *    });
- *    xwalk.utils.log(result);
- *
- *    To send async method and handle response:
- *    bridge.async({
- *        cmd: 'my_cpp_function_symbol',
- *        args: {
- *            name: 'My name'
- *        }
- *    }).then({
- *        success: function (data) {
- *            var age = data.age;
- *            args.successCallback(age);
- *        },
- *        error: function (e) {...},
- *        someCallback: function (data) {...}
- *    });
- *bridge.async will add special param to passed data called cid
- *that param need to be kept and returned with respons
- *To determine which callback should be invoked, response should
- *contain "action" param. Value of "action" param indicates name of
- *triggered callback.
- *Callbask are removed from listenr by defoult to prevent that behaviour
- *param "keep" should be assigned to value true
- *Example of c++ async response:
- *    Simple succes with data:
- *    {
- *        cid: 23,
- *        action: 'success',
- *        args: {
- *            age: 23
- *        }
- *    }
- *    More complicated example:
- *    {
- *        cid: 23,
- *        action: 'progress',
- *        keep: true,
- *        args: {
- *            age: 23
- *        }
- *    }
- */
-var NativeBridge = (function (extension, debug) {
-    debug = !!debug;
-    var Callbacks = (function () {
-        var _collection = {};
-        var _cid = 0;
-        var _next = function () {
-            return (_cid += 1);
-        };
-
-        var CallbackManager = function () {};
-
-        CallbackManager.prototype = {
-            add: function (/*callbacks, cid?*/) {
-                if (debug) xwalk.utils.log('bridge.CallbackManager.add');
-                var args = Array.prototype.slice.call(arguments);
-                var c = args.shift();
-                var cid = args.pop();
-                if (cid) {
-                    if (c !== null && typeof c === 'object') {
-                        for (var key in c) {
-                            if (c.hasOwnProperty(key)) _collection[cid][key] = c[key];
-                        }
-                    }
-                } else {
-                    cid = _next();
-                    _collection[cid] = c;
-                }
-                return cid;
-            },
-            remove: function (cid) {
-                if (debug)  xwalk.utils.log('bridge.CallbackManager.remove, cid: ' + cid);
-                if (_collection[cid]) delete _collection[cid];
-            },
-            call: function (cid, key, args, keep) {
-                if (debug) xwalk.utils.log('bridge.CallbackManager.call, cid: '+ cid + ', key: ' + key);
-                var callbacks = _collection[cid];
-                keep = !!keep;
-                if (callbacks) {
-                    var fn = callbacks[key];
-                    if (fn) {
-                        fn.apply(null, args);
-                        if (!keep) this.remove(cid)
-                    }
-                }
-            }
-        };
-
-        return {
-            getInstance: function () {
-                return this.instance || (this.instance = new CallbackManager);
-            }
-        };
-    })();
-
-
-    var Listeners = (function () {
-        var _listeners = {};
-        var _id = 0;
-        var _next = function () {
-            return (_id += 1);
-        };
-
-        var ListenerManager = function () {};
-
-        ListenerManager.prototype = {
-            add: function (l) {
-                if (debug) xwalk.utils.log('bridge.ListenerManager.add');
-                var id = _next();
-                _listeners[id] = l;
-                return id;
-            },
-            resolve: function (id, action, data, keep) {
-                if (debug) xwalk.utils.log('bridge.ListenerManager.resolve, id: ' + id + ', action: ' + action);
-                keep = !!keep;
-                var l = _listeners[id];
-                if (l) {
-                    var cm = Callbacks.getInstance();
-                    cm.call(l.cid, action, [data], keep);
-                }
-                return l;
-            },
-            remove: function (id) {
-                if (debug) xwalk.utils.log('bridge.ListenerManager.remove, id: ' + id);
-                var l = _listeners[id];
-                if (l) {
-                    var cm = Callbacks.getInstance();
-                    if (l.cid) cm.remove(l.cid);
-                    delete _listeners[id];
-                }
-            },
-            attach: function (id, key, value) {
-                if (_listeners[id]) {
-                    _listeners[id][key] = value;
-                    return true;
-                }
-                return false;
-            },
-            find: function (key, value) {
-                var result = [];
-                for (var p in _listeners) {
-                    if (_listeners.hasOwnProperty(p)) {
-                        var l = _listeners[p];
-                        if (l[key] === value) result.push({id: p, listener: l});
-                    }
-                }
-                return result;
-            }
-        }
-
-        return {
-            getInstance: function () {
-                return this.instance || (this.instance = new ListenerManager);
-            }
-        };
-    })();
-
-    var Listener = function () {
-        if (debug) xwalk.utils.log('bridge: Listener constructor');
-        this.cid = null;
-    };
-    Listener.prototype = {
-        then: function (c) {
-            if (debug) xwalk.utils.log('bridge.Listener.then');
-            var cm = Callbacks.getInstance();
-            this.cid = cm.add(c, this.cid);
-            return this;
-        }
-    };
-
-    var Bridge = function () {};
-    Bridge.prototype = {
-        sync: function (data) {
-            var json = JSON_.stringify({
-              cmd: data.cmd,
-              args: data
-            });
-            if (debug) xwalk.utilss.log('bridge.sync, json: ' + json);
-            var result = extension.internal.sendSyncMessage(json);
-            var obj = JSON_.parse(result);
-            if (obj.error)
-                throw new WebAPIException(obj.code, obj.name, obj.message);
-            return obj.result;
-        },
-        async: function (data) {
-            var l = new Listener();
-            data.cid = Listeners.getInstance().add(l);
-            var json = JSON_.stringify({
-                cmd: data.cmd,
-                args: data
-            });
-            if (debug) xwalk.utils.log('bridge.async, json: ' + json);
-            setTimeout(function () {
-                extension.postMessage(json);
-            });
-            return l;
-        },
-        listener: function (c) {
-            var l = (new Listener()).then(c);
-            var cid = Listeners.getInstance().add(l);
-            return cid;
-        },
-        attach: function (id, key, value) {
-            return Listeners.getInstance().attach(id, key, value);
-        },
-        find: function (key, value) {
-            return Listeners.getInstance().find(key, value);
-        },
-        remove: function (id) {
-            Listeners.getInstance().remove(id);
-        }
-    };
-
-    extension.setMessageListener(function (json) {
-        /*
-         *Expected response:
-         *{
-         *    cid: 23,                        // callback id
-         *    action: 'success',              // expected callback action
-         *    keep: false                     // optional param
-         *    args: {...}                     // data pased to callback
-         *}
-         */
-
-        if (debug) xwalk.utils.log('bridge.setMessageListener, json: ' + json);
-        var data = JSON_.parse(json);
-        if (data.cid && data.action) {
-            setTimeout(function() {
-                Listeners.getInstance().resolve(data.cid, data.action, data.args, data.keep);
-            }, 0);
-        }
-    });
-
-    return new Bridge;
-});
-
 // WebAPIException and WebAPIError definition moved to Utils for compliance
 // reasons with blink-wrt environment.
 // In blink-wrt the original Tizen module is loaded, which is not providing exception constructor.
@@ -1612,7 +1363,6 @@ Utils.prototype.type = _type;
 Utils.prototype.converter = _converter;
 Utils.prototype.validator = _validator;
 Utils.prototype.NativeManager = NativeManager;
-Utils.prototype.NativeBridge = NativeBridge;
 
 var native_ = new NativeManager(extension);
 
@@ -1622,5 +1372,4 @@ Object.freeze(exports);
 Object.freeze(exports.utils);
 Object.freeze(Utils.prototype);
 Object.freeze(NativeManager.prototype);
-Object.freeze(NativeBridge.prototype);