int main(int argc, char **argv) { Aria::init(); ArServerBase server; ArConfig *config; config = Aria::getConfig(); std::string section; char joy[512]; sprintf(joy, "Joy"); section = "section1"; config->addParam(ArConfigArg("int", new int, "fun int", 0), section.c_str(), ArPriority::NORMAL); config->addParam(ArConfigArg("double", new double, "fun double", 0, 1), section.c_str(), ArPriority::NORMAL); config->addParam(ArConfigArg("bool", new bool, "fun bool"), section.c_str(), ArPriority::IMPORTANT); config->addParam(ArConfigArg("string", joy, "fun string", sizeof(joy)), section.c_str(), ArPriority::TRIVIAL); section = "section8"; config->addParam(ArConfigArg("int", new int, "fun int", 0), section.c_str(), ArPriority::NORMAL); config->addParam(ArConfigArg("double", new double, "fun double", 0, 1), section.c_str(), ArPriority::NORMAL); config->addParam(ArConfigArg("doubleFOUR", (double).4, "fun double", 0.0, 1.0), section.c_str(), ArPriority::NORMAL); config->addParam(ArConfigArg("double three", new double, "fun double", 0, 1), section.c_str(), ArPriority::NORMAL); config->addParam(ArConfigArg("double two", new double, "fun double", 0, 1), section.c_str(), ArPriority::NORMAL); config->addParam(ArConfigArg("double one", new double, "fun double", 0, 1), section.c_str(), ArPriority::NORMAL); config->addParam(ArConfigArg("double", new double, "fun double", 0, 1), section.c_str(), ArPriority::NORMAL); config->addParam(ArConfigArg("bool", new bool, "fun bool"), section.c_str(), ArPriority::IMPORTANT); config->addParam(ArConfigArg("string", joy, "fun string", sizeof(joy)), section.c_str(), ArPriority::TRIVIAL); section = "some section"; config->setSectionComment("some section", "this is a random section with 4 ints"); config->addParam(ArConfigArg("int1", new int, "fun int"), section.c_str(), ArPriority::TRIVIAL); config->addParam(ArConfigArg("int2", new int, "fun int", -1, 1200), section.c_str(), ArPriority::NORMAL); config->addParam(ArConfigArg("int3", new int, "fun int"), section.c_str(), ArPriority::IMPORTANT); config->addParam(ArConfigArg("int4", new int, "fun int"), section.c_str(), ArPriority::NORMAL); config->addParam(ArConfigArg("int4", new int, "fun int"), section.c_str(), ArPriority::NORMAL); config->addParam(ArConfigArg("int1", new int, "fun int"), section.c_str(), ArPriority::TRIVIAL); section = "another section"; config->setSectionComment("another section", "this is another section with 1 of each type"); config->addParam(ArConfigArg("inta", new int, "fun int"), section.c_str(), ArPriority::NORMAL); config->addParam(ArConfigArg("doublea", new double, "fun double"), section.c_str(), ArPriority::NORMAL); config->addParam(ArConfigArg("boola", new bool, "fun bool"), section.c_str(), ArPriority::NORMAL); config->addParam(ArConfigArg("stringa", new char[512], "fun string", 512), section.c_str(), ArPriority::NORMAL); if (!server.open(7272)) { printf("Could not open server port\n"); exit(1); } config->setBaseDirectory("./"); config->writeFile("default.txt"); config->parseFile("modified.txt"); config->writeFile("modifiedModified.txt"); ArServerHandlerConfig configHandler(&server, Aria::getConfig(), "default.txt"); server.run(); Aria::shutdown(); return 0; }
int main(int argc, char **argv) { Aria::init(); ArArgumentParser argParser(&argc, argv); argParser.loadDefaultArguments(); if (argc < 2 || !Aria::parseArgs() || argParser.checkArgument("-help")) { ArLog::log(ArLog::Terse, "configExample usage: configExample <config file>.\nFor example, \"configExample examples/configExample.cfg\"."); Aria::logOptions(); Aria::shutdown(); return 1; } // Object containing config parameters, and responding to changes: ConfigExample configExample; // Load a config file given on the command line into the global // ArConfig object kept by Aria. Normally ArConfig expects config // files to be in the main ARIA directory (i.e. /usr/local/Aria or // a directory specified by the $ARIA environment variable). char error[512]; const char* filename = argParser.getArg(1); ArConfig* config = Aria::getConfig(); ArLog::log(ArLog::Normal, "configExample: loading configuration file \"%s\"...", filename); if (! config->parseFile(filename, true, false, error, 512) ) { ArLog::log(ArLog::Terse, "configExample: Error loading configuration file \"%s\" %s. Try \"examples/configExample.cfg\".", filename, error); Aria::shutdown(); return -1; } ArLog::log(ArLog::Normal, "configExample: Loaded configuration file \"%s\".", filename); // After changing a config value, you should invoke the callbacks: ArConfigSection* section = config->findSection("Example Section"); if (section) { ArConfigArg* arg = section->findParam("ExampleBoolParameter"); if (arg) { arg->setBool(!arg->getBool()); if (! config->callProcessFileCallBacks(false, error, 512) ) { ArLog::log(ArLog::Terse, "configExample: Error processing modified config: %s.", error); } else { ArLog::log(ArLog::Normal, "configExample: Successfully modified config and invoked callbacks."); } } } // You can save the configuration as well: ArLog::log(ArLog::Normal, "configExample: Saving configuration..."); if(!config->writeFile(filename)) { ArLog::log(ArLog::Terse, "configExample: Error saving configuration to file \"%s\"!", filename); } // end of program. ArLog::log(ArLog::Normal, "configExample: end of program."); Aria::shutdown(); return 0; }