State Storage

digraph inheritance { rankdir=LR; GObject -> WpState; }

struct WpState

The WpState class saves and loads properties from a file

GObject Properties

WpState* wp_state_new(const gchar * name)

Constructs a new state object.

Return

(transfer full): the new WpState

Parameters
  • name: the state name

const gchar* wp_state_get_name(WpState * self)

Gets the name of a state object.

Return

the name of this state

Parameters
  • self: the state

const gchar* wp_state_get_location(WpState * self)

Gets the location of a state object.

Return

the location of this state

Parameters
  • self: the state

void wp_state_clear(WpState * self)

Clears the state removing its file.

Parameters
  • self: the state

gboolean wp_state_save(WpState * self, WpProperties * props, GError ** error)

Saves new properties in the state, overwriting all previous data.

Return

TRUE if the properties could be saved, FALSE otherwise

Parameters
  • self: the state

  • props: (transfer none): the properties to save

  • error: (out)(optional): return location for a GError, or NULL

void wp_state_save_after_timeout(WpState * self, WpCore * core, WpProperties * props)

Saves new properties in the state, overwriting all previous data, after a timeout.

This is similar to wp_state_save() but it will save the state after a timeout has elapsed. If the state is saved again before the timeout elapses, the timeout is reset.

This function is useful to avoid saving the state too often. When called consecutively, it will save the state only once. Every time it is called, it will cancel the previous timer and start a new one, resulting in timing out only after the last call.

Since

0.5.0

Parameters
  • self: the state

  • core: the core, used to add the timeout callback to the main loop

  • props: (transfer none): the properties to save. This object will be referenced and kept alive until the timeout elapses, but not deep copied.

WpProperties* wp_state_load(WpState * self)

Loads the state data from the file system.

This function will never fail. If it cannot load the state, for any reason, it will simply return an empty WpProperties, behaving as if there was no previous state stored.

Return

(transfer full): a new WpProperties containing the state data

Parameters
  • self: the state

WP_TYPE_STATE (wp_state_get_type ())

The WpState GType.