From 84a2828f9756c012d045293388ab91166c1454d1 Mon Sep 17 00:00:00 2001 From: lakinduakash Date: Sun, 14 Apr 2019 15:36:12 +0530 Subject: [PATCH] set and return read values from config file --- src/ui/read_config.cpp | 33 +++++++++++++++++++++++++++++++++ src/ui/read_config.h | 5 ++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/ui/read_config.cpp b/src/ui/read_config.cpp index 56acf36..3b4768c 100644 --- a/src/ui/read_config.cpp +++ b/src/ui/read_config.cpp @@ -7,18 +7,28 @@ #include #include #include +#include #include "read_config.h" #include "h_prop.h" +#define CONFIG_KEY_COUNT 30 +#define STRING_MAX_LENGTH 100 + extern "C" { +ConfigValues configValues; + +char configs[CONFIG_KEY_COUNT][STRING_MAX_LENGTH]; + int read_config_file() { // std::ifstream is RAII, i.e. no need to call close std::ifstream cFile(CONFIG_FILE); if (cFile.is_open()) { std::string line; + + int i=0; while (getline(cFile, line)) { line.erase(std::remove_if(line.begin(), line.end(), isspace), line.end()); @@ -27,7 +37,11 @@ int read_config_file() { auto delimiterPos = line.find('='); auto name = line.substr(0, delimiterPos); auto value = line.substr(delimiterPos + 1); + + strcpy(configs[i],value.c_str()); + setConfigValues(name.c_str(),configs[i]); std::cout << name << " " << value << '\n'; + ++i; } } else { @@ -36,4 +50,23 @@ int read_config_file() { return 0; } + +ConfigValues* getConfigValues(){ + return &configValues; } + + +static void setConfigValues(const char * key, char *value){ + + if( !strcmp ( SSID, key )) + configValues.ssid = value; + + if( !strcmp ( PASSPHRASE, key )) + configValues.pass = value; +} + +} + + + + diff --git a/src/ui/read_config.h b/src/ui/read_config.h index eaf116d..c2e4c52 100644 --- a/src/ui/read_config.h +++ b/src/ui/read_config.h @@ -5,12 +5,15 @@ #ifndef WIHOTSPOT_READ_CONFIG_H #define WIHOTSPOT_READ_CONFIG_H +#include "h_prop.h" + #ifdef __cplusplus extern "C" { #endif int read_config_file(); - +static void setConfigValues(const char * key, char *value); +ConfigValues* getConfigValues(void); #ifdef __cplusplus } #endif