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
35
48static inline bool store_restore(uint32_t key, void *state, size_t size, uint8_t tag)
49{
50 if (!persist_exists(key) || persist_get_size(key) != (int)size)
51 {
52 return false;
53 }
54
55 // read the tag on its own first. reading the whole blob to check it would already have
56 // stomped the defaults by the time we found out it was the wrong shape
57 uint8_t stored = 0;
58 if (persist_read_data(key, &stored, sizeof(stored)) != (int)sizeof(stored) || stored != tag)
59 {
60 return false;
61 }
62
63 return persist_read_data(key, state, size) == (int)size;
64}
65
77static inline bool store_save(uint32_t key, void *state, size_t size, uint8_t tag)
78{
79 *(uint8_t *)state = tag;
80 return persist_write_data(key, state, size) == (int)size;
81}
82
103bool store_save_changed(uint32_t key, void *state, size_t size, size_t reading_size, uint8_t tag,
104 uint32_t *saved_sum);
105
120bool store_restore_reading(uint32_t key, void *state, size_t size, size_t reading_size, uint8_t tag,
121 uint32_t *saved_sum);
122
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:48
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:77
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.