From 5874a272d02e88e3e42351229c4f5cd5ea8bd796 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Tue, 18 Dec 2018 19:03:22 -0500 Subject: [PATCH] Added appletHolderJoin and appletHolderGetExitReason. --- nx/include/switch/services/applet.h | 31 ++++++++++++++++++++++++----- nx/source/services/applet.c | 25 +++++++++++++++++++++++ 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/nx/include/switch/services/applet.h b/nx/include/switch/services/applet.h index fe27f1bb..60171f5e 100644 --- a/nx/include/switch/services/applet.h +++ b/nx/include/switch/services/applet.h @@ -87,6 +87,14 @@ typedef enum { LibAppletMode_Unknown3 = 3, } LibAppletMode; +/// LibraryAppletExitReason +typedef enum { + LibAppletExitReason_Normal = 0, + LibAppletExitReason_Canceled = 1, + LibAppletExitReason_Abnormal = 2, + LibAppletExitReason_Unexpected = 10, +} LibAppletExitReason; + /// applet hook function. typedef void (*AppletHookFn)(AppletHookType hook, void* param); @@ -108,11 +116,12 @@ typedef struct { /// LibraryApplet state. typedef struct { - Service s; ///< ILibraryAppletAccessor - Event StateChangedEvent; ///< Output from GetAppletStateChangedEvent, autoclear=false. - LibAppletMode mode; ///< See ref \ref LibAppletMode. - u64 layer_handle; ///< Output from GetIndirectLayerConsumerHandle on 2.0.0+. - bool creating_self; ///< When set, indicates that the LibraryApplet title is creating itself. + Service s; ///< ILibraryAppletAccessor + Event StateChangedEvent; ///< Output from GetAppletStateChangedEvent, autoclear=false. + LibAppletMode mode; ///< See ref \ref LibAppletMode. + u64 layer_handle; ///< Output from GetIndirectLayerConsumerHandle on 2.0.0+. + bool creating_self; ///< When set, indicates that the LibraryApplet title is creating itself. + LibAppletExitReason exitreason; ///< Set by \ref appletHolderJoin using the output from cmd GetResult, see \ref LibAppletExitReason. } AppletHolder; Result appletInitialize(void); @@ -216,6 +225,18 @@ Result appletHolderGetIndirectLayerConsumerHandle(AppletHolder *h, u64 *out); */ Result appletHolderStart(AppletHolder *h); +/** + * @brief Waits for the LibraryApplet to exit. + * @param h AppletHolder object. + */ +void appletHolderJoin(AppletHolder *h); + +/** + * @brief Gets the \ref LibAppletExitReason set by \ref appletHolderJoin. + * @param h AppletHolder object. + */ +LibAppletExitReason appletHolderGetExitReason(AppletHolder *h); + /** * @brief Creates a storage. * @param s Storage object. diff --git a/nx/source/services/applet.c b/nx/source/services/applet.c index 1c621b9d..c518a92f 100644 --- a/nx/source/services/applet.c +++ b/nx/source/services/applet.c @@ -1602,6 +1602,31 @@ Result appletHolderStart(AppletHolder *h) { return rc; } +void appletHolderJoin(AppletHolder *h) { + Result rc=0; + LibAppletExitReason res = LibAppletExitReason_Normal; + u32 desc=0; + eventWait(&h->StateChangedEvent, U64_MAX); + rc = _appletCmdNoIO(&h->s, 30);//GetResult + + if (R_FAILED(rc)) { + res = LibAppletExitReason_Unexpected; + if (R_MODULE(rc) == 128) { + desc = R_DESCRIPTION(rc); + if (desc == 22) res = LibAppletExitReason_Canceled; + else { + if (desc >= 0x14 && desc < 0x32)res = LibAppletExitReason_Abnormal; + } + } + } + + h->exitreason = res; +} + +u32 appletHolderGetExitReason(AppletHolder *h) { + return h->exitreason; +} + Result appletCreateStorage(AppletStorage *s, s64 size) { memset(s, 0, sizeof(AppletStorage));