SDK improvements (#352)
TactilityC additions for: - C randomization functions - Tactility app paths - Tactility locks
This commit is contained in:
committed by
GitHub
parent
6dc4f698c9
commit
c7621b5e4c
@@ -2,6 +2,7 @@
|
||||
#include <Tactility/app/App.h>
|
||||
#include <Tactility/app/AppPaths.h>
|
||||
#include <Tactility/app/AppContext.h>
|
||||
#include <Tactility/file/FileLock.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
@@ -34,13 +35,13 @@ void tt_app_stop() {
|
||||
tt::app::stop();
|
||||
}
|
||||
|
||||
void tt_app_get_data_directory(AppPathsHandle handle, char* buffer, size_t* size) {
|
||||
void tt_app_get_user_data_path(AppHandle handle, char* buffer, size_t* size) {
|
||||
assert(buffer != nullptr);
|
||||
assert(size != nullptr);
|
||||
assert(*size > 0);
|
||||
auto paths = HANDLE_AS_APP_CONTEXT(handle)->getPaths();
|
||||
auto data_path = paths->getUserDataPath();
|
||||
auto expected_length = data_path.length() + 1;
|
||||
const auto paths = HANDLE_AS_APP_CONTEXT(handle)->getPaths();
|
||||
const auto data_path = paths->getUserDataPath();
|
||||
const auto expected_length = data_path.length() + 1;
|
||||
if (*size < expected_length) {
|
||||
TT_LOG_E(TAG, "Path buffer not large enough (%d < %d)", *size, expected_length);
|
||||
*size = 0;
|
||||
@@ -52,4 +53,59 @@ void tt_app_get_data_directory(AppPathsHandle handle, char* buffer, size_t* size
|
||||
*size = data_path.length();
|
||||
}
|
||||
|
||||
void tt_app_get_user_data_child_path(AppHandle handle, const char* childPath, char* buffer, size_t* size) {
|
||||
assert(buffer != nullptr);
|
||||
assert(size != nullptr);
|
||||
assert(*size > 0);
|
||||
const auto paths = HANDLE_AS_APP_CONTEXT(handle)->getPaths();
|
||||
const auto resolved_path = paths->getUserDataPath(childPath);
|
||||
const auto resolved_path_length = resolved_path.length();
|
||||
if (*size < (resolved_path_length + 1)) {
|
||||
TT_LOG_E(TAG, "Path buffer not large enough (%d < %d)", *size, (resolved_path_length + 1));
|
||||
*size = 0;
|
||||
buffer[0] = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
strcpy(buffer, resolved_path.c_str());
|
||||
*size = resolved_path_length;
|
||||
}
|
||||
|
||||
void tt_app_get_assets_path(AppHandle handle, char* buffer, size_t* size) {
|
||||
assert(buffer != nullptr);
|
||||
assert(size != nullptr);
|
||||
assert(*size > 0);
|
||||
const auto paths = HANDLE_AS_APP_CONTEXT(handle)->getPaths();
|
||||
const auto assets_path = paths->getAssetsPath();
|
||||
const auto expected_length = assets_path.length() + 1;
|
||||
if (*size < expected_length) {
|
||||
TT_LOG_E(TAG, "Path buffer not large enough (%d < %d)", *size, expected_length);
|
||||
*size = 0;
|
||||
buffer[0] = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
strcpy(buffer, assets_path.c_str());
|
||||
*size = assets_path.length();
|
||||
}
|
||||
|
||||
void tt_app_get_assets_child_path(AppHandle handle, const char* childPath, char* buffer, size_t* size) {
|
||||
assert(buffer != nullptr);
|
||||
assert(size != nullptr);
|
||||
assert(*size > 0);
|
||||
const auto paths = HANDLE_AS_APP_CONTEXT(handle)->getPaths();
|
||||
const auto resolved_path = paths->getAssetsPath(childPath);
|
||||
const auto resolved_path_length = resolved_path.length();
|
||||
if (*size < (resolved_path_length + 1)) {
|
||||
TT_LOG_E(TAG, "Path buffer not large enough (%d < %d)", *size, (resolved_path_length + 1));
|
||||
*size = 0;
|
||||
buffer[0] = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
strcpy(buffer, resolved_path.c_str());
|
||||
*size = resolved_path_length;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#include <tt_file.h>
|
||||
#include <tt_lock_private.h>
|
||||
#include <Tactility/file/FileLock.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
LockHandle tt_lock_alloc_for_file(const char* path) {
|
||||
auto lock = tt::file::getLock(path);
|
||||
auto holder = new LockHolder(lock);
|
||||
return holder;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -38,6 +38,7 @@
|
||||
#include <lvgl.h>
|
||||
#include <pthread.h>
|
||||
#include <setjmp.h>
|
||||
#include <tt_file.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
@@ -54,6 +55,9 @@ const esp_elfsym elf_symbols[] {
|
||||
ESP_ELFSYM_EXPORT(calloc),
|
||||
ESP_ELFSYM_EXPORT(realloc),
|
||||
ESP_ELFSYM_EXPORT(free),
|
||||
ESP_ELFSYM_EXPORT(rand),
|
||||
ESP_ELFSYM_EXPORT(srand),
|
||||
ESP_ELFSYM_EXPORT(rand_r),
|
||||
// unistd.h
|
||||
ESP_ELFSYM_EXPORT(usleep),
|
||||
ESP_ELFSYM_EXPORT(sleep),
|
||||
@@ -116,6 +120,7 @@ const esp_elfsym elf_symbols[] {
|
||||
ESP_ELFSYM_EXPORT(snprintf),
|
||||
ESP_ELFSYM_EXPORT(sprintf),
|
||||
ESP_ELFSYM_EXPORT(vsprintf),
|
||||
ESP_ELFSYM_EXPORT(vsnprintf),
|
||||
// cstring
|
||||
ESP_ELFSYM_EXPORT(strlen),
|
||||
ESP_ELFSYM_EXPORT(strcmp),
|
||||
@@ -225,7 +230,14 @@ const esp_elfsym elf_symbols[] {
|
||||
ESP_ELFSYM_EXPORT(tt_app_selectiondialog_get_result_index),
|
||||
ESP_ELFSYM_EXPORT(tt_app_alertdialog_start),
|
||||
ESP_ELFSYM_EXPORT(tt_app_alertdialog_get_result_index),
|
||||
ESP_ELFSYM_EXPORT(tt_app_get_data_directory),
|
||||
ESP_ELFSYM_EXPORT(tt_app_get_user_data_path),
|
||||
ESP_ELFSYM_EXPORT(tt_app_get_user_data_child_path),
|
||||
ESP_ELFSYM_EXPORT(tt_app_get_assets_path),
|
||||
ESP_ELFSYM_EXPORT(tt_app_get_assets_child_path),
|
||||
ESP_ELFSYM_EXPORT(tt_lock_alloc_for_file),
|
||||
ESP_ELFSYM_EXPORT(tt_lock_acquire),
|
||||
ESP_ELFSYM_EXPORT(tt_lock_release),
|
||||
ESP_ELFSYM_EXPORT(tt_lock_free),
|
||||
ESP_ELFSYM_EXPORT(tt_bundle_alloc),
|
||||
ESP_ELFSYM_EXPORT(tt_bundle_free),
|
||||
ESP_ELFSYM_EXPORT(tt_bundle_opt_bool),
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
#include <tt_lock.h>
|
||||
#include <tt_lock_private.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
bool tt_lock_acquire(LockHandle handle, TickType timeout) {
|
||||
auto holder = static_cast<LockHolder*>(handle);
|
||||
return holder->lock->lock(timeout);
|
||||
}
|
||||
|
||||
bool tt_lock_release(LockHandle handle) {
|
||||
auto holder = static_cast<LockHolder*>(handle);
|
||||
return holder->lock->unlock();
|
||||
}
|
||||
|
||||
void tt_lock_free(LockHandle handle) {
|
||||
auto holder = static_cast<LockHolder*>(handle);
|
||||
delete holder;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,11 +5,11 @@ extern "C" {
|
||||
|
||||
#define HANDLE_AS_MUTEX(handle) ((tt::Mutex*)(handle))
|
||||
|
||||
MutexHandle tt_mutex_alloc(enum TtMutexType type) {
|
||||
MutexHandle tt_mutex_alloc(TtMutexType type) {
|
||||
switch (type) {
|
||||
case TtMutexType::MUTEX_TYPE_NORMAL:
|
||||
case MUTEX_TYPE_NORMAL:
|
||||
return new tt::Mutex(tt::Mutex::Type::Normal);
|
||||
case TtMutexType::MUTEX_TYPE_RECURSIVE:
|
||||
case MUTEX_TYPE_RECURSIVE:
|
||||
return new tt::Mutex(tt::Mutex::Type::Recursive);
|
||||
default:
|
||||
tt_crash("Type not supported");
|
||||
@@ -20,8 +20,8 @@ void tt_mutex_free(MutexHandle handle) {
|
||||
delete HANDLE_AS_MUTEX(handle);
|
||||
}
|
||||
|
||||
bool tt_mutex_lock(MutexHandle handle, TickType_t timeout) {
|
||||
return HANDLE_AS_MUTEX(handle)->lock((TickType_t)timeout);
|
||||
bool tt_mutex_lock(MutexHandle handle, TickType timeout) {
|
||||
return HANDLE_AS_MUTEX(handle)->lock(timeout);
|
||||
}
|
||||
|
||||
bool tt_mutex_unlock(MutexHandle handle) {
|
||||
|
||||
Reference in New Issue
Block a user