mirror of
https://github.com/pebble-dev/clay.git
synced 2026-09-05 16:47:37 -04:00
[WIP] - Move callbacks registration to init method
This commit is contained in:
+1
-3
@@ -8,7 +8,7 @@ typedef struct ClayCallbacks {
|
|||||||
ClayUpdatedCallback settings_updated;
|
ClayUpdatedCallback settings_updated;
|
||||||
} ClayCallbacks;
|
} ClayCallbacks;
|
||||||
|
|
||||||
void clay_init(uint32_t inbox_size);
|
void clay_init(uint32_t inbox_size, const ClayCallbacks *callbacks, void *context);
|
||||||
|
|
||||||
void clay_remove(const char *key);
|
void clay_remove(const char *key);
|
||||||
|
|
||||||
@@ -29,5 +29,3 @@ bool clay_get_data(const char *key, void *value_out, size_t n);
|
|||||||
bool clay_get_int(const char *key, int *value_out);
|
bool clay_get_int(const char *key, int *value_out);
|
||||||
|
|
||||||
bool clay_get_string(const char *key, char *value_out, size_t n);
|
bool clay_get_string(const char *key, char *value_out, size_t n);
|
||||||
|
|
||||||
bool clay_register_callbacks(const ClayCallbacks *callbacks, void *context);
|
|
||||||
|
|||||||
+10
-14
@@ -4,11 +4,9 @@
|
|||||||
#define SIMPLE_APP_MESSAGE_NAMESPACE ("CLAY")
|
#define SIMPLE_APP_MESSAGE_NAMESPACE ("CLAY")
|
||||||
|
|
||||||
static ClayCallbacks s_callbacks;
|
static ClayCallbacks s_callbacks;
|
||||||
static void *s_context;
|
|
||||||
|
|
||||||
static bool prv_store_settings(const char *key, SimpleDictDataType type, const void *data,
|
|
||||||
size_t data_size, void *context) {
|
|
||||||
|
|
||||||
|
static bool prv_store_settings(
|
||||||
|
const char *key, SimpleDictDataType type, const void *data, size_t data_size, void *context) {
|
||||||
uint32_t persist_key = hash((uint8_t *) key, strlen(key));
|
uint32_t persist_key = hash((uint8_t *) key, strlen(key));
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@@ -22,7 +20,8 @@ static bool prv_store_settings(const char *key, SimpleDictDataType type, const v
|
|||||||
}
|
}
|
||||||
case SimpleDictDataType_Int: {
|
case SimpleDictDataType_Int: {
|
||||||
const int value = *((int *) data);
|
const int value = *((int *) data);
|
||||||
APP_LOG(APP_LOG_LEVEL_INFO, "CLAY: writing %d - %d to storage", (int)persist_key, value);
|
APP_LOG(APP_LOG_LEVEL_INFO, "CLAY: writing %d - %d to storage",
|
||||||
|
(int) persist_key, value);
|
||||||
persist_write_int(persist_key, value);
|
persist_write_int(persist_key, value);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -48,23 +47,20 @@ static void prv_simple_app_message_received_callback(const SimpleDict *message,
|
|||||||
s_callbacks.settings_updated(context);
|
s_callbacks.settings_updated(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool clay_register_callbacks(const ClayCallbacks *callbacks, void *context) {
|
void clay_init(uint32_t inbox_size, const ClayCallbacks *callbacks, void *context) {
|
||||||
s_callbacks = *callbacks;
|
s_callbacks = *callbacks;
|
||||||
s_context = context;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void clay_init(uint32_t inbox_size) {
|
const SimpleAppMessageCallbacks simple_app_message_callbacks = {
|
||||||
const SimpleAppMessageCallbacks simple_app_message_callbacks = (SimpleAppMessageCallbacks) {
|
|
||||||
.message_received = prv_simple_app_message_received_callback,
|
.message_received = prv_simple_app_message_received_callback,
|
||||||
};
|
};
|
||||||
const bool register_success = simple_app_message_register_callbacks(SIMPLE_APP_MESSAGE_NAMESPACE,
|
const bool register_success = simple_app_message_register_callbacks(
|
||||||
&simple_app_message_callbacks,
|
SIMPLE_APP_MESSAGE_NAMESPACE, &simple_app_message_callbacks, context);
|
||||||
s_context);
|
|
||||||
if (!register_success) {
|
if (!register_success) {
|
||||||
APP_LOG(APP_LOG_LEVEL_ERROR, "Failed to register callbacks for namespace %s", SIMPLE_APP_MESSAGE_NAMESPACE);
|
APP_LOG(APP_LOG_LEVEL_ERROR, "Failed to register callbacks for namespace %s", SIMPLE_APP_MESSAGE_NAMESPACE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool request_inbox_size_success = simple_app_message_request_inbox_size(inbox_size);
|
const bool request_inbox_size_success = simple_app_message_request_inbox_size(inbox_size);
|
||||||
if (!request_inbox_size_success) {
|
if (!request_inbox_size_success) {
|
||||||
APP_LOG(APP_LOG_LEVEL_ERROR, "Failed to request inbox size of %d", (int)inbox_size);
|
APP_LOG(APP_LOG_LEVEL_ERROR, "Failed to request inbox size of %d", (int)inbox_size);
|
||||||
|
|||||||
Reference in New Issue
Block a user