Loading...
Searching...
No Matches
plugin_source.h
Go to the documentation of this file.
1
21#pragma once
23
24#include <stddef.h>
25#include <string.h>
26
31
33#if defined(PLUGIN_WEATHER) && PLUGIN_WEATHER && defined(HAS_MESSAGE_KEY_WEATHER_PROVIDER)
34#define PLUGIN_SOURCE_KEEPS_WEATHER 1
35#else
36#define PLUGIN_SOURCE_KEEPS_WEATHER 0
37#endif
38
40#if defined(PLUGIN_CALENDAR) && PLUGIN_CALENDAR && defined(HAS_MESSAGE_KEY_CALENDAR_SOURCE)
41#define PLUGIN_SOURCE_KEEPS_CALENDAR 1
42#else
43#define PLUGIN_SOURCE_KEEPS_CALENDAR 0
44#endif
45
47#if defined(PLUGIN_STOCKS) && PLUGIN_STOCKS && defined(HAS_MESSAGE_KEY_STOCK_PROVIDER)
48#define PLUGIN_SOURCE_KEEPS_STOCK 1
49#else
50#define PLUGIN_SOURCE_KEEPS_STOCK 0
51#endif
52
54#define PLUGIN_SOURCE_KEEPS_ANY (PLUGIN_SOURCE_KEEPS_WEATHER || PLUGIN_SOURCE_KEEPS_CALENDAR || PLUGIN_SOURCE_KEEPS_STOCK)
55
60#define PLUGIN_SOURCE_WEATHER_LEN 12
61
66#define PLUGIN_SOURCE_CALENDAR_LEN 8
67
72#define PLUGIN_SOURCE_STOCK_LEN 14
73
74#define PLUGIN_SOURCE_VERSION 2
75#define PLUGIN_SOURCE_FIRST_SIZE 21
76
92
93// a saved choice is read back from these offsets, so moving a field would read the other kind's
94// bytes into it after an update. a new field goes on the end
95_Static_assert(offsetof(PluginSourceSettings, weather) == 1, "the weather source moved, so older saves would read wrong");
96_Static_assert(offsetof(PluginSourceSettings, calendar) == 13, "the calendar source moved, so older saves would read wrong");
97_Static_assert(offsetof(PluginSourceSettings, stock) == PLUGIN_SOURCE_FIRST_SIZE, "the stock source has to start where a first release blob ends");
98
99#if PLUGIN_SOURCE_KEEPS_WEATHER
100#ifndef PLUGIN_SOURCE_WEATHER_DEFAULT
101#error "PLUGIN_WEATHER keeps the weather source on the watch, so it needs PLUGIN_SOURCE_WEATHER_DEFAULT. Build the face with paf build, which writes it from the providers list"
102#endif
103// the "" in front makes anything but a string literal stop the build
104_Static_assert(sizeof("" PLUGIN_SOURCE_WEATHER_DEFAULT) > 1 && sizeof("" PLUGIN_SOURCE_WEATHER_DEFAULT) <= PLUGIN_SOURCE_WEATHER_LEN,
105 "the default weather source has to be 1 to 11 characters, which is as much as the watch keeps");
106#endif
107
108#if PLUGIN_SOURCE_KEEPS_CALENDAR
109#ifndef PLUGIN_SOURCE_CALENDAR_DEFAULT
110#error "PLUGIN_CALENDAR keeps the calendar source on the watch, so it needs PLUGIN_SOURCE_CALENDAR_DEFAULT. Build the face with paf build, which writes it from the providers list"
111#endif
112_Static_assert(sizeof("" PLUGIN_SOURCE_CALENDAR_DEFAULT) > 1 && sizeof("" PLUGIN_SOURCE_CALENDAR_DEFAULT) <= PLUGIN_SOURCE_CALENDAR_LEN,
113 "the default calendar source has to be 1 to 7 characters, which is as much as the watch keeps");
114#endif
115
116#if PLUGIN_SOURCE_KEEPS_STOCK
117#ifndef PLUGIN_SOURCE_STOCK_DEFAULT
118#error "PLUGIN_STOCKS keeps the stock source on the watch, so it needs PLUGIN_SOURCE_STOCK_DEFAULT. Build the face with paf build, which writes it from the providers list"
119#endif
120_Static_assert(sizeof("" PLUGIN_SOURCE_STOCK_DEFAULT) > 1 && sizeof("" PLUGIN_SOURCE_STOCK_DEFAULT) <= PLUGIN_SOURCE_STOCK_LEN,
121 "the default stock source has to be 1 to 13 characters, which is as much as the watch keeps");
122#endif
123
132#if PLUGIN_SOURCE_KEEPS_WEATHER
133#define PLUGIN_SOURCE_WEATHER_FIELD \
134 { .id = SETTING_COUNT, .message_key = &MESSAGE_KEY_WEATHER_PROVIDER, .type = SETTING_CSTRING, \
135 .offset = offsetof(PluginSourceSettings, weather), .size = PLUGIN_SOURCE_WEATHER_LEN, \
136 .default_str = PLUGIN_SOURCE_WEATHER_DEFAULT },
137#else
138#define PLUGIN_SOURCE_WEATHER_FIELD
139#endif
140
145#if PLUGIN_SOURCE_KEEPS_CALENDAR
146#define PLUGIN_SOURCE_CALENDAR_FIELD \
147 { .id = SETTING_COUNT, .message_key = &MESSAGE_KEY_CALENDAR_SOURCE, .type = SETTING_CSTRING, \
148 .offset = offsetof(PluginSourceSettings, calendar), .size = PLUGIN_SOURCE_CALENDAR_LEN, \
149 .default_str = PLUGIN_SOURCE_CALENDAR_DEFAULT },
150#else
151#define PLUGIN_SOURCE_CALENDAR_FIELD
152#endif
153
158#if PLUGIN_SOURCE_KEEPS_STOCK
159#define PLUGIN_SOURCE_STOCK_FIELD { .id = SETTING_COUNT, .message_key = &MESSAGE_KEY_STOCK_PROVIDER, .type = SETTING_CSTRING, .offset = offsetof(PluginSourceSettings, stock), .size = PLUGIN_SOURCE_STOCK_LEN, .default_str = PLUGIN_SOURCE_STOCK_DEFAULT },
160#else
161#define PLUGIN_SOURCE_STOCK_FIELD
162#endif
163
165#define PLUGIN_SOURCE_FIELDS PLUGIN_SOURCE_WEATHER_FIELD PLUGIN_SOURCE_CALENDAR_FIELD PLUGIN_SOURCE_STOCK_FIELD
166
181static inline bool plugin_source_write_needed(const PluginSourceSettings *now, const PluginSourceSettings *on_flash,
182 bool on_flash_known)
183{
184 return !on_flash_known || memcmp(now, on_flash, sizeof(*now)) != 0;
185}
186
static bool plugin_source_write_needed(const PluginSourceSettings *now, const PluginSourceSettings *on_flash, bool on_flash_known)
Whether a save has to write the choices to flash.
Definition plugin_source.h:181
#define PLUGIN_SOURCE_WEATHER_LEN
The size of the weather source buffer. weatherapi is the longest value the settings page saves,...
Definition plugin_source.h:60
#define PLUGIN_SOURCE_CALENDAR_LEN
The size of the calendar source buffer. plugin is the longest value the settings page saves,...
Definition plugin_source.h:66
#define PLUGIN_SOURCE_STOCK_LEN
The size of the stock source buffer. alphavantage is the longest value the settings page saves,...
Definition plugin_source.h:72
#define PLUGIN_SOURCE_FIRST_SIZE
The struct's size in its first release, which never changes.
Definition plugin_source.h:75
The persist API. A per-face SettingField table drives versioned load and save, sanitizing,...
The saved choices, version byte first.
Definition plugin_source.h:86
char stock[PLUGIN_SOURCE_STOCK_LEN]
What the stocks' Data Source select saved.
Definition plugin_source.h:90
char weather[PLUGIN_SOURCE_WEATHER_LEN]
What the weather's Data Source select saved.
Definition plugin_source.h:88
uint8_t version
The schema version this blob was saved at.
Definition plugin_source.h:87
char calendar[PLUGIN_SOURCE_CALENDAR_LEN]
What the Calendar Source select saved.
Definition plugin_source.h:89