Skip to content

Commit

Permalink
Respond to PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
aliddell committed Sep 25, 2024
1 parent a2878df commit 82df0a2
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 106 deletions.
8 changes: 4 additions & 4 deletions include/acquire.zarr.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ extern "C"

/**
* @brief Get the version of the Zarr API.
* @return The version of the Zarr API.
* @return Semver formatted version of the Zarr API.
*/
uint32_t Zarr_get_api_version();
const char* Zarr_get_api_version();

/**
* @brief Set the log level for the Zarr API.
Expand All @@ -58,10 +58,10 @@ extern "C"

/**
* @brief Get the message for the given status code.
* @param status The status code.
* @param code The status code.
* @return A human-readable status message.
*/
const char* Zarr_get_status_message(ZarrStatusCode status);
const char* Zarr_get_status_message(ZarrStatusCode code);

/**
* @brief Allocate memory for the dimension array in the Zarr stream settings struct.
Expand Down
4 changes: 4 additions & 0 deletions src/logger/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ std::mutex Logger::log_mutex_{};
void
Logger::set_log_level(LogLevel level)
{
if (level < LogLevel_Debug || level > LogLevel_Error) {
throw std::invalid_argument("Invalid log level");
}

current_level_ = level;
}

Expand Down
7 changes: 5 additions & 2 deletions src/streaming/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ target_include_directories(${tgt}
)

target_link_libraries(${tgt} PRIVATE
acquire-zarr-logger
acquire-logger
blosc_static
miniocpp::miniocpp
)

target_compile_definitions(${tgt} PRIVATE
"ACQUIRE_ZARR_API_VERSION=\"0.0.1\""
)

set_target_properties(${tgt} PROPERTIES
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>"
)
Expand All @@ -33,5 +37,4 @@ install(TARGETS ${tgt}
# Install public header files
install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/
DESTINATION include
FILES_MATCHING PATTERN "*.h"
)
60 changes: 49 additions & 11 deletions src/streaming/acquire.zarr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,65 @@

#include <cstdint> // uint32_t

#define ACQUIRE_ZARR_API_VERSION 0

extern "C"
{
uint32_t Zarr_get_api_version()
const char* Zarr_get_api_version()
{
return ACQUIRE_ZARR_API_VERSION;
}

ZarrStatusCode Zarr_set_log_level(ZarrLogLevel level)
ZarrStatusCode Zarr_set_log_level(ZarrLogLevel level_)
{
EXPECT_VALID_ARGUMENT(
level < ZarrLogLevelCount, "Invalid log level: %d", level);
LogLevel level;
switch (level_) {
case ZarrLogLevel_Debug:
level = LogLevel_Debug;
break;
case ZarrLogLevel_Info:
level = LogLevel_Info;
break;
case ZarrLogLevel_Warning:
level = LogLevel_Warning;
break;
case ZarrLogLevel_Error:
level = LogLevel_Error;
break;
default:
return ZarrStatusCode_InvalidArgument;
}

Logger::set_log_level(level);
try {
Logger::set_log_level(level);
} catch (const std::exception& e) {
LOG_ERROR("Error setting log level: %s", e.what());
return ZarrStatusCode_InternalError;
}
return ZarrStatusCode_Success;
}

ZarrLogLevel Zarr_get_log_level()
{
return Logger::get_log_level();
ZarrLogLevel level;
switch (Logger::get_log_level()) {
case LogLevel_Debug:
level = ZarrLogLevel_Debug;
break;
case LogLevel_Info:
level = ZarrLogLevel_Info;
break;
case LogLevel_Warning:
level = ZarrLogLevel_Warning;
break;
default:
level = ZarrLogLevel_Error;
break;
}
return level;
}

const char* Zarr_get_status_message(ZarrStatusCode error)
const char* Zarr_get_status_message(ZarrStatusCode code)
{
switch (error) {
switch (code) {
case ZarrStatusCode_Success:
return "Success";
case ZarrStatusCode_InvalidArgument:
Expand Down Expand Up @@ -83,10 +116,15 @@ extern "C"
void ZarrStreamSettings_destroy_dimension_array(
struct ZarrStreamSettings_s* settings)
{
if (nullptr != settings && nullptr != settings->dimensions) {
if (settings == nullptr) {
return;
}

if (settings->dimensions != nullptr) {
delete[] settings->dimensions;
settings->dimensions = nullptr;
}
settings->dimension_count = 0;
}

ZarrStream_s* ZarrStream_create(struct ZarrStreamSettings_s* settings)
Expand Down
Loading

0 comments on commit 82df0a2

Please sign in to comment.