AREXPORT bool ArServerHandlerConfig::loadDefaultsFromPacket(
	ArNetPacket *packet)
{
  bool ret = true;

  lockConfig();
  if (myDefault != NULL)
  {
    delete myDefault;
    myDefault = NULL;  
  }

  createDefaultConfig(NULL);
  myDefault->clearAllValueSet();
  // now fill in that copy
  if (internalSetConfig(NULL, packet))
  {
      addDefaultServerCommands();    
  }
  else
  {
    ArLog::log(ArLog::Normal, "Did not load default from packet successfully, not allowing getDefault");
    delete myDefault;
    myDefault = NULL;
  }
  if (myDefault != NULL)
    myDefault->removeAllUnsetValues();
  unlockConfig();
  ArNetPacket emptyPacket;
  myServer->broadcastPacketTcp(&emptyPacket, "configDefaultsUpdated");
  return ret;
}
Exemple #2
0
bool ConfigXml::initConfigXml()
{
    if(!init(CONFIG_XML_NAME, CONFIG_XML_ROOT_NAME)) return false;

    if(!getElement("version")) createDefaultConfig();
    return true;
}
AREXPORT bool ArServerHandlerConfig::loadDefaultsFromFile(void)
{
  bool ret = true;

  lockConfig();
  if (myDefault != NULL)
  {
    delete myDefault;
    myDefault = NULL;  
  }

  if (!myDefaultFile.empty())
  {
    createDefaultConfig(myDefaultFileBaseDir.c_str());
    myDefault->clearAllValueSet();
    // now fill in that copy
    if (myDefault->parseFile(myDefaultFile.c_str()))
    {
      addDefaultServerCommands();
    }
    else
    {
      ret = false;
      ArLog::log(ArLog::Normal, "Did not load default file '%s' successfully, not allowing getDefault", myDefaultFile.c_str());
      delete myDefault;
      myDefault = NULL;
    }
    if (myDefault != NULL)
      myDefault->removeAllUnsetValues();
  }
  unlockConfig();
  ArNetPacket emptyPacket;
  myServer->broadcastPacketTcp(&emptyPacket, "configDefaultsUpdated");
  return ret;
}
Exemple #4
0
void loadConfig(std::string root)
{
    std::string dir = root + "/";
    std::string config = dir + "/nmbls.json";

    if ( !boost::filesystem::is_regular_file(config) )
    {
        createDefaultConfig(root);
    }

    try
    {
        boost::property_tree::ptree pt;
        boost::property_tree::read_json(config, pt);

        boost::property_tree::ptree::const_iterator it;
        boost::property_tree::ptree libs = pt.get_child("libs");
        boost::property_tree::ptree::const_iterator libsit;

        for (libsit = libs.begin(); libsit != libs.end(); ++libsit)
        {
            std::string lib = libsit->second.get<std::string>("");
            std::cout << "Need lib " << lib << std::endl;

            loadlib(lib, root);
        }
    }
    catch (std::exception const& e)
    {
        std::cerr << e.what() << std::endl;
    }
}
Exemple #5
0
static void resetConf(void)
{
    createDefaultConfig(&masterConfig);

    setProfile(0);

#ifdef LED_STRIP
    reevaluateLedConfig();
#endif
}
Exemple #6
0
void loadConfiguration(void)
{
    createDefaultConfig();

    FILE *cfgFile = fopen("/accounts/1000/shared/misc/gbaemu/gpsp.cfg", "r");
    if (cfgFile) {
        sdlReadPreferences(cfgFile);
        fclose(cfgFile);
    }
}
Exemple #7
0
int Context::initialize (int argc, const char** argv)
{
  timer_init.start ();
  int rc = 0;

  try
  {
    // char** argv --> std::vector <std::string> Context::a3.
    a3.capture (argc, argv);

    // echo one two -- three | task zero --> task zero one two
    // 'three' is left in the input buffer.
    a3.append_stdin ();

    // Assume default .taskrc and .task locations.
    assumeLocations ();

    // Process 'rc:<file>' command line override, and remove the argument from the
    // Context::a3.
    a3.categorize ();
    a3.rc_override (home_dir, rc_file);

    // TASKRC environment variable overrides the command line.
    char* override = getenv ("TASKRC");
    if (override)
    {
      rc_file = File (override);
      debug ("TASKRC override: ");
      header (format (STRING_CONTEXT_RC_OVERRIDE, rc_file._data));
    }

    // Dump any existing values and load rc file.
    config.clear ();
    config.load  (rc_file);

    // The data location, Context::data_dir, is determined from the assumed
    // location (~/.task), or set by data.location in the config file, or
    // overridden by rc.data.location on the command line.
    std::string location;
    a3.get_data_location (location);
    data_dir = Directory (location);

    override = getenv ("TASKDATA");
    if (override)
    {
      data_dir = Directory (override);
      config.set ("data.location", data_dir._data);
      header (format (STRING_CONTEXT_DATA_OVERRIDE, data_dir._data));
    }

/* TODO Enable this when the time is right, say for 2.1
    extension_dir = data_dir._data + "/extensions";
*/

    // Create missing config file and data directory, if necessary.
    createDefaultConfig ();

    // Handle Aliases.
    loadAliases ();
    a3.resolve_aliases ();

    // Apply rc overrides to Context::config, capturing raw args for later use.
    a3.apply_overrides ();

    // Initialize the color rules, if necessary.
    if (color ())
      initializeColorRules ();

    // Instantiate built-in command objects.
    Command::factory (commands);

    // Instantiate built-in column objects.
    Column::factory (columns);

    // Categorize all arguments one more time.  THIS IS NECESSARY - it helps the
    // following inject_defaults method determine whether there needs to be a
    // default command assumed.
    a3.categorize ();

    // Handle default command and assumed 'info' command.
    a3.inject_defaults ();

    // The re-categorization allows all injected arguments to be properly given
    // a category.
    a3.categorize ();
    a3.dump ("Context::initialize");

    // TODO Instantiate extension command objects.
    // TODO Instantiate default command object.

    // TODO Instantiate extension column objects.

    // TODO Instantiate extension UDA objects.
    // TODO Instantiate extension format objects.

    // If there is a locale variant (en-US.<variant>), then strip it.
    std::string locale = config.get ("locale");
    std::string::size_type period = locale.find ('.');
    if (period != std::string::npos)
      locale = locale.substr (0, period);

    // Initialize the database.
    tdb2.set_location (data_dir);

    // Hook system init, plus post-start event occurring at the first possible
    // moment after hook initialization.
    hooks.initialize ();
    hooks.trigger ("on-launch");
  }
Exemple #8
0
int Context::initialize (int argc, const char** argv)
{
  timer_init.start ();
  int rc = 0;

  try
  {
    ////////////////////////////////////////////////////////////////////////////
    //
    // [1] Load the correct config file.
    //     - Default to ~/.taskrc (ctor).
    //     - Allow command line override rc:<file>
    //     - Allow $TASKRC override.
    //     - Load resultant file.
    //     - Apply command line overrides to the config.
    //
    ////////////////////////////////////////////////////////////////////////////

    CLI::getOverride (argc, argv, home_dir, rc_file);

    char* override = getenv ("TASKRC");
    if (override)
    {
      rc_file = File (override);
      header (format (STRING_CONTEXT_RC_OVERRIDE, rc_file._data));
    }

    config.clear ();
    config.load (rc_file);
    CLI::applyOverrides (argc, argv);

    ////////////////////////////////////////////////////////////////////////////
    //
    // [2] Locate the data directory.
    //     - Default to ~/.task (ctor).
    //     - Allow command line override rc.data.location:<dir>
    //     - Allow $TASKDATA override.
    //     - Inform TDB2 where to find data.
    //     - Create the rc_file and data_dir, if necessary.
    //
    ////////////////////////////////////////////////////////////////////////////

    CLI::getDataLocation (argc, argv, data_dir);

    override = getenv ("TASKDATA");
    if (override)
    {
      data_dir = Directory (override);
      config.set ("data.location", data_dir._data);
      header (format (STRING_CONTEXT_DATA_OVERRIDE, data_dir._data));
    }

    tdb2.set_location (data_dir);
    createDefaultConfig ();

    ////////////////////////////////////////////////////////////////////////////
    //
    // [3] Instantiate Command objects and capture entities.
    //
    ////////////////////////////////////////////////////////////////////////////

    Command::factory (commands);
    std::map <std::string, Command*>::iterator cmd;
    for (cmd = commands.begin (); cmd != commands.end (); ++cmd)
    {
      cli.entity ("cmd", cmd->first);
      cli.entity ((cmd->second->read_only () ? "readcmd" : "writecmd"), cmd->first);

      if (cmd->first[0] == '_')
        cli.entity ("helper", cmd->first);
    }

    ////////////////////////////////////////////////////////////////////////////
    //
    // [4] Instantiate Column objects and capture entities.
    //
    ////////////////////////////////////////////////////////////////////////////

    Column::factory (columns);
    std::map <std::string, Column*>::iterator col;
    for (col = columns.begin (); col != columns.end (); ++col)
      cli.entity ("attribute", col->first);

    cli.entity ("pseudo", "limit");

    ////////////////////////////////////////////////////////////////////////////
    //
    // [5] Capture modifier and operator entities.
    //
    ////////////////////////////////////////////////////////////////////////////

    for (unsigned int i = 0; i < NUM_MODIFIER_NAMES; ++i)
      cli.entity ("modifier", modifierNames[i]);

    std::vector <std::string> operators;
    Eval::getOperators (operators);
    std::vector <std::string>::iterator op;
    for (op = operators.begin (); op != operators.end (); ++op)
      cli.entity ("operator", *op);

    Eval::getBinaryOperators (operators);
    for (op = operators.begin (); op != operators.end (); ++op)
      cli.entity ("binary_operator", *op);

    ////////////////////////////////////////////////////////////////////////////
    //
    // [6] Complete the Context initialization.
    //
    ////////////////////////////////////////////////////////////////////////////

    initializeColorRules ();
    staticInitialization ();
    propagateDebug ();
    loadAliases ();

    ////////////////////////////////////////////////////////////////////////////
    //
    // [7] Parse the command line.
    //
    ////////////////////////////////////////////////////////////////////////////

    // Scan command line for 'rc:<file>' only.
    cli.initialize (argc, argv);
    cli.analyze (true, true);

    // Extract a recomposed command line.
    bool foundDefault = false;
    bool foundAssumed = false;
    std::string combined;
    std::vector <A>::const_iterator a;
    for (a = cli._args.begin (); a != cli._args.end (); ++a)
    {
      if (combined.length ())
        combined += ' ';

      if (a->attribute ("canonical") != "")
        combined += a->attribute ("canonical");
      else
        combined += a->attribute ("raw");

      if (a->hasTag ("DEFAULT"))
        foundDefault = true;

      if (a->hasTag ("ASSUMED"))
        foundAssumed = true;
    }

    if (foundDefault)
      header ("[" + combined + "]");

    if (foundAssumed)
      header (STRING_ASSUME_INFO);

    ////////////////////////////////////////////////////////////////////////////
    //
    // [8] Initialize hooks.
    //
    ////////////////////////////////////////////////////////////////////////////

    hooks.initialize ();
  }