+/*****************
+ * ASync helpers *
+ *****************/
+typedef struct {
+ AWeatherRadar *self;
+ gchar *radar_file;
+} decompressed_t;
+
+static void decompressed_cb(GPid pid, gint status, gpointer _self)
+{
+ decompressed_t *udata = _self;
+ if (status != 0) {
+ g_warning("wsr88ddec exited with status %d", status);
+ return;
+ }
+ // TODO: pass cur_file as params?
+ load_radar(udata->self, udata->radar_file);
+ g_free(udata->radar_file);
+ g_free(udata);
+}
+
+static void cached_cb(char *path, gboolean updated, gpointer _self)
+{
+ AWeatherRadar *self = AWEATHER_RADAR(_self);
+ char *decompressed = g_strconcat(path, ".raw", NULL);
+ if (!updated) {
+ load_radar(self, decompressed);
+ return;
+ }
+
+ decompressed_t *udata = g_malloc(sizeof(decompressed_t));
+ udata->self = self;
+ udata->radar_file = decompressed;
+ g_message("File updated, decompressing..");
+ char *argv[] = {"wsr88ddec", path, decompressed, NULL};
+ GPid pid;
+ GError *error = NULL;
+ g_spawn_async(
+ NULL, // const gchar *working_directory,
+ argv, // gchar **argv,
+ NULL, // gchar **envp,
+ G_SPAWN_SEARCH_PATH|
+ G_SPAWN_DO_NOT_REAP_CHILD,
+ // GSpawnFlags flags,
+ NULL, // GSpawnChildSetupFunc child_setup,
+ NULL, // gpointer user_data,
+ &pid, // GPid *child_pid,
+ &error); // GError **error
+ if (error) {
+ g_warning("failed to decompress WSR88D data: %s",
+ error->message);
+ g_error_free(error);
+ }
+ g_child_watch_add(pid, decompressed_cb, udata);
+}
+