Message ID | 20200104050947.7673-3-laurent.pinchart@ideasonboard.com |
---|---|
State | Accepted |
Commit | a915a65fab5b202b51fadf585797384adb7f6b0c |
Headers | show |
Series |
|
Related | show |
Hi Laurent, Thanks for your work. On 2020-01-04 07:09:35 +0200, Laurent Pinchart wrote: > The Object::invokeMethod() implementation duplicates pack creation code > from BoundMemberMethod::activate(). Call activate() instead of > activatePack() to share code. > > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> > --- > include/libcamera/bound_method.h | 15 ++++++++++----- > include/libcamera/object.h | 7 ++----- > 2 files changed, 12 insertions(+), 10 deletions(-) > > diff --git a/include/libcamera/bound_method.h b/include/libcamera/bound_method.h > index b841a2aed147..5743cacf5388 100644 > --- a/include/libcamera/bound_method.h > +++ b/include/libcamera/bound_method.h > @@ -37,10 +37,11 @@ public: > Object *object() const { return object_; } > ConnectionType connectionType() const { return connectionType_; } > > - void activatePack(void *pack, bool deleteMethod); > virtual void invokePack(void *pack) = 0; > > protected: > + void activatePack(void *pack, bool deleteMethod); > + > void *obj_; > Object *object_; > ConnectionType connectionType_; > @@ -88,7 +89,7 @@ public: > invokePack(pack, typename generator<sizeof...(Args)>::type()); > } > > - virtual void activate(Args... args) = 0; > + virtual void activate(Args... args, bool deleteMethod = false) = 0; > virtual void invoke(Args... args) = 0; > }; > > @@ -106,10 +107,10 @@ public: > > bool match(void (T::*func)(Args...)) const { return func == func_; } > > - void activate(Args... args) > + void activate(Args... args, bool deleteMethod = false) > { > if (this->object_) > - BoundMethodBase::activatePack(new PackType{ args... }, false); > + BoundMethodBase::activatePack(new PackType{ args... }, deleteMethod); > else > (static_cast<T *>(this->obj_)->*func_)(args...); > } > @@ -135,7 +136,11 @@ public: > > bool match(void (*func)(Args...)) const { return func == func_; } > > - void activate(Args... args) { (*func_)(args...); } > + void activate(Args... args, bool deleteMethod = false) > + { > + (*func_)(args...); > + } > + > void invoke(Args...) {} > > private: > diff --git a/include/libcamera/object.h b/include/libcamera/object.h > index 21b70460b516..c45165dec8ef 100644 > --- a/include/libcamera/object.h > +++ b/include/libcamera/object.h > @@ -35,11 +35,8 @@ public: > Args... args) > { > T *obj = static_cast<T *>(this); > - BoundMethodBase *method = > - new BoundMemberMethod<T, FuncArgs...>(obj, this, func, type); > - void *pack = new typename BoundMemberMethod<T, FuncArgs...>::PackType{ args... }; > - > - method->activatePack(pack, true); > + auto *method = new BoundMemberMethod<T, FuncArgs...>(obj, this, func, type); > + method->activate(args..., true); > } > > Thread *thread() const { return thread_; } > -- > Regards, > > Laurent Pinchart > > _______________________________________________ > libcamera-devel mailing list > libcamera-devel@lists.libcamera.org > https://lists.libcamera.org/listinfo/libcamera-devel
diff --git a/include/libcamera/bound_method.h b/include/libcamera/bound_method.h index b841a2aed147..5743cacf5388 100644 --- a/include/libcamera/bound_method.h +++ b/include/libcamera/bound_method.h @@ -37,10 +37,11 @@ public: Object *object() const { return object_; } ConnectionType connectionType() const { return connectionType_; } - void activatePack(void *pack, bool deleteMethod); virtual void invokePack(void *pack) = 0; protected: + void activatePack(void *pack, bool deleteMethod); + void *obj_; Object *object_; ConnectionType connectionType_; @@ -88,7 +89,7 @@ public: invokePack(pack, typename generator<sizeof...(Args)>::type()); } - virtual void activate(Args... args) = 0; + virtual void activate(Args... args, bool deleteMethod = false) = 0; virtual void invoke(Args... args) = 0; }; @@ -106,10 +107,10 @@ public: bool match(void (T::*func)(Args...)) const { return func == func_; } - void activate(Args... args) + void activate(Args... args, bool deleteMethod = false) { if (this->object_) - BoundMethodBase::activatePack(new PackType{ args... }, false); + BoundMethodBase::activatePack(new PackType{ args... }, deleteMethod); else (static_cast<T *>(this->obj_)->*func_)(args...); } @@ -135,7 +136,11 @@ public: bool match(void (*func)(Args...)) const { return func == func_; } - void activate(Args... args) { (*func_)(args...); } + void activate(Args... args, bool deleteMethod = false) + { + (*func_)(args...); + } + void invoke(Args...) {} private: diff --git a/include/libcamera/object.h b/include/libcamera/object.h index 21b70460b516..c45165dec8ef 100644 --- a/include/libcamera/object.h +++ b/include/libcamera/object.h @@ -35,11 +35,8 @@ public: Args... args) { T *obj = static_cast<T *>(this); - BoundMethodBase *method = - new BoundMemberMethod<T, FuncArgs...>(obj, this, func, type); - void *pack = new typename BoundMemberMethod<T, FuncArgs...>::PackType{ args... }; - - method->activatePack(pack, true); + auto *method = new BoundMemberMethod<T, FuncArgs...>(obj, this, func, type); + method->activate(args..., true); } Thread *thread() const { return thread_; }
The Object::invokeMethod() implementation duplicates pack creation code from BoundMemberMethod::activate(). Call activate() instead of activatePack() to share code. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> --- include/libcamera/bound_method.h | 15 ++++++++++----- include/libcamera/object.h | 7 ++----- 2 files changed, 12 insertions(+), 10 deletions(-)