[WIP] - refactor and code format

This commit is contained in:
Keegan
2016-10-29 00:25:14 -07:00
parent 8d53645a3a
commit df3965ccac
+12 -9
View File
@@ -6,7 +6,7 @@
static ClayCallbacks s_callbacks; static ClayCallbacks s_callbacks;
static uint32_t prv_hash_key(const char *key) { 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) { 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; 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); uint32_t persist_key = prv_hash_key(key);
int bytes_written = persist_write_data(persist_key, data, size); int bytes_written = persist_write_data(persist_key, data, size);
return bytes_written >= 0 && (size_t)bytes_written == size; return bytes_written >= 0 && (size_t)bytes_written == size;
} }
static void prv_simple_app_message_received_callback(const SimpleDict *message, void *context) { static bool prv_simple_dict_foreach_callback(
if (!message) { const char *key, SimpleDictDataType type, const void *data, size_t size, void *context) {
return; return prv_write(key, data, size);
} }
APP_LOG(APP_LOG_LEVEL_INFO, "CLAY: Received SimpleAppMessage"); static void prv_simple_app_message_received_callback(const SimpleDict *message, void *context) {
simple_dict_foreach(message, prv_write, NULL); if (!message) return;
simple_dict_foreach(message, prv_simple_dict_foreach_callback, NULL);
s_callbacks.settings_updated(context); 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); SIMPLE_APP_MESSAGE_NAMESPACE, &simple_app_message_callbacks, context);
if (!register_success) { 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);
} }
} }