aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2020-08-21 16:30:09 +0200
committerThomas White <taw@physics.org>2020-08-21 16:30:09 +0200
commit16d605d60a11b8513bb19829a6e3e851fa46c26a (patch)
tree6b2245ff462ba5e46ef94db5d380caaadfe2065d
parent9c57e7d61658fb79967e1b1a46c98995a1fed020 (diff)
Redefine backend interface functions
-rw-r--r--src/crystfel_gui.c11
-rw-r--r--src/crystfel_gui.h13
-rw-r--r--src/gui_backend_local.c80
-rw-r--r--src/gui_backend_slurm.c21
-rw-r--r--src/gui_project.c19
-rw-r--r--src/gui_project.h5
6 files changed, 41 insertions, 108 deletions
diff --git a/src/crystfel_gui.c b/src/crystfel_gui.c
index ffd62e57..d9b9bec1 100644
--- a/src/crystfel_gui.c
+++ b/src/crystfel_gui.c
@@ -1000,9 +1000,6 @@ int main(int argc, char *argv[])
update_peaks(&proj);
}
- /* Initialise backend */
- proj.backend->init(&proj);
-
gtk_window_set_default_size(GTK_WINDOW(proj.window), 1024, 768);
gtk_paned_set_position(GTK_PANED(hpaned), 172);
gtk_paned_set_position(GTK_PANED(vpaned), 600);
@@ -1016,13 +1013,10 @@ int main(int argc, char *argv[])
static void infobar_response_sig(GtkInfoBar *infobar, gint resp,
gpointer data)
{
- struct crystfelproject *proj = data;
+ //struct crystfelproject *proj = data;
if ( resp == GTK_RESPONSE_CANCEL ) {
- proj->backend->cancel(proj);
-
- } else if ( resp == GTK_RESPONSE_OK ) {
- proj->infobar_callback(proj);
+ /* FIXME: Cancel processing */
} else {
ERROR("Unrecognised infobar response!\n");
@@ -1059,7 +1053,6 @@ GtkWidget *create_infobar(struct crystfelproject *proj, const char *task,
gtk_box_pack_end(GTK_BOX(proj->main_vbox), GTK_WIDGET(info_bar),
FALSE, FALSE, 0.0);
proj->info_bar = info_bar;
- proj->infobar_callback = cbfunc;
bar_area = gtk_info_bar_get_content_area(GTK_INFO_BAR(info_bar));
diff --git a/src/crystfel_gui.h b/src/crystfel_gui.h
index 27b2e8b6..4d2dcf06 100644
--- a/src/crystfel_gui.h
+++ b/src/crystfel_gui.h
@@ -35,20 +35,11 @@ struct crystfel_backend {
const char *name;
const char *friendly_name;
GtkWidget *(*make_parameters)(void);
- int (*run_unitcell)(struct crystfelproject *proj,
- const char *algo);
+ void *(*run_indexing)(struct crystfelproject *proj,
+ const char *algo);
void (*cancel)(struct crystfelproject *proj);
- void (*init)(struct crystfelproject *proj);
- void (*shutdown)(struct crystfelproject *proj);
};
extern const struct crystfel_backend *backends[];
-
-extern void remove_infobar(struct crystfelproject *proj);
-
-extern GtkWidget *create_infobar(struct crystfelproject *proj, const char *task,
- const char *extra_button,
- void (*cbfunc)(struct crystfelproject *proj));
-
#endif
diff --git a/src/gui_backend_local.c b/src/gui_backend_local.c
index fc729a41..2ddf2488 100644
--- a/src/gui_backend_local.c
+++ b/src/gui_backend_local.c
@@ -32,10 +32,14 @@
#include <gtk/gtk.h>
#include "crystfel_gui.h"
+#include "gui_project.h"
struct local_backend_priv
{
+ struct crystfelproject *proj; /* FIXME: Once started, the process should
+ * be considered detatched. Therefore, this
+ * shouldn't be stored */
int indexamajig_running;
guint indexamajig_watch;
GPid indexamajig_pid;
@@ -46,8 +50,8 @@ struct local_backend_priv
static void watch_indexamajig(GPid pid, gint status, gpointer vp)
{
- struct crystfelproject *proj = vp;
- struct local_backend_priv *priv = proj->backend_private;
+ struct local_backend_priv *priv = vp;
+ struct crystfelproject *proj = priv->proj;
STATUS("Indexamajig exited with status %i\n", status);
priv->indexamajig_running = 0;
g_spawn_close_pid(priv->indexamajig_pid);
@@ -60,8 +64,8 @@ static gboolean index_readable(GIOChannel *source, GIOCondition cond,
{
GIOStatus r;
GError *err = NULL;
- struct crystfelproject *proj = vp;
- struct local_backend_priv *priv = proj->backend_private;
+ struct local_backend_priv *priv = priv;
+ struct crystfelproject *proj = priv->proj;
gchar *line;
r = g_io_channel_read_line(source, &line, NULL, NULL, &err);
@@ -139,8 +143,7 @@ void setup_subprocess(gpointer user_data)
}
-static int run_unitcell(struct crystfelproject *proj,
- const char *algo)
+static void *run_indexing(struct crystfelproject *proj)
{
GIOChannel *ioch;
char *args[64];
@@ -151,20 +154,25 @@ static int run_unitcell(struct crystfelproject *proj,
int r;
int ch_stderr;
GError *error;
- struct local_backend_priv *priv = proj->backend_private;
+ struct local_backend_priv *priv;
if ( priv->indexamajig_running != 0 ) {
STATUS("Indexamajig already running.\n");
- return 1;
+ return NULL;
}
+ priv = malloc(sizeof(struct local_backend_priv));
+ if ( priv == NULL ) return NULL;
+
+ priv->proj = proj;
+
if ( write_file_list(proj) ) {
STATUS("Failed to write list\n");
- return 1;
+ free(priv);
+ return NULL;
}
- strcpy(index_str, "--indexing=");
- strncat(index_str, algo, 50);
+ strcpy(index_str, "--indexing=dirax"); /* FIXME */
strcpy(peaks_str, "--peaks=");
strncat(peaks_str,
@@ -226,25 +234,28 @@ static int run_unitcell(struct crystfelproject *proj,
if ( r == FALSE ) {
ERROR("Failed to run indexamajig: %s\n",
error->message);
- return 1;
+ free(priv);
+ return NULL;
}
priv->indexamajig_running = 1;
priv->child_watch_source = g_child_watch_add(priv->indexamajig_pid,
- watch_indexamajig, proj);
+ watch_indexamajig,
+ priv);
ioch = g_io_channel_unix_new(ch_stderr);
priv->index_readable_source = g_io_add_watch(ioch,
G_IO_IN | G_IO_ERR | G_IO_HUP,
- index_readable, proj);
+ index_readable,
+ priv);
- return 0;
+ return priv;
}
-static void cancel(struct crystfelproject *proj)
+static void cancel(void *vp)
{
- struct local_backend_priv *priv = proj->backend_private;
+ struct local_backend_priv *priv = vp;
if ( !priv->indexamajig_running ) return;
@@ -253,37 +264,6 @@ static void cancel(struct crystfelproject *proj)
}
-static void shutdown_backend(struct crystfelproject *proj)
-{
- struct local_backend_priv *priv = proj->backend_private;
-
- if ( priv->indexamajig_running ) {
- g_source_remove(priv->child_watch_source);
- g_source_remove(priv->index_readable_source);
- kill(-priv->indexamajig_pid, SIGINT);
- }
-
- free(priv);
-}
-
-
-static void init_backend(struct crystfelproject *proj)
-{
- struct local_backend_priv *priv;
-
- priv = malloc(sizeof(struct local_backend_priv));
- if ( priv == NULL ) {
- ERROR("Failed to initialise backend\n");
- return;
- }
-
- priv->indexamajig_running = 0;
-
- proj->backend_private = priv;
- STATUS("Local backend initialised.\n");
-}
-
-
static GtkWidget *make_parameters(void)
{
return gtk_label_new("Local params");
@@ -295,9 +275,7 @@ struct crystfel_backend _backend_local =
.name = "local",
.friendly_name = "Local (run on this computer)",
.make_parameters = make_parameters,
- .init = init_backend,
- .shutdown = shutdown_backend,
- .run_unitcell = run_unitcell,
+ .run_indexing = run_indexing,
.cancel = cancel,
};
diff --git a/src/gui_backend_slurm.c b/src/gui_backend_slurm.c
index 1ac0328b..b5c75bb5 100644
--- a/src/gui_backend_slurm.c
+++ b/src/gui_backend_slurm.c
@@ -40,25 +40,14 @@ struct slurm_backend_priv
};
-static void init_backend(struct crystfelproject *proj)
+static void cancel(void *vp)
{
}
-static void shutdown_backend(struct crystfelproject *proj)
+static void *run_indexing(struct crystfelproject *proj)
{
-}
-
-
-static void cancel(struct crystfelproject *proj)
-{
-}
-
-
-static int run_unitcell(struct crystfelproject *proj,
- const char *algo)
-{
- return 0;
+ return NULL;
}
@@ -73,9 +62,7 @@ const struct crystfel_backend _backend_slurm =
.name = "slurm",
.friendly_name = "SLURM",
.make_parameters = make_parameters,
- .init = init_backend,
- .shutdown = shutdown_backend,
- .run_unitcell = run_unitcell,
+ .run_indexing = run_indexing,
.cancel = cancel,
};
diff --git a/src/gui_project.c b/src/gui_project.c
index c10d9a99..f383f77b 100644
--- a/src/gui_project.c
+++ b/src/gui_project.c
@@ -66,17 +66,6 @@ static int parse_int(const char *val)
}
-static struct crystfel_backend *parse_backend(const char *val)
-{
- if ( strcmp(val, "local") == 0 ) {
- return backend_local;
- }
-
- ERROR("Invalid backend '%s'\n", val);
- return NULL;
-}
-
-
static const char *str_matchtype(enum match_type_id mt)
{
switch ( mt ) {
@@ -274,7 +263,7 @@ static void handle_var(const char *key, const char *val,
}
if ( strcmp(key, "backend") == 0 ) {
- proj->backend = parse_backend(val);
+ proj->backend_name = strdup(val);
}
if ( strcmp(key, "geom") == 0 ) {
@@ -485,7 +474,7 @@ int save_project(struct crystfelproject *proj)
fprintf(fh, "show_peaks %i\n", proj->show_peaks);
fprintf(fh, "show_refls %i\n", proj->show_refls);
- fprintf(fh, "backend %s\n", proj->backend->name);
+ fprintf(fh, "backend %s\n", proj->backend_name);
fprintf(fh, "-----\n");
if ( proj->stream == NULL ) {
@@ -514,7 +503,7 @@ void default_project(struct crystfelproject *proj)
proj->events = NULL;
proj->peak_params = NULL;
proj->info_bar = NULL;
- proj->backend_private = NULL;
+ proj->backend_name = strdup("local");
proj->data_top_folder = NULL;
proj->data_search_pattern = 0;
proj->stream_filename = NULL;
@@ -563,6 +552,4 @@ void default_project(struct crystfelproject *proj)
proj->indexing_params.integration_method = strdup("rings");
proj->indexing_params.overpredict = 0;
proj->indexing_params.push_res = INFINITY;
-
- proj->backend = backend_local;
}
diff --git a/src/gui_project.h b/src/gui_project.h
index 1a6688dc..0c7e9616 100644
--- a/src/gui_project.h
+++ b/src/gui_project.h
@@ -125,15 +125,12 @@ struct crystfelproject {
GtkWidget *peak_params; /* Peak search parameter widgets */
struct peak_params original_params;
+ char *backend_name;
GtkWidget *backend_opts;
GtkWidget *backend_opts_box;
GtkWidget *info_bar;
- void (*infobar_callback)(struct crystfelproject *proj);
GtkWidget *progressbar;
-
- struct crystfel_backend *backend;
- void *backend_private;
};
extern enum match_type_id decode_matchtype(const char *type_id);