Updated dummy backend 77/13077/1
authorJimmy Huang <jimmy.huang@intel.com>
Wed, 27 Nov 2013 20:40:45 +0000 (12:40 -0800)
committerJimmy Huang <jimmy.huang@intel.com>
Wed, 27 Nov 2013 20:41:48 +0000 (12:41 -0800)
Change-Id: I02379f9cf765c3c66d2485cb6ef724189f20d041
Signed-off-by: Jimmy Huang <jimmy.huang@intel.com>
js/websocket.js
packaging/Settings.changes

index 01f19e6..4229a2d 100644 (file)
@@ -168,6 +168,7 @@ var wsAPI = (function() {
 
     function fireEvent(type, id, name, value) {
         var event = new this.EventObject(type, id, name, value);
+        console.log('Firing ' + type + ' event id=' + id + ', name=' + name + ', value=' + value);
         event_callbacks.fire(event);
     }
 
@@ -268,27 +269,99 @@ var wsAPI = (function() {
                 if (call && (!call.done) && (call.transactionid === msg.transactionid)) {
                     call.finish();
                     if (msg.error !== undefined) {
-                        call.errorCB(msg.error);
+                        if (call.errorCB) {
+                            call.errorCB(msg.error);
+                        }
                     }
-                    if (msg.value !== undefined && call.successCB && call.errorCB !== undefined) {
+                    if (msg.value !== undefined && call.successCB !== undefined) {
                         switch (msg.type) {
-                        case WS_REQUEST_TYPE.WIFI:
-                            if (msg.name === 'is_enabled') {
-                                /* default to enabled */
-                                var result = true;
-                                call.successCB(result);
+                        case WS_REQUEST_TYPE.CONNMAN_MANAGER:
+                        case WS_REQUEST_TYPE.CONNMAN_TECHNOLOGY:
+                            if (msg.name === 'get_technologies') {
+                                var results = [
+                                    [
+                                        ["/net/connman/technology/ethernet",
+                                        {
+                                            "Name": "Wired",
+                                            "Type": "ethernet",
+                                            "Powered": true,
+                                            "Connected": true,
+                                            "Tethering": false
+                                        }],
+                                        ["/net/connman/technology/wifi",
+                                        {
+                                            "Name": "WiFi",
+                                            "Type": "wifi",
+                                            "Powered": false,
+                                            "Connected": false,
+                                            "Tethering": false
+                                        }],
+                                        ["/net/connman/technology/bluetooth",
+                                        {
+                                            "Name": "Bluetooth",
+                                            "Type": "bluetooth",
+                                            "Powered": false,
+                                            "Connected": false,
+                                            "Tethering": false
+                                        }]
+                                    ]
+                                ];
+
+                                replyMsg = JSON.stringify(results);
+                                call.successCB(results);
                                 return;
-                            } else if (msg.name === 'enable' && msg.value === true) {
+                            } else if (msg.name === 'enable' && msg.value[1] === true) {
                                 call.successCB();
+                                fireEvent(WS_EVENT_TYPE.CONNMAN, msg.value[0], 'PropertyChanged', ["Powered", true]);
                                 return;
-                            } else if (msg.name === 'enable' && msg.value === false) {
+                            } else if (msg.name === 'enable' && msg.value[1] === false) {
                                 call.successCB();
+                                fireEvent(WS_EVENT_TYPE.CONNMAN, msg.value[0], 'PropertyChanged', ["Powered", false]);
                                 return;
-                            } else if (msg.name === 'scan') {
+                            } else if (msg.name === 'get_services' || msg.name === 'scan') {
                                 var results = [
                                     [
                                         ["/net/connman/service/ethernet_0010f32f5a70_cable",
-                                        {}],
+                                        {
+                                            "Type": "ethernet",
+                                            "Security": [],
+                                            "State": "ready",
+                                            "AutoConnect": true,
+                                            "Domains": ["ftrdhcpuser.net"],
+                                            "Domains.Configuration": [],
+                                            "Ethernet": {
+                                                "Address": "10:20:F3:2F:5E:23",
+                                                "Interface": "eno1",
+                                                "MTU": 1500,
+                                                "Method": "auto"
+                                            },
+                                            "Favorite": true,
+                                            "IPv4": {
+                                                "Address": "192.168.1.20",
+                                                "Gateway": "192.168.1.1",
+                                                "Method": "dhcp",
+                                                "Netmask": "255.255.255.0"
+                                            },
+                                            "IPv4.Configuration": {
+                                                "Method": "dhcp"
+                                            },
+                                            "IPv6": {},
+                                            "IPv6.Configuration": {
+                                                "Method": "auto",
+                                                "Privacy": "disabled"
+                                            },
+                                            "Immutable": false,
+                                            "Name": "Wired",
+                                            "Nameservers": ["192.168.1.1", "184.11.12.13"],
+                                            "Nameservers.Configuration": [],
+                                            "Provider": {},
+                                            "Proxy": {
+                                                "Method": "direct"
+                                            },
+                                            "Proxy.Configuration": {},
+                                            "Timeservers": ["192.168.1.1", "pool.ntp.org"],
+                                            "Timeservers.Configuration": []
+                                        }],
                                         ["/net/connman/service/wifi_c8f733acdf96_3558364737_managed_psk",
                                         {
                                             "Type": "wifi",
@@ -420,45 +493,41 @@ var wsAPI = (function() {
                                     call.successCB(results);
                                 }, 2000);
                                 return;
-                            } else if (msg.name === 'connect') {
-                                call.successCB();
-                                setTimeout(function() {
-                                    fireEvent(WS_REQUEST_TYPE.WIFI, '/net/connman/service/wifi_c8f733acdf96_3558364737_managed_psk', 'PropertyChanged', ["Connected", true]);
-                                }, 2000);
+                            }
+                        case WS_REQUEST_TYPE.CONNMAN_SERVICE:
+                            if (msg.name === 'connect') {
+                                if (msg.value[0] === '/net/connman/service/wifi_c8f733acdf96_3558364737_managed_psk' && msg.value[1].Passphrase !== '123') {
+                                    call.errorCB('Invalid passphrase');
+                                } else if (msg.value[0] === '/net/connman/service/wifi_c8f733acdf96_446f75636865626167_managed_psk' && msg.value[1].Passphrase !== '123') {
+                                    call.errorCB('Invalid passphrase');
+                                } else {
+                                    call.successCB();
+                                    setTimeout(function() {
+                                        fireEvent(WS_EVENT_TYPE.CONNMAN, msg.value[0], 'PropertyChanged', ["Connected", true]);
+                                    }, 2000);
+                                }
                                 return;
                             } else if (msg.name === 'disconnect') {
                                 call.successCB();
                                 setTimeout(function() {
-                                    fireEvent(WS_REQUEST_TYPE.WIFI, '/net/connman/service/wifi_c8f733acdf96_3558364737_managed_psk', 'PropertyChanged', ["Connected", false]);
+                                    fireEvent(WS_EVENT_TYPE.CONNMAN, msg.value[0], 'PropertyChanged', ["Connected", false]);
                                 }, 2000);
                                 return;
                             } else {
-                                call.errorCB('Unsupported request: ' + msg.name + ', ' + msg.value);
-                                return;
-                            }
-                            break;
-                        case WS_REQUEST_TYPE.BLUETOOTH:
-                            if (msg.name === 'enable' && msg.value === true) {
-                                call.successCB();
-                                return;
-                            } else if (msg.name === 'enable' && msg.value === false) {
-                                call.successCB();
-                                return;
-                            } else {
-                                call.errorCB('Unsupported request: ' + msg.name + ', ' + msg.value);
+                                if (call.errorCB) {
+                                    call.errorCB('Unsupported request: ' + msg.name + ', ' + msg.value);
+                                }
                                 return;
                             }
                             break;
                         case WS_REQUEST_TYPE.DATETIME:
                             if (msg.name === 'is_time_updates_auto' && msg.value !== undefined) {
                                 /* default to manual */
-                                var result = false;
-                                call.successCB(result);
+                                call.successCB(false);
                                 return;
                             } else if (msg.name === 'is_timezone_updates_auto' && msg.value !== undefined) {
                                 /* default to manual */
-                                var result = false;
-                                call.successCB(result);
+                                call.successCB(false);
                                 return;
                             } else if (msg.name === 'time' && msg.value !== undefined) {
                                 call.successCB();
@@ -473,17 +542,23 @@ var wsAPI = (function() {
                                 call.successCB();
                                 return;
                             } else {
-                                call.errorCB('Unsupported request: ' + msg.name + ', ' + msg.value);
+                                if (call.errorCB) {
+                                    call.errorCB('Unsupported request: ' + msg.name + ', ' + msg.value);
+                                }
                                 return;
                             }
                             break;
                         case WS_REQUEST_TYPE.DISPLAY:
                         case WS_REQUEST_TYPE.SOUND:
                         case WS_REQUEST_TYPE.LOCALE:
-                            call.errorCB('Request not implemented');
+                            if (call.errorCB) {
+                                call.errorCB('Request not implemented');
+                            }
                             return;
                         default:
-                            call.errorCB('Invalid request type: ' + msg.type);
+                            if (call.errorCB) {
+                                call.errorCB('Invalid request type: ' + msg.type);
+                            }
                             return;
                         }
                     }
index 0e25d0b..d6a3874 100644 (file)
@@ -1,3 +1,6 @@
+* Wed Nov 27 2013 Jimmy Huang <jimmy.huang@intel.com> ivi_oct_m2@6917fc4
+- Updated dummy backend
+
 * Wed Nov 27 2013 Jimmy Huang <jimmy.huang@intel.com> ivi_oct_m2@d39bf75
 - Updated connman and bluetooth settings to the new connman protocols in settings-daemon