From df3965ccac19aea45a3344f1995933d166c80cf0 Mon Sep 17 00:00:00 2001 From: Keegan Date: Sat, 29 Oct 2016 00:25:14 -0700 Subject: [PATCH] [WIP] - refactor and code format --- src/c/clay.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/c/clay.c b/src/c/clay.c index 3f94c4c..74b3910 100644 --- a/src/c/clay.c +++ b/src/c/clay.c @@ -6,7 +6,7 @@ static ClayCallbacks s_callbacks; static uint32_t prv_hash_key(const char *key) { - return hash((uint8_t *)key, strlen(key)); + return hash((uint8_t *)key, (uint32_t)strlen(key)); } static bool prv_read(const char *key, void *value_out, size_t size) { @@ -15,19 +15,21 @@ static bool prv_read(const char *key, void *value_out, size_t size) { return bytes_read >= 0 && (size_t)bytes_read == size; } -static bool prv_write(const char *key, const SimpleDictDataType type, const void *data, size_t size, void *context) { +static bool prv_write(const char *key, const void *data, size_t size) { uint32_t persist_key = prv_hash_key(key); int bytes_written = persist_write_data(persist_key, data, size); return bytes_written >= 0 && (size_t)bytes_written == size; } -static void prv_simple_app_message_received_callback(const SimpleDict *message, void *context) { - if (!message) { - return; - } +static bool prv_simple_dict_foreach_callback( + const char *key, SimpleDictDataType type, const void *data, size_t size, void *context) { + return prv_write(key, data, size); +} - APP_LOG(APP_LOG_LEVEL_INFO, "CLAY: Received SimpleAppMessage"); - simple_dict_foreach(message, prv_write, NULL); +static void prv_simple_app_message_received_callback(const SimpleDict *message, void *context) { + if (!message) return; + + simple_dict_foreach(message, prv_simple_dict_foreach_callback, NULL); s_callbacks.settings_updated(context); } @@ -58,7 +60,8 @@ void clay_register_callbacks(const ClayCallbacks *callbacks, void *context) { SIMPLE_APP_MESSAGE_NAMESPACE, &simple_app_message_callbacks, context); if (!register_success) { - APP_LOG(APP_LOG_LEVEL_ERROR, "CLAY: Failed to register callbacks for namespace %s", SIMPLE_APP_MESSAGE_NAMESPACE); + APP_LOG(APP_LOG_LEVEL_ERROR, "CLAY: Failed to register callbacks for namespace %s", + SIMPLE_APP_MESSAGE_NAMESPACE); } }