parent
61d7305766
commit
06b177887e
@ -0,0 +1,33 @@
|
||||
#include "load.h"
|
||||
|
||||
namespace Lib_Load{
|
||||
void Load::set_sections(vector<string> vec_sections){
|
||||
this->vec_sections = vec_sections;
|
||||
}
|
||||
map<string, string> Load::get_load_data(string str_flag_load) {
|
||||
string cmd = "";
|
||||
string response = "";
|
||||
string key = "";
|
||||
string value = "";
|
||||
map<string, string> map_data;
|
||||
for (const string §ion: this->vec_sections) {
|
||||
cmd = "ubconfig --default --source " + str_flag_load + " get " + section;
|
||||
response = process.call_all_sections(cmd);
|
||||
vector<string> vec_str_key_value = Utils::split(response, '\n');
|
||||
for (const string ¶m: vec_str_key_value) {
|
||||
if ((param.find("(null)") == std::string::npos) && (param.length() != 0 )) {
|
||||
if (param.find("=") != std::string::npos) {
|
||||
size_t index = param.find("=");
|
||||
key = param.substr(0, index);
|
||||
value = param.substr(index + 1, param.length());
|
||||
map_data[key] = value;
|
||||
cout << key << "=" << value << endl;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return map_data;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
#ifndef LOAD_H
|
||||
#define LOAD_H
|
||||
|
||||
#include "my_process.h"
|
||||
namespace Lib_Load{
|
||||
class Load {
|
||||
|
||||
private:
|
||||
vector<string> vec_sections;
|
||||
My_Process::My_Process_call process = My_Process::My_Process_call();
|
||||
public:
|
||||
Load(/* args */);
|
||||
~Load();
|
||||
void set_sections(vector<string> vec_sections);
|
||||
map<string, string> get_load_data(string str_flag_load);
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
#endif
|
@ -0,0 +1,73 @@
|
||||
#include "my_process.h"
|
||||
#include "util.h"
|
||||
|
||||
namespace My_Process{
|
||||
|
||||
struct Utils::Result<string> My_Process_call::call(string cmd) {
|
||||
this->i_error_old = this->i_error;
|
||||
struct Utils::Result<string> obj_result;
|
||||
string response = Utils::call(cmd);
|
||||
obj_result.response = response;
|
||||
if ((response.find("(null)") == std::string::npos) && (response.length() != 0 )) {
|
||||
if (response.find("=") != std::string::npos) {
|
||||
if (response.find("\n") != std::string::npos) {
|
||||
response = response.substr(response.find("=")+1,response.length());
|
||||
response = response.substr(0,response.find("\n"));
|
||||
obj_result.response = response;
|
||||
obj_result.error = 0;
|
||||
}
|
||||
else {
|
||||
obj_result.error = 1;
|
||||
this->i_error += 1;
|
||||
this->log_mess_error(cmd);
|
||||
}
|
||||
}
|
||||
else {
|
||||
obj_result.error = 2;
|
||||
this->i_error += 1;
|
||||
str_cmd_error = cmd;
|
||||
this->log_mess_error(cmd);
|
||||
}
|
||||
}
|
||||
else {
|
||||
obj_result.error = 3;
|
||||
this->i_error += 1;
|
||||
str_cmd_error = cmd;
|
||||
this->log_mess_error(cmd);
|
||||
}
|
||||
return obj_result;
|
||||
}
|
||||
|
||||
int My_Process::get_count_error() {
|
||||
return this->i_error;
|
||||
}
|
||||
|
||||
void My_Process::set_back_count_error() {
|
||||
this->i_error = this->i_error_old;
|
||||
}
|
||||
|
||||
void My_Process_system::call(string cmd, string thread_str = "") {
|
||||
string cmd_new = cmd + " " + thread_str;
|
||||
int response_cmd = system(cmd_new.c_str());
|
||||
if (response_cmd != 0) {
|
||||
this->i_error += 1;
|
||||
}
|
||||
}
|
||||
|
||||
void My_Process::set_count_error(int count_error) {
|
||||
this->i_error = count_error;
|
||||
this->str_cmd_error = "";
|
||||
}
|
||||
|
||||
void My_Process::log_mess_error(string cmd) {
|
||||
|
||||
}
|
||||
|
||||
string My_Process::get_cmd_error() {
|
||||
return this->str_cmd_error;
|
||||
}
|
||||
string My_Process_call::call_all_sections(string cmd) {
|
||||
string response = Utils::call(cmd);
|
||||
return response;
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
#ifndef SAVE_H
|
||||
#define SAVE_H
|
||||
|
||||
#include "util.h"
|
||||
namespace My_Process{
|
||||
class My_Process {
|
||||
public:
|
||||
int i_error = 0;
|
||||
int i_error_old = 0;
|
||||
string str_cmd_error = "";
|
||||
int get_count_error();
|
||||
void set_count_error(int count_error);
|
||||
void set_back_count_error();
|
||||
void log_mess_error(string cmd);
|
||||
string get_cmd_error();
|
||||
};
|
||||
|
||||
|
||||
class My_Process_call: My_Process {
|
||||
public:
|
||||
My_Process_call();
|
||||
struct Utils::Result<string> call(string cmd);
|
||||
string call_all_sections(string cmd);
|
||||
|
||||
};
|
||||
|
||||
class My_Process_system: My_Process {
|
||||
public:
|
||||
My_Process_system();
|
||||
void call(string cmd, string thread_str);
|
||||
|
||||
};
|
||||
}
|
||||
#endif
|
@ -1,10 +0,0 @@
|
||||
#include "process.h"
|
||||
|
||||
struct Result<string> Process_call::call(string cmd) {}
|
||||
int Process::get_count_error() {
|
||||
return this->i_error;
|
||||
}
|
||||
void Process::set_count_error(int count_error) {
|
||||
this->i_error = count_error;
|
||||
}
|
||||
void Process_system::call(string cmd) {}
|
@ -1,22 +0,0 @@
|
||||
#include "util.h"
|
||||
|
||||
class Process {
|
||||
int i_error = 0;
|
||||
int i_error_old = 0;
|
||||
virtual int get_count_error() = 0;
|
||||
virtual void set_count_error(int count_error) = 0;
|
||||
};
|
||||
|
||||
|
||||
class Process_call: Process {
|
||||
public:
|
||||
Process_call();
|
||||
struct Result<string> call(string cmd);
|
||||
|
||||
};
|
||||
class Process_system: Process {
|
||||
public:
|
||||
Process_system();
|
||||
void call(string cmd);
|
||||
|
||||
};
|
@ -0,0 +1,87 @@
|
||||
#include "save.h"
|
||||
|
||||
namespace Lib_save {
|
||||
|
||||
vector<string> Save::get_error() {
|
||||
return this->vec_errors;
|
||||
}
|
||||
|
||||
bool Save::get_state_save() {
|
||||
return this->flag_no_save;
|
||||
}
|
||||
|
||||
void Save::set_data_local(std::map <string, string> &map_global) {
|
||||
this->map_global = &map_global;
|
||||
}
|
||||
|
||||
void Save::set_data_local(std::map <string, string> &map_local) {
|
||||
this->map_local = &map_local;
|
||||
}
|
||||
|
||||
void Save::set_data_local(std::map <string, string> &map_gui) {
|
||||
this->map_gui = &map_gui;
|
||||
}
|
||||
|
||||
bool Save::check_save(string flag_save, string key_name) {
|
||||
std::map <string, string>:: iterator iter_map_data;
|
||||
std::map <string, string>:: iterator iter_map_data_old;
|
||||
std::map <string, string> *map_data_old;
|
||||
if (flag_save == "system") {
|
||||
map_data_old = map_local;
|
||||
}
|
||||
else if (flag_save == "global") {
|
||||
map_data_old = map_global;
|
||||
}
|
||||
iter_map_data = (*map_gui).find(key_name);
|
||||
iter_map_data_old = (*map_data_old).find(key_name);
|
||||
if (iter_map_data_old == (*map_data_old).end() && iter_map_data != (*map_gui).end()) {
|
||||
return true;
|
||||
}
|
||||
else if (iter_map_data->second != iter_map_data_old->second) {
|
||||
return true;
|
||||
}
|
||||
else if (iter_map_data->second.length() == 0 && iter_map_data_old->second.length() == 0) {
|
||||
return false;
|
||||
}
|
||||
else if (iter_map_data->second == iter_map_data_old->second) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void Save::save(std::map <string, string> &map_gui, std::map <string, string> &map_temp,string sections, string str_flag_save) {
|
||||
string key = "";
|
||||
string value = "";
|
||||
string cmd = "";
|
||||
string str_error = "";
|
||||
this->flag_no_save = false;
|
||||
for (const auto &map_iter: map_gui) {
|
||||
key = map_iter.first;
|
||||
value = map_iter.second;
|
||||
if (this->check_save(str_flag_save, key) == true) {
|
||||
if (value.length() != 0) {
|
||||
cmd = "ubconfig --target " + str_flag_save + " set " + sections + " " +
|
||||
key + "=\"" + value + "\"";
|
||||
}
|
||||
else if (value.length() == 0) {
|
||||
cmd = "ubconfig --target " + str_flag_save + " remove " + sections + " " + key;
|
||||
}
|
||||
else {
|
||||
cmd = "";
|
||||
}
|
||||
if (cmd.length() != 0) {
|
||||
process.call(cmd, "");
|
||||
this->flag_no_save = true;
|
||||
str_error = process.get_cmd_error();
|
||||
if (str_error.length() != 0) {
|
||||
this->vec_errors.push_back(str_error);
|
||||
str_error = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
#ifndef MY_PROCESS_H
|
||||
#define MY_PROCESS_H
|
||||
|
||||
#include "my_process.h"
|
||||
namespace Lib_save {
|
||||
|
||||
class Save {
|
||||
private:
|
||||
std::map <string, string> *map_global;
|
||||
std::map <string, string> *map_local;
|
||||
std::map <string, string> *map_gui;
|
||||
vector<string> vec_errors;
|
||||
My_Process::My_Process_system process = My_Process::My_Process_system();
|
||||
bool flag_no_save;
|
||||
public:
|
||||
Save(/* args */);
|
||||
~Save();
|
||||
void set_data_local(std::map <string, string> &map_global);
|
||||
void set_data_local(std::map <string, string> &map_local);
|
||||
void set_data_local(std::map <string, string> &map_gui);
|
||||
bool check_save(string flag_save, string key_name);
|
||||
bool get_state_save();
|
||||
void save(std::map <string, string> &map_gui, std::map <string, string> &map_temp,string sections, string str_flag_save) ;
|
||||
vector<string> get_error();
|
||||
};
|
||||
}
|
||||
#endif
|
Loading…
Reference in new issue