Loading...
Searching...
No Matches
store_persist.h
Go to the documentation of this file.
1
7#pragma once
8#include <pebble.h>
9
10#include "io/stores/store_sum.h"
11
16
29#define STORE_TAG_WEATHER 0x13
30#define STORE_TAG_STOCK 0x21
31#define STORE_TAG_CALENDAR 0x31
32#define STORE_TAG_HEALTH 0x42
33#define STORE_TAG_LOCATION 0x51
34#define STORE_TAG_HRV 0x61
36
49static inline bool store_restore(uint32_t key, void *state, size_t size, uint8_t tag)
50{
51 if (!persist_exists(key) || persist_get_size(key) != (int)size)
52 {
53 return false;
54 }
55
56 // read the tag on its own first. reading the whole blob to check it would already have
57 // stomped the defaults by the time we found out it was the wrong shape
58 uint8_t stored = 0;
59 if (persist_read_data(key, &stored, sizeof(stored)) != (int)sizeof(stored) || stored != tag)
60 {
61 return false;
62 }
63
64 return persist_read_data(key, state, size) == (int)size;
65}
66
78static inline bool store_save(uint32_t key, void *state, size_t size, uint8_t tag)
79{
80 *(uint8_t *)state = tag;
81 return persist_write_data(key, state, size) == (int)size;
82}
83
104bool store_save_changed(uint32_t key, void *state, size_t size, size_t reading_size, uint8_t tag,
105 uint32_t *saved_sum);
106
121bool store_restore_reading(uint32_t key, void *state, size_t size, size_t reading_size, uint8_t tag,
122 uint32_t *saved_sum);
123
bool store_save_changed(uint32_t key, void *state, size_t size, size_t reading_size, uint8_t tag, uint32_t *saved_sum)
Save a store's blob only when its reading is different from what is already on flash.
Definition store_persist.c:10
static bool store_restore(uint32_t key, void *state, size_t size, uint8_t tag)
Restore a saved blob into state, but only when it is this store's own current layout.
Definition store_persist.h:49
static bool store_save(uint32_t key, void *state, size_t size, uint8_t tag)
Save a store's blob with its tag stamped in, so the next restore can recognize it.
Definition store_persist.h:78
bool store_restore_reading(uint32_t key, void *state, size_t size, size_t reading_size, uint8_t tag, uint32_t *saved_sum)
Restore a saved blob as store_restore does, and record the sum of the reading it holds.
Definition store_persist.c:33
A checksum of a store's reading, so a reply that brings nothing new costs no flash write.