X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafm-launch-mode.c;h=79a31f4c63a74d668a4d268267ca83008df51319;hb=dc4d29d0b8c3393ab8ba85b6278fd231b1191509;hp=99add62547be8ec413373b03771877ac68090f76;hpb=fc453a43f14a50a2b4dc1f332649ce4bc13af1fa;p=src%2Fapp-framework-main.git 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 +#include #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; } }