From patchwork Fri Dec 14 08:12:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Parthiban Nallathambi X-Patchwork-Id: 1013375 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::338; helo=mail-wm1-x338.google.com; envelope-from=swupdate+bncbaabbfwmzxqakgqeu7h6dna@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="H3j1V1Nu"; dkim-atps=neutral Received: from mail-wm1-x338.google.com (mail-wm1-x338.google.com [IPv6:2a00:1450:4864:20::338]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43GNbJ5XZLz9s1c for ; Fri, 14 Dec 2018 19:13:14 +1100 (AEDT) Received: by mail-wm1-x338.google.com with SMTP id v7sf1247622wme.9 for ; Fri, 14 Dec 2018 00:13:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1544775190; cv=pass; d=google.com; s=arc-20160816; b=o4mO64UmttONV5MEgP86Qxo2UTPZh223OxSQFM5vV3fRcMlcASGCcFKrH9YYA5opDQ vWirMTPa3MwfD2roFwUrp6BbohEZJ8A1xTG4nXpa8RrK+PweZE8e5GE0FVYiu6mEQxoV trU1n16PD72myjALJx/CbJimSGzy0ZOMHKSsekdr6s+T277vRuSbSNckgeOnIhxXj6vg 31DZ949DSZ2auYRlc5QrFaTT9sAmXE/0D6atAX33Xgcnd5JdXtc6RVTQicK4bTlAGQsQ ZpYPmrisGezNwTHwNwJnUr161R656JR/dSPwBuYZlI7TFtn7DY180o9YgANqsZGRuj8T 6T1A== 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:message-id:date:subject:cc:to:from :mime-version:sender:dkim-signature; bh=gHE5rikaoeFNEtL39zsoWJPAcg3U86Mc9QQ3c4bsmHA=; b=wk/CEBw3XLzuD3CX5uT+272tcJWs3FT7WBGtZVOJ2865l79V7yNRwc6mo3nWPaRt+4 ZdANdo02BUPqbvddSGtWPo0gxU2onpg1I0ssDoFQaF6n7Kp2awwkVPz7mo8DkPufqYC2 r7eG9LIYqmrXiwe79F1hRqPCSZYuMHVvdfu5oq+Xf3DGpzXwAYEGEbycFLIZ0u2UfgHL 6Z8kgQg2ibCwnJZpWIL35eeagMcjsMfZMMW8qZu5KQtPKjZt8jrOlAReJCumyzGQKHbF HUEh2xQnLaTdluKCVklBFkBLeavIJdCoqJk51IZ+1PiDjpUatG1+R69FEbCHSmKHcPqQ Na2A== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of pn@denx.de) smtp.mailfrom=pn@denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=gHE5rikaoeFNEtL39zsoWJPAcg3U86Mc9QQ3c4bsmHA=; b=H3j1V1Nu32H4Zs5cSt4Vm8vpxer6k6q3zY6Zi+HqsRDRPb0c+IrzFqCTgAaHDvZd2M Mh2LrsnngE29joFPt/3nMoUUOFR/QwSs6cep/YK3k2FDGFeOJVcrnHTqd93dR0ntMeu+ eRVtvrU9L87+fptGqZIjourDxqOwCGnRaWyHbmYivIJJCRl6v+fZJoXd/MqylTv5XlSr zcfL0LGKS1G1U1Uue3BNR5gvHih0EthbAf1mEl8PIc7DVFHgHdSjRK8omurV+zNT2+MA oQhHz07DzRnm6FTSyrofRztPUEpcx8hj90+ceqPLZaWoia2mnZsKkBTPdRfTAoyWcXYE fgGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post :list-help:list-archive:list-subscribe:list-unsubscribe; bh=gHE5rikaoeFNEtL39zsoWJPAcg3U86Mc9QQ3c4bsmHA=; b=VnqNEdksqCIn/405WCAr802e0gwdX18xYCyLhlLb1pi+9bFehEJONwxpjrUMhbOvvq jZzIAQl12nZWUs57mHhA7a62yU6d0Ka3bMhtgme+vQ8XXFwjD1dkz5/MGWhZ5U97XnnF v0wU1vE19tty7PjcWiUxzoL8ns37Un65lTseZwC68uXP20zLA5+BDW0czLRLwQFh4odN 2WScvkF4ce777jbVFDbTTRCnNasR3Bk82XZlacBltOspQ3jJJ7MkMungadSMo/huTc3Q LdBB2akDc5C8bWsUaeFjkQw79cu3CabU9yJCjKsiiRK7AEOgkQRp2sLjWrPHQK6X6ATz pkTA== Sender: swupdate@googlegroups.com X-Gm-Message-State: AA+aEWbEWK/m9RGvALO92UgDm9I8BcrPl9rTvB2rKEINYyKD6mdTKeSV DhQkAoxJ+xwaNuPpRmacmZ0= X-Google-Smtp-Source: AFSGD/VOvxcl2Xx5DTBwKDLySTBRGzPs2Ln+DLNcSRLTUJbJXAH6Ku40g8PhPOoX4VZmw/SBBEwKnw== X-Received: by 2002:adf:dc47:: with SMTP id m7mr2750wrj.1.1544775190768; Fri, 14 Dec 2018 00:13:10 -0800 (PST) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 2002:a5d:4982:: with SMTP id r2ls1173020wrq.0.gmail; Fri, 14 Dec 2018 00:13:10 -0800 (PST) X-Received: by 2002:a5d:49c4:: with SMTP id t4mr163727wrs.31.1544775190398; Fri, 14 Dec 2018 00:13:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544775190; cv=none; d=google.com; s=arc-20160816; b=xT41Ld4pDyFx92NF/v0BbAiloAukSGHwk7bAJ/D9ExkTsINQQFVC31Gb9msXQCeBv6 cnJuPKpCOgW2B4IgSCTfY1qdtyMKU+0qhRe8HpNRk2EbtqJ3abZ5OyCqcTthWyEuxExh 19sPipCEyvznqAYBkWC5w5s+4ck+oFAxMusaW6PxVqEWtlCwvpIbKLiZwJjCSQxQw3bS 1jC2tELQuxMFVgP7sBGwsqTc02+wE+hRO61Nuysz2dvhVQT5/qn2B7j3oFxdgp3qR9Rs QlFfB+tCFZMnWzOqIRX7rAtnZ9wInmHMUvL2yFnqEYXOjtYNu9y7nZtiv+MZn5IeqqUG K9wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from; bh=21zljY+cMWpBa4EWa3vh7TBL3KW0RHdIMu/ynNYxOS4=; b=fow1KiOfIiW2tE4DbRCElYth3E/3EUrfjTOP59lzN4sKnYWXXTUXJd9ojcNl9MbHba /EMPEs/Zm0PZQTno8yfOsD0/Bml7daQdDXaOD8p7pPwegASEWrz3FY64EFq56wwQjJFQ H+BsnOdSxD+5FUFWvUajiCkdvld0QlSlpqaZfUnZezwHv3WvA3r12HQUALcOgVow8QmR 3HZg4uePaPYZRxcStvbKCTXf4e8c6jlUIXXLvtm5j2r+Pm/z0jB0P85h/p+Q6AmowK8M Xf29yI72QbitAjlwjdLJWow6U6WkHJz9pgo8lmLMNb+hs6TftssTH5Hapd6w61Fm3u8Z owbw== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of pn@denx.de) smtp.mailfrom=pn@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 k39si171775wre.2.2018.12.14.00.13.10 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Dec 2018 00:13:10 -0800 (PST) Received-SPF: neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of pn@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 43GNbB13CPz1qvwY; Fri, 14 Dec 2018 09:13:10 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 43GNbB0yJFz1qsJR; Fri, 14 Dec 2018 09:13:10 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id tI-_vpEp0vh7; Fri, 14 Dec 2018 09:13:08 +0100 (CET) X-Auth-Info: YO8+PYWrtjY4+6h4AJ6KYLcHqUO2Ok9kyTgRuT2/8xQ= Received: from xpert.denx.de (unknown [62.91.23.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Fri, 14 Dec 2018 09:13:08 +0100 (CET) From: Parthiban Nallathambi To: swupdate@googlegroups.com Cc: Parthiban Nallathambi Subject: [swupdate] [PATCH] ipc: add custom argument for client callbacks Date: Fri, 14 Dec 2018 09:12:58 +0100 Message-Id: <20181214081258.1763273-1-pn@denx.de> X-Mailer: git-send-email 2.17.2 X-Original-Sender: pn@denx.de X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of pn@denx.de) smtp.mailfrom=pn@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: , current implementation of swupdate_async_start doesn't take custom argument for callbacks (read, finish). This leaves consumer of this API to maintain global memory always. Added extra argument to swupdate_async_start and writedata, terminated callsback with this argument. This makes consumer of this API to use custom memory and preserve arguments for later usage. Signed-off-by: Parthiban Nallathambi --- include/network_ipc.h | 6 +++--- ipc/network_ipc.c | 8 +++++--- tools/client.c | 6 +++--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/include/network_ipc.h b/include/network_ipc.h index ea997b8..d9540ed 100644 --- a/include/network_ipc.h +++ b/include/network_ipc.h @@ -69,12 +69,12 @@ int ipc_get_status(ipc_message *msg); int ipc_postupdate(ipc_message *msg); int ipc_send_cmd(ipc_message *msg); -typedef int (*writedata)(char **buf, int *size); +typedef int (*writedata)(char **buf, int *size, void *arg); typedef int (*getstatus)(ipc_message *msg); -typedef int (*terminated)(RECOVERY_STATUS status); +typedef int (*terminated)(RECOVERY_STATUS status, void *arg); int ipc_wait_for_complete(getstatus callback); int swupdate_image_write(char *buf, int size); int swupdate_async_start(writedata wr_func, getstatus status_func, - terminated end_func, bool dryrun); + terminated end_func, void *arg, bool dryrun); #endif diff --git a/ipc/network_ipc.c b/ipc/network_ipc.c index 4cfe2f3..d9a481f 100644 --- a/ipc/network_ipc.c +++ b/ipc/network_ipc.c @@ -42,6 +42,7 @@ struct async_lib { writedata wr; getstatus get; terminated end; + void *arg; }; static int handle = 0; @@ -291,7 +292,7 @@ static void *swupdate_async_thread(void *data) if (!rq->wr) break; - rq->wr(&pbuf, &size); + rq->wr(&pbuf, &size, rq->arg); if (size) swupdate_image_write(pbuf, size); } while(size > 0); @@ -316,7 +317,7 @@ static void *swupdate_async_thread(void *data) } if (rq->end) - rq->end((RECOVERY_STATUS)swupdate_result); + rq->end((RECOVERY_STATUS)swupdate_result, rq->arg); pthread_exit(NULL); } @@ -347,7 +348,7 @@ static pthread_t start_ipc_thread(void *(* start_routine) (void *), void *arg) * Only one running request is accepted */ int swupdate_async_start(writedata wr_func, getstatus status_func, - terminated end_func, bool dryrun) + terminated end_func, void *arg, bool dryrun) { struct async_lib *rq; int connfd; @@ -360,6 +361,7 @@ int swupdate_async_start(writedata wr_func, getstatus status_func, rq->wr = wr_func; rq->get = status_func; rq->end = end_func; + rq->arg = arg; connfd = ipc_inst_start_ext(SOURCE_UNKNOWN, 0, NULL, dryrun); diff --git a/tools/client.c b/tools/client.c index 1a59d97..7a0db59 100644 --- a/tools/client.c +++ b/tools/client.c @@ -49,7 +49,7 @@ pthread_mutex_t mymutex; * It is called by a thread generated by the library and * can block. */ -static int readimage(char **p, int *size) { +static int readimage(char **p, int *size, void *arg) { int ret; ret = read(fd, buf, sizeof(buf)); @@ -79,7 +79,7 @@ static int printstatus(ipc_message *msg) * this is called at the end reporting the status * of the upgrade */ -static int end(RECOVERY_STATUS status) +static int end(RECOVERY_STATUS status, void *arg) { printf("Swupdate %s\n", status == FAILURE ? "*failed* !" : @@ -103,7 +103,7 @@ static int send_file(const char* filename) { /* synchronize with a mutex */ pthread_mutex_lock(&mymutex); rc = swupdate_async_start(readimage, printstatus, - end, false); + end, NULL, false); if (rc) printf("swupdate_async_start returns %d\n", rc);