From d2f9655d8a087863be966bbf3d84bbe31e7385f1 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Tue, 5 Apr 2016 12:07:24 -0400 Subject: [PATCH] Added udsWaitDataAvailable(), based on gspWaitForEvent(). --- libctru/include/3ds/services/uds.h | 9 +++++++++ libctru/source/services/uds.c | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/libctru/include/3ds/services/uds.h b/libctru/include/3ds/services/uds.h index 608783b..a34e6bc 100644 --- a/libctru/include/3ds/services/uds.h +++ b/libctru/include/3ds/services/uds.h @@ -182,6 +182,15 @@ Result udsBind(udsBindContext *bindcontext, u16 NetworkNodeID); */ Result udsUnbind(udsBindContext *bindcontext); +/** + * @brief Waits for the bind event to occur, or checks if the event was signalled. This event is signalled every time new data is available via udsPullPacket(). + * @return Always true. However if wait=false, this will return false if the event wasn't signalled. + * @param bindcontext The bind context. + * @param nextEvent Whether to discard the current event and wait for the next event. + * @param wait When true this will not return until the event is signalled. When false this checks if the event was signalled without waiting for it. + */ +bool udsWaitDataAvailable(udsBindContext *bindcontext, bool nextEvent, bool wait); + /** * @brief Receives data over the network. * @param bindcontext Bind context. diff --git a/libctru/source/services/uds.c b/libctru/source/services/uds.c index fef849b..bce9bb4 100644 --- a/libctru/source/services/uds.c +++ b/libctru/source/services/uds.c @@ -458,6 +458,22 @@ Result udsUnbind(udsBindContext *bindcontext) return ret; } +bool udsWaitDataAvailable(udsBindContext *bindcontext, bool nextEvent, bool wait) +{ + bool ret = true; + u64 delayvalue = U64_MAX; + + if(!wait)delayvalue = 0; + + if(nextEvent)svcClearEvent(bindcontext->event); + + if(svcWaitSynchronization(bindcontext->event, delayvalue)!=0 && !wait)ret = false; + + if(!nextEvent)svcClearEvent(bindcontext->event); + + return ret; +} + static Result usd_parsebeacon(u8 *buf, u32 size, udsNetworkScanInfo *networkscan) { Result ret=0;