-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Standalone 5/N: Implement and test ZarrStream_s (#297)
Depends on #295
- Loading branch information
Showing
12 changed files
with
1,003 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
add_subdirectory(logger) | ||
add_subdirectory(streaming) | ||
|
||
if (BUILD_ACQUIRE_DRIVER_ZARR) | ||
add_subdirectory(driver) | ||
endif () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
set(tgt acquire-zarr) | ||
|
||
add_library(${tgt} | ||
macros.hh | ||
acquire.zarr.cpp | ||
zarr.stream.hh | ||
zarr.stream.cpp | ||
) | ||
|
||
target_include_directories(${tgt} | ||
PUBLIC | ||
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include> | ||
PRIVATE | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> | ||
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/src/logger> | ||
) | ||
|
||
target_link_libraries(${tgt} PRIVATE | ||
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>" | ||
) | ||
|
||
install(TARGETS ${tgt} | ||
LIBRARY DESTINATION lib | ||
ARCHIVE DESTINATION lib | ||
) | ||
|
||
# Install public header files | ||
install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/ | ||
DESTINATION include | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
#include "acquire.zarr.h" | ||
#include "zarr.stream.hh" | ||
#include "macros.hh" | ||
|
||
#include <cstdint> // uint32_t | ||
|
||
extern "C" | ||
{ | ||
const char* Zarr_get_api_version() | ||
{ | ||
return ACQUIRE_ZARR_API_VERSION; | ||
} | ||
|
||
ZarrStatusCode Zarr_set_log_level(ZarrLogLevel 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; | ||
} | ||
|
||
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() | ||
{ | ||
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 code) | ||
{ | ||
switch (code) { | ||
case ZarrStatusCode_Success: | ||
return "Success"; | ||
case ZarrStatusCode_InvalidArgument: | ||
return "Invalid argument"; | ||
case ZarrStatusCode_Overflow: | ||
return "Buffer overflow"; | ||
case ZarrStatusCode_InvalidIndex: | ||
return "Invalid index"; | ||
case ZarrStatusCode_NotYetImplemented: | ||
return "Not yet implemented"; | ||
case ZarrStatusCode_InternalError: | ||
return "Internal error"; | ||
case ZarrStatusCode_OutOfMemory: | ||
return "Out of memory"; | ||
case ZarrStatusCode_IOError: | ||
return "I/O error"; | ||
case ZarrStatusCode_CompressionError: | ||
return "Compression error"; | ||
case ZarrStatusCode_InvalidSettings: | ||
return "Invalid settings"; | ||
default: | ||
return "Unknown error"; | ||
} | ||
} | ||
|
||
ZarrStatusCode ZarrStreamSettings_create_dimension_array( | ||
struct ZarrStreamSettings_s* settings, | ||
size_t dimension_count) | ||
{ | ||
EXPECT_VALID_ARGUMENT(settings, "Null pointer: settings"); | ||
EXPECT_VALID_ARGUMENT(dimension_count >= 3, | ||
"Invalid dimension count: %zu", | ||
dimension_count); | ||
|
||
ZarrDimensionProperties* dimensions = nullptr; | ||
|
||
try { | ||
dimensions = new ZarrDimensionProperties[dimension_count]; | ||
} catch (const std::bad_alloc&) { | ||
LOG_ERROR("Failed to allocate memory for dimensions"); | ||
return ZarrStatusCode_OutOfMemory; | ||
} | ||
|
||
ZarrStreamSettings_destroy_dimension_array(settings); | ||
settings->dimensions = dimensions; | ||
settings->dimension_count = dimension_count; | ||
|
||
return ZarrStatusCode_Success; | ||
} | ||
|
||
void ZarrStreamSettings_destroy_dimension_array( | ||
struct ZarrStreamSettings_s* settings) | ||
{ | ||
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) | ||
{ | ||
|
||
ZarrStream_s* stream = nullptr; | ||
|
||
try { | ||
stream = new ZarrStream_s(settings); | ||
} catch (const std::bad_alloc&) { | ||
LOG_ERROR("Failed to allocate memory for Zarr stream"); | ||
} catch (const std::exception& e) { | ||
LOG_ERROR("Error creating Zarr stream: %s", e.what()); | ||
} | ||
|
||
return stream; | ||
} | ||
|
||
void ZarrStream_destroy(struct ZarrStream_s* stream) | ||
{ | ||
delete stream; | ||
} | ||
|
||
ZarrStatusCode ZarrStream_append(struct ZarrStream_s* stream, | ||
const void* data, | ||
size_t bytes_in, | ||
size_t* bytes_out) | ||
{ | ||
EXPECT_VALID_ARGUMENT(stream, "Null pointer: stream"); | ||
EXPECT_VALID_ARGUMENT(data, "Null pointer: data"); | ||
EXPECT_VALID_ARGUMENT(bytes_out, "Null pointer: bytes_out"); | ||
|
||
try { | ||
*bytes_out = stream->append(data, bytes_in); | ||
} catch (const std::exception& e) { | ||
LOG_ERROR("Error appending data: %s", e.what()); | ||
return ZarrStatusCode_InternalError; | ||
} | ||
|
||
return ZarrStatusCode_Success; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#pragma once | ||
|
||
#include "logger.hh" | ||
|
||
#define EXPECT(e, ...) \ | ||
do { \ | ||
if (!(e)) { \ | ||
const std::string __err = LOG_ERROR(__VA_ARGS__); \ | ||
throw std::runtime_error(__err); \ | ||
} \ | ||
} while (0) | ||
#define CHECK(e) EXPECT(e, "Expression evaluated as false:\n\t%s", #e) | ||
|
||
#define EXPECT_VALID_ARGUMENT(e, ...) \ | ||
do { \ | ||
if (!(e)) { \ | ||
LOG_ERROR(__VA_ARGS__); \ | ||
return ZarrStatusCode_InvalidArgument; \ | ||
} \ | ||
} while (0) | ||
|
||
#define EXPECT_VALID_INDEX(e, ...) \ | ||
do { \ | ||
if (!(e)) { \ | ||
LOG_ERROR(__VA_ARGS__); \ | ||
return ZarrStatusCode_InvalidIndex; \ | ||
} \ | ||
} while (0) |
Oops, something went wrong.