/* Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2009 Copyright Stichting C.A. Muller Radioastronomiestation, 2009 This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include #include #include enum variable_type { VARIABLE_STRING, VARIABLE_DOUBLE, VARIABLE_INT, }; struct variable { enum variable_type type; char *name; double doubleval; char *stringval; int intval; struct variable *next; }; static struct variable *variables = NULL; int controller_load_variable_int_get(char *varname) { struct variable *entry; for (entry = variables; entry; entry = entry->next) { if (!strcmp(entry->name, varname) && entry->type == VARIABLE_INT) return entry->intval; } log_send(LOG_T_ERROR, "Integer variable %s does not exist", varname); return 0; } double controller_load_variable_double_get(char *varname) { struct variable *entry; for (entry = variables; entry; entry = entry->next) { if (!strcmp(entry->name, varname) && entry->type == VARIABLE_DOUBLE) return entry->doubleval; } log_send(LOG_T_ERROR, "Double variable %s does not exist", varname); return 0.0; } void controller_load_variable_double_set(char *varname, double val) { struct variable *entry; for (entry = variables; entry; entry = entry->next) { if (!strcmp(entry->name, varname)) { if (entry->type == VARIABLE_STRING) { free(entry->stringval); } break; } } if (!entry) { entry = calloc(sizeof(struct variable), 1); entry->name = strdup(varname); entry->next = variables; variables = entry; } entry->type = VARIABLE_DOUBLE; entry->doubleval = val; } void controller_load_variable_int_set(char *varname, int val) { struct variable *entry; for (entry = variables; entry; entry = entry->next) { if (!strcmp(entry->name, varname)) { if (entry->type == VARIABLE_STRING) { free(entry->stringval); } break; } } if (!entry) { entry = calloc(sizeof(struct variable), 1); entry->name = strdup(varname); entry->next = variables; variables = entry; } entry->type = VARIABLE_INT; entry->intval = val; } char * controller_load_variable_string_get(char *varname) { struct variable *entry; for (entry = variables; entry; entry = entry->next) { if (!strcmp(entry->name, varname) && entry->type == VARIABLE_STRING) return entry->stringval; } log_send(LOG_T_ERROR, "String variable %s does not exist", varname); return ""; } void controller_load_variable_string_set(char *varname, char *val) { struct variable *entry; for (entry = variables; entry; entry = entry->next) { if (!strcmp(entry->name, varname)) { if (entry->type == VARIABLE_STRING) { free(entry->stringval); } break; } } if (!entry) { entry = calloc(sizeof(struct variable), 1); entry->name = strdup(varname); entry->next = variables; variables = entry; } entry->type = VARIABLE_STRING; entry->stringval = strdup(val); }