From patchwork Tue Jul 4 10:33:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 1803140 X-Patchwork-Delegate: sbabic@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::13c; helo=mail-lf1-x13c.google.com; envelope-from=swupdate+bncbcxploxj6ikrbd7lr6sqmgqeoyocv4a@googlegroups.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20221208 header.b=SZ/e31s8; dkim-atps=neutral Received: from mail-lf1-x13c.google.com (mail-lf1-x13c.google.com [IPv6:2a00:1450:4864:20::13c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QwK0539Xmz20b1 for ; Tue, 4 Jul 2023 20:33:55 +1000 (AEST) Received: by mail-lf1-x13c.google.com with SMTP id 2adb3069b0e04-4f76712f950sf5086483e87.0 for ; Tue, 04 Jul 2023 03:33:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1688466832; cv=pass; d=google.com; s=arc-20160816; b=syAdFXnLkHysTjHMhBLNibyAIUp9Wko+Fwz+Lwj3/X0rwvY8kMdV94lAh0a+fbnfer Mdkw93zNt/P9ySIr7OEQqa+aer5SZ63acKq9lFDCG5iCqrzwDkgAN+pWBCXAjdvEuYNl +pdtZnJJeNOQK/gXStuWdOnhCqSbEQNGP52maj3ZHG2vAXORJiV2TsZVxhuPT6ZzgM8w /zUBNC7PsdLwlsvtjFddbiU2uu9bc3Bm0kivNoAITS0Qt6fDENDqN7k3q1mrKnnY0Oo+ Bn6xHF+1ceC5yzxOSWj1YGi5G9xsSQRhCcD0KG66nKwUnvrsFvT4WWs2YIcDkZCwTU3A BNOA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:mime-version:message-id:date :subject:cc:to:from:sender:dkim-signature; bh=mDkoIHVJNruGjFYyFnX1Nr/DqPin+bqrKz4RX7QgoAw=; fh=lWBtl6pS9pyAnqZoOD8LO/oehp4+grVVQDFlD36xIhM=; b=qVFRoMDZDp134nnOTStjex0JGmBSbwo6BRfuxs0XJyQQCCVXtDWsfQWDVNy6RzPvk7 +4tKNnx97vsHQOgxmCevKIzMLix2ceYs9GM8RmGZu16VeZQ815Sqy5ntwySwq/0l7OEp smdv0o/ApHrG0ORUlEs1Pzr+EZr9G0l2b/AKoZYFiuLRUq0L9UKf3U/L339qchz2iJtA lzGCIhvJ+wrqPlouUhePruJmYf8ydpQZ/KXk4BRWDVLKWMnoPlSVh4UCehhvHBft/rB8 g60jqZGWZcdzZdqKR5BCYWwj8MOQ0gae51NQfSZaC37eN22D3d8Rx8mrNCuDJQu9HD24 86CQ== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20221208; t=1688466832; x=1691058832; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:x-original-authentication-results :x-original-sender:mime-version:message-id:date:subject:cc:to:from :sender:from:to:cc:subject:date:message-id:reply-to; bh=mDkoIHVJNruGjFYyFnX1Nr/DqPin+bqrKz4RX7QgoAw=; b=SZ/e31s8/EdpLO2yiGKu8Bsm5CE5Gr4YT3v1wgadFX4hXQr0ao0yagtAVyFzwLpp4S tZmEmv3C8R91M+3yCa3RjR/DzYGHMi38HfL3M8iM9Ko+d8Cixk4YfjEcP+5i6w6s2oJ9 RjJdaWTz97ZxRABkenPQ3hK174eNayDDd6AIMJFgBrG9X45F2HI08z6dX8E5EST/ihpv MxEPdCDKNKqBGzamTLBo1WbxOThX0HvG3zmOucFSPHWoPCVkWclqOcJuXypuWSHjmbkt cLT2ktc7jeSVe4FY5H4g+gDpW6rmf31fFNYx6adhUWylhWf0BLDvA81kR/icjtr+yxhd R2YQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688466832; x=1691058832; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender:mime-version :message-id:date:subject:cc:to:from:x-beenthere:x-gm-message-state :sender:from:to:cc:subject:date:message-id:reply-to; bh=mDkoIHVJNruGjFYyFnX1Nr/DqPin+bqrKz4RX7QgoAw=; b=D3Vsc3V7+8nqzuOJQmkqUP52ojZTeE+v9RqIvatXI9NSy6kjIgSq2IbF7+oDn6icWN GWLNgemET378JlYPDViA2G9v4PplVB3MqJWSL8J/McEFaMKKkTLGkpU6tpEOIwJczWLa ZwA/ZV+B4fXYnAD6edumcB65PoGBSdSqIAvvarxsfyaDewKmAF9b65WsmGPsjWANv4aV xMgPknk74i2oADsmStxGa/zOezjYPejx7aQt9ioav1Yv9eK1lCKLuVjk2oTVVnqGtg4A dtqPfl8UBMelBXA2l3W5SBaUaQkqGJNUXAg0IsGDsTgFORRMmu4fKzel7Msma/gUqMmd WW4w== Sender: swupdate@googlegroups.com X-Gm-Message-State: ABy/qLZbHK68NKLfFCRI9Qm0kHIzE9icUamUPX75qNAWVkgW00H7h/Jo kzmR7A4XPePzWQQQZcsLGA4= X-Google-Smtp-Source: APBJJlHfuxntepFoUxgFXjSN/YDHjsC3/c50wx/quiBqlr7fkMM/YwlpfEM6An+H0/uLcYfNcu2a4g== X-Received: by 2002:ac2:58e2:0:b0:4fb:7665:9b0d with SMTP id v2-20020ac258e2000000b004fb76659b0dmr7674208lfo.12.1688466832371; Tue, 04 Jul 2023 03:33:52 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a19:645e:0:b0:4fb:a37b:86ac with SMTP id b30-20020a19645e000000b004fba37b86acls601774lfj.2.-pod-prod-03-eu; Tue, 04 Jul 2023 03:33:50 -0700 (PDT) X-Received: by 2002:a05:6512:3448:b0:4fb:780d:2a49 with SMTP id j8-20020a056512344800b004fb780d2a49mr7614320lfr.5.1688466830527; Tue, 04 Jul 2023 03:33:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688466830; cv=none; d=google.com; s=arc-20160816; b=wxG861wgK4+wLIhJti/90QWdHg5Gs7GG1YZj+fL46AMvGCHb6pc61t/PQwCDs5yQl2 OpiYplUOrsF1Q0WDa7rVyaUH/LT8snQbxnd0SawhzaZL050lvrTdXne7XRy526h61S+z 6mdGGSvWn2/p7o8qkGF7nmcm/Eh13+Co8MXB9Ld70dnQd/PLuLX3D9Ax0TlrbJUoH4ub e41dMEsq0Bfe/YBBcQjctYZPnPy+5qeYdn2utEKYQZfIwnopiEGOoLw6DeBetSCZPQ5T YX5rn6bxcaoFW7zY8ZKLk1Nyiv+riVLSIJGGazEbC97Y3uvQZcIjOohDRe/G7/5/3D7o INuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from; bh=2H3wn5yct5I9otX5zfGl4vrKUMMkxL3rCrH8krsbOJ8=; fh=sS/JG7DayaPJPeuvXRO/hM8Bw9v5Z/HG6btrevW4/5k=; b=uxzOSkXMzq8xuDiwi2Vqy7iJolQeT/MdjN3MHYB1CYlXlYIeAj/qdkgHIm5JGURw6i WEe37lS3qLAWvVOKBcPhj8vsMyyVX1ooMfHJwwzOquvOpxg9bdgJMU6yAeUJ78E+UxfF Qq/wfYuPDLwy3X9uOtrRLb7AMaH2FJCnRcK3zi8g5CpMXZAAkEbD0WWP4ACai2bCKfL8 8WzoByz0FeQDMHsGxBxw9e+9OmcmOvZu8n665NI/SVTgpCDI5z10pV24AgrB8XguZMoY Cb9vrV84JXBM85w32pzsu+8pQ+Ik2v6LHAiqwOVkI486ePSiFcp097NMbeyDLPdtokv+ bSUQ== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=denx.de Received: from mail-out.m-online.net (mail-out.m-online.net. [212.18.0.9]) by gmr-mx.google.com with ESMTPS id o18-20020a056512231200b004fba307ab75si674951lfu.7.2023.07.04.03.33.50 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Jul 2023 03:33:50 -0700 (PDT) Received-SPF: neutral (google.com: 212.18.0.9 is neither permitted nor denied by domain of sbabic@denx.de) client-ip=212.18.0.9; Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 4QwJzx611Mz1r6RW; Tue, 4 Jul 2023 12:33:49 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.68]) by mail.m-online.net (Postfix) with ESMTP id 4QwJzx5lxxz1qqlW; Tue, 4 Jul 2023 12:33:49 +0200 (CEST) X-Virus-Scanned: amavis at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.68]) (amavis, port 10024) with ESMTP id GuZ-Ahc6IObh; Tue, 4 Jul 2023 12:33:49 +0200 (CEST) Received: from babic.homelinux.org (host-88-217-136-221.customer.m-online.net [88.217.136.221]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPS; Tue, 4 Jul 2023 12:33:48 +0200 (CEST) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id CAB8D454070E; Tue, 4 Jul 2023 12:33:47 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([127.0.0.1]) by localhost (mail.babic.homelinux.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Nc6A3HSSI7TO; Tue, 4 Jul 2023 12:33:44 +0200 (CEST) Received: from paperino.fritz.box (paperino.fritz.box [192.168.178.48]) by babic.homelinux.org (Postfix) with ESMTP id 165244540709; Tue, 4 Jul 2023 12:33:44 +0200 (CEST) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH] Add nodejs binding for progress interface Date: Tue, 4 Jul 2023 12:33:42 +0200 Message-Id: <20230704103342.44447-1-sbabic@denx.de> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Original-Sender: sbabic@denx.de X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=denx.de Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Add javascript module that can be used bz nodejs applications to follow the update via progress interface. Signed-off-by: Stefano Babic --- bindings/nodejs/index.js | 90 ++++++++++++++++++++++++++++++++++++ bindings/nodejs/package.json | 17 +++++++ 2 files changed, 107 insertions(+) create mode 100644 bindings/nodejs/index.js create mode 100644 bindings/nodejs/package.json diff --git a/bindings/nodejs/index.js b/bindings/nodejs/index.js new file mode 100644 index 00000000..c30a7d8d --- /dev/null +++ b/bindings/nodejs/index.js @@ -0,0 +1,90 @@ +var net = require('net'); +var c = require('c-struct'); + +const msgsize = 2416; + +var progressmsg = new c.Schema({ + magic: c.type.uint32, + status: c.type.uint32, + dwl_percent : c.type.uint32, + dwl_bytes_0 : c.type.uint32, + dwl_bytes_1 : c.type.uint32, + dwl_bytes_2 : c.type.uint32, + nsteps : c.type.uint32, + curstep : c.type.uint32, + curpercent : c.type.uint32, + curimage : c.type.string(256), + handler : c.type.string(64), + source : c.type.uint32, + infolen : c.type.uint32, + info : c.type.string(2048) +}) + +c.register('Progress', progressmsg); + +const statusMap = [ + "IDLE", + "START", + "RUN", + "SUCCESS", + "FAILURE", + "DOWNLOAD", + "DONE", + "SUBPROGRESS", + "PROGRESS" +]; + +class SWUpdate { + constructor(ctrlpath, progresspath, mycallback) { + this.ctrlsocket = ctrlpath; + this.progresssocket = progresspath; + this.mycallback = mycallback; + this.connected = false; + if (typeof this.mycallback != 'function') + console.log("Wrong callback !"); + } + + isConnected() { + return this.connected; + } + + receive = (msgsize, buffer) => { + var out = []; + if (!msgsize) + return; + out = (c.unpackSync('Progress', buffer)) + var status = out.status; + out.status = statusMap[out.status]; + var json = JSON.stringify(out); + this.mycallback(json); + } + + progress() { + if (this.connected) { + console.log('WRONG: already connected to SWUpdate'); + return false; + } + var clientProgress = net.createConnection({ + path : this.progresssocket, + onread: { + buffer : Buffer.alloc(msgsize), + callback : this.receive + } + }, () => { + this.connected = true; + }); + + clientProgress.on('end', () => { + console.log('disconnected from server'); + }); + clientProgress.on('close', () => { + this.connected = false; + console.log('close from server'); + }); + clientProgress.on('error', () => { + console.log('error connecting to SWUpdate'); + }); + } +} + +module.exports = (ctrl, progress, fun) => {return new SWUpdate(ctrl, progress, fun)}; diff --git a/bindings/nodejs/package.json b/bindings/nodejs/package.json new file mode 100644 index 00000000..af38f9be --- /dev/null +++ b/bindings/nodejs/package.json @@ -0,0 +1,17 @@ +{ + "name": "swupdateprog", + "version": "1.0.0", + "description": "Node Module to connect to SWUpdate", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [ + "SWUpdate" + ], + "author": "Stefano Babic ", + "license": "MIT", + "dependencies": { + "c-struct": "^0.0.5" + } +}