finished implementing basic config-get and config-set for both live settings and...
authorLogxen <logxen@hotmail.com>
Tue, 19 Jun 2012 23:29:05 +0000 (16:29 -0700)
committerLogxen <logxen@hotmail.com>
Tue, 19 Jun 2012 23:29:05 +0000 (16:29 -0700)
src/libs/Config.cpp
src/libs/utils.cpp
src/modules/utils/configurator/Configurator.cpp

index 6cc2ee0..6d904b1 100644 (file)
@@ -34,7 +34,18 @@ Config::Config(){
 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){ }
 
 
@@ -52,7 +63,6 @@ void Config::config_cache_load(){
         ConfigSource* source = this->config_sources[i];
         source->transfer_values_to_cache(&this->config_cache);
     }
-
     
     this->config_cache_loaded = true;
 }
index 836f483..9d65a3c 100644 (file)
@@ -26,9 +26,10 @@ uint16_t get_checksum(string to_check){
 }
 
 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));
index e288f49..a00a0fb 100644 (file)
@@ -60,13 +60,17 @@ void Configurator::config_get_command( string parameters, StreamOutput* stream )
         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;
             }
         }
@@ -83,10 +87,16 @@ void Configurator::config_set_command( string parameters, StreamOutput* stream )
         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;
+            }
+        }
     }
 }