Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into doc-headers
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-sweet committed Nov 16, 2023
2 parents 0c8d226 + 8bea9c8 commit 4dbf2de
Show file tree
Hide file tree
Showing 20 changed files with 368 additions and 96 deletions.
29 changes: 29 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Description

*Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.*

## Related issue(s)

- Issue: #<issue_number_here>
- See also:
- #<issue_number>

## Type of change

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Documentation
- [ ] Other (please describe):

# How has this been tested?

*Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce.*

# Checklist

- [ ] I have performed a self-review of my own code.
- [ ] I have commented my code, particularly in hard-to-understand areas.
- [ ] I have updated the documentation, if necessary.
- [ ] I added tests for my changes, and/or the testing strategy is described above.
- [ ] I updated the [changelog](../CHANGELOG.md).
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Users can specify the full chunk size in width, height, and planes.

### Removed

- `max_bytes_per_chunk` from `StorageProperties` chunking properties.

### Fixed

- Removes 30-second timeout from `thread_join` on Windows.
Expand All @@ -17,6 +25,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `acquire-device-properties`: A corresponding entry in `StoragePropertyMetadata`.
- `acquire-device-properties`: A convenience function for enabling multiscale, similar to the function for
setting chunking properties.
- `acquire-device-properties`: A `struct storage_properties_sharding_s` member `shard_dims_chunks` of
`StorageProperties`. Users can now configure sharding properties where supported.
- `acquire-device-properties`: A convenience function for setting sharding parameters.

## [0.1.3](https://github.com/acquire-project/acquire-core-libs/compare/v0.1.2...v0.1.3) - 2023-06-27

Expand Down
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ cmake_policy(SET CMP0079 NEW) # use targets from other directories
enable_testing()

include(cmake/aq_require.cmake)
include(cmake/git-versioning.cmake)
include(cmake/ide.cmake)
include(cmake/msvc.cmake)

Expand Down
30 changes: 0 additions & 30 deletions cmake/git-versioning.cmake

This file was deleted.

1 change: 1 addition & 0 deletions src/acquire-core-logger/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
set(tgt acquire-core-logger)
add_library(${tgt} STATIC logger.h logger.c)
target_include_directories(${tgt} PUBLIC "${CMAKE_CURRENT_LIST_DIR}")

install(TARGETS ${tgt})
2 changes: 1 addition & 1 deletion src/acquire-core-platform/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ add_library(${tgt} STATIC
platform.h
platform.c)
target_include_directories(${tgt} PUBLIC "${CMAKE_CURRENT_LIST_DIR}")
target_link_libraries(${tgt} PRIVATE Threads::Threads acquire-core-logger)
target_link_libraries(${tgt} PRIVATE Threads::Threads acquire-core-logger)
21 changes: 18 additions & 3 deletions src/acquire-core-platform/linux/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <fcntl.h>
#include <unistd.h>
#include <dlfcn.h>
#include <sys/file.h>

#define L (aq_logger)
#define LOG(...) L(0, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)
Expand Down Expand Up @@ -37,17 +38,28 @@ int
file_create(struct file* file, const char* filename, size_t bytesof_filename)
{
file->fid = open(filename, O_RDWR | O_CREAT | O_NONBLOCK, 0666);
if (file->fid < 0)
if (file->fid < 0) {
CHECK_POSIX(errno);
} else {
int ret = flock(file->fid, LOCK_EX | LOCK_NB);
if (ret < 0) {
LOGE("Failed to create existing file \"%s\"", filename);
int tmp = errno;
close(file->fid);
CHECK_POSIX(tmp);
}
}
return 1;
Error:
LOGE("Failed to create \"%s\"", filename);
return 0;
}

void
file_close(struct file* file)
{
CHECK_POSIX(close(file->fid));
if (close(file->fid) < 0)
CHECK_POSIX(errno);
Error:;
}

Expand Down Expand Up @@ -77,8 +89,11 @@ int
file_exists(const char* filename, size_t nbytes)
{
int ret = access(filename, F_OK);
if (ret < 0)
if (ret < 0) {
if (errno == ENOENT)
return 0;
CHECK_POSIX(errno);
}
return ret == 0;
Error:
return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/acquire-core-platform/osx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ add_library(${tgt} STATIC
platform.h
platform.c)
target_include_directories(${tgt} PUBLIC "${CMAKE_CURRENT_LIST_DIR}")
target_link_libraries(${tgt} PRIVATE acquire-core-logger)
target_link_libraries(${tgt} PRIVATE acquire-core-logger)
14 changes: 10 additions & 4 deletions src/acquire-core-platform/osx/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,21 @@
int
file_create(struct file* file, const char* filename, size_t bytesof_filename)
{
file->fid = open(filename, O_RDWR | O_CREAT | O_NONBLOCK, 0666);
if (file->fid < 0)
file->fid = open(filename, O_RDWR | O_CREAT | O_EXLOCK | O_NONBLOCK, 0666);
if (file->fid < 0) {
CHECK_POSIX(errno);
}
return 1;
Error:
LOGE("Failed to create \"%s\"", filename);
return 0;
}

void
file_close(struct file* file)
{
CHECK_POSIX(close(file->fid));
if (close(file->fid) < 0)
CHECK_POSIX(errno);
Error:;
}

Expand Down Expand Up @@ -85,8 +88,11 @@ int
file_exists(const char* filename, size_t nbytes)
{
int ret = access(filename, F_OK);
if (ret < 0)
if (ret < 0) {
if (errno == ENOENT)
return 0;
CHECK_POSIX(errno);
}
return ret == 0;
Error:
return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/acquire-core-platform/win32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ add_library(${tgt} STATIC
platform.h
platform.c)
target_link_libraries(${tgt} PUBLIC acquire-core-logger)
target_include_directories(${tgt} PUBLIC "${CMAKE_CURRENT_LIST_DIR}")
target_include_directories(${tgt} PUBLIC "${CMAKE_CURRENT_LIST_DIR}")
6 changes: 3 additions & 3 deletions src/acquire-core-platform/win32/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,14 @@ file_create(struct file* file, const char* filename, size_t bytes_of_filename)

CHECK_HANDLE(file->hfile = CreateFileA(filename,
GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
FILE_SHARE_READ,
0,
CREATE_ALWAYS,
FILE_FLAG_OVERLAPPED,
0));
return 1;
Error:
LOGE("Could not create \"%s\"", filename);
return 0;
}

Expand Down Expand Up @@ -438,8 +439,7 @@ thread_join(struct thread* self)
if (thread != INVALID_HANDLE_VALUE) {
self->inner_ = INVALID_HANDLE_VALUE;
TRACE("WFSO %p", thread);
WaitForSingleObject(thread,
INFINITE);
WaitForSingleObject(thread, INFINITE);
CloseHandle(thread);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/acquire-device-hal/device/hal/device.manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ DeviceManagerV0::init(void (*reporter)(int is_error,
drivers_.push_back(driver_load("acquire-driver-zarr", reporter));
drivers_.push_back(driver_load("acquire-driver-egrabber", reporter));
drivers_.push_back(driver_load("acquire-driver-spinnaker", reporter));
drivers_.push_back(driver_load("acquire-driver-pvcam", reporter));

// enumerate devices
const DeviceIdentifier dflt{ 0, 0, DeviceKind_Unknown, "" };
Expand Down
1 change: 1 addition & 0 deletions src/acquire-device-properties/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ set(tgt acquire-device-properties)
add_library(${tgt} STATIC
device/props/device.c
device/props/storage.c
device/props/components.c
)
target_sources(${tgt} PUBLIC FILE_SET HEADERS
BASE_DIRS "${CMAKE_CURRENT_LIST_DIR}"
Expand Down
97 changes: 97 additions & 0 deletions src/acquire-device-properties/device/props/components.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#include "components.h"

#define countof(e) (sizeof(e) / sizeof(*(e)))

const char*
sample_type_as_string(enum SampleType type)
{
// Note: This table needs to get updated whenever a SampleType gets
// added. The unit test below should crash when an entry is
// missing.

// clang-format off
const char* table[] = {
#define XXX(name) [SampleType_##name] = #name
XXX(u8),
XXX(u16),
XXX(i8),
XXX(i16),
XXX(f32),
XXX(u10),
XXX(u12),
XXX(u14),
#undef XXX
};
// clang-format on
if (type >= countof(table))
return "(unknown)";

return table[type];
}

size_t
bytes_of_type(enum SampleType type)
{
size_t table[SampleTypeCount]; // = { 1, 2, 1, 2, 4, 2, 2, 2 };

// clang-format off
#define XXX(s, b) table[(s)] = (b)
XXX(SampleType_u8, 1);
XXX(SampleType_u16, 2);
XXX(SampleType_i8, 1);
XXX(SampleType_i16, 2);
XXX(SampleType_f32, 4);
XXX(SampleType_u10, 2);
XXX(SampleType_u12, 2);
XXX(SampleType_u14, 2);
#undef XXX
// clang-format on
if (type >= countof(table))
return 0;

return table[type];
}

//
// UNIT TESTS
//

#ifndef NO_UNIT_TESTS
#include "logger.h"

#define L (aq_logger)
#define LOG(...) L(0, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)
#define ERR(...) L(1, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)
#define CHECK(e) \
do { \
if (!(e)) { \
ERR("Expression evaluated as false:\n\t%s", #e); \
goto Error; \
} \
} while (0)

int
unit_test__sample_type_as_string__is_defined_for_all()
{
for (int i = 0; i < SampleTypeCount; ++i) {
// Check this isn't returning "unknown" for known counts
CHECK(sample_type_as_string(i)[0] != '(');
}
return 1;
Error:
return 0;
}

int
unit_test__bytes_of_type__is_defined_for_all()
{
for (int i = 0; i < SampleTypeCount; ++i) {
// Check this isn't returning 0 for known counts
CHECK(bytes_of_type(i) != 0);
}
return 1;
Error:
return 0;
}

#endif // NO_UNIT_TESTS
3 changes: 3 additions & 0 deletions src/acquire-device-properties/device/props/components.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ extern "C"
double x, y;
};

const char* sample_type_as_string(enum SampleType type);
size_t bytes_of_type(enum SampleType type);

#ifdef __cplusplus
}
#endif
Expand Down
Loading

0 comments on commit 4dbf2de

Please sign in to comment.