From 726c8297cf4d4e198a4daf9a7fc008d35a156d12 Mon Sep 17 00:00:00 2001 From: Luis Michaelis Date: Fri, 3 May 2024 17:15:35 +0200 Subject: [PATCH] feat(DmSegment): add getters for GUID and name --- include/dmusic.h | 12 ++++++++++++ src/Segment.c | 16 ++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/include/dmusic.h b/include/dmusic.h index c647592..f5ada4a 100644 --- a/include/dmusic.h +++ b/include/dmusic.h @@ -218,6 +218,18 @@ DMAPI void DmSegment_release(DmSegment* slf); /// \retval #DmResult_MEMORY_EXHAUSTED A dynamic memory allocation failed. DMAPI DmResult DmSegment_download(DmSegment* slf, DmLoader* loader); +/// \brief Get the GUID of the given segment. +/// \note The returned pointer is only valid for as long as a strong reference to the segment is held. +/// \param slf[in] The segment to get the GUID of. +/// \return A read-only pointer to the segment's GUID. +DMAPI DmGuid const* DmSegment_getGuid(DmSegment const* slf); + +/// \brief Get the name of the given segment. +/// \note The returned pointer is only valid for as long as a strong reference to the segment is held. +/// \param slf[in] The segment to get the name of. +/// \return A read-only pointer to the segment's name in UTF-8. +DMAPI char const* DmSegment_getName(DmSegment const* slf); + /// \} /// \defgroup DmLoaderGroup Loader diff --git a/src/Segment.c b/src/Segment.c index 9ba4b0f..303df8c 100644 --- a/src/Segment.c +++ b/src/Segment.c @@ -72,3 +72,19 @@ DmResult DmSegment_download(DmSegment* slf, DmLoader* loader) { slf->downloaded = true; return rv; } + +DmGuid const* DmSegment_getGuid(DmSegment const* slf) { + if (slf == NULL) { + return NULL; + } + + return &slf->guid; +} + +char const* DmSegment_getName(DmSegment const* slf) { + if (slf == NULL) { + return NULL; + } + + return slf->info.unam; +}