Usage examples
Retrieving current configuration
using namespace kaa;
... 
...
  
Subscribing for configuration updates
using namespace kaa;
public:
    void onConfigurationUpdated(
const ICommonRecord &configuration) {
 
        std::cout << "Configuration updated!" << std::endl;
    }
    
};
...
IConfigurationReceiver * configurationReceiver = new ConfigurationReceiver();
 
Working with configuration objects
Configuration in C++ sdk is represented as tree of kaa::ICommonValue objects.
 Use kaa::CommonValueTools helper class to extract values from ICommonValue object.
 
 Extracting primitive from ICommonValue:
using namespace kaa;
std::string fieldName = "foo";
if (configuration.hasField(fieldName)) {
    boost::shared_ptr<ICommonValue> fooField = configuration.
getField(fieldName);
 
    
    if (CommonValueTools::isBoolean(fooField)) {
        bool fooValue = boost::any_cast<bool>(fooField->getValue());
    }
}
try {
    bool fooValue = boost::any_cast<bool>(configuration.getField(fieldName)->getValue());
    std::cerr << 
"'foo' field is not present in record. "<< e.
what() << std::endl;
 
} catch (const boost::bad_cast &e) {
    std::cerr << "'foo' field is not of boolean type. " << e.what() << std::endl;
}
 
 Extracting data from ICommonRecord:
using namespace kaa;
std::string fieldName = "foo";
if (configuration.hasField(fieldName)) {
    
    boost::shared_ptr<ICommonValue> fooField = configuration.
getField(fieldName);
 
    
        
    }
}
try {
    std::cerr << 
"Failed to get record 'foo': "<< e.
what() << std::endl;
 
}
 
 Extracting array from ICommonValue:
using namespace kaa;
std::string fieldName = "fooArray";
if (configuration.hasField(fieldName)) {
    boost::shared_ptr<ICommonValue> fooField = configuration.
getField(fieldName);
 
        auto fooArray = CommonValueTools::getArray(fooField);
    }
}
try {
    auto fooArray = CommonValueTools::getArray(configuration.getField(fieldName))
    std::cerr << 
"Failed to get array 'fooArray': "<< e.
what() << std::endl;
 
}
Setting configuration persistent storage
#include <vector>
#include <boost/cstdint.hpp>
using namespace kaa;
    byte_buffer configurationBytes_;
public:
    MemoryConfigurationStorage() {}
    
    void saveConfiguration(const byte_buffer &bytes) {
        configurationBytes_.assign(bytes.begin(), bytes.end());
    }
    
    byte_buffer loadConfiguration() {
        return configurationBytes_;
    }
};
...
IConfigurationStorage * storage = new MemoryConfigurationStorage();
Kaa::getKaaClient().getConfigurationPersistanceManager().setConfigurationStorage(storage);
 
Setting configuration schema persistent storage
#include <vector>
#include <boost/cstdint.hpp>
using namespace kaa;
    byte_buffer schemaBytes_;
public:
    MemoryConfigurationSchemaStorage() {}
    
    void saveSchema(const byte_buffer &data) {
        schemaBytes_.assign(data.begin(), data.end());
    }
    
    byte_buffer loadSchema() {
        return schemaBytes_;
    }
};
...
ISchemaStorage * storage = new MemoryConfigurationSchemaStorage();