Message ID | 20220214100519.282223-1-michael.adler@siemens.com |
---|---|
State | Accepted |
Headers | show |
Series | corelib/lua_interface: added 'progress' method | expand |
Hallo Michael, On 14.02.22 11:05, Michael Adler wrote: > This makes it possible to send messages from the Lua realm (e.g. > handlers) to clients listening on the IPC progress interface. > > For example, this could be used to extract some data from the update > package and show it to the user (which could be the duty of the IPC > listener). > As I have already used this feature, I just ask if we are talking about the same thing. We can already call swupdate.notify from Lua. This code from Lua had worked for me: fancy_string="some info" swupdate.notify(swupdate.RECOVERY_STATUS.SUBPROCESS, 0, fancy_string) A notify as SUBPROCESS is then forwarded via swupdate_progress_info(), that is the string is received as INFO by all listeners. Your patch should do exactly the same, but with a much more consistent name (feature was present but surely hidden). Am I right or is there somethin I have not understood ? > Signed-off-by: Christian Storm <christian.storm@siemens.com> > Signed-off-by: Michael Adler <michael.adler@siemens.com> > --- > corelib/lua_interface.c | 18 ++++++++++++++++++ > 1 file changed, 18 insertions(+) > > diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c > index de05749..53e55e2 100644 > --- a/corelib/lua_interface.c > +++ b/corelib/lua_interface.c > @@ -955,6 +955,23 @@ static int l_getversion(lua_State *L) > return 1; > } > > +/** > + * @brief Dispatch a message to the progress interface. > + * > + * @param [Lua] Message to dispatch to progress interface. > + * @return [Lua] nil. > + */ > +static int l_notify_progress(lua_State *L) { > + /* > + * NOTE: level is INFOLEVEL for the sake of specifying a level. > + * It is unused in core/notifier.c :: progress_notifier() as the > + * progress emitter doesn't know about log levels. > + */ > + notify(PROGRESS, RECOVERY_NO_ERROR, INFOLEVEL, luaL_checkstring(L, -1)); > + lua_pop(L, 1); > + return 0; > +} > + > /** > * @brief array with the function which are exported to Lua > */ > @@ -969,6 +986,7 @@ static const luaL_Reg l_swupdate[] = { > { "umount", l_umount }, > { "getroot", l_getroot }, > { "getversion", l_getversion }, > + { "progress", l_notify_progress }, > { NULL, NULL } > }; > Best regards, Stefano
Hi Stefano, > Your patch should do exactly the same, but with a much more consistent name > (feature was present but surely hidden). Am I right or is there somethin I > have not understood ? you are right, your example does the same. I wasn't aware of this possibility, thanks! As far as I'm concerned, I'm happy now because I can already use your approach with the 2021.11 release. Others might appreciate the more obvious interface though. Not sure what's best. Your call :) Kind regards, Michael
Hi Michael, On 14.02.22 16:42, Michael Adler wrote: > Hi Stefano, > >> Your patch should do exactly the same, but with a much more consistent name >> (feature was present but surely hidden). Am I right or is there somethin I >> have not understood ? > > you are right, your example does the same. I wasn't aware of this possibility, thanks! > As far as I'm concerned, I'm happy now because I can already use your approach with the 2021.11 release. Fine. > Others might appreciate the more obvious interface though. Not sure what's best. Your call :) I will apply your patch because it makes much more clearer how to do. Best regards, Stefano
On 14.02.22 11:05, Michael Adler wrote: > This makes it possible to send messages from the Lua realm (e.g. > handlers) to clients listening on the IPC progress interface. > > For example, this could be used to extract some data from the update > package and show it to the user (which could be the duty of the IPC > listener). > > Signed-off-by: Christian Storm <christian.storm@siemens.com> > Signed-off-by: Michael Adler <michael.adler@siemens.com> > --- > corelib/lua_interface.c | 18 ++++++++++++++++++ > 1 file changed, 18 insertions(+) > > diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c > index de05749..53e55e2 100644 > --- a/corelib/lua_interface.c > +++ b/corelib/lua_interface.c > @@ -955,6 +955,23 @@ static int l_getversion(lua_State *L) > return 1; > } > > +/** > + * @brief Dispatch a message to the progress interface. > + * > + * @param [Lua] Message to dispatch to progress interface. > + * @return [Lua] nil. > + */ > +static int l_notify_progress(lua_State *L) { > + /* > + * NOTE: level is INFOLEVEL for the sake of specifying a level. > + * It is unused in core/notifier.c :: progress_notifier() as the > + * progress emitter doesn't know about log levels. > + */ > + notify(PROGRESS, RECOVERY_NO_ERROR, INFOLEVEL, luaL_checkstring(L, -1)); > + lua_pop(L, 1); > + return 0; > +} > + > /** > * @brief array with the function which are exported to Lua > */ > @@ -969,6 +986,7 @@ static const luaL_Reg l_swupdate[] = { > { "umount", l_umount }, > { "getroot", l_getroot }, > { "getversion", l_getversion }, > + { "progress", l_notify_progress }, > { NULL, NULL } > }; > Applied to -master, thanks ! Best regards, Stefano Babic
diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c index de05749..53e55e2 100644 --- a/corelib/lua_interface.c +++ b/corelib/lua_interface.c @@ -955,6 +955,23 @@ static int l_getversion(lua_State *L) return 1; } +/** + * @brief Dispatch a message to the progress interface. + * + * @param [Lua] Message to dispatch to progress interface. + * @return [Lua] nil. + */ +static int l_notify_progress(lua_State *L) { + /* + * NOTE: level is INFOLEVEL for the sake of specifying a level. + * It is unused in core/notifier.c :: progress_notifier() as the + * progress emitter doesn't know about log levels. + */ + notify(PROGRESS, RECOVERY_NO_ERROR, INFOLEVEL, luaL_checkstring(L, -1)); + lua_pop(L, 1); + return 0; +} + /** * @brief array with the function which are exported to Lua */ @@ -969,6 +986,7 @@ static const luaL_Reg l_swupdate[] = { { "umount", l_umount }, { "getroot", l_getroot }, { "getversion", l_getversion }, + { "progress", l_notify_progress }, { NULL, NULL } };