diff options
Diffstat (limited to 'src/afm-launch-mode.c')
-rw-r--r-- | src/afm-launch-mode.c | 71 |
1 files changed, 64 insertions, 7 deletions
diff --git a/src/afm-launch-mode.c b/src/afm-launch-mode.c index 99add62..79a31f4 100644 --- a/src/afm-launch-mode.c +++ b/src/afm-launch-mode.c @@ -17,28 +17,85 @@ */ #include <string.h> +#include <assert.h> #include "afm-launch-mode.h" +/* + * There is actually 2 possible launch mode: + * - local + * - remote + */ static const char s_mode_local[] = "local"; static const char s_mode_remote[] = "remote"; -enum afm_launch_mode launch_mode_of_string(const char *s) +/* + * Records the current default mode + */ +static enum afm_launch_mode default_mode = mode_local; + +/* + * Set the default launch mode to 'mode' + */ +int is_valid_launch_mode(enum afm_launch_mode mode) +{ + switch(mode) { + case mode_local: + case mode_remote: + return 1; + default: + return 0; + } +} + +/* + * Get the default launch mode + * + * Ensure a valid result + */ +enum afm_launch_mode get_default_launch_mode() +{ + return default_mode; +} + +/* + * Set the default launch mode to 'mode' + * + * Requires 'mode' to be valid + */ +void set_default_launch_mode(enum afm_launch_mode mode) { - if (s) { - if (!strcmp(s, s_mode_local)) + assert(is_valid_launch_mode(mode)); + default_mode = mode; +} + +/* + * Get the launch mode corresponding to the 'name' + * + * Returns invalid_launch_mode if the 'name' is not valid. + */ +enum afm_launch_mode launch_mode_of_name(const char *name) +{ + if (name) { + if (!strcmp(name, s_mode_local)) return mode_local; - if (!strcmp(s, s_mode_remote)) + if (!strcmp(name, s_mode_remote)) return mode_remote; } return invalid_launch_mode; } -const char *name_of_launch_mode(enum afm_launch_mode m) +/* + * Get the name of the launch 'mode' + * + * Requires 'mode' to be valid + */ +const char *name_of_launch_mode(enum afm_launch_mode mode) { - switch (m) { + assert(is_valid_launch_mode(mode)); + switch (mode) { case mode_local: return s_mode_local; case mode_remote: return s_mode_remote; - default: return "(INVALID LAUNCH MODE)"; + default: return NULL; } } |