Added appletHolderRequestExitOrTerminate and appletApplicationRequestExitLibraryAppletOrTerminate. Minor internal improvements.

This commit is contained in:
yellows8 2019-08-18 23:15:41 -04:00
parent c34bea8d4c
commit ecd9127bed
No known key found for this signature in database
GPG Key ID: 0AF90DA3F1E60E43
2 changed files with 77 additions and 14 deletions

View File

@ -979,6 +979,13 @@ Result appletHolderJump(AppletHolder *h);
*/
Result appletHolderRequestExit(AppletHolder *h);
/**
* @brief Uses cmds GetAppletStateChangedEvent and RequestExit, then waits for the LibraryApplet to exit with the specified timeout. If a timeout occurs, the Terminate cmd is used.
* @param h AppletHolder object.
* @param[in] timeout Timeout in nanoseconds. U64_MAX for no timeout.
*/
Result appletHolderRequestExitOrTerminate(AppletHolder *h, u64 timeout);
/**
* @brief Waits for the LibraryApplet to exit.
* @param h AppletHolder object.
@ -1518,6 +1525,13 @@ AppletApplicationExitReason appletApplicationGetExitReason(AppletApplication *a)
*/
Result appletApplicationRequestForApplicationToGetForeground(AppletApplication *a);
/**
* @brief Calls the same func as \ref appletHolderRequestExitOrTerminate with the output IAppletAccessor from the GetCurrentLibraryApplet cmd.
* @param a \ref AppletApplication
* @param[in] timeout Timeout in nanoseconds. U64_MAX for no timeout.
*/
Result appletApplicationRequestExitLibraryAppletOrTerminate(AppletApplication *a, u64 timeout);
/**
* @brief Gets the titleID for the Application.
* @param a \ref AppletApplication

View File

@ -115,6 +115,7 @@ static Result _appletGetLaunchReason(AppletProcessLaunchReason *reason);
static Result _appletOpenCallingLibraryApplet(AppletHolder *h);
static Result _appletHolderCreateState(AppletHolder *h, LibAppletMode mode, bool creating_self);
static Result _appletOpenExistingLibraryApplet(AppletHolder *h, Service* srv, u64 cmd_id);
Result appletInitialize(void)
{
@ -2661,20 +2662,7 @@ static Result _appletOpenCallingLibraryApplet(AppletHolder *h) {
if (__nx_applet_type != AppletType_LibraryApplet)
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
Result rc=0;
LibAppletInfo info={0};
memset(h, 0, sizeof(AppletHolder));
rc = _appletGetSession(&g_appletIProcessWindingController, &h->s, 11);
if (R_SUCCEEDED(rc)) rc = appletHolderGetLibraryAppletInfo(h, &info);
if (R_SUCCEEDED(rc)) rc = _appletHolderCreateState(h, info.mode, false);
if (R_FAILED(rc)) appletHolderClose(h);
return rc;
return _appletOpenExistingLibraryApplet(h, &g_appletIProcessWindingController, 11);
}
Result appletPushContext(AppletStorage *s) {
@ -2908,6 +2896,26 @@ static Result _appletHolderCreate(AppletHolder *h, AppletId id, LibAppletMode mo
return rc;
}
static Result _appletOpenExistingLibraryApplet(AppletHolder *h, Service* srv, u64 cmd_id) {
if (__nx_applet_type != AppletType_LibraryApplet)
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
Result rc=0;
LibAppletInfo info={0};
memset(h, 0, sizeof(AppletHolder));
rc = _appletGetSession(srv, &h->s, cmd_id);
if (R_SUCCEEDED(rc)) rc = appletHolderGetLibraryAppletInfo(h, &info);
if (R_SUCCEEDED(rc)) rc = _appletHolderCreateState(h, info.mode, false);
if (R_FAILED(rc)) appletHolderClose(h);
return rc;
}
Result appletCreateLibraryApplet(AppletHolder *h, AppletId id, LibAppletMode mode) {
return _appletHolderCreate(h, id, mode, false);
}
@ -2985,6 +2993,33 @@ Result appletHolderRequestExit(AppletHolder *h) {
return rc;
}
static Result _appletAccessorRequestExitOrTerminate(Service* srv, u64 timeout) {
Result rc=0;
Event StateChangedEvent={0};
if (!serviceIsActive(srv))
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
rc = _appletGetEvent(srv, &StateChangedEvent, 0, false);//GetAppletStateChangedEvent
if (R_SUCCEEDED(rc)) rc = _appletCmdNoIO(srv, 20);//RequestExit
if (R_SUCCEEDED(rc)) {
rc = eventWait(&StateChangedEvent, timeout);
if (R_FAILED(rc) && R_VALUE(rc) == KERNELRESULT(TimedOut))
rc = _appletCmdNoIO(srv, 25);//Terminate
}
eventClose(&StateChangedEvent);
return rc;
}
Result appletHolderRequestExitOrTerminate(AppletHolder *h, u64 timeout) {
return _appletAccessorRequestExitOrTerminate(&h->s, timeout);
}
void appletHolderJoin(AppletHolder *h) {
Result rc=0;
LibAppletExitReason res = LibAppletExitReason_Normal;
@ -4466,6 +4501,20 @@ Result appletApplicationRequestForApplicationToGetForeground(AppletApplication *
return rc;
}
Result appletApplicationRequestExitLibraryAppletOrTerminate(AppletApplication *a, u64 timeout) {
Result rc=0;
Service srv={0};
if (!serviceIsActive(&a->s))
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
rc = _appletGetSession(&a->s, &srv, 112);//GetCurrentLibraryApplet
if (R_SUCCEEDED(rc)) rc = _appletAccessorRequestExitOrTerminate(&srv, timeout);
serviceClose(&srv);
return rc;
}
Result appletApplicationGetApplicationId(AppletApplication *a, u64 *titleID) {
Result rc=0;