void Config::on_module_loaded(){}
void Config::on_console_line_received( void* argument ){}
-void Config::set_string( string setting, string value ){ kernel->serial->printf( "WARNING: Writing to live values is unimplemented\r\n" ); }
+
+void Config::set_string( string setting, string value ){
+ ConfigValue* cv = new ConfigValue;
+ cv->found = true;
+ cv->check_sums = get_checksums(setting);
+ cv->value = value;
+
+ this->config_cache.replace_or_push_back(cv);
+
+ this->kernel->call_event(ON_CONFIG_RELOAD);
+}
+
void Config::get_module_list(vector<uint16_t>* list, uint16_t family){ }
ConfigSource* source = this->config_sources[i];
source->transfer_values_to_cache(&this->config_cache);
}
-
this->config_cache_loaded = true;
}
}
vector<uint16_t> get_checksums(string key){
+ key = key.append(" ");
vector<uint16_t> check_sums;
size_t begin_key = 0;
- while( begin_key < key.size() ){
+ while( begin_key < key.size()-1 ){
size_t end_key = key.find_first_of(" .", begin_key);
string key_node = key.substr(begin_key, end_key - begin_key);
check_sums.push_back(get_checksum(key_node));
setting = source;
source = "";
vector<uint16_t> setting_checksums = get_checksums( setting );
- stream->printf( "%s is set to %s\r\n", setting.c_str(), this->kernel->config->value(setting_checksums)->as_string().c_str() );
+ ConfigValue* cv = this->kernel->config->value(setting_checksums);
+ string value = "";
+ if(cv->found){ value = cv->as_string(); }
+ stream->printf( "live: %s is set to %s\r\n", setting.c_str(), value.c_str() );
} else { // output setting from specified source
uint16_t source_checksum = get_checksum( source );
vector<uint16_t> setting_checksums = get_checksums( setting );
for(int i=0; i < this->kernel->config->config_sources.size(); i++){
if( this->kernel->config->config_sources[i]->is_named(source_checksum) ){
- stream->printf( "%s: %s is set to %s\r\n", source.c_str(), setting.c_str(), this->kernel->config->config_sources[i]->read(setting_checksums).c_str() );
+ string value = this->kernel->config->config_sources[i]->read(setting_checksums);
+ stream->printf( "%s: %s is set to %s\r\n", source.c_str(), setting.c_str(), value.c_str() );
break;
}
}
setting = source;
source = "";
this->kernel->config->set_string(setting, value);
+ stream->printf( "live: %s has been set to %s\r\n", setting.c_str(), value.c_str() );
} else {
uint16_t source_checksum = get_checksum(source);
- uint16_t setting_checksum = get_checksum(setting);
- stream->printf( "WARNING: Writing to values is unimplemented\r\n" );
+ for(int i=0; i < this->kernel->config->config_sources.size(); i++){
+ if( this->kernel->config->config_sources[i]->is_named(source_checksum) ){
+ this->kernel->config->config_sources[i]->write(setting, value);
+ stream->printf( "%s: %s has been set to %s\r\n", source.c_str(), setting.c_str(), value.c_str() );
+ break;
+ }
+ }
}
}