Use eventActive for g_appletLibraryAppletLaunchableEvent. Fixed _appletWaitLibraryAppletLaunchableEvent, and set rc to eventWait ret in _appletWaitLibraryAppletLaunchableEvent. Added appletHolderWaitInteractiveOut.

This commit is contained in:
yellows8 2018-12-19 12:59:38 -05:00
parent 63e0e3502c
commit 9f63f29988
2 changed files with 44 additions and 17 deletions

View File

@ -116,12 +116,13 @@ typedef struct {
/// LibraryApplet state. /// LibraryApplet state.
typedef struct { typedef struct {
Service s; ///< ILibraryAppletAccessor Service s; ///< ILibraryAppletAccessor
Event StateChangedEvent; ///< Output from GetAppletStateChangedEvent, autoclear=false. Event StateChangedEvent; ///< Output from GetAppletStateChangedEvent, autoclear=false.
LibAppletMode mode; ///< See ref \ref LibAppletMode. Event PopInteractiveOutDataEvent; ///< Output from GetPopInteractiveOutDataEvent, autoclear=false.
u64 layer_handle; ///< Output from GetIndirectLayerConsumerHandle on 2.0.0+. LibAppletMode mode; ///< See ref \ref LibAppletMode.
bool creating_self; ///< When set, indicates that the LibraryApplet title is creating itself. u64 layer_handle; ///< Output from GetIndirectLayerConsumerHandle on 2.0.0+.
LibAppletExitReason exitreason; ///< Set by \ref appletHolderJoin using the output from cmd GetResult, see \ref LibAppletExitReason. 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; } AppletHolder;
Result appletInitialize(void); Result appletInitialize(void);
@ -240,6 +241,13 @@ void appletHolderJoin(AppletHolder *h);
*/ */
LibAppletExitReason appletHolderGetExitReason(AppletHolder *h); LibAppletExitReason appletHolderGetExitReason(AppletHolder *h);
/**
* @brief Waits for the PopInteractiveOutDataEvent and StateChangedEvent.
* @return false for error / when StateChangedEvent was signaled, and true when PopInteractiveOutDataEvent was signaled.
* @param h AppletHolder object.
*/
bool appletHolderWaitInteractiveOut(AppletHolder *h);
/** /**
* @brief Pushes a storage for LibraryApplet input. * @brief Pushes a storage for LibraryApplet input.
* @note This uses \ref appletStorageClose automatically. * @note This uses \ref appletStorageClose automatically.

View File

@ -56,7 +56,6 @@ static TransferMemory g_appletRecordingTmem;
static u32 g_appletRecordingInitialized; static u32 g_appletRecordingInitialized;
static Event g_appletLibraryAppletLaunchableEvent; static Event g_appletLibraryAppletLaunchableEvent;
static bool g_appletLibraryAppletLaunchableEventInitialized;
static Result _appletGetHandle(Service* srv, Handle* handle_out, u64 cmd_id); static Result _appletGetHandle(Service* srv, Handle* handle_out, u64 cmd_id);
static Result _appletGetEvent(Service* srv, Event* event_out, u64 cmd_id, bool autoclear); static Result _appletGetEvent(Service* srv, Event* event_out, u64 cmd_id, bool autoclear);
@ -101,7 +100,6 @@ Result appletInitialize(void)
g_appletNotifiedRunning = 0; g_appletNotifiedRunning = 0;
g_appletExitProcessFlag = 0; g_appletExitProcessFlag = 0;
g_appletRecordingInitialized = 0; g_appletRecordingInitialized = 0;
g_appletLibraryAppletLaunchableEventInitialized = false;
switch (__nx_applet_type) { switch (__nx_applet_type) {
case AppletType_Default: case AppletType_Default:
@ -315,10 +313,7 @@ void appletExit(void)
} }
} }
if (g_appletLibraryAppletLaunchableEventInitialized) { eventClose(&g_appletLibraryAppletLaunchableEvent);
g_appletLibraryAppletLaunchableEventInitialized = false;
eventClose(&g_appletLibraryAppletLaunchableEvent);
}
eventClose(&g_appletMessageEvent); eventClose(&g_appletMessageEvent);
@ -1239,12 +1234,10 @@ Result appletUnlockExit(void) {
static Result _appletWaitLibraryAppletLaunchableEvent(void) { static Result _appletWaitLibraryAppletLaunchableEvent(void) {
Result rc=0; Result rc=0;
if (!g_appletLibraryAppletLaunchableEventInitialized) { if (!eventActive(&g_appletLibraryAppletLaunchableEvent))
rc = _appletGetEvent(&g_appletICommonStateGetter, &g_appletLibraryAppletLaunchableEvent, 9, false); rc = _appletGetEvent(&g_appletISelfController, &g_appletLibraryAppletLaunchableEvent, 9, false);
if (R_SUCCEEDED(rc)) g_appletLibraryAppletLaunchableEventInitialized = true;
}
if (R_SUCCEEDED(rc)) eventWait(&g_appletLibraryAppletLaunchableEvent, U64_MAX); if (R_SUCCEEDED(rc)) rc = eventWait(&g_appletLibraryAppletLaunchableEvent, U64_MAX);
return rc; return rc;
} }
@ -1584,6 +1577,8 @@ Result appletCreateLibraryAppletSelf(AppletHolder *h, AppletId id, LibAppletMode
} }
void appletHolderClose(AppletHolder *h) { void appletHolderClose(AppletHolder *h) {
eventClose(&h->PopInteractiveOutDataEvent);
eventClose(&h->StateChangedEvent); eventClose(&h->StateChangedEvent);
serviceClose(&h->s); serviceClose(&h->s);
memset(h, 0, sizeof(AppletHolder)); memset(h, 0, sizeof(AppletHolder));
@ -1619,6 +1614,7 @@ void appletHolderJoin(AppletHolder *h) {
Result rc=0; Result rc=0;
LibAppletExitReason res = LibAppletExitReason_Normal; LibAppletExitReason res = LibAppletExitReason_Normal;
u32 desc=0; u32 desc=0;
eventWait(&h->StateChangedEvent, U64_MAX); eventWait(&h->StateChangedEvent, U64_MAX);
rc = _appletCmdNoIO(&h->s, 30);//GetResult rc = _appletCmdNoIO(&h->s, 30);//GetResult
@ -1640,6 +1636,29 @@ u32 appletHolderGetExitReason(AppletHolder *h) {
return h->exitreason; return h->exitreason;
} }
static Result _appletHolderGetPopInteractiveOutDataEvent(AppletHolder *h) {
Result rc=0;
if (eventActive(&h->PopInteractiveOutDataEvent)) return 0;
rc = _appletGetEvent(&h->s, &h->PopInteractiveOutDataEvent, 106, false);
return rc;
}
bool appletHolderWaitInteractiveOut(AppletHolder *h) {
Result rc=0;
s32 idx = 0;
rc = _appletHolderGetPopInteractiveOutDataEvent(h);
if (R_FAILED(rc)) return false;
rc = waitMulti(&idx, U64_MAX, waiterForEvent(&h->PopInteractiveOutDataEvent), waiterForEvent(&h->StateChangedEvent));
if (R_FAILED(rc)) return false;
return idx==0;
}
Result appletHolderPushInData(AppletHolder *h, AppletStorage *s) { Result appletHolderPushInData(AppletHolder *h, AppletStorage *s) {
return _appletCmdInStorage(&h->s, s, 100); return _appletCmdInStorage(&h->s, s, 100);
} }