Skip to content

Commit

Permalink
[util][build] Add UUID generation methods
Browse files Browse the repository at this point in the history
Links to libuuid on Linux, which comes with util-linux. On Windows it
uses rpc.h's UuidCreate method.

UUIDs will be used as globally unique preset identifiers.
  • Loading branch information
grandchild committed Nov 1, 2024
1 parent 7d15447 commit 47e43fd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ file(GLOB SRC_FILES_AVS_COMMON
avs/vis_avs/video.cpp
avs/vis_avs/video_libav.cpp
avs/platform.c
avs/uuid.cpp
avs/3rdparty/md_fft.cpp
)

Expand Down Expand Up @@ -211,7 +212,7 @@ elseif(LINUX)
include(FindPkgConfig)
pkg_search_module(PIPEWIRE REQUIRED libpipewire-0.3)
target_include_directories(avs_common PUBLIC ${PIPEWIRE_INCLUDE_DIRS})
target_link_libraries(libavs ${PIPEWIRE_LIBRARIES})
target_link_libraries(libavs ${PIPEWIRE_LIBRARIES} uuid)
target_link_options(libavs PUBLIC -Wl,-m elf_i386)
set(AVS_DYLIB_EXTENSION "so")
add_executable(avs-cli avs/avs-cli.c)
Expand Down
24 changes: 24 additions & 0 deletions avs/uuid.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "uuid.h"

#ifdef _WIN32
#include <rpc.h>
#elif defined __linux__
#include <uuid/uuid.h>
#endif

std::string uuid4() {
auto uuid_str = (char*)malloc(37);
uuid_str[36] = '\0';
#ifdef _WIN32
UUID uuid;
UuidCreate(&uuid);
UuidToString(&uuid, (unsigned char**)&uuid_str);
#elif defined __linux__
uuid_t uuid;
uuid_generate(uuid);
uuid_unparse_lower(uuid, uuid_str);
#endif
auto retval = std::string(uuid_str);
free(uuid_str);
return retval;
}
3 changes: 3 additions & 0 deletions avs/uuid.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include <string>

std::string uuid4();

0 comments on commit 47e43fd

Please sign in to comment.