Coder Social home page Coder Social logo

Comments (4)

ChaitanyaYeole02 avatar ChaitanyaYeole02 commented on June 7, 2024

@matth-x

This is the snippet of my code

if (remove_config) {
    Serial.println(F("[Configuration] Removing Configuration"));
    container->removeConfiguration(configuration);
    configuration->setToBeRemoved();
    configuration = NULL;
}

I added this snippet at the end of declareConfiguration function and made remove_config = true so that it will delete the configuration which I am defining.

But it's not getting removed. What is wrong here or is there any other simple way to remove the configuration?

from microocpp.

akashdk191 avatar akashdk191 commented on June 7, 2024

bool removeConfiguration(const char *key,const char *filename) {

std::shared_ptr<ConfigurationContainer> container = getContainer(filename);

if (!container) {
    Serial.print(F("[Configuration] removeConfiguration: init new configurations container on flash filesystem: "));
    Serial.println(filename);

    if (!container->load()) {
        Serial.print(F("[Configuration] Cannot load file contents.\n"));
    }
}

std::shared_ptr<AbstractConfiguration> configuration = container->getConfiguration(key);

if (configuration ) {
    if(DEBUG_OUT)
    {
        Serial.println(F("[Configuration] Removing configuration"));
        Serial.println(key);
        Serial.println("\n");
    }
    container->removeConfiguration(configuration);
    configuration->setToBeRemoved();
    configuration = NULL;
    return true;
}

return false;

}

I added a new function to remove configuration and it's working perfectly fine.

from microocpp.

prakharkalani avatar prakharkalani commented on June 7, 2024

Why are we removing this configuration file?

from microocpp.

matth-x avatar matth-x commented on June 7, 2024

Once a configuration is declared, it is valid for the lifetime of the library. You can only control if to write the configuration back to the persistent memory with setToBeRemoved(). If set, after the next reboot the information about the configuration will be gone and the configuration is finally deleted.

Thank you for your input @ChaitanyaYeole02 and @akashdk191. Flagging the object as removed did not invalidate the persistent memory. You probably observed that the remove operation was comitted too late.

And I introduced that the operation Change Configuration removes (writeable) configurations if "value": "". Both changes are in 004b60b.

from microocpp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.