Align code style (#40)

- Mutex -> Mutex*
- Cleanup enum names
- Other small changes
This commit is contained in:
Ken Van Hoeylandt
2024-02-11 00:58:43 +01:00
committed by GitHub
parent 9327d61427
commit e0db8767c7
30 changed files with 117 additions and 121 deletions
+17 -17
View File
@@ -7,9 +7,9 @@
// region BundleEntry
typedef enum {
BUNDLE_ENTRY_TYPE_BOOL,
BUNDLE_ENTRY_TYPE_INT32,
BUNDLE_ENTRY_TYPE_STRING,
BundleEntryTypeBool,
BundleEntryTypeInt32,
BundleEntryTypeString,
} BundleEntryType;
typedef struct {
@@ -23,21 +23,21 @@ typedef struct {
BundleEntry* bundle_entry_alloc_bool(bool value) {
BundleEntry* entry = malloc(sizeof(BundleEntry));
entry->type = BUNDLE_ENTRY_TYPE_BOOL;
entry->type = BundleEntryTypeBool;
entry->bool_value = value;
return entry;
}
BundleEntry* bundle_entry_alloc_int32(int32_t value) {
BundleEntry* entry = malloc(sizeof(BundleEntry));
entry->type = BUNDLE_ENTRY_TYPE_INT32;
entry->type = BundleEntryTypeInt32;
entry->int32_value = value;
return entry;
}
BundleEntry* bundle_entry_alloc_string(const char* text) {
BundleEntry* entry = malloc(sizeof(BundleEntry));
entry->type = BUNDLE_ENTRY_TYPE_STRING;
entry->type = BundleEntryTypeString;
entry->string_ptr = malloc(strlen(text) + 1);
strcpy(entry->string_ptr, text);
return entry;
@@ -46,7 +46,7 @@ BundleEntry* bundle_entry_alloc_string(const char* text) {
BundleEntry* bundle_entry_alloc_copy(BundleEntry* source) {
BundleEntry* entry = malloc(sizeof(BundleEntry));
entry->type = source->type;
if (source->type == BUNDLE_ENTRY_TYPE_STRING) {
if (source->type == BundleEntryTypeString) {
entry->string_ptr = malloc(strlen(source->string_ptr) + 1);
strcpy(entry->string_ptr, source->string_ptr);
} else {
@@ -56,7 +56,7 @@ BundleEntry* bundle_entry_alloc_copy(BundleEntry* source) {
}
void bundle_entry_free(BundleEntry* entry) {
if (entry->type == BUNDLE_ENTRY_TYPE_STRING) {
if (entry->type == BundleEntryTypeString) {
free(entry->string_ptr);
}
free(entry);
@@ -129,19 +129,19 @@ const char* tt_bundle_get_string(Bundle bundle, const char* key) {
bool tt_bundle_has_bool(Bundle bundle, const char* key) {
BundleData* data = (BundleData*)bundle;
BundleEntry** entry = BundleDict_get(data->dict, key);
return (entry != NULL) && ((*entry)->type == BUNDLE_ENTRY_TYPE_BOOL);
return (entry != NULL) && ((*entry)->type == BundleEntryTypeBool);
}
bool tt_bundle_has_int32(Bundle bundle, const char* key) {
BundleData* data = (BundleData*)bundle;
BundleEntry** entry = BundleDict_get(data->dict, key);
return (entry != NULL) && ((*entry)->type == BUNDLE_ENTRY_TYPE_INT32);
return (entry != NULL) && ((*entry)->type == BundleEntryTypeInt32);
}
bool tt_bundle_has_string(Bundle bundle, const char* key) {
BundleData* data = (BundleData*)bundle;
BundleEntry** entry = BundleDict_get(data->dict, key);
return (entry != NULL) && ((*entry)->type == BUNDLE_ENTRY_TYPE_STRING);
return (entry != NULL) && ((*entry)->type == BundleEntryTypeString);
}
bool tt_bundle_opt_bool(Bundle bundle, const char* key, bool* out) {
@@ -149,7 +149,7 @@ bool tt_bundle_opt_bool(Bundle bundle, const char* key, bool* out) {
BundleEntry** entry_ptr = BundleDict_get(data->dict, key);
if (entry_ptr != NULL) {
BundleEntry* entry = *entry_ptr;
if (entry->type == BUNDLE_ENTRY_TYPE_BOOL) {
if (entry->type == BundleEntryTypeBool) {
*out = entry->bool_value;
return true;
} else {
@@ -165,7 +165,7 @@ bool tt_bundle_opt_int32(Bundle bundle, const char* key, int32_t* out) {
BundleEntry** entry_ptr = BundleDict_get(data->dict, key);
if (entry_ptr != NULL) {
BundleEntry* entry = *entry_ptr;
if (entry->type == BUNDLE_ENTRY_TYPE_INT32) {
if (entry->type == BundleEntryTypeInt32) {
*out = entry->int32_value;
return true;
} else {
@@ -181,7 +181,7 @@ bool tt_bundle_opt_string(Bundle bundle, const char* key, char** out) {
BundleEntry** entry_ptr = BundleDict_get(data->dict, key);
if (entry_ptr != NULL) {
BundleEntry* entry = *entry_ptr;
if (entry->type == BUNDLE_ENTRY_TYPE_STRING) {
if (entry->type == BundleEntryTypeString) {
*out = entry->string_ptr;
return true;
} else {
@@ -197,7 +197,7 @@ void tt_bundle_put_bool(Bundle bundle, const char* key, bool value) {
BundleEntry** entry_handle = BundleDict_get(data->dict, key);
if (entry_handle != NULL) {
BundleEntry* entry = *entry_handle;
tt_assert(entry->type == BUNDLE_ENTRY_TYPE_BOOL);
tt_assert(entry->type == BundleEntryTypeBool);
entry->bool_value = value;
} else {
BundleEntry* entry = bundle_entry_alloc_bool(value);
@@ -210,7 +210,7 @@ void tt_bundle_put_int32(Bundle bundle, const char* key, int32_t value) {
BundleEntry** entry_handle = BundleDict_get(data->dict, key);
if (entry_handle != NULL) {
BundleEntry* entry = *entry_handle;
tt_assert(entry->type == BUNDLE_ENTRY_TYPE_INT32);
tt_assert(entry->type == BundleEntryTypeInt32);
entry->int32_value = value;
} else {
BundleEntry* entry = bundle_entry_alloc_int32(value);
@@ -223,7 +223,7 @@ void tt_bundle_put_string(Bundle bundle, const char* key, const char* value) {
BundleEntry** entry_handle = BundleDict_get(data->dict, key);
if (entry_handle != NULL) {
BundleEntry* entry = *entry_handle;
tt_assert(entry->type == BUNDLE_ENTRY_TYPE_STRING);
tt_assert(entry->type == BundleEntryTypeString);
if (entry->string_ptr != NULL) {
free(entry->string_ptr);
}
+2 -2
View File
@@ -197,8 +197,8 @@ void tt_delay_us(uint32_t microseconds) {
Platform tt_get_platform() {
#ifdef ESP_PLATFORM
return PLATFORM_ESP;
return PlatformEsp;
#else
return PLATFORM_PC;
return PlatformPc;
#endif
}
+2 -2
View File
@@ -7,8 +7,8 @@ extern "C" {
#endif
typedef enum {
PLATFORM_ESP,
PLATFORM_PC
PlatformEsp,
PlatformPc
} Platform;
/** Check if CPU is in IRQ or kernel running and IRQ is masked
+10 -10
View File
@@ -13,15 +13,15 @@
static char tt_loglevel_to_prefix(LogLevel level) {
switch (level) {
case LOG_LEVEL_ERROR:
case LogLevelError:
return 'E';
case LOG_LEVEL_WARNING:
case LogLevelWarning:
return 'W';
case LOG_LEVEL_INFO:
case LogLevelInfo:
return 'I';
case LOG_LEVEL_DEBUG:
case LogLevelDebug:
return 'D';
case LOG_LEVEL_TRACE:
case LogLevelTrace:
return 'T';
default:
return '?';
@@ -30,15 +30,15 @@ static char tt_loglevel_to_prefix(LogLevel level) {
static const char* tt_loglevel_to_colour(LogLevel level) {
switch (level) {
case LOG_LEVEL_ERROR:
case LogLevelError:
return "\033[1;31m";
case LOG_LEVEL_WARNING:
case LogLevelWarning:
return "\033[33m";
case LOG_LEVEL_INFO:
case LogLevelInfo:
return "\033[32m";
case LOG_LEVEL_DEBUG:
case LogLevelDebug:
return "\033[1;37m";
case LOG_LEVEL_TRACE:
case LogLevelTrace:
return "\033[37m";
default:
return "";
+9 -9
View File
@@ -27,23 +27,23 @@ extern "C" {
#else
typedef enum {
LOG_LEVEL_ERROR,
LOG_LEVEL_WARNING,
LOG_LEVEL_INFO,
LOG_LEVEL_DEBUG,
LOG_LEVEL_TRACE
LogLevelError,
LogLevelWarning,
LogLevelInfo,
LogLevelDebug,
LogLevelTrace
} LogLevel;
void tt_log(LogLevel level, const char* tag, const char* format, ...);
#define TT_LOG_E(tag, format, ...) \
tt_log(LOG_LEVEL_ERROR, tag, format, ##__VA_ARGS__)
tt_log(LogLevelError, tag, format, ##__VA_ARGS__)
#define TT_LOG_W(tag, format, ...) \
tt_log(LOG_LEVEL_WARNING, tag, format, ##__VA_ARGS__)
tt_log(LogLevelWarning, tag, format, ##__VA_ARGS__)
#define TT_LOG_I(tag, format, ...) \
tt_log(LOG_LEVEL_INFO, tag, format, ##__VA_ARGS__)
tt_log(LogLevelInfo, tag, format, ##__VA_ARGS__)
#define TT_LOG_D(tag, format, ...) \
tt_log(LOG_LEVEL_DEBUG, tag, format, ##__VA_ARGS__)
tt_log(LogLevelDebug, tag, format, ##__VA_ARGS__)
#define TT_LOG_T(tag, format, ...) \
tt_log(LOG_LEVEL_TRACE, tag, format, ##__VA_ARGS__)
+6 -6
View File
@@ -33,7 +33,7 @@ void tt_mutex_info(Mutex mutex, const char* label) {
#define tt_mutex_info(mutex, text)
#endif
Mutex tt_mutex_alloc(MutexType type) {
Mutex* tt_mutex_alloc(MutexType type) {
tt_assert(!TT_IS_IRQ_MODE());
MutexData* data = malloc(sizeof(MutexData));
@@ -52,10 +52,10 @@ Mutex tt_mutex_alloc(MutexType type) {
tt_check(data->handle != NULL);
tt_mutex_info(data, "alloc ");
return (Mutex)data;
return (Mutex*)data;
}
void tt_mutex_free(Mutex mutex) {
void tt_mutex_free(Mutex* mutex) {
tt_assert(!TT_IS_IRQ_MODE());
tt_assert(mutex);
@@ -66,7 +66,7 @@ void tt_mutex_free(Mutex mutex) {
free(data);
}
TtStatus tt_mutex_acquire(Mutex mutex, uint32_t timeout) {
TtStatus tt_mutex_acquire(Mutex* mutex, uint32_t timeout) {
tt_assert(mutex);
tt_assert(!TT_IS_IRQ_MODE());
MutexData* data = (MutexData*)mutex;
@@ -101,7 +101,7 @@ TtStatus tt_mutex_acquire(Mutex mutex, uint32_t timeout) {
return status;
}
TtStatus tt_mutex_release(Mutex mutex) {
TtStatus tt_mutex_release(Mutex* mutex) {
tt_assert(mutex);
assert(!TT_IS_IRQ_MODE());
MutexData* data = (MutexData*)mutex;
@@ -129,7 +129,7 @@ TtStatus tt_mutex_release(Mutex mutex) {
return status;
}
ThreadId tt_mutex_get_owner(Mutex mutex) {
ThreadId tt_mutex_get_owner(Mutex* mutex) {
tt_assert(mutex != NULL);
tt_assert(!TT_IS_IRQ_MODE());
MutexData* data = (MutexData*)mutex;
+6 -6
View File
@@ -16,7 +16,7 @@ typedef enum {
MutexTypeRecursive,
} MutexType;
typedef void* Mutex;
typedef void Mutex;
/** Allocate Mutex
*
@@ -24,13 +24,13 @@ typedef void* Mutex;
*
* @return pointer to Mutex instance
*/
Mutex tt_mutex_alloc(MutexType type);
Mutex* tt_mutex_alloc(MutexType type);
/** Free Mutex
*
* @param mutex The Mutex instance
*/
void tt_mutex_free(Mutex mutex);
void tt_mutex_free(Mutex* mutex);
/** Acquire mutex
*
@@ -39,7 +39,7 @@ void tt_mutex_free(Mutex mutex);
*
* @return The status.
*/
TtStatus tt_mutex_acquire(Mutex mutex, uint32_t timeout);
TtStatus tt_mutex_acquire(Mutex* mutex, uint32_t timeout);
/** Release mutex
*
@@ -47,7 +47,7 @@ TtStatus tt_mutex_acquire(Mutex mutex, uint32_t timeout);
*
* @return The status.
*/
TtStatus tt_mutex_release(Mutex mutex);
TtStatus tt_mutex_release(Mutex* mutex);
/** Get mutex owner thread id
*
@@ -55,7 +55,7 @@ TtStatus tt_mutex_release(Mutex mutex);
*
* @return The thread identifier.
*/
ThreadId tt_mutex_get_owner(Mutex mutex);
ThreadId tt_mutex_get_owner(Mutex* mutex);
#ifdef __cplusplus
}
+1 -1
View File
@@ -13,7 +13,7 @@ LIST_DEF(PubSubSubscriptionList, PubSubSubscription, M_POD_OPLIST);
struct PubSub {
PubSubSubscriptionList_t items;
Mutex mutex;
Mutex* mutex;
};
PubSub* tt_pubsub_alloc() {