Message ID | 20220316135322.1478358-2-ben.hutchings_ext@softathome.com |
---|---|
State | Accepted |
Headers | show |
Series | Add support for script handlers written in Lua | expand |
On 16.03.22 14:53, Ben Hutchings wrote: > Script handlers currently receive a pointer to the installation phase > enumerator (script_fn), rather than their private data pointer. This > prevents writing script handlers in Lua, since the Lua support layer > always requires its private data pointer. > > Replace this with a pointer to a structure that contains both the > installation phase and the private data pointer. This preserves > backward API and ABI compatibility. > > Signed-off-by: Ben Hutchings <ben.hutchings_ext@softathome.com> > --- > core/installer.c | 7 ++++++- > doc/source/handlers.rst | 6 ++++++ > include/handler.h | 9 +++++++++ > 3 files changed, 21 insertions(+), 1 deletion(-) > > diff --git a/core/installer.c b/core/installer.c > index 5e4cbe5..b97e97a 100644 > --- a/core/installer.c > +++ b/core/installer.c > @@ -200,7 +200,12 @@ static int run_prepost_scripts(struct imglist *list, script_fn type) > continue; > hnd = find_handler(img); > if (hnd) { > - ret = hnd->installer(img, &type); > + struct script_handler_data data = { > + .scriptfn = type, > + .data = hnd->data > + }; > + > + ret = hnd->installer(img, &data); > if (ret) > return ret; > } > diff --git a/doc/source/handlers.rst b/doc/source/handlers.rst > index 333c912..da31af2 100644 > --- a/doc/source/handlers.rst > +++ b/doc/source/handlers.rst > @@ -68,6 +68,12 @@ The structure *img_type* contains the file descriptor of the stream pointing to > of the image to be installed. The handler must read the whole image, and when it returns > back SWUpdate can go on with the next image in the stream. > > +The data parameter is usually a pointer that was registered with the > +handler. For script handlers it is instead a pointer to a ``struct > +script_handler_data`` which contains a ``script_fn`` enum value, > +indicating the current installation phase, and the registered data > +pointer. > + > SWUpdate provides a general function to extract data from the stream and copy > to somewhere else: > > diff --git a/include/handler.h b/include/handler.h > index a060623..2ca8817 100644 > --- a/include/handler.h > +++ b/include/handler.h > @@ -41,6 +41,15 @@ struct installer_handler{ > unsigned int mask; > }; > > +struct script_handler_data { > + /* > + * scriptfn must be first, as script handlers may expect to > + * receive just a script_fn > + */ > + script_fn scriptfn; > + void *data; > +}; > + > int register_handler(const char *desc, > handler installer, HANDLER_MASK mask, void *data); > Applied to -master, thanks ! Best regards, Stefano Babic
diff --git a/core/installer.c b/core/installer.c index 5e4cbe5..b97e97a 100644 --- a/core/installer.c +++ b/core/installer.c @@ -200,7 +200,12 @@ static int run_prepost_scripts(struct imglist *list, script_fn type) continue; hnd = find_handler(img); if (hnd) { - ret = hnd->installer(img, &type); + struct script_handler_data data = { + .scriptfn = type, + .data = hnd->data + }; + + ret = hnd->installer(img, &data); if (ret) return ret; } diff --git a/doc/source/handlers.rst b/doc/source/handlers.rst index 333c912..da31af2 100644 --- a/doc/source/handlers.rst +++ b/doc/source/handlers.rst @@ -68,6 +68,12 @@ The structure *img_type* contains the file descriptor of the stream pointing to of the image to be installed. The handler must read the whole image, and when it returns back SWUpdate can go on with the next image in the stream. +The data parameter is usually a pointer that was registered with the +handler. For script handlers it is instead a pointer to a ``struct +script_handler_data`` which contains a ``script_fn`` enum value, +indicating the current installation phase, and the registered data +pointer. + SWUpdate provides a general function to extract data from the stream and copy to somewhere else: diff --git a/include/handler.h b/include/handler.h index a060623..2ca8817 100644 --- a/include/handler.h +++ b/include/handler.h @@ -41,6 +41,15 @@ struct installer_handler{ unsigned int mask; }; +struct script_handler_data { + /* + * scriptfn must be first, as script handlers may expect to + * receive just a script_fn + */ + script_fn scriptfn; + void *data; +}; + int register_handler(const char *desc, handler installer, HANDLER_MASK mask, void *data);
Script handlers currently receive a pointer to the installation phase enumerator (script_fn), rather than their private data pointer. This prevents writing script handlers in Lua, since the Lua support layer always requires its private data pointer. Replace this with a pointer to a structure that contains both the installation phase and the private data pointer. This preserves backward API and ABI compatibility. Signed-off-by: Ben Hutchings <ben.hutchings_ext@softathome.com> --- core/installer.c | 7 ++++++- doc/source/handlers.rst | 6 ++++++ include/handler.h | 9 +++++++++ 3 files changed, 21 insertions(+), 1 deletion(-)