--- /dev/null
+#include <errno.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <system_info.h>
+
+#define SUCCESS 0
+
+#define OPT_MAX 16
+#define KEY_MAX 256
+
+#define RUNTIME_ENV "RUNTIME_TYPE"
+
+#define DEFAULT_OPT 0
+
+#define CONVERT_ARGUMENT(input_str, output_num, table) \
+{ \
+ int __idx; \
+ bool __is_converted = false; \
+ for (__idx = 0; __idx < sizeof(table) / sizeof(struct str_num_table); __idx++) { \
+ if (!strncmp(input_str, table[__idx].str, strlen(table[__idx].str) + 1)) { \
+ output_num = table[__idx].num; \
+ __is_converted = true; \
+ break; \
+ } \
+ } \
+ if (!__is_converted) { \
+ if (input_str[0] == '\0') { \
+ output_num = table[DEFAULT_OPT].num; \
+ strncpy(input_str, table[DEFAULT_OPT].str, strlen(table[DEFAULT_OPT].str) + 1); \
+ } else { \
+ printf("Invalid argument %s\n\n", input_str); \
+ show_help(); \
+ return EINVAL; \
+ } \
+ } \
+}
+
+enum tag {
+ TAG_PLATFORM,
+ TAG_CUSTOM,
+ TAG_MAX
+};
+
+enum type {
+ TYPE_BOOL,
+ TYPE_INT,
+ TYPE_DOUBLE,
+ TYPE_STRING,
+ TYPE_MAX
+};
+
+enum runtime {
+ RUNTIME_C,
+ RUNTIME_WEB,
+ RUNTIME_DOTNET,
+ RUNTIME_MAX
+};
+
+struct str_num_table {
+ const char *str;
+ int num;
+};
+
+/**
+ * @remarks If there is no input, set to the first element.
+ * It means the first element is default value.
+ * To disable default value, check essential options.
+ */
+
+struct str_num_table tag_table[TAG_MAX] = {
+ { "platform", TAG_PLATFORM },
+ { "custom", TAG_CUSTOM },
+};
+
+struct str_num_table type_table[TYPE_MAX] = {
+ { "bool", TYPE_BOOL },
+ { "int", TYPE_INT },
+ { "double", TYPE_DOUBLE },
+ { "string", TYPE_STRING },
+};
+
+struct str_num_table runtime_table[RUNTIME_MAX] = {
+ { "c", RUNTIME_C },
+ { "web", RUNTIME_WEB },
+ { "dotnet", RUNTIME_DOTNET },
+};
+
+static char tag_str[OPT_MAX];
+static enum tag tag_num;
+
+static char type_str[OPT_MAX];
+static enum type type_num;
+
+static char key[KEY_MAX];
+
+static char runtime_str[OPT_MAX];
+static enum runtime runtime_num;
+
+static void show_help(void)
+{
+ printf("system_info_test [OPTIONS]\n");
+ printf(" -g TAG System info tag to read (platform/custom)\n");
+ printf(" (Optional, default value is platform)\n");
+ printf(" -t TYPE System info type to read (bool/int/double/string)\n");
+ printf(" (Essential)\n");
+ printf(" -k KEY System info key to read\n");
+ printf(" (Essential)\n");
+ printf(" -r RUNTIME Runtime type (c/web/dotnet)\n");
+ printf(" (Optional, default value is c)\n");
+ printf("\n");
+ printf(" -h Show this message\n");
+ printf("\n");
+ printf("Example:\n");
+ printf(" system_info_test -g platform -t string -k tizen.org/system/platform.name -r c\n");
+}
+
+int main(int argc, char *argv[])
+{
+ int ret;
+ int opt;
+
+ bool val_bool;
+ int val_int;
+ double val_double;
+ char *val_string = NULL;
+
+ /* Parse arguments */
+ while ((opt = getopt(argc, argv, "g:t:k:r:h")) != -1) {
+ switch (opt) {
+ case 'g':
+ snprintf(tag_str, OPT_MAX, "%s", optarg);
+ break;
+ case 't':
+ snprintf(type_str, OPT_MAX, "%s", optarg);
+ break;
+ case 'k':
+ snprintf(key, KEY_MAX, "%s", optarg);
+ break;
+ case 'r':
+ snprintf(runtime_str, OPT_MAX, "%s", optarg);
+ break;
+ case 'h':
+ show_help();
+ return SUCCESS;
+ default:
+ show_help();
+ return EINVAL;
+ }
+ }
+
+ /* Check whether essential options are inputted */
+ if (type_str[0] == '\0' || key[0] == '\0') {
+ printf("Essential options aren't inputted\n\n");
+ show_help();
+ return EINVAL;
+ }
+
+ /* Convert string arguments into the enum value */
+ CONVERT_ARGUMENT(tag_str, tag_num, tag_table);
+ CONVERT_ARGUMENT(type_str, type_num, type_table);
+ CONVERT_ARGUMENT(runtime_str, runtime_num, runtime_table);
+
+ /* Set the runtime environment value */
+ switch (runtime_num) {
+ case RUNTIME_C:
+ ret = setenv(RUNTIME_ENV, "capp", 1);
+ break;
+ case RUNTIME_WEB:
+ ret = setenv(RUNTIME_ENV, "webapp", 1);
+ break;
+ case RUNTIME_DOTNET:
+ ret = setenv(RUNTIME_ENV, "dotnet", 1);
+ break;
+ default:
+ printf("Failed to convert runtime argument\n");
+ return EIO;
+ break;
+ }
+
+ if (ret != SUCCESS) {
+ printf("setenv failed : %m\n");
+ return errno;
+ }
+
+ printf("TAG(%s), TYPE(%s), RUNTIME(%s), KEY(%s), RESULT(",
+ tag_str, type_str, runtime_str, key);
+
+ /* Call appropriate system-info API and print result */
+ switch (tag_num) {
+ case TAG_PLATFORM:
+ switch (type_num) {
+ case TYPE_BOOL:
+ ret = system_info_get_platform_bool(key, &val_bool);
+ if (ret == SYSTEM_INFO_ERROR_NONE)
+ printf("%d", val_bool);
+ break;
+ case TYPE_INT:
+ ret = system_info_get_platform_int(key, &val_int);
+ if (ret == SYSTEM_INFO_ERROR_NONE)
+ printf("%d", val_int);
+ break;
+ case TYPE_DOUBLE:
+ ret = system_info_get_platform_double(key, &val_double);
+ if (ret == SYSTEM_INFO_ERROR_NONE)
+ printf("%lf", val_double);
+ break;
+ case TYPE_STRING:
+ ret = system_info_get_platform_string(key, &val_string);
+ if (ret == SYSTEM_INFO_ERROR_NONE)
+ printf("%s", val_string);
+ break;
+ default:
+ ret = SYSTEM_INFO_ERROR_INVALID_PARAMETER;
+ break;
+ }
+ break;
+ case TAG_CUSTOM:
+ switch (type_num) {
+ case TYPE_BOOL:
+ ret = system_info_get_custom_bool(key, &val_bool);
+ if (ret == SYSTEM_INFO_ERROR_NONE)
+ printf("%d", val_bool);
+ break;
+ case TYPE_INT:
+ ret = system_info_get_custom_int(key, &val_int);
+ if (ret == SYSTEM_INFO_ERROR_NONE)
+ printf("%d", val_int);
+ break;
+ case TYPE_DOUBLE:
+ ret = system_info_get_custom_double(key, &val_double);
+ if (ret == SYSTEM_INFO_ERROR_NONE)
+ printf("%lf", val_double);
+ break;
+ case TYPE_STRING:
+ ret = system_info_get_custom_string(key, &val_string);
+ if (ret == SYSTEM_INFO_ERROR_NONE)
+ printf("%s", val_string);
+ break;
+ default:
+ ret = SYSTEM_INFO_ERROR_INVALID_PARAMETER;
+ break;
+ }
+ break;
+ default:
+ ret = SYSTEM_INFO_ERROR_INVALID_PARAMETER;
+ break;
+ }
+
+ if (ret != SYSTEM_INFO_ERROR_NONE) {
+ printf("ERROR : %d", ret);
+ }
+
+ printf(")\n");
+
+ return SUCCESS;
+}