[{"id":2986,"web_url":"https://patchwork.libcamera.org/comment/2986/","msgid":"<20191029144127.GL20198@bigcity.dyn.berto.se>","date":"2019-10-29T14:41:27","subject":"Re: [libcamera-devel] [PATCH v2 4/9] libcamera: bound_method:\n\tSupport connection types","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Laurent,\n\nThanks for your work.\n\nOn 2019-10-28 12:49:08 +0200, Laurent Pinchart wrote:\n> Support all connection types in the BoundMethodBase::activePack()\n> method. To support this, add a semaphore to the InvokeMessage to signal\n> delivery.\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\n> ---\n>  src/libcamera/bound_method.cpp  | 30 ++++++++++++++++++++++++++++--\n>  src/libcamera/include/message.h |  5 +++++\n>  src/libcamera/message.cpp       | 11 +++++++++--\n>  src/libcamera/object.cpp        |  8 +++++++-\n>  4 files changed, 49 insertions(+), 5 deletions(-)\n> \n> diff --git a/src/libcamera/bound_method.cpp b/src/libcamera/bound_method.cpp\n> index ab6ecd9423d1..600717363444 100644\n> --- a/src/libcamera/bound_method.cpp\n> +++ b/src/libcamera/bound_method.cpp\n> @@ -8,6 +8,7 @@\n>  #include <libcamera/bound_method.h>\n>  \n>  #include \"message.h\"\n> +#include \"semaphore.h\"\n>  #include \"thread.h\"\n>  #include \"utils.h\"\n>  \n> @@ -49,12 +50,37 @@ namespace libcamera {\n>  \n>  void BoundMethodBase::activatePack(void *pack)\n>  {\n> -\tif (Thread::current() == object_->thread()) {\n> +\tConnectionType type = connectionType_;\n> +\tif (type == ConnectionTypeAuto) {\n> +\t\tif (Thread::current() == object_->thread())\n> +\t\t\ttype = ConnectionTypeDirect;\n> +\t\telse\n> +\t\t\ttype = ConnectionTypeQueued;\n> +\t}\n> +\n> +\tswitch (type) {\n> +\tcase ConnectionTypeDirect:\n> +\tdefault:\n>  \t\tinvokePack(pack);\n> -\t} else {\n> +\t\tbreak;\n> +\n> +\tcase ConnectionTypeQueued: {\n>  \t\tstd::unique_ptr<Message> msg =\n>  \t\t\tutils::make_unique<InvokeMessage>(this, pack);\n>  \t\tobject_->postMessage(std::move(msg));\n> +\t\tbreak;\n> +\t}\n> +\n> +\tcase ConnectionTypeBlocking: {\n> +\t\tSemaphore semaphore;\n> +\n> +\t\tstd::unique_ptr<Message> msg =\n> +\t\t\tutils::make_unique<InvokeMessage>(this, pack, &semaphore);\n> +\t\tobject_->postMessage(std::move(msg));\n> +\n> +\t\tsemaphore.acquire();\n> +\t\tbreak;\n> +\t}\n>  \t}\n>  }\n>  \n> diff --git a/src/libcamera/include/message.h b/src/libcamera/include/message.h\n> index 1cfde5669ede..311755cc60fe 100644\n> --- a/src/libcamera/include/message.h\n> +++ b/src/libcamera/include/message.h\n> @@ -15,6 +15,7 @@ namespace libcamera {\n>  \n>  class BoundMethodBase;\n>  class Object;\n> +class Semaphore;\n>  class Thread;\n>  \n>  class Message\n> @@ -48,14 +49,18 @@ class InvokeMessage : public Message\n>  {\n>  public:\n>  \tInvokeMessage(BoundMethodBase *method, void *pack,\n> +\t\t      Semaphore *semaphore = nullptr,\n>  \t\t      bool deleteMethod = false);\n>  \t~InvokeMessage();\n>  \n> +\tSemaphore *semaphore() const { return semaphore_; }\n> +\n>  \tvoid invoke();\n>  \n>  private:\n>  \tBoundMethodBase *method_;\n>  \tvoid *pack_;\n> +\tSemaphore *semaphore_;\n>  \tbool deleteMethod_;\n>  };\n>  \n> diff --git a/src/libcamera/message.cpp b/src/libcamera/message.cpp\n> index efafb655c17e..daf653221077 100644\n> --- a/src/libcamera/message.cpp\n> +++ b/src/libcamera/message.cpp\n> @@ -119,13 +119,14 @@ Message::Type Message::registerMessageType()\n>   * \\brief Construct an InvokeMessage for method invocation on an Object\n>   * \\param[in] method The bound method\n>   * \\param[in] pack The packed method arguments\n> + * \\param[in] semaphore The semaphore used to signal message delivery\n>   * \\param[in] deleteMethod True to delete the \\a method when the message is\n>   * destroyed\n>   */\n>  InvokeMessage::InvokeMessage(BoundMethodBase *method, void *pack,\n> -\t\t\t     bool deleteMethod)\n> +\t\t\t     Semaphore *semaphore, bool deleteMethod)\n>  \t: Message(Message::InvokeMessage), method_(method), pack_(pack),\n> -\t  deleteMethod_(deleteMethod)\n> +\t  semaphore_(semaphore), deleteMethod_(deleteMethod)\n>  {\n>  }\n>  \n> @@ -135,6 +136,12 @@ InvokeMessage::~InvokeMessage()\n>  \t\tdelete method_;\n>  }\n>  \n> +/**\n> + * \\fn InvokeMessage::semaphore()\n> + * \\brief Retrieve the message semaphore passed to the constructor\n> + * \\return The message semaphore\n> + */\n> +\n>  /**\n>   * \\brief Invoke the method bound to InvokeMessage::method_ with arguments\n>   * InvokeMessage::pack_\n> diff --git a/src/libcamera/object.cpp b/src/libcamera/object.cpp\n> index 98aa0af2f9b9..b0818f9aa25f 100644\n> --- a/src/libcamera/object.cpp\n> +++ b/src/libcamera/object.cpp\n> @@ -13,6 +13,7 @@\n>  \n>  #include \"log.h\"\n>  #include \"message.h\"\n> +#include \"semaphore.h\"\n>  #include \"thread.h\"\n>  #include \"utils.h\"\n>  \n> @@ -123,7 +124,12 @@ void Object::message(Message *msg)\n>  \tswitch (msg->type()) {\n>  \tcase Message::InvokeMessage: {\n>  \t\tInvokeMessage *iMsg = static_cast<InvokeMessage *>(msg);\n> +\t\tSemaphore *semaphore = iMsg->semaphore();\n>  \t\tiMsg->invoke();\n> +\n> +\t\tif (semaphore)\n> +\t\t\tsemaphore->release();\n> +\n>  \t\tbreak;\n>  \t}\n>  \n> @@ -150,7 +156,7 @@ void Object::message(Message *msg)\n>  void Object::invokeMethod(BoundMethodBase *method, void *args)\n>  {\n>  \tstd::unique_ptr<Message> msg =\n> -\t\tutils::make_unique<InvokeMessage>(method, args, true);\n> +\t\tutils::make_unique<InvokeMessage>(method, args, nullptr, true);\n>  \tpostMessage(std::move(msg));\n>  }\n>  \n> -- \n> Regards,\n> \n> Laurent Pinchart\n> \n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from mail-lj1-x243.google.com (mail-lj1-x243.google.com\n\t[IPv6:2a00:1450:4864:20::243])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0A49C6017E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 29 Oct 2019 15:41:29 +0100 (CET)","by mail-lj1-x243.google.com with SMTP id v2so1303133lji.4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 29 Oct 2019 07:41:28 -0700 (PDT)","from localhost (h-93-159.A463.priv.bahnhof.se. [46.59.93.159])\n\tby smtp.gmail.com with ESMTPSA id\n\tb23sm8077966lfj.49.2019.10.29.07.41.27\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 29 Oct 2019 07:41:27 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to\n\t:user-agent; bh=QU1l1HWanNR+FFDB2vc5c0seb1PWMbphKj8Fzejr3SA=;\n\tb=ng3JgkBmEsmE72UzbDeywzkmZ9Og/U0B6phJBlZ7ZpyKiLWqIzSqBjgdmJPsnl7mFo\n\tWimYnCahMW8AMXQkVL4rY/xE25jNCbhMWqwRg0OKKn+9AZrtmhLr+K4KZ4861/ZeSNy3\n\t8hvNHBQjaZdz4lQ911a2jPtUvTZZtD2SNBXxSJZSxB4WkAFGfaQ7ClYUzdAwQzfP4vNy\n\tHUn+cMbpFvm6mGk2XlcNrxspATsXnDj3Dn389RGDlQfYDU6vDIgxKikyqZ8k4bebHxo5\n\t00KYlM6EgZIRD7yf7ZlELOlKOrgICY+r5j7sMniEpunxtOcCaQDLKVblFPNcxhG93k1N\n\ttpeQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to:user-agent;\n\tbh=QU1l1HWanNR+FFDB2vc5c0seb1PWMbphKj8Fzejr3SA=;\n\tb=kl5yVJEk2Dkp20KqbJO0K/RYRmF+ewe4EuSdfTVs4WPc8T4GlmJr31kan3I7jfDfih\n\tfOThiUtYfPdmiWjlLEon/da0+GPRhqDF0izgwPUs1t/RSpnnTYPWvUat3gBa4qg+DgDN\n\tYmx/+MmethgKhca8FV9cMKx6/kXBqtXgl4BAya+g3eBqH+1ENUY5kQOYiIFEeBxFU08C\n\t3xOGzhEF3202sosZLXwp35fk6rymkjXPEe73M5YZqCBV7yaSPAZF25+OB4DjeoJ2d25H\n\tF7NCdvxSPV4IM9MCEFzbStrx+uEfJSelrqwr97W0iywLRll7J94XCzjvMll31u5/oGNz\n\tDZKg==","X-Gm-Message-State":"APjAAAXbXEtBZ1tVH60g4NAt3aMtnrVTQKJVnRUTE9SFxPs33fuVJkrv\n\tYRAV2N8LyzhoIoU13+VlbUv2Rg==","X-Google-Smtp-Source":"APXvYqz+qI/CeYZnU67dtKLZS2jw/2GdBZS1OeDi64Xpba/7i4dfTahGLzaXO4U35+oKRbFq6MEgOQ==","X-Received":"by 2002:a2e:161b:: with SMTP id\n\tw27mr2989481ljd.183.1572360088327; \n\tTue, 29 Oct 2019 07:41:28 -0700 (PDT)","Date":"Tue, 29 Oct 2019 15:41:27 +0100","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20191029144127.GL20198@bigcity.dyn.berto.se>","References":"<20191028104913.14985-1-laurent.pinchart@ideasonboard.com>\n\t<20191028104913.14985-5-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20191028104913.14985-5-laurent.pinchart@ideasonboard.com>","User-Agent":"Mutt/1.12.1 (2019-06-15)","Subject":"Re: [libcamera-devel] [PATCH v2 4/9] libcamera: bound_method:\n\tSupport connection types","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Tue, 29 Oct 2019 14:41:29 -0000"}}]