PebbleOS
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Enumerations | Functions
weather_db.h File Reference
#include <pbl/services/weather/weather_service.h>
#include <pbl/services/weather/weather_types.h>
#include <system/status_codes.h>
#include <pbl/kernel/compiler.h>
#include <pbl/util/pstring.h>
#include <time.h>
#include <pbl/util/uuid.h>
#include <stddef.h>
#include <stdbool.h>
#include <stdint.h>

Data Structures

struct  WeatherDBEntryV3
 Legacy v3 record. More...
 
struct  WeatherDBDailyForecast
 One day of daily forecast (v4). More...
 
struct  WeatherDBDailyMetrics
 Extended metrics of one day (v4 minor 1), parallel to daily (index 0 is today). More...
 
struct  WeatherDBEntry
 v4 record. More...
 

Macros

#define WEATHER_DB_CURRENT_VERSION   (4)
 Current major version of the record schema.
 
#define WEATHER_DB_CURRENT_MINOR_VERSION   (5)
 Newest minor version of the v4 schema understood by the firmware.
 
#define WEATHER_DB_LEGACY_VERSION   (3)
 Major version of the legacy record schema.
 
#define WEATHER_DB_MAX_FORECAST_DAYS   (7)
 Days of daily forecast in a v4 record (today + 6).
 
#define WEATHER_DB_HOURLY_COUNT   (24)
 Hours of hourly data in a v4 series (one day, keeps the record small).
 
#define WEATHER_DB_V4_0_FIXED_SIZE   (offsetof(WeatherDBEntry, location_utc_offset_min))
 Fixed size of a v4.0 record, the minimum of any v4 record and where its strings start.
 
#define WEATHER_DB_V4_1_FIXED_SIZE   (offsetof(WeatherDBEntry, today_wmo_code))
 Fixed size of a v4.1 record, where its strings start.
 
#define WEATHER_DB_V4_2_FIXED_SIZE   (offsetof(WeatherDBEntry, today_wind_dir_deg))
 Fixed size of a v4.2 record, where its strings start.
 
#define WEATHER_DB_V4_3_FIXED_SIZE   (offsetof(WeatherDBEntry, today_hourly_uv_x10))
 Fixed size of a v4.3 record, where its strings start.
 
#define WEATHER_DB_V4_4_FIXED_SIZE   (offsetof(WeatherDBEntry, tomorrow_hourly_count))
 Fixed size of a v4.4 record, where its strings start.
 
#define WEATHER_DB_V4_FIXED_SIZE   (offsetof(WeatherDBEntry, pstring16s))
 Fixed size of a current (v4.5) record, everything but the trailing strings.
 
#define MIN_ENTRY_SIZE   (sizeof(WeatherDBEntryV3))
 Smallest acceptable record, a legacy v3 record.
 
#define MAX_ENTRY_SIZE
 Largest acceptable record.
 

Typedefs

typedef Uuid WeatherDBKey
 Record key, the location UUID.
 
typedef void(* WeatherDBIteratorCallback) (WeatherDBKey *key, WeatherDBEntry *entry, void *context)
 Callback of weather_db_for_each().
 

Enumerations

enum  WeatherDbStringIndex { WeatherDbStringIndex_LocationName , WeatherDbStringIndex_ShortPhrase , WeatherDbStringIndexCount }
 Index of the strings in a record's pstring16s. More...
 

Functions

static bool weather_db_version_is_supported (uint8_t version)
 Check whether the firmware can parse a major version.
 
static bool weather_db_entry_is_supported (const WeatherDBEntry *entry)
 Check whether the firmware can parse a record.
 
static size_t weather_db_entry_strings_offset (uint8_t version, uint8_t minor_version)
 Get the offset of the trailing strings for a record version.
 
static struct pbl_serialized_array * weather_db_entry_get_strings (WeatherDBEntry *entry)
 Locate the trailing strings of a record.
 
status_t weather_db_for_each (WeatherDBIteratorCallback cb, void *context)
 Call a function for every supported record.
 
void weather_db_init (void)
 Initialize the weather database.
 
status_t weather_db_flush (void)
 Delete all records of the weather database.
 
status_t weather_db_compact (void)
 Compact the settings file backing the weather database.
 
status_t weather_db_insert (const uint8_t *key, int key_len, const uint8_t *val, int val_len)
 Insert or replace a record in the weather database.
 
int weather_db_get_len (const uint8_t *key, int key_len)
 Get the length of a record in the weather database.
 
status_t weather_db_read (const uint8_t *key, int key_len, uint8_t *val_out, int val_out_len)
 Read a record from the weather database.
 
status_t weather_db_delete (const uint8_t *key, int key_len)
 Delete a record from the weather database.