[{"id":2989,"web_url":"https://patchwork.libcamera.org/comment/2989/","msgid":"<20191029144934.GO20198@bigcity.dyn.berto.se>","date":"2019-10-29T14:49:34","subject":"Re: [libcamera-devel] [PATCH v2 7/9] libcamera: object: Add\n\tconnection type parameter to invokeMethod()","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Jacopo,\n\nThanks for your work.\n\nOn 2019-10-28 12:49:11 +0200, Laurent Pinchart wrote:\n> From: Jacopo Mondi <jacopo@jmondi.org>\n> \n> Allow specifying a different connection type than ConnectionTypeQueued\n> for Object::invokeMethod().\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\n> ---\n>  include/libcamera/object.h       |  5 ++---\n>  src/android/camera_proxy.cpp     |  3 ++-\n>  src/libcamera/event_notifier.cpp |  3 ++-\n>  src/libcamera/object.cpp         |  9 +++++----\n>  src/libcamera/timer.cpp          |  3 ++-\n>  test/object-invoke.cpp           | 14 ++++++++------\n>  6 files changed, 21 insertions(+), 16 deletions(-)\n> \n> diff --git a/include/libcamera/object.h b/include/libcamera/object.h\n> index 603a229288c2..91b56596c9db 100644\n> --- a/include/libcamera/object.h\n> +++ b/include/libcamera/object.h\n> @@ -30,12 +30,11 @@ public:\n>  \tvoid postMessage(std::unique_ptr<Message> msg);\n>  \n>  \ttemplate<typename T, typename... Args, typename std::enable_if<std::is_base_of<Object, T>::value>::type * = nullptr>\n> -\tvoid invokeMethod(void (T::*func)(Args...), Args... args)\n> +\tvoid invokeMethod(void (T::*func)(Args...), ConnectionType type, Args... args)\n>  \t{\n>  \t\tT *obj = static_cast<T *>(this);\n>  \t\tBoundMethodBase *method =\n> -\t\t\tnew BoundMemberMethod<T, Args...>(obj, this, func,\n> -\t\t\t\t\t\t\t  ConnectionTypeQueued);\n> +\t\t\tnew BoundMemberMethod<T, Args...>(obj, this, func, type);\n>  \t\tvoid *pack = new typename BoundMemberMethod<T, Args...>::PackType{ args... };\n>  \n>  \t\tmethod->activatePack(pack, true);\n> diff --git a/src/android/camera_proxy.cpp b/src/android/camera_proxy.cpp\n> index 4f5c0a024903..43e1e1c3af53 100644\n> --- a/src/android/camera_proxy.cpp\n> +++ b/src/android/camera_proxy.cpp\n> @@ -187,6 +187,7 @@ int CameraProxy::processCaptureRequest(camera3_capture_request_t *request)\n>  \n>  void CameraProxy::threadRpcCall(ThreadRpc &rpcRequest)\n>  {\n> -\tcameraDevice_->invokeMethod(&CameraDevice::call, &rpcRequest);\n> +\tcameraDevice_->invokeMethod(&CameraDevice::call, ConnectionTypeQueued,\n> +\t\t\t\t    &rpcRequest);\n>  \trpcRequest.waitDelivery();\n>  }\n> diff --git a/src/libcamera/event_notifier.cpp b/src/libcamera/event_notifier.cpp\n> index 687969b0a8d1..4326b0b413e2 100644\n> --- a/src/libcamera/event_notifier.cpp\n> +++ b/src/libcamera/event_notifier.cpp\n> @@ -128,7 +128,8 @@ void EventNotifier::message(Message *msg)\n>  \tif (msg->type() == Message::ThreadMoveMessage) {\n>  \t\tif (enabled_) {\n>  \t\t\tsetEnabled(false);\n> -\t\t\tinvokeMethod(&EventNotifier::setEnabled, true);\n> +\t\t\tinvokeMethod(&EventNotifier::setEnabled,\n> +\t\t\t\t     ConnectionTypeQueued, true);\n>  \t\t}\n>  \t}\n>  \n> diff --git a/src/libcamera/object.cpp b/src/libcamera/object.cpp\n> index 509b2ebac537..db2c6f68fbc8 100644\n> --- a/src/libcamera/object.cpp\n> +++ b/src/libcamera/object.cpp\n> @@ -139,14 +139,15 @@ void Object::message(Message *msg)\n>  }\n>  \n>  /**\n> - * \\fn void Object::invokeMethod(void (T::*func)(Args...), Args... args)\n> + * \\fn void Object::invokeMethod()\n>   * \\brief Invoke a method asynchronously on an Object instance\n>   * \\param[in] func The object method to invoke\n> + * \\param[in] type Connection type for method invocation\n>   * \\param[in] args The method arguments\n>   *\n> - * This method invokes the member method \\a func when control returns to the\n> - * event loop of the object's thread. The method is executed in the object's\n> - * thread with arguments \\a args.\n> + * This method invokes the member method \\a func with arguments \\a args, based\n> + * on the connection \\a type. Depending on the type, the method will be called\n> + * synchronously in the same thread or asynchronously in the object's thread.\n>   *\n>   * Arguments \\a args passed by value or reference are copied, while pointers\n>   * are passed untouched. The caller shall ensure that any pointer argument\n> diff --git a/src/libcamera/timer.cpp b/src/libcamera/timer.cpp\n> index ddb20954afa7..4c68883204e8 100644\n> --- a/src/libcamera/timer.cpp\n> +++ b/src/libcamera/timer.cpp\n> @@ -170,7 +170,8 @@ void Timer::message(Message *msg)\n>  \tif (msg->type() == Message::ThreadMoveMessage) {\n>  \t\tif (isRunning()) {\n>  \t\t\tunregisterTimer();\n> -\t\t\tinvokeMethod(&Timer::registerTimer);\n> +\t\t\tinvokeMethod(&Timer::registerTimer,\n> +\t\t\t\t     ConnectionTypeQueued);\n>  \t\t}\n>  \t}\n>  \n> diff --git a/test/object-invoke.cpp b/test/object-invoke.cpp\n> index 37a274402e6d..f6ae2604db76 100644\n> --- a/test/object-invoke.cpp\n> +++ b/test/object-invoke.cpp\n> @@ -64,10 +64,11 @@ protected:\n>  \t\tInvokedObject object;\n>  \n>  \t\t/*\n> -\t\t * Test that method invocation in the same thread goes through\n> -\t\t * the event dispatcher.\n> +\t\t * Test that queued method invocation in the same thread goes\n> +\t\t * through the event dispatcher.\n>  \t\t */\n> -\t\tobject.invokeMethod(&InvokedObject::method, 42);\n> +\t\tobject.invokeMethod(&InvokedObject::method,\n> +\t\t\t\t    ConnectionTypeQueued, 42);\n>  \n>  \t\tif (object.status() != InvokedObject::NoCall) {\n>  \t\t\tcerr << \"Method not invoked asynchronously\" << endl;\n> @@ -93,15 +94,16 @@ protected:\n>  \t\t}\n>  \n>  \t\t/*\n> -\t\t * Move the object to a thread and verify that the method is\n> -\t\t * delivered in the correct thread.\n> +\t\t * Move the object to a thread and verify that auto method\n> +\t\t * invocation is delivered in the correct thread.\n>  \t\t */\n>  \t\tobject.reset();\n>  \t\tobject.moveToThread(&thread_);\n>  \n>  \t\tthread_.start();\n>  \n> -\t\tobject.invokeMethod(&InvokedObject::method, 42);\n> +\t\tobject.invokeMethod(&InvokedObject::method,\n> +\t\t\t\t    ConnectionTypeAuto, 42);\n>  \t\tthis_thread::sleep_for(chrono::milliseconds(100));\n>  \n>  \t\tswitch (object.status()) {\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-lf1-x144.google.com (mail-lf1-x144.google.com\n\t[IPv6:2a00:1450:4864:20::144])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D52FD6017E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 29 Oct 2019 15:49:35 +0100 (CET)","by mail-lf1-x144.google.com with SMTP id b20so10741636lfp.4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 29 Oct 2019 07:49:35 -0700 (PDT)","from localhost (h-93-159.A463.priv.bahnhof.se. [46.59.93.159])\n\tby smtp.gmail.com with ESMTPSA id\n\t71sm6694887lfh.87.2019.10.29.07.49.34\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 29 Oct 2019 07:49:34 -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=TxA9uvohHQCxD9bks5vax2HJiy7D9ukMGGkMJJatq+g=;\n\tb=m2EMc7D09PYYxPSX037dfYxZHcc448rRfccLq7Af1EeLee8py478LUBDc2u0crsr5e\n\tgcDhKX3KLTMbgFYxFRNlbSTScW+Xs0hVZBHrR2FU9SO/YdljeOmhyOzt5q+EztPKRkIg\n\tX3pL8zjur5JmirOA2dJJphE1Id4De/hRJqRlRVQt+BQnOI9XRjVQqGaF7Y1DWDaLwT3V\n\tcsnHl/7FIsH+hiDO74D3EkZtiDhKE5UICdb5ssLncvLqd0nn8t/LoTQrw4Sz5KzuUh8Y\n\tMagAMzfXvRc83pdngoAhS5OfDOoiHFKjwJUTUSPq3i1Ah2Ll6RUru6cwOu1kaz2aZ2JM\n\t+bcA==","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=TxA9uvohHQCxD9bks5vax2HJiy7D9ukMGGkMJJatq+g=;\n\tb=Y+cR5y5rwAVG5k6o3HMwHF0cKGIzTXgE2hFayFu+ZWi4Nfot7YoS2dfmVGty7hClOU\n\tqUp1LoimaBIXvlyZXY6feYYkRqS1IP9j4mF1uODYCPzcW7g04rYhM+XE2qUka1aTaG96\n\t9BEHSZaKROKr08eWDnTvTfLwHv7esB2HPBN4ZHkuxm7tIlzr1+9s3R2ulicguA4qbgVZ\n\tkbWRqmpbKviHLibPF4NvUfeaF1AZe3JXu2zmTfUWNWQf46kuRwMtdjGBMtgqoRSa7X9B\n\txrKH3jCHudHv89bqTfbyRaxlyNghN4ipTS3DgZTGimFz321W8aQH2EJYMxxY7nun1zGi\n\tp9vQ==","X-Gm-Message-State":"APjAAAUFB1NNUxyGqDxalvxoqAdKrDg9VflRLFFdgG2rkhicHPZ9yq2L\n\ty9GhFtdxjV9YfuZlfGuOLOHyAA==","X-Google-Smtp-Source":"APXvYqxLh7nhEB5e6MXCmtBP1R2d1g1+ddq7BtVFrTjqoGbL54ceuwVHIzh+nh0HYe0o/fv29upong==","X-Received":"by 2002:a19:98e:: with SMTP id 136mr2724198lfj.27.1572360575279; \n\tTue, 29 Oct 2019 07:49:35 -0700 (PDT)","Date":"Tue, 29 Oct 2019 15:49:34 +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":"<20191029144934.GO20198@bigcity.dyn.berto.se>","References":"<20191028104913.14985-1-laurent.pinchart@ideasonboard.com>\n\t<20191028104913.14985-8-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-8-laurent.pinchart@ideasonboard.com>","User-Agent":"Mutt/1.12.1 (2019-06-15)","Subject":"Re: [libcamera-devel] [PATCH v2 7/9] libcamera: object: Add\n\tconnection type parameter to invokeMethod()","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:49:36 -0000"}}]