Loading...
Searching...
No Matches
location_store.c File Reference

The active location store: holds the phone's coordinates and owns the appmessage coords channel. More...

#include "io/stores/location_store.h"
#include "io/stores/store_persist.h"
#include <stdio.h>
#include <string.h>
#include "io/appmessage/appmessage.h"
#include "wire/coords.h"
#include "text/cstring_fit.h"

Data Structures

struct  [struct].s_state

Functions

static void persist_save (void)
 Stash the coords so a relaunch can restore them.
static void copy_pair (char *out_lat, char *out_lon, const char *lat, const char *lon)
 Copy a pair of coordinates into two fields the size of the state's, reading a missing one as empty.
static void set (const char *lat, const char *lon)
 Save the latest coordinates, and tell whoever is listening when they changed. It is the coords channel handler, since its signature matches.
void location_store_subscribe (void(*cb)(void))
 Hand it the function to call when the coordinates change (the screen redraw).
void location_store_init (LocationConfig cfg, const LocationSeed *seed)
 Start the store with its rules. Pass seed = NULL for normal use.
const char * location_store_lat (void)
 The latitude string, or empty if we have not got one yet.
const char * location_store_lon (void)
 The longitude string, or empty if we have not got one yet.

Variables

static uint32_t s_persist_key
 Where the last good fix is kept, handed in by the face.
static struct  s_state
 The last fix, laid out as the blob that gets persisted.
static void(*) s_cb (void)
 Called whenever the coords change, so the face can redraw.
static uint32_t s_saved_sum
 Sum of the reading last written, so a reply that changes nothing is not written again.
static bool s_live
 True on a live face, so the cache is worth reading and writing.

Detailed Description

The active location store: holds the phone's coordinates and owns the appmessage coords channel.

Function Documentation

◆ copy_pair()

void copy_pair ( char * out_lat,
char * out_lon,
const char * lat,
const char * lon )
static

Copy a pair of coordinates into two fields the size of the state's, reading a missing one as empty.

Parameters
out_latWhere the latitude goes, sizeof(s_state.lat) long.
out_lonWhere the longitude goes, sizeof(s_state.lon) long.
latLatitude string, or NULL.
lonLongitude string, or NULL.

◆ persist_save()

void persist_save ( void )
static

Stash the coords so a relaunch can restore them.

Only a live face writes, and only a real fix, so a dropped one can't stomp the last good location.

◆ set()

void set ( const char * lat,
const char * lon )
static

Save the latest coordinates, and tell whoever is listening when they changed. It is the coords channel handler, since its signature matches.

Parameters
latLatitude string, empty when unavailable.
lonLongitude string, empty when unavailable.

Variable Documentation

◆ s_persist_key

uint32_t s_persist_key
static

Where the last good fix is kept, handed in by the face.

A relaunch, such as coming back from the timeline, shows the coords straight away rather than blanking to "--". The face picks the slot, so it is the one place that knows which keys it has already spent.