2010-09-04 08:03:46 +08:00
|
|
|
//====-- UserSettingsController.cpp ------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include "lldb/Core/UserSettingsController.h"
|
|
|
|
#include "lldb/Core/Error.h"
|
2010-12-19 11:41:24 +08:00
|
|
|
#include "lldb/Core/RegularExpression.h"
|
2010-09-04 08:03:46 +08:00
|
|
|
#include "lldb/Core/Stream.h"
|
|
|
|
#include "lldb/Core/StreamString.h"
|
|
|
|
#include "lldb/Interpreter/CommandInterpreter.h"
|
|
|
|
|
2011-02-18 09:44:25 +08:00
|
|
|
using namespace lldb;
|
2010-09-04 08:03:46 +08:00
|
|
|
using namespace lldb_private;
|
|
|
|
|
2011-02-18 09:44:25 +08:00
|
|
|
static void
|
|
|
|
DumpSettingEntry (CommandInterpreter &interpreter,
|
2011-04-20 06:32:36 +08:00
|
|
|
Stream &strm,
|
2011-02-18 09:44:25 +08:00
|
|
|
const uint32_t max_len,
|
|
|
|
const SettingEntry &entry)
|
|
|
|
{
|
|
|
|
StreamString description;
|
|
|
|
|
|
|
|
if (entry.description)
|
|
|
|
description.Printf ("%s", entry.description);
|
|
|
|
|
|
|
|
if (entry.default_value && entry.default_value[0])
|
|
|
|
description.Printf (" (default: %s)", entry.default_value);
|
|
|
|
|
2011-04-20 06:32:36 +08:00
|
|
|
interpreter.OutputFormattedHelpText (strm,
|
2011-02-18 09:44:25 +08:00
|
|
|
entry.var_name,
|
|
|
|
"--",
|
|
|
|
description.GetData(),
|
|
|
|
max_len);
|
|
|
|
|
|
|
|
if (entry.enum_values && entry.enum_values[0].string_value)
|
|
|
|
{
|
2011-04-20 06:32:36 +08:00
|
|
|
interpreter.OutputFormattedHelpText (strm,
|
2011-02-18 09:44:25 +08:00
|
|
|
"",
|
|
|
|
" ",
|
|
|
|
"Enumeration values:",
|
|
|
|
max_len);
|
|
|
|
for (uint32_t enum_idx=0; entry.enum_values[enum_idx].string_value != NULL; ++enum_idx)
|
|
|
|
{
|
|
|
|
description.Clear();
|
|
|
|
if (entry.enum_values[enum_idx].usage)
|
|
|
|
description.Printf ("%s = %s",
|
|
|
|
entry.enum_values[enum_idx].string_value,
|
|
|
|
entry.enum_values[enum_idx].usage);
|
|
|
|
else
|
|
|
|
description.Printf ("%s", entry.enum_values[enum_idx].string_value);
|
2011-04-20 06:32:36 +08:00
|
|
|
interpreter.OutputFormattedHelpText (strm,
|
2011-02-18 09:44:25 +08:00
|
|
|
"",
|
|
|
|
" ",
|
|
|
|
description.GetData(),
|
|
|
|
max_len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-04 08:03:46 +08:00
|
|
|
UserSettingsController::UserSettingsController (const char *level_name,
|
2011-02-18 09:44:25 +08:00
|
|
|
const UserSettingsControllerSP &parent) :
|
2010-09-04 08:03:46 +08:00
|
|
|
m_default_settings (),
|
|
|
|
m_settings (),
|
|
|
|
m_children (),
|
|
|
|
m_pending_settings (),
|
|
|
|
m_live_settings (),
|
|
|
|
m_children_mutex (Mutex::eMutexTypeNormal),
|
2010-09-08 07:31:30 +08:00
|
|
|
m_pending_settings_mutex (Mutex::eMutexTypeRecursive),
|
|
|
|
m_live_settings_mutex (Mutex::eMutexTypeRecursive)
|
2010-09-04 08:03:46 +08:00
|
|
|
{
|
|
|
|
m_settings.parent = parent;
|
|
|
|
m_settings.level_name.SetCString (level_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
UserSettingsController::~UserSettingsController ()
|
|
|
|
{
|
2011-04-20 06:32:36 +08:00
|
|
|
Mutex::Locker locker (m_live_settings_mutex);
|
2010-09-04 08:03:46 +08:00
|
|
|
m_live_settings.clear();
|
|
|
|
}
|
|
|
|
|
2010-09-19 10:33:57 +08:00
|
|
|
bool
|
|
|
|
UserSettingsController::SetGlobalVariable
|
|
|
|
(
|
|
|
|
const ConstString &var_name,
|
|
|
|
const char *index_value,
|
|
|
|
const char *value,
|
|
|
|
const SettingEntry &entry,
|
2011-02-18 09:44:25 +08:00
|
|
|
const VarSetOperationType op,
|
2010-09-19 10:33:57 +08:00
|
|
|
Error &err
|
|
|
|
)
|
|
|
|
{
|
|
|
|
err.SetErrorString ("UserSettingsController has no global settings");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
UserSettingsController::GetGlobalVariable
|
|
|
|
(
|
|
|
|
const ConstString &var_name,
|
2010-09-21 04:44:43 +08:00
|
|
|
StringList &value,
|
|
|
|
Error &err
|
2010-09-19 10:33:57 +08:00
|
|
|
)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-09-08 04:27:09 +08:00
|
|
|
bool
|
2011-02-18 09:44:25 +08:00
|
|
|
UserSettingsController::InitializeSettingsController (UserSettingsControllerSP &controller_sp,
|
2010-09-08 04:27:09 +08:00
|
|
|
SettingEntry *global_settings,
|
|
|
|
SettingEntry *instance_settings)
|
|
|
|
{
|
2011-02-18 09:44:25 +08:00
|
|
|
const UserSettingsControllerSP &parent = controller_sp->GetParent ();
|
2010-09-08 04:27:09 +08:00
|
|
|
if (parent)
|
2010-11-19 11:46:01 +08:00
|
|
|
parent->RegisterChild (controller_sp);
|
2010-09-08 04:27:09 +08:00
|
|
|
|
2010-09-09 01:48:55 +08:00
|
|
|
controller_sp->CreateSettingsVector (global_settings, true);
|
|
|
|
controller_sp->CreateSettingsVector (instance_settings, false);
|
2010-09-08 04:27:09 +08:00
|
|
|
|
2010-09-09 01:48:55 +08:00
|
|
|
controller_sp->InitializeGlobalVariables ();
|
2010-09-08 04:27:09 +08:00
|
|
|
controller_sp->CreateDefaultInstanceSettings ();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-02-18 09:44:25 +08:00
|
|
|
UserSettingsController::FinalizeSettingsController (UserSettingsControllerSP &controller_sp)
|
2010-09-08 04:27:09 +08:00
|
|
|
{
|
2011-02-18 09:44:25 +08:00
|
|
|
const UserSettingsControllerSP &parent = controller_sp->GetParent ();
|
2010-09-08 04:27:09 +08:00
|
|
|
if (parent)
|
|
|
|
parent->RemoveChild (controller_sp);
|
|
|
|
}
|
|
|
|
|
2010-09-04 08:03:46 +08:00
|
|
|
void
|
|
|
|
UserSettingsController::InitializeGlobalVariables ()
|
|
|
|
{
|
|
|
|
int num_entries;
|
2011-04-20 06:32:36 +08:00
|
|
|
const char *prefix = GetLevelName().GetCString();
|
2010-09-04 08:03:46 +08:00
|
|
|
|
2010-09-21 04:44:43 +08:00
|
|
|
num_entries = m_settings.global_settings.size();
|
|
|
|
for (int i = 0; i < num_entries; ++i)
|
2010-09-04 08:03:46 +08:00
|
|
|
{
|
2011-02-18 09:44:25 +08:00
|
|
|
const SettingEntry &entry = m_settings.global_settings[i];
|
2010-09-21 04:44:43 +08:00
|
|
|
if (entry.default_value != NULL)
|
2010-09-04 08:03:46 +08:00
|
|
|
{
|
2010-09-21 04:44:43 +08:00
|
|
|
StreamString full_name;
|
|
|
|
if (prefix[0] != '\0')
|
|
|
|
full_name.Printf ("%s.%s", prefix, entry.var_name);
|
|
|
|
else
|
|
|
|
full_name.Printf ("%s", entry.var_name);
|
2011-02-18 09:44:25 +08:00
|
|
|
SetVariable (full_name.GetData(), entry.default_value, eVarSetOperationAssign, false, "");
|
2010-09-04 08:03:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-18 09:44:25 +08:00
|
|
|
const UserSettingsControllerSP &
|
2010-09-04 08:03:46 +08:00
|
|
|
UserSettingsController::GetParent ()
|
|
|
|
{
|
|
|
|
return m_settings.parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-02-18 09:44:25 +08:00
|
|
|
UserSettingsController::RegisterChild (const UserSettingsControllerSP &child)
|
2010-09-04 08:03:46 +08:00
|
|
|
{
|
|
|
|
Mutex::Locker locker (m_children_mutex);
|
|
|
|
|
|
|
|
// Verify child is not already in m_children.
|
|
|
|
size_t num_children = m_children.size();
|
|
|
|
bool found = false;
|
|
|
|
for (size_t i = 0; i < num_children; ++i)
|
|
|
|
{
|
|
|
|
if (m_children[i].get() == child.get())
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add child to m_children.
|
|
|
|
if (! found)
|
|
|
|
m_children.push_back (child);
|
|
|
|
}
|
|
|
|
|
|
|
|
const ConstString &
|
|
|
|
UserSettingsController::GetLevelName ()
|
|
|
|
{
|
|
|
|
return m_settings.level_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
UserSettingsController::GetNumChildren ()
|
|
|
|
{
|
|
|
|
return m_children.size();
|
|
|
|
}
|
|
|
|
|
2011-02-18 09:44:25 +08:00
|
|
|
const UserSettingsControllerSP
|
2010-09-04 08:03:46 +08:00
|
|
|
UserSettingsController::GetChildAtIndex (size_t index)
|
|
|
|
{
|
|
|
|
if (index < m_children.size())
|
|
|
|
return m_children[index];
|
|
|
|
|
2011-02-18 09:44:25 +08:00
|
|
|
UserSettingsControllerSP dummy_value;
|
2010-09-04 08:03:46 +08:00
|
|
|
|
|
|
|
return dummy_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
const SettingEntry *
|
|
|
|
UserSettingsController::GetGlobalEntry (const ConstString &var_name)
|
|
|
|
{
|
|
|
|
|
|
|
|
for (int i = 0; i < m_settings.global_settings.size(); ++i)
|
|
|
|
{
|
2011-02-18 09:44:25 +08:00
|
|
|
const SettingEntry &entry = m_settings.global_settings[i];
|
2010-09-04 08:03:46 +08:00
|
|
|
ConstString entry_name (entry.var_name);
|
|
|
|
if (entry_name == var_name)
|
|
|
|
return &entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const SettingEntry *
|
|
|
|
UserSettingsController::GetInstanceEntry (const ConstString &const_var_name)
|
|
|
|
{
|
|
|
|
|
|
|
|
for (int i = 0; i < m_settings.instance_settings.size(); ++i)
|
|
|
|
{
|
|
|
|
SettingEntry &entry = m_settings.instance_settings[i];
|
|
|
|
ConstString entry_name (entry.var_name);
|
|
|
|
if (entry_name == const_var_name)
|
|
|
|
return &entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UserSettingsController::BuildParentPrefix (std::string &parent_prefix)
|
|
|
|
{
|
2011-02-18 09:44:25 +08:00
|
|
|
UserSettingsControllerSP parent = GetParent();
|
2010-09-04 08:03:46 +08:00
|
|
|
if (parent.get() != NULL)
|
|
|
|
{
|
|
|
|
parent->BuildParentPrefix (parent_prefix);
|
|
|
|
if (parent_prefix.length() > 0)
|
|
|
|
parent_prefix.append (".");
|
|
|
|
}
|
2011-04-20 06:32:36 +08:00
|
|
|
parent_prefix.append (GetLevelName().GetCString());
|
2010-09-04 08:03:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-02-18 09:44:25 +08:00
|
|
|
UserSettingsController::RemoveChild (const UserSettingsControllerSP &child)
|
2010-09-04 08:03:46 +08:00
|
|
|
{
|
|
|
|
Mutex::Locker locker (m_children_mutex);
|
2011-02-18 09:44:25 +08:00
|
|
|
std::vector<UserSettingsControllerSP>::iterator pos, end = m_children.end();
|
2010-09-04 08:03:46 +08:00
|
|
|
|
|
|
|
for (pos = m_children.begin(); pos != end; ++pos)
|
|
|
|
{
|
2011-02-18 09:44:25 +08:00
|
|
|
UserSettingsControllerSP entry = *pos;
|
2010-09-04 08:03:46 +08:00
|
|
|
if (entry == child)
|
|
|
|
{
|
|
|
|
m_children.erase (pos);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Error
|
|
|
|
UserSettingsController::SetVariable (const char *full_dot_name,
|
|
|
|
const char *value,
|
2011-02-18 09:44:25 +08:00
|
|
|
const VarSetOperationType op,
|
2010-09-04 08:03:46 +08:00
|
|
|
const bool override,
|
2010-09-09 14:25:08 +08:00
|
|
|
const char *debugger_instance_name,
|
2010-09-04 08:03:46 +08:00
|
|
|
const char *index_value)
|
|
|
|
{
|
|
|
|
Error err;
|
|
|
|
ConstString const_var_name;
|
|
|
|
const ConstString &default_name = InstanceSettings::GetDefaultName();
|
|
|
|
|
|
|
|
Args names = UserSettingsController::BreakNameIntoPieces (full_dot_name);
|
|
|
|
int num_pieces = names.GetArgumentCount();
|
|
|
|
|
|
|
|
if (num_pieces < 1)
|
|
|
|
{
|
|
|
|
err.SetErrorStringWithFormat ("'%s' is not a valid variable name; cannot assign value.\n", full_dot_name);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
ConstString prefix (names.GetArgumentAtIndex (0));
|
|
|
|
|
|
|
|
if ((prefix == m_settings.level_name)
|
|
|
|
|| (m_settings.level_name.GetLength() == 0))
|
|
|
|
{
|
|
|
|
|
|
|
|
if (prefix == m_settings.level_name)
|
|
|
|
{
|
|
|
|
names.Shift ();
|
|
|
|
num_pieces = names.GetArgumentCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num_pieces == 0)
|
|
|
|
{
|
|
|
|
err.SetErrorString ("No variable name specified; cannot assign value.\n");
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
else if (num_pieces == 1)
|
|
|
|
{
|
|
|
|
|
|
|
|
// Must be one of the class-wide settings.
|
|
|
|
|
|
|
|
const_var_name.SetCString (names.GetArgumentAtIndex (0));
|
|
|
|
const SettingEntry *entry = GetGlobalEntry (const_var_name);
|
|
|
|
if (entry)
|
|
|
|
{
|
|
|
|
UserSettingsController::VerifyOperationForType (entry->var_type, op, const_var_name, err);
|
|
|
|
|
|
|
|
if (err.Fail())
|
|
|
|
return err;
|
|
|
|
|
|
|
|
if ((value == NULL || value[0] == '\0')
|
2011-02-18 09:44:25 +08:00
|
|
|
&& (op == eVarSetOperationAssign))
|
2010-09-04 08:03:46 +08:00
|
|
|
{
|
2011-02-18 09:44:25 +08:00
|
|
|
if (entry->var_type != eSetVarTypeEnum)
|
2010-09-04 08:03:46 +08:00
|
|
|
value = entry->default_value;
|
|
|
|
else
|
|
|
|
value = entry->enum_values[0].string_value;
|
|
|
|
}
|
2010-09-19 10:33:57 +08:00
|
|
|
SetGlobalVariable (const_var_name, index_value, value, *entry, op, err);
|
2010-09-04 08:03:46 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// MIGHT be instance variable, to be for ALL instances.
|
|
|
|
|
|
|
|
entry = GetInstanceEntry (const_var_name);
|
|
|
|
if (entry == NULL)
|
|
|
|
{
|
|
|
|
err.SetErrorStringWithFormat ("Unable to find variable '%s.%s'; cannot assign value.\n",
|
2011-04-20 06:32:36 +08:00
|
|
|
prefix.GetCString(), const_var_name.GetCString());
|
2010-09-04 08:03:46 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
UserSettingsController::VerifyOperationForType (entry->var_type, op, const_var_name, err);
|
|
|
|
|
|
|
|
if (err.Fail())
|
|
|
|
return err;
|
|
|
|
|
|
|
|
if ((value == NULL || value[0] == '\0')
|
2011-02-18 09:44:25 +08:00
|
|
|
&& (op == eVarSetOperationAssign))
|
2010-09-04 08:03:46 +08:00
|
|
|
{
|
2011-02-18 09:44:25 +08:00
|
|
|
if (entry->var_type != eSetVarTypeEnum)
|
2010-09-04 08:03:46 +08:00
|
|
|
value = entry->default_value;
|
|
|
|
else
|
|
|
|
value = entry->enum_values[0].string_value;
|
|
|
|
}
|
|
|
|
|
2010-09-09 14:25:08 +08:00
|
|
|
if ((m_settings.level_name.GetLength() > 0)
|
|
|
|
|| strlen (debugger_instance_name) == 0)
|
|
|
|
{
|
|
|
|
// Set the default settings
|
|
|
|
m_default_settings->UpdateInstanceSettingsVariable (const_var_name, index_value, value,
|
|
|
|
default_name, *entry, op, err, true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// We're at the Debugger level; find the correct debugger instance and set those settings
|
|
|
|
StreamString tmp_name;
|
|
|
|
if (debugger_instance_name[0] != '[')
|
|
|
|
tmp_name.Printf ("[%s]", debugger_instance_name);
|
|
|
|
else
|
|
|
|
tmp_name.Printf ("%s", debugger_instance_name);
|
|
|
|
ConstString dbg_name (tmp_name.GetData());
|
|
|
|
InstanceSettings *dbg_settings = FindSettingsForInstance (dbg_name);
|
|
|
|
if (dbg_settings)
|
|
|
|
dbg_settings->UpdateInstanceSettingsVariable (const_var_name, index_value, value, dbg_name,
|
|
|
|
*entry, op, err, false);
|
|
|
|
}
|
|
|
|
|
2010-09-04 08:03:46 +08:00
|
|
|
if (override)
|
|
|
|
{
|
|
|
|
OverrideAllInstances (const_var_name, value, op, index_value, err);
|
|
|
|
|
|
|
|
// Update all pending records as well.
|
2011-02-18 09:44:25 +08:00
|
|
|
// std::map<std::string, InstanceSettingsSP>::iterator pos, end = m_pending_settings.end();
|
2010-09-27 08:30:10 +08:00
|
|
|
// for (pos = m_pending_settings.begin(); pos != end; end++)
|
|
|
|
// {
|
|
|
|
// const ConstString instance_name (pos->first.c_str());
|
2011-02-18 09:44:25 +08:00
|
|
|
// InstanceSettingsSP setting_sp = pos->second;
|
2010-09-27 08:30:10 +08:00
|
|
|
// setting_sp->UpdateInstanceSettingsVariable (const_var_name, index_value, value,
|
|
|
|
// instance_name, *entry, op, err, true);
|
|
|
|
// }
|
2010-09-04 08:03:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Either a child's setting or an instance setting.
|
|
|
|
|
|
|
|
if (names.GetArgumentAtIndex(0)[0] == '[')
|
|
|
|
{
|
|
|
|
// An instance setting. Supposedly.
|
|
|
|
|
|
|
|
ConstString instance_name (names.GetArgumentAtIndex (0));
|
|
|
|
|
|
|
|
// First verify that there is only one more name.
|
|
|
|
|
|
|
|
names.Shift();
|
|
|
|
|
|
|
|
if (names.GetArgumentCount() != 1)
|
|
|
|
{
|
|
|
|
err.SetErrorStringWithFormat ("Invalid variable name format '%s'; cannot assign value.\n",
|
|
|
|
full_dot_name);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Next verify that it is a valid instance setting name.
|
|
|
|
|
|
|
|
const_var_name.SetCString (names.GetArgumentAtIndex (0));
|
|
|
|
const SettingEntry *entry = GetInstanceEntry (const_var_name);
|
|
|
|
|
|
|
|
if (entry == NULL)
|
|
|
|
{
|
|
|
|
err.SetErrorStringWithFormat ("Unknown instance variable '%s'; cannot assign value.\n",
|
2011-04-20 06:32:36 +08:00
|
|
|
const_var_name.GetCString());
|
2010-09-04 08:03:46 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
UserSettingsController::VerifyOperationForType (entry->var_type, op, const_var_name, err);
|
|
|
|
|
|
|
|
if (err.Fail())
|
|
|
|
return err;
|
|
|
|
|
|
|
|
if ((value == NULL || value[0] == '\0')
|
2011-02-18 09:44:25 +08:00
|
|
|
&& (op == eVarSetOperationAssign))
|
2010-09-04 08:03:46 +08:00
|
|
|
{
|
2011-02-18 09:44:25 +08:00
|
|
|
if (entry->var_type != eSetVarTypeEnum)
|
2010-09-04 08:03:46 +08:00
|
|
|
value = entry->default_value;
|
|
|
|
else
|
|
|
|
value = entry->enum_values[0].string_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now look for existing instance with given instance name; if not found, find or create pending
|
|
|
|
// setting for instance with given name.
|
|
|
|
|
|
|
|
InstanceSettings *current_settings = FindSettingsForInstance (instance_name);
|
|
|
|
|
|
|
|
if (current_settings != NULL)
|
|
|
|
{
|
|
|
|
current_settings->UpdateInstanceSettingsVariable (const_var_name, index_value, value,
|
|
|
|
instance_name, *entry, op, err, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Instance does not currently exist; make or update a pending setting for it.
|
2011-02-18 09:44:25 +08:00
|
|
|
InstanceSettingsSP current_settings_sp = PendingSettingsForInstance (instance_name);
|
2010-09-04 08:03:46 +08:00
|
|
|
|
|
|
|
// Now we have a settings record, update it appropriately.
|
|
|
|
|
|
|
|
current_settings_sp->UpdateInstanceSettingsVariable (const_var_name, index_value, value,
|
|
|
|
instance_name, *entry, op, err, true);
|
|
|
|
|
|
|
|
{ // Scope for mutex.
|
|
|
|
Mutex::Locker locker (m_pending_settings_mutex);
|
2011-04-20 06:32:36 +08:00
|
|
|
m_pending_settings[instance_name.GetCString()] = current_settings_sp;
|
2010-09-04 08:03:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (override)
|
|
|
|
{
|
|
|
|
OverrideAllInstances (const_var_name, value, op, index_value, err);
|
|
|
|
|
|
|
|
// Update all pending records as well.
|
2011-02-18 09:44:25 +08:00
|
|
|
std::map<std::string, InstanceSettingsSP>::iterator pos;
|
|
|
|
std::map<std::string, InstanceSettingsSP>::iterator end = m_pending_settings.end();
|
2010-09-04 08:03:46 +08:00
|
|
|
for (pos = m_pending_settings.begin(); pos != end; end++)
|
|
|
|
{
|
|
|
|
const ConstString tmp_inst_name (pos->first.c_str());
|
2011-02-18 09:44:25 +08:00
|
|
|
InstanceSettingsSP setting_sp = pos->second;
|
2010-09-04 08:03:46 +08:00
|
|
|
setting_sp->UpdateInstanceSettingsVariable (const_var_name, index_value, value,
|
|
|
|
tmp_inst_name, *entry, op, err, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// A child setting.
|
2011-02-18 09:44:25 +08:00
|
|
|
UserSettingsControllerSP child;
|
2010-09-04 08:03:46 +08:00
|
|
|
ConstString child_prefix (names.GetArgumentAtIndex (0));
|
|
|
|
int num_children = GetNumChildren();
|
|
|
|
bool found = false;
|
|
|
|
for (int i = 0; i < num_children && !found; ++i)
|
|
|
|
{
|
|
|
|
child = GetChildAtIndex (i);
|
|
|
|
ConstString current_prefix = child->GetLevelName();
|
|
|
|
if (current_prefix == child_prefix)
|
|
|
|
{
|
|
|
|
found = true;
|
|
|
|
std::string new_name;
|
|
|
|
for (int j = 0; j < names.GetArgumentCount(); ++j)
|
|
|
|
{
|
|
|
|
if (j > 0)
|
|
|
|
new_name += '.';
|
|
|
|
new_name += names.GetArgumentAtIndex (j);
|
|
|
|
}
|
2010-09-09 14:25:08 +08:00
|
|
|
return child->SetVariable (new_name.c_str(), value, op, override, debugger_instance_name,
|
|
|
|
index_value);
|
2010-09-04 08:03:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
err.SetErrorStringWithFormat ("Unable to find variable '%s'; cannot assign value.\n",
|
|
|
|
full_dot_name);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
err.SetErrorStringWithFormat ("'%s' is not a valid level name; was expecting '%s'. Cannot assign value.\n",
|
2011-04-20 06:32:36 +08:00
|
|
|
prefix.GetCString(), m_settings.level_name.GetCString());
|
2010-09-04 08:03:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
StringList
|
2010-09-19 10:33:57 +08:00
|
|
|
UserSettingsController::GetVariable
|
|
|
|
(
|
|
|
|
const char *full_dot_name,
|
2011-02-18 09:44:25 +08:00
|
|
|
SettableVariableType &var_type,
|
2010-09-21 04:44:43 +08:00
|
|
|
const char *debugger_instance_name,
|
|
|
|
Error &err
|
2010-09-19 10:33:57 +08:00
|
|
|
)
|
2010-09-04 08:03:46 +08:00
|
|
|
{
|
|
|
|
Args names = UserSettingsController::BreakNameIntoPieces (full_dot_name);
|
|
|
|
ConstString const_var_name;
|
|
|
|
StringList value;
|
|
|
|
|
|
|
|
int num_pieces = names.GetArgumentCount();
|
|
|
|
|
|
|
|
ConstString prefix (names.GetArgumentAtIndex (0));
|
|
|
|
const_var_name.SetCString (names.GetArgumentAtIndex (num_pieces - 1));
|
|
|
|
|
|
|
|
const SettingEntry *global_entry = GetGlobalEntry (const_var_name);
|
|
|
|
const SettingEntry *instance_entry = GetInstanceEntry (const_var_name);
|
|
|
|
|
|
|
|
if ((prefix != m_settings.level_name)
|
|
|
|
&& (m_settings.level_name.GetLength () > 0))
|
|
|
|
{
|
2010-09-21 04:44:43 +08:00
|
|
|
err.SetErrorString ("Invalid variable name");
|
2010-09-04 08:03:46 +08:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
// prefix name matched; remove it from names.
|
|
|
|
if (m_settings.level_name.GetLength() > 0)
|
|
|
|
names.Shift();
|
|
|
|
|
|
|
|
// Should we pass this off to a child? If there is more than one name piece left, and the next name piece
|
|
|
|
// matches a child prefix, then yes.
|
|
|
|
|
2011-02-18 09:44:25 +08:00
|
|
|
UserSettingsControllerSP child;
|
2010-09-04 08:03:46 +08:00
|
|
|
if (names.GetArgumentCount() > 1)
|
|
|
|
{
|
|
|
|
ConstString child_prefix (names.GetArgumentAtIndex (0));
|
|
|
|
bool found = false;
|
|
|
|
for (int i = 0; i < m_children.size() && !found; ++i)
|
|
|
|
{
|
|
|
|
if (child_prefix == m_children[i]->GetLevelName())
|
|
|
|
{
|
|
|
|
found = true;
|
|
|
|
child = m_children[i];
|
|
|
|
std::string new_name;
|
|
|
|
for (int j = 0; j < names.GetArgumentCount(); ++j)
|
|
|
|
{
|
|
|
|
if (j > 0)
|
|
|
|
new_name += '.';
|
|
|
|
new_name += names.GetArgumentAtIndex (j);
|
|
|
|
}
|
2010-09-21 04:44:43 +08:00
|
|
|
return child->GetVariable (new_name.c_str(), var_type, debugger_instance_name, err);
|
2010-09-04 08:03:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
// Cannot be handled by a child, because name did not match any child prefixes.
|
|
|
|
// Cannot be a class-wide variable because there are too many name pieces.
|
|
|
|
|
|
|
|
if (instance_entry != NULL)
|
|
|
|
{
|
|
|
|
var_type = instance_entry->var_type;
|
|
|
|
ConstString instance_name (names.GetArgumentAtIndex (0));
|
|
|
|
InstanceSettings *current_settings = FindSettingsForInstance (instance_name);
|
|
|
|
|
|
|
|
if (current_settings != NULL)
|
|
|
|
{
|
2010-09-21 05:37:42 +08:00
|
|
|
current_settings->GetInstanceSettingsValue (*instance_entry, const_var_name, value, &err);
|
2010-09-04 08:03:46 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Look for instance name setting in pending settings.
|
|
|
|
|
2011-04-20 06:32:36 +08:00
|
|
|
std::string inst_name_str = instance_name.GetCString();
|
2011-02-18 09:44:25 +08:00
|
|
|
std::map<std::string, InstanceSettingsSP>::iterator pos;
|
2010-09-04 08:03:46 +08:00
|
|
|
|
|
|
|
pos = m_pending_settings.find (inst_name_str);
|
|
|
|
if (pos != m_pending_settings.end())
|
|
|
|
{
|
2011-02-18 09:44:25 +08:00
|
|
|
InstanceSettingsSP settings_sp = pos->second;
|
2010-09-21 05:37:42 +08:00
|
|
|
settings_sp->GetInstanceSettingsValue (*instance_entry, const_var_name, value, &err);
|
2010-09-04 08:03:46 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-09-09 14:25:08 +08:00
|
|
|
if (m_settings.level_name.GetLength() > 0)
|
|
|
|
{
|
|
|
|
// No valid instance name; assume they want the default settings.
|
2010-09-21 05:37:42 +08:00
|
|
|
m_default_settings->GetInstanceSettingsValue (*instance_entry, const_var_name, value, &err);
|
2010-09-09 14:25:08 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// We're at the Debugger level; use the debugger's instance settings.
|
|
|
|
StreamString tmp_name;
|
|
|
|
if (debugger_instance_name[0] != '[')
|
|
|
|
tmp_name.Printf ("[%s]", debugger_instance_name);
|
|
|
|
else
|
|
|
|
tmp_name.Printf ("%s", debugger_instance_name);
|
|
|
|
ConstString dbg_name (debugger_instance_name);
|
|
|
|
InstanceSettings *dbg_settings = FindSettingsForInstance (dbg_name);
|
|
|
|
if (dbg_settings)
|
2010-09-21 05:37:42 +08:00
|
|
|
dbg_settings->GetInstanceSettingsValue (*instance_entry, const_var_name, value, &err);
|
2010-09-09 14:25:08 +08:00
|
|
|
}
|
2010-09-04 08:03:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2010-09-21 04:44:43 +08:00
|
|
|
err.SetErrorString ("Invalid variable name");
|
2010-09-04 08:03:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Only one name left. It must belong to the current level, or be an error.
|
|
|
|
if ((global_entry == NULL)
|
|
|
|
&& (instance_entry == NULL))
|
|
|
|
{
|
2010-09-21 04:44:43 +08:00
|
|
|
err.SetErrorString ("Invalid variable name");
|
2010-09-04 08:03:46 +08:00
|
|
|
}
|
|
|
|
else if (global_entry)
|
|
|
|
{
|
|
|
|
var_type = global_entry->var_type;
|
2010-09-21 04:44:43 +08:00
|
|
|
GetGlobalVariable (const_var_name, value, err);
|
2010-09-04 08:03:46 +08:00
|
|
|
}
|
|
|
|
else if (instance_entry)
|
|
|
|
{
|
|
|
|
var_type = instance_entry->var_type;
|
2010-09-09 14:25:08 +08:00
|
|
|
if (m_settings.level_name.GetLength() > 0)
|
2010-09-21 05:37:42 +08:00
|
|
|
m_default_settings->GetInstanceSettingsValue (*instance_entry, const_var_name, value, &err);
|
2010-09-09 14:25:08 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// We're at the Debugger level; use the debugger's instance settings.
|
|
|
|
StreamString tmp_name;
|
|
|
|
if (debugger_instance_name[0] != '[')
|
|
|
|
tmp_name.Printf ("[%s]", debugger_instance_name);
|
|
|
|
else
|
|
|
|
tmp_name.Printf ("%s", debugger_instance_name);
|
|
|
|
ConstString dbg_name (tmp_name.GetData());
|
|
|
|
InstanceSettings *dbg_settings = FindSettingsForInstance (dbg_name);
|
|
|
|
if (dbg_settings)
|
2010-09-21 05:37:42 +08:00
|
|
|
dbg_settings->GetInstanceSettingsValue (*instance_entry, const_var_name, value, &err);
|
2010-09-09 14:25:08 +08:00
|
|
|
}
|
2010-09-04 08:03:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UserSettingsController::RemovePendingSettings (const ConstString &instance_name)
|
|
|
|
{
|
2010-09-09 01:48:55 +08:00
|
|
|
StreamString tmp_name;
|
|
|
|
|
|
|
|
// Add surrounding brackets to instance name if not already present.
|
|
|
|
|
2011-04-20 06:32:36 +08:00
|
|
|
if (instance_name.GetCString()[0] != '[')
|
|
|
|
tmp_name.Printf ("[%s]", instance_name.GetCString());
|
2010-09-09 01:48:55 +08:00
|
|
|
else
|
2011-04-20 06:32:36 +08:00
|
|
|
tmp_name.Printf ("%s", instance_name.GetCString());
|
2010-09-09 01:48:55 +08:00
|
|
|
|
|
|
|
std::string instance_name_str (tmp_name.GetData());
|
2011-02-18 09:44:25 +08:00
|
|
|
std::map<std::string, InstanceSettingsSP>::iterator pos;
|
2010-09-04 08:03:46 +08:00
|
|
|
Mutex::Locker locker (m_pending_settings_mutex);
|
|
|
|
|
|
|
|
m_pending_settings.erase (instance_name_str);
|
|
|
|
}
|
|
|
|
|
2011-02-18 09:44:25 +08:00
|
|
|
const InstanceSettingsSP &
|
2010-09-04 08:03:46 +08:00
|
|
|
UserSettingsController::FindPendingSettings (const ConstString &instance_name)
|
|
|
|
{
|
2011-02-18 09:44:25 +08:00
|
|
|
std::map<std::string, InstanceSettingsSP>::iterator pos;
|
2010-09-09 01:48:55 +08:00
|
|
|
StreamString tmp_name;
|
|
|
|
|
|
|
|
// Add surrounding brackets to instance name if not already present.
|
|
|
|
|
2011-04-20 06:32:36 +08:00
|
|
|
if (instance_name.GetCString()[0] != '[')
|
|
|
|
tmp_name.Printf ("[%s]", instance_name.GetCString());
|
2010-09-09 01:48:55 +08:00
|
|
|
else
|
2011-04-20 06:32:36 +08:00
|
|
|
tmp_name.Printf ("%s", instance_name.GetCString());
|
2010-09-09 01:48:55 +08:00
|
|
|
|
|
|
|
std::string instance_name_str (tmp_name.GetData()); // Need std::string for std::map look-up
|
2010-09-04 08:03:46 +08:00
|
|
|
|
|
|
|
{ // Scope for mutex.
|
|
|
|
Mutex::Locker locker (m_pending_settings_mutex);
|
|
|
|
|
|
|
|
pos = m_pending_settings.find (instance_name_str);
|
|
|
|
if (pos != m_pending_settings.end())
|
|
|
|
return pos->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_default_settings;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UserSettingsController::CreateDefaultInstanceSettings ()
|
|
|
|
{
|
|
|
|
Error err;
|
|
|
|
const ConstString &default_name = InstanceSettings::GetDefaultName();
|
|
|
|
for (int i = 0; i < m_settings.instance_settings.size(); ++i)
|
|
|
|
{
|
|
|
|
SettingEntry &entry = m_settings.instance_settings[i];
|
|
|
|
ConstString var_name (entry.var_name);
|
|
|
|
const char *value = entry.default_value;
|
|
|
|
|
2011-02-18 09:44:25 +08:00
|
|
|
if (entry.var_type == eSetVarTypeEnum)
|
2010-09-04 08:03:46 +08:00
|
|
|
value = entry.enum_values[0].string_value;
|
|
|
|
|
|
|
|
m_default_settings->UpdateInstanceSettingsVariable (var_name, NULL, value, default_name, entry,
|
2011-02-18 09:44:25 +08:00
|
|
|
eVarSetOperationAssign, err, true);
|
2010-09-04 08:03:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-02-18 09:44:25 +08:00
|
|
|
UserSettingsController::CopyDefaultSettings (const InstanceSettingsSP &actual_settings,
|
2010-09-04 08:03:46 +08:00
|
|
|
const ConstString &instance_name,
|
|
|
|
bool pending)
|
|
|
|
{
|
|
|
|
Error err;
|
|
|
|
for (int i = 0; i < m_settings.instance_settings.size(); ++i)
|
|
|
|
{
|
|
|
|
SettingEntry &entry = m_settings.instance_settings[i];
|
|
|
|
ConstString var_name (entry.var_name);
|
|
|
|
StringList value;
|
2010-09-21 05:37:42 +08:00
|
|
|
m_default_settings->GetInstanceSettingsValue (entry, var_name, value, NULL);
|
2010-09-04 08:03:46 +08:00
|
|
|
|
|
|
|
std::string value_str;
|
|
|
|
if (value.GetSize() == 1)
|
|
|
|
value_str.append (value.GetStringAtIndex (0));
|
|
|
|
else if (value.GetSize() > 1)
|
|
|
|
{
|
|
|
|
for (int j = 0; j < value.GetSize(); ++j)
|
|
|
|
{
|
|
|
|
if (j > 0)
|
|
|
|
value_str.append (" ");
|
|
|
|
value_str.append (value.GetStringAtIndex (j));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
actual_settings->UpdateInstanceSettingsVariable (var_name, NULL, value_str.c_str(), instance_name, entry,
|
2011-02-18 09:44:25 +08:00
|
|
|
eVarSetOperationAssign, err, pending);
|
2010-09-04 08:03:46 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-18 09:44:25 +08:00
|
|
|
InstanceSettingsSP
|
2010-09-04 08:03:46 +08:00
|
|
|
UserSettingsController::PendingSettingsForInstance (const ConstString &instance_name)
|
|
|
|
{
|
2011-04-20 06:32:36 +08:00
|
|
|
std::string name_str (instance_name.GetCString());
|
2011-02-18 09:44:25 +08:00
|
|
|
std::map<std::string, InstanceSettingsSP>::iterator pos;
|
2010-09-04 08:03:46 +08:00
|
|
|
Mutex::Locker locker (m_pending_settings_mutex);
|
|
|
|
|
|
|
|
pos = m_pending_settings.find (name_str);
|
|
|
|
if (pos != m_pending_settings.end())
|
2010-09-19 10:33:57 +08:00
|
|
|
{
|
2011-02-18 09:44:25 +08:00
|
|
|
InstanceSettingsSP settings_sp = pos->second;
|
2010-09-04 08:03:46 +08:00
|
|
|
return settings_sp;
|
2010-09-19 10:33:57 +08:00
|
|
|
}
|
2010-09-04 08:03:46 +08:00
|
|
|
else
|
2010-09-19 10:33:57 +08:00
|
|
|
{
|
2011-04-20 06:32:36 +08:00
|
|
|
InstanceSettingsSP new_settings_sp = CreateInstanceSettings (instance_name.GetCString());
|
2010-09-04 08:03:46 +08:00
|
|
|
CopyDefaultSettings (new_settings_sp, instance_name, true);
|
|
|
|
m_pending_settings[name_str] = new_settings_sp;
|
|
|
|
return new_settings_sp;
|
2010-09-19 10:33:57 +08:00
|
|
|
}
|
|
|
|
|
2010-09-04 08:03:46 +08:00
|
|
|
// Should never reach this line.
|
|
|
|
|
2011-02-18 09:44:25 +08:00
|
|
|
InstanceSettingsSP dummy;
|
2010-09-04 08:03:46 +08:00
|
|
|
|
|
|
|
return dummy;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-04-20 06:32:36 +08:00
|
|
|
UserSettingsController::GetAllDefaultSettingValues (Stream &strm)
|
2010-09-04 08:03:46 +08:00
|
|
|
{
|
|
|
|
std::string parent_prefix;
|
|
|
|
BuildParentPrefix (parent_prefix);
|
|
|
|
|
|
|
|
for (int i = 0; i < m_settings.instance_settings.size(); ++i)
|
|
|
|
{
|
|
|
|
SettingEntry &entry = m_settings.instance_settings[i];
|
|
|
|
ConstString var_name (entry.var_name);
|
2011-04-20 06:32:36 +08:00
|
|
|
StringList value;
|
|
|
|
m_default_settings->GetInstanceSettingsValue (entry, var_name, value, NULL);
|
|
|
|
|
|
|
|
if (!parent_prefix.empty())
|
|
|
|
strm.Printf ("%s.", parent_prefix.c_str());
|
|
|
|
|
|
|
|
DumpValue (var_name.GetCString(),
|
|
|
|
entry.var_type,
|
|
|
|
value,
|
|
|
|
strm);
|
2010-09-04 08:03:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-04-20 06:32:36 +08:00
|
|
|
UserSettingsController::GetAllPendingSettingValues (Stream &strm)
|
2010-09-04 08:03:46 +08:00
|
|
|
{
|
2011-02-18 09:44:25 +08:00
|
|
|
std::map<std::string, InstanceSettingsSP>::iterator pos;
|
2010-09-04 08:03:46 +08:00
|
|
|
|
|
|
|
std::string parent_prefix;
|
|
|
|
BuildParentPrefix (parent_prefix);
|
|
|
|
const char *prefix = parent_prefix.c_str();
|
|
|
|
|
|
|
|
for (pos = m_pending_settings.begin(); pos != m_pending_settings.end(); ++pos)
|
|
|
|
{
|
|
|
|
std::string tmp_name = pos->first;
|
2011-02-18 09:44:25 +08:00
|
|
|
InstanceSettingsSP settings_sp = pos->second;
|
2010-09-04 08:03:46 +08:00
|
|
|
|
|
|
|
const ConstString instance_name (tmp_name.c_str());
|
|
|
|
|
|
|
|
for (int i = 0; i < m_settings.instance_settings.size(); ++i)
|
|
|
|
{
|
|
|
|
SettingEntry &entry = m_settings.instance_settings[i];
|
|
|
|
ConstString var_name (entry.var_name);
|
|
|
|
StringList tmp_value;
|
2010-09-21 05:37:42 +08:00
|
|
|
settings_sp->GetInstanceSettingsValue (entry, var_name, tmp_value, NULL);
|
2010-09-04 08:03:46 +08:00
|
|
|
|
|
|
|
StreamString value_str;
|
|
|
|
|
|
|
|
if (tmp_value.GetSize() == 0)
|
2010-09-15 13:35:14 +08:00
|
|
|
value_str.Printf ("");
|
|
|
|
else if (tmp_value.GetSize() == 1)
|
2010-09-04 08:03:46 +08:00
|
|
|
value_str.Printf ("%s", tmp_value.GetStringAtIndex (0));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (int j = 0; j < tmp_value.GetSize(); ++j)
|
|
|
|
value_str.Printf ("%s ", tmp_value.GetStringAtIndex (j));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parent_prefix.length() > 0)
|
|
|
|
{
|
2011-04-20 06:32:36 +08:00
|
|
|
strm.Printf ("%s.%s.%s (%s) = '%s' [pending]\n", prefix, instance_name.GetCString(),
|
|
|
|
var_name.GetCString(), UserSettingsController::GetTypeString (entry.var_type),
|
2010-09-04 08:03:46 +08:00
|
|
|
value_str.GetData());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-04-20 06:32:36 +08:00
|
|
|
strm.Printf ("%s (%s) = '%s' [pending]\n", var_name.GetCString(),
|
2010-09-04 08:03:46 +08:00
|
|
|
UserSettingsController::GetTypeString (entry.var_type),
|
|
|
|
value_str.GetData());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
InstanceSettings *
|
|
|
|
UserSettingsController::FindSettingsForInstance (const ConstString &instance_name)
|
|
|
|
{
|
2011-04-20 06:32:36 +08:00
|
|
|
std::string instance_name_str (instance_name.GetCString());
|
|
|
|
Mutex::Locker locker (m_live_settings_mutex);
|
|
|
|
InstanceSettingsMap::iterator pos = m_live_settings.find (instance_name_str);
|
2010-09-04 08:03:46 +08:00
|
|
|
if (pos != m_live_settings.end ())
|
2011-04-20 06:32:36 +08:00
|
|
|
return pos->second;
|
2010-09-04 08:03:46 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UserSettingsController::GetAllInstanceVariableValues (CommandInterpreter &interpreter,
|
2011-04-20 06:32:36 +08:00
|
|
|
Stream &strm)
|
2010-09-04 08:03:46 +08:00
|
|
|
{
|
|
|
|
std::string parent_prefix;
|
|
|
|
BuildParentPrefix (parent_prefix);
|
|
|
|
StreamString description;
|
|
|
|
|
2011-04-20 06:32:36 +08:00
|
|
|
Mutex::Locker locker (m_live_settings_mutex);
|
|
|
|
for (InstanceSettingsMap::iterator pos = m_live_settings.begin(); pos != m_live_settings.end(); ++pos)
|
2010-09-04 08:03:46 +08:00
|
|
|
{
|
|
|
|
std::string instance_name = pos->first;
|
|
|
|
InstanceSettings *settings = pos->second;
|
|
|
|
|
|
|
|
for (int i = 0; i < m_settings.instance_settings.size(); ++i)
|
|
|
|
{
|
|
|
|
SettingEntry &entry = m_settings.instance_settings[i];
|
|
|
|
const ConstString var_name (entry.var_name);
|
|
|
|
StringList tmp_value;
|
2010-09-21 05:37:42 +08:00
|
|
|
settings->GetInstanceSettingsValue (entry, var_name, tmp_value, NULL);
|
2010-09-04 08:03:46 +08:00
|
|
|
|
2011-04-20 06:32:36 +08:00
|
|
|
if (!parent_prefix.empty())
|
|
|
|
strm.Printf ("%s.", parent_prefix.c_str());
|
|
|
|
|
|
|
|
DumpValue(var_name.GetCString(), entry.var_type, tmp_value, strm);
|
2010-09-04 08:03:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UserSettingsController::OverrideAllInstances (const ConstString &var_name,
|
|
|
|
const char *value,
|
2011-02-18 09:44:25 +08:00
|
|
|
VarSetOperationType op,
|
2010-09-04 08:03:46 +08:00
|
|
|
const char *index_value,
|
|
|
|
Error &err)
|
|
|
|
{
|
|
|
|
StreamString description;
|
|
|
|
|
2011-04-20 06:32:36 +08:00
|
|
|
Mutex::Locker locker (m_live_settings_mutex);
|
|
|
|
for (InstanceSettingsMap::iterator pos = m_live_settings.begin(); pos != m_live_settings.end(); ++pos)
|
2010-09-04 08:03:46 +08:00
|
|
|
{
|
|
|
|
InstanceSettings *settings = pos->second;
|
|
|
|
StreamString tmp_name;
|
2011-04-20 06:32:36 +08:00
|
|
|
tmp_name.Printf ("[%s]", settings->GetInstanceName().GetCString());
|
2010-09-04 08:03:46 +08:00
|
|
|
const ConstString instance_name (tmp_name.GetData());
|
|
|
|
const SettingEntry *entry = GetInstanceEntry (var_name);
|
|
|
|
settings->UpdateInstanceSettingsVariable (var_name, index_value, value, instance_name, *entry, op, err, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UserSettingsController::RegisterInstanceSettings (InstanceSettings *instance_settings)
|
|
|
|
{
|
|
|
|
Mutex::Locker locker (m_live_settings_mutex);
|
|
|
|
StreamString tmp_name;
|
2011-04-20 06:32:36 +08:00
|
|
|
tmp_name.Printf ("[%s]", instance_settings->GetInstanceName().GetCString());
|
2010-09-04 08:03:46 +08:00
|
|
|
const ConstString instance_name (tmp_name.GetData());
|
2011-04-20 06:32:36 +08:00
|
|
|
std::string instance_name_str (instance_name.GetCString());
|
|
|
|
if (instance_name_str.compare (InstanceSettings::GetDefaultName().GetCString()) != 0)
|
2010-09-04 08:03:46 +08:00
|
|
|
m_live_settings[instance_name_str] = instance_settings;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UserSettingsController::UnregisterInstanceSettings (InstanceSettings *instance)
|
|
|
|
{
|
|
|
|
Mutex::Locker locker (m_live_settings_mutex);
|
|
|
|
StreamString tmp_name;
|
2011-04-20 06:32:36 +08:00
|
|
|
tmp_name.Printf ("[%s]", instance->GetInstanceName().GetCString());
|
2010-09-04 08:03:46 +08:00
|
|
|
std::string instance_name (tmp_name.GetData());
|
|
|
|
|
2011-04-20 06:32:36 +08:00
|
|
|
InstanceSettingsMap::iterator pos = m_live_settings.find (instance_name);
|
2010-09-04 08:03:46 +08:00
|
|
|
if (pos != m_live_settings.end())
|
|
|
|
m_live_settings.erase (pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UserSettingsController::CreateSettingsVector (const SettingEntry *table,
|
|
|
|
bool global)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
while (table[i].var_name != NULL)
|
|
|
|
{
|
|
|
|
const SettingEntry &table_entry = table[i];
|
|
|
|
ConstString const_var_name (table_entry.var_name);
|
|
|
|
SettingEntry new_entry;
|
|
|
|
|
|
|
|
new_entry = table_entry;
|
2011-04-20 06:32:36 +08:00
|
|
|
new_entry.var_name = const_var_name.GetCString();
|
2010-09-04 08:03:46 +08:00
|
|
|
|
|
|
|
if (global)
|
|
|
|
m_settings.global_settings.push_back (new_entry);
|
|
|
|
else
|
|
|
|
m_settings.instance_settings.push_back (new_entry);
|
|
|
|
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// UserSettingsController static methods
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
int
|
|
|
|
FindMaxNameLength (std::vector<SettingEntry> table)
|
|
|
|
{
|
|
|
|
int max_length = 1;
|
|
|
|
|
|
|
|
for (int i = 0; i < table.size(); ++i)
|
|
|
|
{
|
|
|
|
int len = strlen (table[i].var_name);
|
|
|
|
if (len > max_length)
|
|
|
|
max_length = len;
|
|
|
|
}
|
|
|
|
|
|
|
|
return max_length;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
2011-02-18 09:44:25 +08:00
|
|
|
UserSettingsController::GetTypeString (SettableVariableType var_type)
|
2010-09-04 08:03:46 +08:00
|
|
|
{
|
|
|
|
switch (var_type)
|
|
|
|
{
|
2011-02-18 09:44:25 +08:00
|
|
|
case eSetVarTypeInt:
|
2010-09-04 08:03:46 +08:00
|
|
|
return "int";
|
2011-02-18 09:44:25 +08:00
|
|
|
case eSetVarTypeBoolean:
|
2010-09-04 08:03:46 +08:00
|
|
|
return "boolean";
|
2011-02-18 09:44:25 +08:00
|
|
|
case eSetVarTypeString:
|
2010-09-04 08:03:46 +08:00
|
|
|
return "string";
|
2011-02-18 09:44:25 +08:00
|
|
|
case eSetVarTypeArray:
|
2010-09-04 08:03:46 +08:00
|
|
|
return "array";
|
2011-02-18 09:44:25 +08:00
|
|
|
case eSetVarTypeDictionary:
|
2010-09-04 08:03:46 +08:00
|
|
|
return "dictionary";
|
2011-02-18 09:44:25 +08:00
|
|
|
case eSetVarTypeEnum:
|
2010-09-04 08:03:46 +08:00
|
|
|
return "enum";
|
2011-02-18 09:44:25 +08:00
|
|
|
case eSetVarTypeNone:
|
2010-09-04 08:03:46 +08:00
|
|
|
return "no type";
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-02-18 09:44:25 +08:00
|
|
|
UserSettingsController::PrintEnumValues (const OptionEnumValueElement *enum_values, Stream &str)
|
2010-09-04 08:03:46 +08:00
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
while (enum_values[i].string_value != NULL)
|
|
|
|
{
|
|
|
|
str.Printf ("%s ", enum_values[i].string_value);
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UserSettingsController::FindAllSettingsDescriptions (CommandInterpreter &interpreter,
|
2011-04-20 06:32:36 +08:00
|
|
|
const UserSettingsControllerSP& usc_sp,
|
|
|
|
const char *current_prefix,
|
|
|
|
Stream &strm,
|
2010-09-04 08:03:46 +08:00
|
|
|
Error &err)
|
|
|
|
{
|
|
|
|
// Write out current prefix line.
|
|
|
|
StreamString prefix_line;
|
|
|
|
StreamString description;
|
2011-04-20 06:32:36 +08:00
|
|
|
uint32_t max_len = FindMaxNameLength (usc_sp->m_settings.global_settings);
|
|
|
|
int num_entries = usc_sp->m_settings.global_settings.size();
|
2010-09-04 08:03:46 +08:00
|
|
|
|
2011-04-20 06:32:36 +08:00
|
|
|
if (current_prefix && current_prefix[0])
|
|
|
|
strm.Printf ("\n'%s' variables:\n\n", current_prefix);
|
2010-09-04 08:03:46 +08:00
|
|
|
else
|
2011-04-20 06:32:36 +08:00
|
|
|
strm.Printf ("\nTop level variables:\n\n");
|
2010-09-04 08:03:46 +08:00
|
|
|
|
|
|
|
if (num_entries > 0)
|
|
|
|
{
|
|
|
|
// Write out all "global" variables.
|
|
|
|
for (int i = 0; i < num_entries; ++i)
|
|
|
|
{
|
2011-04-20 06:32:36 +08:00
|
|
|
DumpSettingEntry (interpreter, strm, max_len, usc_sp->m_settings.global_settings[i]);
|
2010-09-04 08:03:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-20 06:32:36 +08:00
|
|
|
num_entries = usc_sp->m_settings.instance_settings.size();
|
|
|
|
max_len = FindMaxNameLength (usc_sp->m_settings.instance_settings);
|
2010-09-04 08:03:46 +08:00
|
|
|
|
|
|
|
if (num_entries > 0)
|
|
|
|
{
|
|
|
|
// Write out all instance variables.
|
|
|
|
for (int i = 0; i < num_entries; ++i)
|
|
|
|
{
|
2011-04-20 06:32:36 +08:00
|
|
|
DumpSettingEntry (interpreter, strm, max_len, usc_sp->m_settings.instance_settings[i]);
|
2010-09-04 08:03:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now, recurse across all children.
|
2011-04-20 06:32:36 +08:00
|
|
|
int num_children = usc_sp->GetNumChildren();
|
2010-09-04 08:03:46 +08:00
|
|
|
for (int i = 0; i < num_children; ++i)
|
|
|
|
{
|
2011-04-20 06:32:36 +08:00
|
|
|
UserSettingsControllerSP child = usc_sp->GetChildAtIndex (i);
|
2010-09-04 08:03:46 +08:00
|
|
|
|
|
|
|
if (child)
|
|
|
|
{
|
|
|
|
ConstString child_prefix = child->GetLevelName();
|
2011-04-20 06:32:36 +08:00
|
|
|
if (current_prefix && current_prefix[0])
|
|
|
|
{
|
|
|
|
StreamString new_prefix;
|
|
|
|
new_prefix.Printf ("%s.%s", current_prefix, child_prefix.GetCString());
|
|
|
|
UserSettingsController::FindAllSettingsDescriptions (interpreter,
|
|
|
|
child,
|
|
|
|
new_prefix.GetData(),
|
|
|
|
strm,
|
|
|
|
err);
|
|
|
|
}
|
2010-09-04 08:03:46 +08:00
|
|
|
else
|
2011-04-20 06:32:36 +08:00
|
|
|
{
|
|
|
|
UserSettingsController::FindAllSettingsDescriptions (interpreter,
|
|
|
|
child,
|
|
|
|
child_prefix.GetCString(),
|
|
|
|
strm,
|
|
|
|
err);
|
|
|
|
}
|
2010-09-04 08:03:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-15 14:56:39 +08:00
|
|
|
void
|
|
|
|
UserSettingsController::FindSettingsDescriptions (CommandInterpreter &interpreter,
|
2011-04-20 06:32:36 +08:00
|
|
|
const UserSettingsControllerSP& usc_sp,
|
|
|
|
const char *current_prefix,
|
2010-09-15 14:56:39 +08:00
|
|
|
const char *search_name,
|
2011-04-20 06:32:36 +08:00
|
|
|
Stream &strm,
|
2010-09-15 14:56:39 +08:00
|
|
|
Error &err)
|
|
|
|
{
|
|
|
|
Args names = UserSettingsController::BreakNameIntoPieces (search_name);
|
|
|
|
int num_pieces = names.GetArgumentCount ();
|
|
|
|
|
|
|
|
if (num_pieces == 0)
|
|
|
|
return;
|
|
|
|
|
2011-04-20 06:32:36 +08:00
|
|
|
if (usc_sp->GetLevelName().GetLength() > 0)
|
2010-09-15 14:56:39 +08:00
|
|
|
{
|
|
|
|
ConstString prefix (names.GetArgumentAtIndex (0));
|
2011-04-20 06:32:36 +08:00
|
|
|
if (prefix != usc_sp->GetLevelName())
|
2010-09-15 14:56:39 +08:00
|
|
|
{
|
|
|
|
std::string parent_prefix;
|
2011-04-20 06:32:36 +08:00
|
|
|
usc_sp->BuildParentPrefix (parent_prefix);
|
2010-09-15 14:56:39 +08:00
|
|
|
err.SetErrorStringWithFormat ("Cannot find match for '%s.%s'\n", parent_prefix.c_str(),
|
2011-04-20 06:32:36 +08:00
|
|
|
prefix.GetCString());
|
2010-09-15 14:56:39 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
names.Shift();
|
|
|
|
--num_pieces;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there's nothing left then dump all global and instance descriptions for this root.
|
|
|
|
if (num_pieces == 0)
|
|
|
|
{
|
|
|
|
StreamString prefix_line;
|
|
|
|
StreamString description;
|
|
|
|
uint32_t max_len;
|
2011-04-20 06:32:36 +08:00
|
|
|
int num_entries = usc_sp->m_settings.global_settings.size();
|
2010-09-15 14:56:39 +08:00
|
|
|
|
2011-04-20 06:32:36 +08:00
|
|
|
max_len = FindMaxNameLength (usc_sp->m_settings.global_settings);
|
2010-09-15 14:56:39 +08:00
|
|
|
|
2011-04-20 06:32:36 +08:00
|
|
|
strm.Printf ("\n'%s' variables:\n\n", search_name);
|
2010-09-15 14:56:39 +08:00
|
|
|
|
|
|
|
if (num_entries > 0)
|
|
|
|
{
|
|
|
|
// Write out all "global" variables.
|
|
|
|
for (int i = 0; i < num_entries; ++i)
|
|
|
|
{
|
2011-04-20 06:32:36 +08:00
|
|
|
DumpSettingEntry (interpreter, strm, max_len, usc_sp->m_settings.global_settings[i]);
|
2010-09-15 14:56:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-20 06:32:36 +08:00
|
|
|
num_entries = usc_sp->m_settings.instance_settings.size();
|
|
|
|
max_len = FindMaxNameLength (usc_sp->m_settings.instance_settings);
|
2010-09-15 14:56:39 +08:00
|
|
|
|
|
|
|
if (num_entries > 0)
|
|
|
|
{
|
|
|
|
// Write out all instance variables.
|
|
|
|
for (int i = 0; i < num_entries; ++i)
|
|
|
|
{
|
2011-04-20 06:32:36 +08:00
|
|
|
DumpSettingEntry (interpreter, strm, max_len, usc_sp->m_settings.instance_settings[i]);
|
2010-09-15 14:56:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (num_pieces == 1)
|
|
|
|
{
|
|
|
|
ConstString var_name (names.GetArgumentAtIndex (0));
|
|
|
|
bool is_global = false;
|
|
|
|
|
2011-04-20 06:32:36 +08:00
|
|
|
const SettingEntry *setting_entry = usc_sp->GetGlobalEntry (var_name);
|
2010-09-15 14:56:39 +08:00
|
|
|
|
|
|
|
if (setting_entry == NULL)
|
2011-04-20 06:32:36 +08:00
|
|
|
setting_entry = usc_sp->GetInstanceEntry (var_name);
|
2010-09-15 14:56:39 +08:00
|
|
|
else
|
|
|
|
is_global = true;
|
|
|
|
|
|
|
|
// Check to see if it is a global or instance variable name.
|
|
|
|
if (setting_entry != NULL)
|
|
|
|
{
|
2011-04-20 06:32:36 +08:00
|
|
|
DumpSettingEntry (interpreter, strm, var_name.GetLength(), *setting_entry);
|
2010-09-15 14:56:39 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// It must be a child name.
|
2011-04-20 06:32:36 +08:00
|
|
|
int num_children = usc_sp->GetNumChildren();
|
2010-09-15 14:56:39 +08:00
|
|
|
bool found = false;
|
|
|
|
for (int i = 0; i < num_children && !found; ++i)
|
|
|
|
{
|
2011-04-20 06:32:36 +08:00
|
|
|
UserSettingsControllerSP child = usc_sp->GetChildAtIndex (i);
|
2010-09-15 14:56:39 +08:00
|
|
|
if (child)
|
|
|
|
{
|
|
|
|
ConstString child_prefix = child->GetLevelName();
|
|
|
|
if (child_prefix == var_name)
|
|
|
|
{
|
|
|
|
found = true;
|
2011-02-18 09:44:25 +08:00
|
|
|
UserSettingsController::FindSettingsDescriptions (interpreter,
|
|
|
|
child,
|
|
|
|
current_prefix,
|
2011-04-20 06:32:36 +08:00
|
|
|
var_name.GetCString(),
|
|
|
|
strm,
|
2011-02-18 09:44:25 +08:00
|
|
|
err);
|
2010-09-15 14:56:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
std::string parent_prefix;
|
2011-04-20 06:32:36 +08:00
|
|
|
usc_sp->BuildParentPrefix (parent_prefix);
|
2010-09-15 14:56:39 +08:00
|
|
|
err.SetErrorStringWithFormat ("Cannot find match for '%s.%s'\n", parent_prefix.c_str(), search_name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// It must be a child name; find the child and call this function recursively on child.
|
|
|
|
ConstString child_name (names.GetArgumentAtIndex (0));
|
|
|
|
|
|
|
|
StreamString rest_of_search_name;
|
|
|
|
for (int i = 0; i < num_pieces; ++i)
|
|
|
|
{
|
|
|
|
rest_of_search_name.Printf ("%s", names.GetArgumentAtIndex (i));
|
|
|
|
if ((i + 1) < num_pieces)
|
|
|
|
rest_of_search_name.Printf (".");
|
|
|
|
}
|
|
|
|
|
2011-04-20 06:32:36 +08:00
|
|
|
int num_children = usc_sp->GetNumChildren();
|
2010-09-15 14:56:39 +08:00
|
|
|
bool found = false;
|
|
|
|
for (int i = 0; i < num_children && !found; ++i)
|
|
|
|
{
|
2011-04-20 06:32:36 +08:00
|
|
|
UserSettingsControllerSP child = usc_sp->GetChildAtIndex (i);
|
2010-09-15 14:56:39 +08:00
|
|
|
if (child)
|
|
|
|
{
|
|
|
|
ConstString child_prefix = child->GetLevelName();
|
|
|
|
if (child_prefix == child_name)
|
|
|
|
{
|
|
|
|
found = true;
|
|
|
|
UserSettingsController::FindSettingsDescriptions (interpreter, child, current_prefix,
|
2011-04-20 06:32:36 +08:00
|
|
|
rest_of_search_name.GetData(), strm,
|
2010-09-15 14:56:39 +08:00
|
|
|
err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
std::string parent_prefix;
|
2011-04-20 06:32:36 +08:00
|
|
|
usc_sp->BuildParentPrefix (parent_prefix);
|
2010-09-15 14:56:39 +08:00
|
|
|
err.SetErrorStringWithFormat ("Cannot find match for '%s.%s'\n", parent_prefix.c_str(), search_name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-04 08:16:49 +08:00
|
|
|
void
|
|
|
|
UserSettingsController::SearchAllSettingsDescriptions (CommandInterpreter &interpreter,
|
2011-04-20 06:32:36 +08:00
|
|
|
const UserSettingsControllerSP& usc_sp,
|
|
|
|
const char *current_prefix,
|
2011-02-04 08:16:49 +08:00
|
|
|
const char *search_word,
|
2011-04-20 06:32:36 +08:00
|
|
|
Stream &strm)
|
2011-02-04 08:16:49 +08:00
|
|
|
{
|
|
|
|
if ((search_word == NULL) || (strlen (search_word) == 0))
|
|
|
|
return;
|
|
|
|
|
2011-04-20 06:32:36 +08:00
|
|
|
int num_entries = usc_sp->m_settings.global_settings.size();
|
2011-02-04 08:16:49 +08:00
|
|
|
|
|
|
|
if (num_entries > 0)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < num_entries; ++i)
|
|
|
|
{
|
2011-04-20 06:32:36 +08:00
|
|
|
const SettingEntry &entry = usc_sp->m_settings.global_settings[i];
|
2011-02-04 08:16:49 +08:00
|
|
|
if (strcasestr (entry.description, search_word) != NULL)
|
|
|
|
{
|
|
|
|
StreamString var_name;
|
2011-04-20 06:32:36 +08:00
|
|
|
if (current_prefix && current_prefix[0])
|
|
|
|
var_name.Printf ("%s.%s", current_prefix, entry.var_name);
|
2011-02-04 08:16:49 +08:00
|
|
|
else
|
|
|
|
var_name.Printf ("%s", entry.var_name);
|
2011-04-20 06:32:36 +08:00
|
|
|
interpreter.OutputFormattedHelpText (strm, var_name.GetData(), "--", entry.description,
|
2011-02-04 08:16:49 +08:00
|
|
|
var_name.GetSize());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-20 06:32:36 +08:00
|
|
|
num_entries = usc_sp->m_settings.instance_settings.size();
|
2011-02-04 08:16:49 +08:00
|
|
|
if (num_entries > 0)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < num_entries; ++i)
|
|
|
|
{
|
2011-04-20 06:32:36 +08:00
|
|
|
SettingEntry &entry = usc_sp->m_settings.instance_settings[i];
|
2011-02-04 08:16:49 +08:00
|
|
|
if (strcasestr (entry.description, search_word) != NULL)
|
|
|
|
{
|
|
|
|
StreamString var_name;
|
2011-04-20 06:32:36 +08:00
|
|
|
if (current_prefix && current_prefix[0])
|
|
|
|
var_name.Printf ("%s.%s", current_prefix, entry.var_name);
|
2011-02-04 08:16:49 +08:00
|
|
|
else
|
|
|
|
var_name.Printf ("%s", entry.var_name);
|
2011-04-20 06:32:36 +08:00
|
|
|
interpreter.OutputFormattedHelpText (strm,
|
|
|
|
var_name.GetData(),
|
|
|
|
"--",
|
|
|
|
entry.description,
|
2011-02-04 08:16:49 +08:00
|
|
|
var_name.GetSize());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-20 06:32:36 +08:00
|
|
|
int num_children = usc_sp->GetNumChildren ();
|
2011-02-04 08:16:49 +08:00
|
|
|
for (int i = 0; i < num_children; ++i)
|
|
|
|
{
|
2011-04-20 06:32:36 +08:00
|
|
|
UserSettingsControllerSP child = usc_sp->GetChildAtIndex (i);
|
2011-02-04 08:16:49 +08:00
|
|
|
|
|
|
|
if (child)
|
|
|
|
{
|
|
|
|
ConstString child_prefix = child->GetLevelName();
|
2011-04-20 06:32:36 +08:00
|
|
|
if (current_prefix && current_prefix[0])
|
|
|
|
{
|
|
|
|
StreamString new_prefix;
|
|
|
|
new_prefix.Printf ("%s.%s", current_prefix, child_prefix.GetCString());
|
|
|
|
UserSettingsController::SearchAllSettingsDescriptions (interpreter,
|
|
|
|
child,
|
|
|
|
new_prefix.GetData(),
|
|
|
|
search_word,
|
|
|
|
strm);
|
|
|
|
}
|
2011-02-04 08:16:49 +08:00
|
|
|
else
|
2011-04-20 06:32:36 +08:00
|
|
|
{
|
|
|
|
UserSettingsController::SearchAllSettingsDescriptions (interpreter,
|
|
|
|
child,
|
|
|
|
child_prefix.GetCString(),
|
|
|
|
search_word,
|
|
|
|
strm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
UserSettingsController::DumpValue (CommandInterpreter &interpreter,
|
|
|
|
const UserSettingsControllerSP& usc_sp,
|
|
|
|
const char *variable_dot_name,
|
|
|
|
Stream &strm)
|
|
|
|
{
|
|
|
|
SettableVariableType var_type;
|
|
|
|
Error err;
|
|
|
|
StringList value = usc_sp->GetVariable (variable_dot_name,
|
|
|
|
var_type,
|
|
|
|
interpreter.GetDebugger().GetInstanceName().GetCString(),
|
|
|
|
err);
|
|
|
|
|
|
|
|
if (err.Success())
|
|
|
|
return DumpValue (variable_dot_name, var_type, value, strm);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
UserSettingsController::DumpValue (const char *variable_dot_name,
|
|
|
|
SettableVariableType var_type,
|
|
|
|
const StringList &value,
|
|
|
|
Stream &strm)
|
|
|
|
{
|
|
|
|
const char *type_name = UserSettingsController::GetTypeString (var_type);
|
|
|
|
|
|
|
|
strm.Printf ("%s (%s) = ", variable_dot_name, type_name);
|
|
|
|
if (value.GetSize() == 0)
|
|
|
|
{
|
|
|
|
strm.EOL();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (var_type)
|
|
|
|
{
|
|
|
|
case eSetVarTypeNone:
|
|
|
|
case eSetVarTypeEnum:
|
|
|
|
case eSetVarTypeInt:
|
|
|
|
case eSetVarTypeBoolean:
|
|
|
|
strm.Printf ("%s\n", value.GetStringAtIndex (0));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eSetVarTypeString:
|
|
|
|
strm.Printf ("\"%s\"\n", value.GetStringAtIndex (0));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eSetVarTypeArray:
|
|
|
|
{
|
|
|
|
strm.EOL();
|
|
|
|
for (unsigned i = 0, e = value.GetSize(); i != e; ++i)
|
|
|
|
strm.Printf (" [%u]: \"%s\"\n", i, value.GetStringAtIndex (i));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eSetVarTypeDictionary:
|
|
|
|
{
|
|
|
|
strm.EOL();
|
|
|
|
for (unsigned i = 0, e = value.GetSize(); i != e; ++i)
|
|
|
|
strm.Printf (" %s\n", value.GetStringAtIndex (i));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
2011-02-04 08:16:49 +08:00
|
|
|
}
|
|
|
|
}
|
2011-04-20 06:32:36 +08:00
|
|
|
return true;
|
2011-02-04 08:16:49 +08:00
|
|
|
}
|
|
|
|
|
2010-09-04 08:03:46 +08:00
|
|
|
void
|
|
|
|
UserSettingsController::GetAllVariableValues (CommandInterpreter &interpreter,
|
2011-04-20 06:32:36 +08:00
|
|
|
const UserSettingsControllerSP& usc_sp,
|
|
|
|
const char *current_prefix,
|
|
|
|
Stream &strm,
|
2010-09-04 08:03:46 +08:00
|
|
|
Error &err)
|
|
|
|
{
|
|
|
|
StreamString description;
|
2011-04-20 06:32:36 +08:00
|
|
|
int num_entries = usc_sp->m_settings.global_settings.size();
|
2010-09-04 08:03:46 +08:00
|
|
|
|
|
|
|
for (int i = 0; i < num_entries; ++i)
|
|
|
|
{
|
|
|
|
StreamString full_var_name;
|
2011-04-20 06:32:36 +08:00
|
|
|
const SettingEntry &entry = usc_sp->m_settings.global_settings[i];
|
|
|
|
|
|
|
|
if (current_prefix && current_prefix[0])
|
|
|
|
full_var_name.Printf ("%s.%s", current_prefix, entry.var_name);
|
2010-09-04 08:03:46 +08:00
|
|
|
else
|
|
|
|
full_var_name.Printf ("%s", entry.var_name);
|
2011-04-20 06:32:36 +08:00
|
|
|
|
|
|
|
DumpValue (interpreter, usc_sp, full_var_name.GetData(), strm);
|
2010-09-04 08:03:46 +08:00
|
|
|
}
|
|
|
|
|
2011-04-20 06:32:36 +08:00
|
|
|
usc_sp->GetAllInstanceVariableValues (interpreter, strm);
|
|
|
|
usc_sp->GetAllPendingSettingValues (strm);
|
|
|
|
if (usc_sp->GetLevelName().GetLength() > 0) // Don't bother with default values for Debugger level.
|
|
|
|
usc_sp->GetAllDefaultSettingValues (strm);
|
2010-09-04 08:03:46 +08:00
|
|
|
|
|
|
|
|
|
|
|
// Now, recurse across all children.
|
2011-04-20 06:32:36 +08:00
|
|
|
int num_children = usc_sp->GetNumChildren();
|
2010-09-04 08:03:46 +08:00
|
|
|
for (int i = 0; i < num_children; ++i)
|
|
|
|
{
|
2011-04-20 06:32:36 +08:00
|
|
|
UserSettingsControllerSP child = usc_sp->GetChildAtIndex (i);
|
2010-09-04 08:03:46 +08:00
|
|
|
|
|
|
|
if (child)
|
|
|
|
{
|
|
|
|
ConstString child_prefix = child->GetLevelName();
|
2011-04-20 06:32:36 +08:00
|
|
|
if (current_prefix && current_prefix[0])
|
|
|
|
{
|
|
|
|
StreamString new_prefix;
|
|
|
|
new_prefix.Printf ("%s.%s", current_prefix, child_prefix.GetCString());
|
|
|
|
UserSettingsController::GetAllVariableValues (interpreter,
|
|
|
|
child,
|
|
|
|
new_prefix.GetData(),
|
|
|
|
strm,
|
|
|
|
err);
|
|
|
|
}
|
2010-09-04 08:03:46 +08:00
|
|
|
else
|
2011-04-20 06:32:36 +08:00
|
|
|
{
|
|
|
|
UserSettingsController::GetAllVariableValues (interpreter,
|
|
|
|
child,
|
|
|
|
child_prefix.GetCString(),
|
|
|
|
strm,
|
|
|
|
err);
|
|
|
|
}
|
2010-09-04 08:03:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Args
|
|
|
|
UserSettingsController::BreakNameIntoPieces (const char *full_dot_name)
|
|
|
|
{
|
|
|
|
Args return_value;
|
|
|
|
std::string name_string (full_dot_name);
|
|
|
|
bool done = false;
|
|
|
|
|
|
|
|
std::string piece;
|
|
|
|
std::string remainder (full_dot_name);
|
|
|
|
|
|
|
|
while (!done)
|
|
|
|
{
|
|
|
|
size_t idx = remainder.find_first_of ('.');
|
|
|
|
piece = remainder.substr (0, idx);
|
|
|
|
return_value.AppendArgument (piece.c_str());
|
|
|
|
if (idx != std::string::npos)
|
|
|
|
remainder = remainder.substr (idx+1);
|
|
|
|
else
|
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
UserSettingsController::IsLiveInstance (const std::string &instance_name)
|
|
|
|
{
|
2011-04-20 06:32:36 +08:00
|
|
|
Mutex::Locker locker (m_live_settings_mutex);
|
|
|
|
InstanceSettingsMap::iterator pos = m_live_settings.find (instance_name);
|
2010-09-04 08:03:46 +08:00
|
|
|
if (pos != m_live_settings.end())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-04-20 06:32:36 +08:00
|
|
|
UserSettingsController::CompleteSettingsValue (const UserSettingsControllerSP& usc_sp,
|
2010-09-04 08:03:46 +08:00
|
|
|
const char *full_dot_name,
|
|
|
|
const char *partial_value,
|
|
|
|
bool &word_complete,
|
|
|
|
StringList &matches)
|
|
|
|
{
|
|
|
|
Args names = UserSettingsController::BreakNameIntoPieces (full_dot_name);
|
|
|
|
int num_pieces = names.GetArgumentCount();
|
|
|
|
word_complete = true;
|
|
|
|
|
2011-04-20 06:32:36 +08:00
|
|
|
ConstString root_level = usc_sp->GetLevelName();
|
2010-09-04 08:03:46 +08:00
|
|
|
int num_extra_levels = num_pieces - 2;
|
|
|
|
if ((num_extra_levels > 0)
|
|
|
|
&& root_level.GetLength() > 0)
|
|
|
|
{
|
|
|
|
ConstString current_level (names.GetArgumentAtIndex (0));
|
|
|
|
if (current_level == root_level)
|
|
|
|
{
|
|
|
|
names.Shift();
|
|
|
|
--num_extra_levels;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < num_extra_levels; ++i)
|
|
|
|
{
|
|
|
|
ConstString child_level (names.GetArgumentAtIndex (0));
|
|
|
|
bool found = false;
|
2011-04-20 06:32:36 +08:00
|
|
|
int num_children = usc_sp->GetNumChildren();
|
|
|
|
UserSettingsControllerSP child_usc_sp = usc_sp;
|
2010-09-04 08:03:46 +08:00
|
|
|
for (int j = 0; j < num_children && !found; ++j)
|
|
|
|
{
|
2011-04-20 06:32:36 +08:00
|
|
|
if (child_usc_sp->GetChildAtIndex (j)->GetLevelName() == child_level)
|
2010-09-04 08:03:46 +08:00
|
|
|
{
|
|
|
|
found = true;
|
2011-04-20 06:32:36 +08:00
|
|
|
child_usc_sp = child_usc_sp->GetChildAtIndex (j);
|
2010-09-04 08:03:46 +08:00
|
|
|
names.Shift();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (names.GetArgumentCount() != 2)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
std::string next_name (names.GetArgumentAtIndex (0));
|
|
|
|
int len = next_name.length();
|
|
|
|
names.Shift();
|
|
|
|
|
|
|
|
if ((next_name[0] == '[') && (next_name[len-1] == ']'))
|
|
|
|
{
|
|
|
|
// 'next_name' is instance name. Instance names are irrelevent here.
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// 'next_name' is child name.
|
|
|
|
bool found = false;
|
2011-04-20 06:32:36 +08:00
|
|
|
int num_children = usc_sp->GetNumChildren();
|
2010-09-04 08:03:46 +08:00
|
|
|
ConstString child_level (next_name.c_str());
|
2011-04-20 06:32:36 +08:00
|
|
|
UserSettingsControllerSP child_usc_sp = usc_sp;
|
2010-09-04 08:03:46 +08:00
|
|
|
for (int j = 0; j < num_children && !found; ++j)
|
|
|
|
{
|
2011-04-20 06:32:36 +08:00
|
|
|
if (child_usc_sp->GetChildAtIndex (j)->GetLevelName() == child_level)
|
2010-09-04 08:03:46 +08:00
|
|
|
{
|
|
|
|
found = true;
|
2011-04-20 06:32:36 +08:00
|
|
|
child_usc_sp = child_usc_sp->GetChildAtIndex (j);
|
2010-09-04 08:03:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ConstString var_name (names.GetArgumentAtIndex(0));
|
2011-04-20 06:32:36 +08:00
|
|
|
const SettingEntry *entry = usc_sp->GetGlobalEntry (var_name);
|
2010-09-04 08:03:46 +08:00
|
|
|
if (entry == NULL)
|
2011-04-20 06:32:36 +08:00
|
|
|
entry = usc_sp->GetInstanceEntry (var_name);
|
2010-09-04 08:03:46 +08:00
|
|
|
|
|
|
|
if (entry == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2011-02-18 09:44:25 +08:00
|
|
|
if (entry->var_type == eSetVarTypeBoolean)
|
2010-09-04 08:03:46 +08:00
|
|
|
return UserSettingsController::BooleanMatches (partial_value, word_complete, matches);
|
2011-02-18 09:44:25 +08:00
|
|
|
else if (entry->var_type == eSetVarTypeEnum)
|
2010-09-04 08:03:46 +08:00
|
|
|
return UserSettingsController::EnumMatches (partial_value, entry->enum_values, word_complete, matches);
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
UserSettingsController::BooleanMatches (const char *partial_value,
|
|
|
|
bool &word_complete,
|
|
|
|
StringList &matches)
|
|
|
|
{
|
|
|
|
static const std::string true_string ("true");
|
|
|
|
static const std::string false_string ("false");
|
|
|
|
|
|
|
|
if (partial_value == NULL)
|
|
|
|
{
|
|
|
|
matches.AppendString ("true");
|
|
|
|
matches.AppendString ("false");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int partial_len = strlen (partial_value);
|
|
|
|
|
|
|
|
if ((partial_len <= true_string.length())
|
|
|
|
&& (true_string.find (partial_value) == 0))
|
|
|
|
matches.AppendString ("true");
|
|
|
|
else if ((partial_len <= false_string.length())
|
|
|
|
&& (false_string.find (partial_value) == 0))
|
|
|
|
matches.AppendString ("false");
|
|
|
|
}
|
|
|
|
|
|
|
|
word_complete = false;
|
|
|
|
if (matches.GetSize() == 1)
|
|
|
|
word_complete = true;
|
|
|
|
|
|
|
|
return matches.GetSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
UserSettingsController::EnumMatches (const char *partial_value,
|
2011-02-18 09:44:25 +08:00
|
|
|
OptionEnumValueElement *enum_values,
|
2010-09-04 08:03:46 +08:00
|
|
|
bool &word_complete,
|
|
|
|
StringList &matches)
|
|
|
|
{
|
|
|
|
int len = (partial_value != NULL) ? strlen (partial_value) : 0;
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
while (enum_values[i].string_value != NULL)
|
|
|
|
{
|
|
|
|
if (len == 0)
|
|
|
|
matches.AppendString (enum_values[i].string_value);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::string tmp_value (enum_values[i].string_value);
|
|
|
|
if ((len <= tmp_value.length())
|
|
|
|
&& tmp_value.find (partial_value) == 0)
|
|
|
|
matches.AppendString (enum_values[i].string_value);
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
word_complete = false;
|
|
|
|
if (matches.GetSize() == 1)
|
|
|
|
word_complete = true;
|
|
|
|
|
|
|
|
return matches.GetSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-04-20 06:32:36 +08:00
|
|
|
UserSettingsController::CompleteSettingsNames (const UserSettingsControllerSP& usc_sp,
|
2010-09-04 08:03:46 +08:00
|
|
|
Args &partial_setting_name_pieces,
|
|
|
|
bool &word_complete,
|
|
|
|
StringList &matches)
|
|
|
|
{
|
|
|
|
int num_matches = 0;
|
|
|
|
int num_name_pieces = partial_setting_name_pieces.GetArgumentCount();
|
|
|
|
|
|
|
|
if (num_name_pieces > 1)
|
|
|
|
{
|
|
|
|
// There are at least two pieces, perhaps with multiple level names preceding them.
|
|
|
|
// First traverse all the extra levels, until we have exactly two pieces left.
|
|
|
|
|
|
|
|
int num_extra_levels = num_name_pieces - 2;
|
|
|
|
|
|
|
|
// Deal with current level first.
|
|
|
|
|
2011-04-20 06:32:36 +08:00
|
|
|
ConstString root_level = usc_sp->GetLevelName();
|
2010-09-04 08:03:46 +08:00
|
|
|
if ((num_extra_levels > 0)
|
|
|
|
&& (root_level.GetLength() > 0))
|
|
|
|
{
|
|
|
|
ConstString current_level (partial_setting_name_pieces.GetArgumentAtIndex (0));
|
|
|
|
if (current_level == root_level)
|
|
|
|
{
|
|
|
|
partial_setting_name_pieces.Shift();
|
|
|
|
--num_extra_levels;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return 0; // The current level did not match the name pieces; something is wrong, so return immediately
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < num_extra_levels; ++i)
|
|
|
|
{
|
|
|
|
ConstString child_level (partial_setting_name_pieces.GetArgumentAtIndex (0));
|
|
|
|
bool found = false;
|
2011-04-20 06:32:36 +08:00
|
|
|
int num_children = usc_sp->GetNumChildren();
|
|
|
|
UserSettingsControllerSP child_usc_sp = usc_sp;
|
|
|
|
|
2010-09-04 08:03:46 +08:00
|
|
|
for (int j = 0; j < num_children && !found; ++j)
|
|
|
|
{
|
2011-04-20 06:32:36 +08:00
|
|
|
if (child_usc_sp->GetChildAtIndex (j)->GetLevelName() == child_level)
|
2010-09-04 08:03:46 +08:00
|
|
|
{
|
|
|
|
found = true;
|
2011-04-20 06:32:36 +08:00
|
|
|
child_usc_sp = child_usc_sp->GetChildAtIndex (j);
|
2010-09-04 08:03:46 +08:00
|
|
|
partial_setting_name_pieces.Shift();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (! found)
|
|
|
|
{
|
|
|
|
return 0; // Unable to find a matching child level name; something is wrong, so return immediately.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now there should be exactly two name pieces left. If not there is an error, so return immediately
|
|
|
|
|
|
|
|
if (partial_setting_name_pieces.GetArgumentCount() != 2)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
std::string next_name (partial_setting_name_pieces.GetArgumentAtIndex (0));
|
|
|
|
int len = next_name.length();
|
|
|
|
partial_setting_name_pieces.Shift();
|
|
|
|
|
|
|
|
if ((next_name[0] == '[') && (next_name[len-1] == ']'))
|
|
|
|
{
|
|
|
|
// 'next_name' is an instance name. The last name piece must be a non-empty partial match against an
|
|
|
|
// instance_name, assuming 'next_name' is valid.
|
|
|
|
|
2011-04-20 06:32:36 +08:00
|
|
|
if (usc_sp->IsLiveInstance (next_name))
|
2010-09-04 08:03:46 +08:00
|
|
|
{
|
|
|
|
std::string complete_prefix;
|
2011-04-20 06:32:36 +08:00
|
|
|
usc_sp->BuildParentPrefix (complete_prefix);
|
2010-09-04 08:03:46 +08:00
|
|
|
|
2011-04-20 06:32:36 +08:00
|
|
|
num_matches = usc_sp->InstanceVariableMatches(partial_setting_name_pieces.GetArgumentAtIndex(0),
|
2010-09-04 08:03:46 +08:00
|
|
|
complete_prefix,
|
|
|
|
next_name.c_str(),
|
|
|
|
matches);
|
|
|
|
word_complete = true;
|
|
|
|
if (num_matches > 1)
|
|
|
|
word_complete = false;
|
|
|
|
|
|
|
|
return num_matches;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return 0; // Invalid instance_name
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// 'next_name' must be a child name. Find the correct child and pass the remaining piece to be resolved.
|
|
|
|
bool found = false;
|
2011-04-20 06:32:36 +08:00
|
|
|
int num_children = usc_sp->GetNumChildren();
|
2010-09-04 08:03:46 +08:00
|
|
|
ConstString child_level (next_name.c_str());
|
|
|
|
for (int i = 0; i < num_children; ++i)
|
|
|
|
{
|
2011-04-20 06:32:36 +08:00
|
|
|
if (usc_sp->GetChildAtIndex (i)->GetLevelName() == child_level)
|
2010-09-04 08:03:46 +08:00
|
|
|
{
|
|
|
|
found = true;
|
2011-04-20 06:32:36 +08:00
|
|
|
return UserSettingsController::CompleteSettingsNames (usc_sp->GetChildAtIndex (i),
|
2010-09-04 08:03:46 +08:00
|
|
|
partial_setting_name_pieces,
|
|
|
|
word_complete, matches);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (num_name_pieces == 1)
|
|
|
|
{
|
|
|
|
std::string complete_prefix;
|
2011-04-20 06:32:36 +08:00
|
|
|
usc_sp->BuildParentPrefix (complete_prefix);
|
2010-09-04 08:03:46 +08:00
|
|
|
|
|
|
|
word_complete = true;
|
|
|
|
std::string name (partial_setting_name_pieces.GetArgumentAtIndex (0));
|
|
|
|
|
|
|
|
if (name[0] == '[')
|
|
|
|
{
|
|
|
|
// It's a partial instance name.
|
|
|
|
|
2011-04-20 06:32:36 +08:00
|
|
|
num_matches = usc_sp->LiveInstanceMatches (name.c_str(), complete_prefix, word_complete, matches);
|
2010-09-04 08:03:46 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// It could be anything *except* an instance name...
|
|
|
|
|
2011-04-20 06:32:36 +08:00
|
|
|
num_matches = usc_sp->GlobalVariableMatches (name.c_str(), complete_prefix, matches);
|
|
|
|
num_matches += usc_sp->InstanceVariableMatches (name.c_str(), complete_prefix, NULL, matches);
|
|
|
|
num_matches += usc_sp->ChildMatches (name.c_str(), complete_prefix, word_complete, matches);
|
2010-09-04 08:03:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (num_matches > 1)
|
|
|
|
word_complete = false;
|
|
|
|
|
|
|
|
return num_matches;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// We have a user settings controller with a blank partial string. Return everything possible at this level.
|
|
|
|
|
|
|
|
std::string complete_prefix;
|
2011-04-20 06:32:36 +08:00
|
|
|
usc_sp->BuildParentPrefix (complete_prefix);
|
|
|
|
num_matches = usc_sp->GlobalVariableMatches (NULL, complete_prefix, matches);
|
|
|
|
num_matches += usc_sp->InstanceVariableMatches (NULL, complete_prefix, NULL, matches);
|
|
|
|
num_matches += usc_sp->LiveInstanceMatches (NULL, complete_prefix, word_complete, matches);
|
|
|
|
num_matches += usc_sp->ChildMatches (NULL, complete_prefix, word_complete, matches);
|
2010-09-04 08:03:46 +08:00
|
|
|
word_complete = false;
|
|
|
|
return num_matches;
|
|
|
|
}
|
|
|
|
|
|
|
|
return num_matches;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
UserSettingsController::GlobalVariableMatches (const char *partial_name,
|
|
|
|
const std::string &complete_prefix,
|
|
|
|
StringList &matches)
|
|
|
|
{
|
|
|
|
int partial_len = (partial_name != NULL) ? strlen (partial_name) : 0;
|
|
|
|
int num_matches = 0;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < m_settings.global_settings.size(); ++i)
|
|
|
|
{
|
2011-02-18 09:44:25 +08:00
|
|
|
const SettingEntry &entry = m_settings.global_settings[i];
|
2010-09-04 08:03:46 +08:00
|
|
|
std::string var_name (entry.var_name);
|
|
|
|
if ((partial_len == 0)
|
|
|
|
|| ((partial_len <= var_name.length())
|
|
|
|
&& (var_name.find (partial_name) == 0)))
|
|
|
|
{
|
|
|
|
StreamString match_name;
|
|
|
|
if (complete_prefix.length() > 0)
|
|
|
|
{
|
|
|
|
match_name.Printf ("%s.%s", complete_prefix.c_str(), var_name.c_str());
|
|
|
|
matches.AppendString (match_name.GetData());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
matches.AppendString (var_name.c_str());
|
|
|
|
++num_matches;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return num_matches;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
UserSettingsController::InstanceVariableMatches (const char *partial_name,
|
|
|
|
const std::string &complete_prefix,
|
|
|
|
const char *instance_name,
|
|
|
|
StringList &matches)
|
|
|
|
{
|
|
|
|
int partial_len = (partial_name != NULL) ? strlen (partial_name) : 0;
|
|
|
|
int num_matches = 0;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < m_settings.instance_settings.size(); ++i)
|
|
|
|
{
|
|
|
|
SettingEntry &entry = m_settings.instance_settings[i];
|
|
|
|
std::string var_name (entry.var_name);
|
|
|
|
if ((partial_len == 0)
|
|
|
|
|| ((partial_len <= var_name.length())
|
|
|
|
&& (var_name.find (partial_name) == 0)))
|
|
|
|
{
|
|
|
|
StreamString match_name;
|
|
|
|
if (complete_prefix.length() > 0)
|
|
|
|
{
|
|
|
|
if (instance_name != NULL)
|
|
|
|
match_name.Printf ("%s.%s.%s", complete_prefix.c_str(), instance_name, var_name.c_str());
|
|
|
|
else
|
|
|
|
match_name.Printf ("%s.%s", complete_prefix.c_str(), var_name.c_str());
|
|
|
|
|
|
|
|
matches.AppendString (match_name.GetData());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (instance_name != NULL)
|
|
|
|
{
|
|
|
|
match_name.Printf ("%s.%s", instance_name, var_name.c_str());
|
|
|
|
matches.AppendString (match_name.GetData());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
matches.AppendString (var_name.c_str());
|
|
|
|
}
|
|
|
|
++num_matches;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return num_matches;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
UserSettingsController::LiveInstanceMatches (const char *partial_name,
|
|
|
|
const std::string &complete_prefix,
|
|
|
|
bool &word_complete,
|
|
|
|
StringList &matches)
|
|
|
|
{
|
|
|
|
int partial_len = (partial_name != NULL) ? strlen (partial_name) : 0;
|
|
|
|
int num_matches = 0;
|
|
|
|
|
2011-04-20 06:32:36 +08:00
|
|
|
InstanceSettingsMap::iterator pos;
|
|
|
|
Mutex::Locker locker (m_live_settings_mutex);
|
2010-09-04 08:03:46 +08:00
|
|
|
for (pos = m_live_settings.begin(); pos != m_live_settings.end(); ++pos)
|
|
|
|
{
|
|
|
|
std::string instance_name = pos->first;
|
|
|
|
if ((partial_len == 0)
|
|
|
|
|| ((partial_len <= instance_name.length())
|
|
|
|
&& (instance_name.find (partial_name) == 0)))
|
|
|
|
{
|
|
|
|
StreamString match_name;
|
|
|
|
if (complete_prefix.length() > 0)
|
|
|
|
match_name.Printf ("%s.%s.", complete_prefix.c_str(), instance_name.c_str());
|
|
|
|
else
|
|
|
|
match_name.Printf ("%s.", instance_name.c_str());
|
|
|
|
matches.AppendString (match_name.GetData());
|
|
|
|
++num_matches;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num_matches > 0)
|
|
|
|
word_complete = false;
|
|
|
|
|
|
|
|
return num_matches;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
UserSettingsController::ChildMatches (const char *partial_name,
|
|
|
|
const std::string &complete_prefix,
|
|
|
|
bool &word_complete,
|
|
|
|
StringList &matches)
|
|
|
|
{
|
|
|
|
int partial_len = (partial_name != NULL) ? strlen (partial_name) : 0;
|
|
|
|
int num_children = GetNumChildren();
|
|
|
|
int num_matches = 0;
|
|
|
|
for (int i = 0; i < num_children; ++i)
|
|
|
|
{
|
2011-04-20 06:32:36 +08:00
|
|
|
std::string child_name (GetChildAtIndex(i)->GetLevelName().GetCString());
|
2010-09-04 08:03:46 +08:00
|
|
|
StreamString match_name;
|
|
|
|
if ((partial_len == 0)
|
|
|
|
|| ((partial_len <= child_name.length())
|
|
|
|
&& (child_name.find (partial_name) == 0)))
|
|
|
|
{
|
|
|
|
if (complete_prefix.length() > 0)
|
|
|
|
match_name.Printf ("%s.%s.", complete_prefix.c_str(), child_name.c_str());
|
|
|
|
else
|
|
|
|
match_name.Printf ("%s.", child_name.c_str());
|
|
|
|
matches.AppendString (match_name.GetData());
|
|
|
|
++num_matches;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num_matches > 0)
|
|
|
|
word_complete = false;
|
|
|
|
|
|
|
|
return num_matches;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-02-18 09:44:25 +08:00
|
|
|
UserSettingsController::VerifyOperationForType (SettableVariableType var_type,
|
|
|
|
VarSetOperationType op,
|
2010-09-04 08:03:46 +08:00
|
|
|
const ConstString &var_name,
|
|
|
|
Error &err)
|
|
|
|
{
|
2011-02-18 09:44:25 +08:00
|
|
|
if (op == eVarSetOperationAssign)
|
2010-09-04 08:03:46 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
2011-02-18 09:44:25 +08:00
|
|
|
if (op == eVarSetOperationInvalid)
|
2010-09-04 08:03:46 +08:00
|
|
|
{
|
|
|
|
err.SetErrorString ("Invalid 'settings ' subcommand operation.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (op)
|
|
|
|
{
|
2011-02-18 09:44:25 +08:00
|
|
|
case eVarSetOperationInsertBefore:
|
|
|
|
case eVarSetOperationInsertAfter:
|
|
|
|
if (var_type != eSetVarTypeArray)
|
2010-09-04 08:03:46 +08:00
|
|
|
err.SetErrorString ("Invalid operation: This operation can only be performed on array variables.\n");
|
|
|
|
break;
|
2011-02-18 09:44:25 +08:00
|
|
|
case eVarSetOperationReplace:
|
|
|
|
case eVarSetOperationRemove:
|
|
|
|
if ((var_type != eSetVarTypeArray)
|
|
|
|
&& (var_type != eSetVarTypeDictionary))
|
2010-09-04 08:03:46 +08:00
|
|
|
err.SetErrorString ("Invalid operation: This operation can only be performed on array or dictionary"
|
|
|
|
" variables.\n");
|
|
|
|
break;
|
2011-02-18 09:44:25 +08:00
|
|
|
case eVarSetOperationAppend:
|
|
|
|
case eVarSetOperationClear:
|
|
|
|
if ((var_type != eSetVarTypeArray)
|
|
|
|
&& (var_type != eSetVarTypeDictionary)
|
|
|
|
&& (var_type != eSetVarTypeString))
|
2010-09-04 08:03:46 +08:00
|
|
|
err.SetErrorString ("Invalid operation: This operation can only be performed on array, dictionary "
|
|
|
|
"or string variables.\n");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-02-18 09:44:25 +08:00
|
|
|
UserSettingsController::UpdateStringVariable (VarSetOperationType op,
|
2010-09-04 08:03:46 +08:00
|
|
|
std::string &string_var,
|
|
|
|
const char *new_value,
|
|
|
|
Error &err)
|
|
|
|
{
|
2011-02-18 09:44:25 +08:00
|
|
|
if (op == eVarSetOperationAssign)
|
Added a new variant of SBTarget::Launch() that deprectates the old one that
takes separate file handles for stdin, stdout, and stder and also allows for
the working directory to be specified.
Added support to "process launch" to a new option: --working-dir=PATH. We
can now set the working directory. If this is not set, it defaults to that
of the process that has LLDB loaded. Added the working directory to the
host LaunchInNewTerminal function to allows the current working directory
to be set in processes that are spawned in their own terminal. Also hooked this
up to the lldb_private::Process and all mac plug-ins. The linux plug-in had its
API changed, but nothing is making use of it yet. Modfied "debugserver" and
"darwin-debug" to also handle the current working directory options and modified
the code in LLDB that spawns these tools to pass the info along.
Fixed ProcessGDBRemote to properly pass along all file handles for stdin, stdout
and stderr.
After clearing the default values for the stdin/out/err file handles for
process to be NULL, we had a crasher in UserSettingsController::UpdateStringVariable
which is now fixed. Also fixed the setting of boolean values to be able to
be set as "true", "yes", "on", "1" for true (case insensitive) and "false", "no",
"off", or "0" for false.
Fixed debugserver to properly handle files for STDIN, STDOUT and STDERR that are not
already opened. Previous to this fix debugserver would only correctly open and dupe
file handles for the slave side of a pseudo terminal. It now correctly handles
getting STDIN for the inferior from a file, and spitting STDOUT and STDERR out to
files. Also made sure the file handles were correctly opened with the NOCTTY flag
for terminals.
llvm-svn: 124060
2011-01-23 13:56:20 +08:00
|
|
|
{
|
|
|
|
if (new_value && new_value[0])
|
|
|
|
string_var.assign (new_value);
|
|
|
|
else
|
|
|
|
string_var.clear();
|
|
|
|
}
|
2011-02-18 09:44:25 +08:00
|
|
|
else if (op == eVarSetOperationAppend)
|
Added a new variant of SBTarget::Launch() that deprectates the old one that
takes separate file handles for stdin, stdout, and stder and also allows for
the working directory to be specified.
Added support to "process launch" to a new option: --working-dir=PATH. We
can now set the working directory. If this is not set, it defaults to that
of the process that has LLDB loaded. Added the working directory to the
host LaunchInNewTerminal function to allows the current working directory
to be set in processes that are spawned in their own terminal. Also hooked this
up to the lldb_private::Process and all mac plug-ins. The linux plug-in had its
API changed, but nothing is making use of it yet. Modfied "debugserver" and
"darwin-debug" to also handle the current working directory options and modified
the code in LLDB that spawns these tools to pass the info along.
Fixed ProcessGDBRemote to properly pass along all file handles for stdin, stdout
and stderr.
After clearing the default values for the stdin/out/err file handles for
process to be NULL, we had a crasher in UserSettingsController::UpdateStringVariable
which is now fixed. Also fixed the setting of boolean values to be able to
be set as "true", "yes", "on", "1" for true (case insensitive) and "false", "no",
"off", or "0" for false.
Fixed debugserver to properly handle files for STDIN, STDOUT and STDERR that are not
already opened. Previous to this fix debugserver would only correctly open and dupe
file handles for the slave side of a pseudo terminal. It now correctly handles
getting STDIN for the inferior from a file, and spitting STDOUT and STDERR out to
files. Also made sure the file handles were correctly opened with the NOCTTY flag
for terminals.
llvm-svn: 124060
2011-01-23 13:56:20 +08:00
|
|
|
{
|
|
|
|
if (new_value && new_value[0])
|
|
|
|
string_var.append (new_value);
|
|
|
|
}
|
2011-02-18 09:44:25 +08:00
|
|
|
else if (op == eVarSetOperationClear)
|
2010-09-04 08:03:46 +08:00
|
|
|
string_var.clear();
|
|
|
|
else
|
|
|
|
err.SetErrorString ("Unrecognized operation. Cannot update value.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-02-18 09:44:25 +08:00
|
|
|
UserSettingsController::UpdateBooleanVariable (VarSetOperationType op,
|
2010-09-04 08:03:46 +08:00
|
|
|
bool &bool_var,
|
|
|
|
const char *new_value,
|
|
|
|
Error &err)
|
|
|
|
{
|
2011-02-18 09:44:25 +08:00
|
|
|
if (op != eVarSetOperationAssign)
|
2010-09-04 08:03:46 +08:00
|
|
|
err.SetErrorString ("Invalid operation for Boolean variable. Cannot update value.\n");
|
|
|
|
|
Added a new variant of SBTarget::Launch() that deprectates the old one that
takes separate file handles for stdin, stdout, and stder and also allows for
the working directory to be specified.
Added support to "process launch" to a new option: --working-dir=PATH. We
can now set the working directory. If this is not set, it defaults to that
of the process that has LLDB loaded. Added the working directory to the
host LaunchInNewTerminal function to allows the current working directory
to be set in processes that are spawned in their own terminal. Also hooked this
up to the lldb_private::Process and all mac plug-ins. The linux plug-in had its
API changed, but nothing is making use of it yet. Modfied "debugserver" and
"darwin-debug" to also handle the current working directory options and modified
the code in LLDB that spawns these tools to pass the info along.
Fixed ProcessGDBRemote to properly pass along all file handles for stdin, stdout
and stderr.
After clearing the default values for the stdin/out/err file handles for
process to be NULL, we had a crasher in UserSettingsController::UpdateStringVariable
which is now fixed. Also fixed the setting of boolean values to be able to
be set as "true", "yes", "on", "1" for true (case insensitive) and "false", "no",
"off", or "0" for false.
Fixed debugserver to properly handle files for STDIN, STDOUT and STDERR that are not
already opened. Previous to this fix debugserver would only correctly open and dupe
file handles for the slave side of a pseudo terminal. It now correctly handles
getting STDIN for the inferior from a file, and spitting STDOUT and STDERR out to
files. Also made sure the file handles were correctly opened with the NOCTTY flag
for terminals.
llvm-svn: 124060
2011-01-23 13:56:20 +08:00
|
|
|
if (new_value && new_value[0])
|
|
|
|
{
|
|
|
|
if ((::strcasecmp(new_value, "true") == 0) ||
|
|
|
|
(::strcasecmp(new_value, "yes") == 0) ||
|
|
|
|
(::strcasecmp(new_value, "on") == 0) ||
|
|
|
|
(::strcasecmp(new_value, "1") == 0))
|
|
|
|
bool_var = true;
|
|
|
|
else
|
|
|
|
if ((::strcasecmp(new_value, "false") == 0) ||
|
|
|
|
(::strcasecmp(new_value, "no") == 0) ||
|
|
|
|
(::strcasecmp(new_value, "off") == 0) ||
|
|
|
|
(::strcasecmp(new_value, "0") == 0))
|
|
|
|
bool_var = false;
|
|
|
|
else
|
|
|
|
err.SetErrorStringWithFormat ("Invalid boolean value '%s'\n", new_value);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
err.SetErrorString ("Invalid value. Cannot perform update.\n");
|
2010-09-04 08:03:46 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-02-18 09:44:25 +08:00
|
|
|
UserSettingsController::UpdateStringArrayVariable (VarSetOperationType op,
|
2010-09-04 08:03:46 +08:00
|
|
|
const char *index_value,
|
|
|
|
Args &array_var,
|
|
|
|
const char *new_value,
|
|
|
|
Error &err)
|
|
|
|
{
|
|
|
|
int index = -1;
|
|
|
|
bool valid_index = true;
|
|
|
|
|
|
|
|
if (index_value != NULL)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < strlen(index_value); ++i)
|
|
|
|
if (!isdigit (index_value[i]))
|
|
|
|
{
|
|
|
|
valid_index = false;
|
|
|
|
err.SetErrorStringWithFormat ("'%s' is not a valid integer index. Cannot update array value.\n",
|
|
|
|
index_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (valid_index)
|
|
|
|
index = atoi (index_value);
|
|
|
|
|
|
|
|
if (index < 0
|
|
|
|
|| index >= array_var.GetArgumentCount())
|
|
|
|
{
|
|
|
|
valid_index = false;
|
|
|
|
err.SetErrorStringWithFormat ("%d is outside the bounds of the specified array variable. "
|
|
|
|
"Cannot update array value.\n", index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (op)
|
|
|
|
{
|
2011-02-18 09:44:25 +08:00
|
|
|
case eVarSetOperationAssign:
|
2010-09-04 08:03:46 +08:00
|
|
|
array_var.SetCommandString (new_value);
|
|
|
|
break;
|
2011-02-18 09:44:25 +08:00
|
|
|
case eVarSetOperationReplace:
|
2010-09-04 08:03:46 +08:00
|
|
|
{
|
|
|
|
if (valid_index)
|
|
|
|
array_var.ReplaceArgumentAtIndex (index, new_value);
|
|
|
|
break;
|
|
|
|
}
|
2011-02-18 09:44:25 +08:00
|
|
|
case eVarSetOperationInsertBefore:
|
|
|
|
case eVarSetOperationInsertAfter:
|
2010-09-04 08:03:46 +08:00
|
|
|
{
|
|
|
|
if (valid_index)
|
|
|
|
{
|
|
|
|
Args new_array (new_value);
|
2011-02-18 09:44:25 +08:00
|
|
|
if (op == eVarSetOperationInsertAfter)
|
2010-09-04 08:03:46 +08:00
|
|
|
++index;
|
|
|
|
for (int i = 0; i < new_array.GetArgumentCount(); ++i)
|
|
|
|
array_var.InsertArgumentAtIndex (index, new_array.GetArgumentAtIndex (i));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2011-02-18 09:44:25 +08:00
|
|
|
case eVarSetOperationRemove:
|
2010-09-04 08:03:46 +08:00
|
|
|
{
|
|
|
|
if (valid_index)
|
|
|
|
array_var.DeleteArgumentAtIndex (index);
|
|
|
|
break;
|
|
|
|
}
|
2011-02-18 09:44:25 +08:00
|
|
|
case eVarSetOperationAppend:
|
2010-09-04 08:03:46 +08:00
|
|
|
{
|
|
|
|
Args new_array (new_value);
|
|
|
|
array_var.AppendArguments (new_array);
|
|
|
|
break;
|
|
|
|
}
|
2011-02-18 09:44:25 +08:00
|
|
|
case eVarSetOperationClear:
|
2010-09-04 08:03:46 +08:00
|
|
|
array_var.Clear();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
err.SetErrorString ("Unrecognized operation. Cannot update value.\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-02-18 09:44:25 +08:00
|
|
|
UserSettingsController::UpdateDictionaryVariable (VarSetOperationType op,
|
2010-09-04 08:03:46 +08:00
|
|
|
const char *index_value,
|
|
|
|
std::map<std::string, std::string> &dictionary,
|
|
|
|
const char *new_value,
|
|
|
|
Error &err)
|
|
|
|
{
|
|
|
|
switch (op)
|
|
|
|
{
|
2011-02-18 09:44:25 +08:00
|
|
|
case eVarSetOperationReplace:
|
2010-09-04 08:03:46 +08:00
|
|
|
if (index_value != NULL)
|
|
|
|
{
|
|
|
|
std::string key (index_value);
|
|
|
|
std::map<std::string, std::string>::iterator pos;
|
|
|
|
|
|
|
|
pos = dictionary.find (key);
|
|
|
|
if (pos != dictionary.end())
|
|
|
|
dictionary[key] = new_value;
|
|
|
|
else
|
|
|
|
err.SetErrorStringWithFormat ("'%s' is not an existing key; cannot replace value.\n", index_value);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
err.SetErrorString ("'settings replace' requires a key for dictionary variables. No key supplied.\n");
|
|
|
|
break;
|
2011-02-18 09:44:25 +08:00
|
|
|
case eVarSetOperationRemove:
|
2010-09-04 08:03:46 +08:00
|
|
|
if (index_value != NULL)
|
|
|
|
{
|
|
|
|
std::string key (index_value);
|
|
|
|
dictionary.erase (key);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
err.SetErrorString ("'settings remove' requires a key for dictionary variables. No key supplied.\n");
|
|
|
|
break;
|
2011-02-18 09:44:25 +08:00
|
|
|
case eVarSetOperationClear:
|
2010-09-04 08:03:46 +08:00
|
|
|
dictionary.clear ();
|
|
|
|
break;
|
2011-02-18 09:44:25 +08:00
|
|
|
case eVarSetOperationAppend:
|
|
|
|
case eVarSetOperationAssign:
|
2010-09-04 08:03:46 +08:00
|
|
|
{
|
2010-10-20 09:03:00 +08:00
|
|
|
// Clear the dictionary if it's an assign with new_value as NULL.
|
2011-02-18 09:44:25 +08:00
|
|
|
if (new_value == NULL && op == eVarSetOperationAssign)
|
2010-10-20 09:03:00 +08:00
|
|
|
{
|
|
|
|
dictionary.clear ();
|
|
|
|
break;
|
|
|
|
}
|
2010-09-04 08:03:46 +08:00
|
|
|
Args args (new_value);
|
|
|
|
size_t num_args = args.GetArgumentCount();
|
2010-12-19 11:41:24 +08:00
|
|
|
RegularExpression regex("(\\[\"?)?" // Regex match 1 (optional key prefix of '["' pr '[')
|
|
|
|
"([A-Za-z_][A-Za-z_0-9]*)" // Regex match 2 (key string)
|
|
|
|
"(\"?\\])?" // Regex match 3 (optional key suffix of '"]' pr ']')
|
|
|
|
"=" // The equal sign that is required
|
|
|
|
"(.*)"); // Regex match 4 (value string)
|
|
|
|
std::string key, value;
|
|
|
|
|
2010-09-04 08:03:46 +08:00
|
|
|
for (size_t i = 0; i < num_args; ++i)
|
|
|
|
{
|
2010-12-19 11:41:24 +08:00
|
|
|
const char *key_equal_value_arg = args.GetArgumentAtIndex (i);
|
|
|
|
// Execute the regular expression on each arg.
|
|
|
|
if (regex.Execute(key_equal_value_arg, 5))
|
2010-09-04 08:03:46 +08:00
|
|
|
{
|
2010-12-19 11:41:24 +08:00
|
|
|
// The regular expression succeeded. The match at index
|
|
|
|
// zero will be the entire string that matched the entire
|
|
|
|
// regular expression. The match at index 1 - 4 will be
|
|
|
|
// as mentioned above by the creation of the regex pattern.
|
|
|
|
// Match index 2 is the key, match index 4 is the value.
|
|
|
|
regex.GetMatchAtIndex (key_equal_value_arg, 2, key);
|
|
|
|
regex.GetMatchAtIndex (key_equal_value_arg, 4, value);
|
|
|
|
dictionary[key] = value;
|
2010-09-04 08:03:46 +08:00
|
|
|
}
|
|
|
|
else
|
2010-12-19 11:41:24 +08:00
|
|
|
{
|
|
|
|
err.SetErrorString ("Invalid format for dictionary value. Expected one of '[\"<key>\"]=<value>', '[<key>]=<value>', or '<key>=<value>'\n");
|
|
|
|
}
|
2010-09-04 08:03:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2011-02-18 09:44:25 +08:00
|
|
|
case eVarSetOperationInsertBefore:
|
|
|
|
case eVarSetOperationInsertAfter:
|
2010-09-04 08:03:46 +08:00
|
|
|
err.SetErrorString ("Specified operation cannot be performed on dictionary variables.\n");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
err.SetErrorString ("Unrecognized operation.\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
2011-02-18 09:44:25 +08:00
|
|
|
UserSettingsController::EnumToString (const OptionEnumValueElement *enum_values,
|
2010-09-04 08:03:46 +08:00
|
|
|
int value)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
while (enum_values[i].string_value != NULL)
|
|
|
|
{
|
|
|
|
if (enum_values[i].value == value)
|
|
|
|
return enum_values[i].string_value;
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
2011-02-18 09:44:25 +08:00
|
|
|
return "";
|
2010-09-04 08:03:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2011-02-18 09:44:25 +08:00
|
|
|
UserSettingsController::UpdateEnumVariable (OptionEnumValueElement *enum_values,
|
2010-09-04 08:03:46 +08:00
|
|
|
int *enum_var,
|
|
|
|
const char *new_value,
|
|
|
|
Error &err)
|
|
|
|
{
|
|
|
|
bool found_one;
|
|
|
|
|
|
|
|
*enum_var = Args::StringToOptionEnum (new_value, enum_values, enum_values[0].value, &found_one);
|
|
|
|
|
|
|
|
if (!found_one)
|
|
|
|
err.SetErrorString ("Invalid enumeration value; cannot update variable.\n");
|
|
|
|
}
|
|
|
|
|
2010-09-15 13:35:14 +08:00
|
|
|
void
|
|
|
|
UserSettingsController::RenameInstanceSettings (const char *old_name, const char *new_name)
|
|
|
|
{
|
|
|
|
Mutex::Locker live_mutex (m_live_settings_mutex);
|
|
|
|
Mutex::Locker pending_mutex (m_pending_settings_mutex);
|
|
|
|
std::string old_name_key (old_name);
|
|
|
|
std::string new_name_key (new_name);
|
|
|
|
|
|
|
|
// First, find the live instance settings for the old_name. If they don't exist in the live settings
|
|
|
|
// list, then this is not a setting that can be renamed.
|
|
|
|
|
|
|
|
if ((old_name_key[0] != '[') || (old_name_key[old_name_key.size() -1] != ']'))
|
2010-09-27 08:30:10 +08:00
|
|
|
{
|
2010-09-15 13:35:14 +08:00
|
|
|
StreamString tmp_str;
|
|
|
|
tmp_str.Printf ("[%s]", old_name);
|
|
|
|
old_name_key = tmp_str.GetData();
|
2010-09-27 08:30:10 +08:00
|
|
|
}
|
2010-09-15 13:35:14 +08:00
|
|
|
|
|
|
|
if ((new_name_key[0] != '[') || (new_name_key[new_name_key.size() -1] != ']'))
|
2010-09-27 08:30:10 +08:00
|
|
|
{
|
2010-09-15 13:35:14 +08:00
|
|
|
StreamString tmp_str;
|
|
|
|
tmp_str.Printf ("[%s]", new_name);
|
|
|
|
new_name_key = tmp_str.GetData();
|
2010-09-27 08:30:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (old_name_key.compare (new_name_key) == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
size_t len = new_name_key.length();
|
|
|
|
std::string stripped_new_name = new_name_key.substr (1, len-2); // new name without the '[ ]'
|
2010-09-15 13:35:14 +08:00
|
|
|
|
2011-04-20 06:32:36 +08:00
|
|
|
InstanceSettingsMap::iterator pos;
|
2010-09-15 13:35:14 +08:00
|
|
|
|
|
|
|
pos = m_live_settings.find (old_name_key);
|
|
|
|
if (pos != m_live_settings.end())
|
|
|
|
{
|
|
|
|
InstanceSettings *live_settings = pos->second;
|
|
|
|
|
|
|
|
// Rename the settings.
|
2010-09-27 08:30:10 +08:00
|
|
|
live_settings->ChangeInstanceName (stripped_new_name);
|
2010-09-15 13:35:14 +08:00
|
|
|
|
|
|
|
// Now see if there are any pending settings for the new name; if so, copy them into live_settings.
|
2011-02-18 09:44:25 +08:00
|
|
|
std::map<std::string, InstanceSettingsSP>::iterator pending_pos;
|
2010-09-15 13:35:14 +08:00
|
|
|
pending_pos = m_pending_settings.find (new_name_key);
|
|
|
|
if (pending_pos != m_pending_settings.end())
|
|
|
|
{
|
2011-02-18 09:44:25 +08:00
|
|
|
InstanceSettingsSP pending_settings_sp = pending_pos->second;
|
2010-09-15 13:35:14 +08:00
|
|
|
live_settings->CopyInstanceSettings (pending_settings_sp, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Erase the old entry (under the old name) from live settings.
|
|
|
|
m_live_settings.erase (pos);
|
|
|
|
|
|
|
|
// Add the new entry, with the new name, into live settings.
|
|
|
|
m_live_settings[new_name_key] = live_settings;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-04 08:03:46 +08:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class InstanceSettings
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2010-09-09 01:48:55 +08:00
|
|
|
InstanceSettings::InstanceSettings (UserSettingsController &owner, const char *instance_name, bool live_instance) :
|
2010-09-04 08:03:46 +08:00
|
|
|
m_owner (owner),
|
|
|
|
m_instance_name (instance_name)
|
|
|
|
{
|
2010-09-09 01:48:55 +08:00
|
|
|
if ((m_instance_name != InstanceSettings::GetDefaultName())
|
2010-09-17 03:05:55 +08:00
|
|
|
&& (m_instance_name != InstanceSettings::InvalidName())
|
2010-09-09 01:48:55 +08:00
|
|
|
&& live_instance)
|
2010-09-04 08:03:46 +08:00
|
|
|
m_owner.RegisterInstanceSettings (this);
|
|
|
|
}
|
|
|
|
|
|
|
|
InstanceSettings::~InstanceSettings ()
|
|
|
|
{
|
|
|
|
if (m_instance_name != InstanceSettings::GetDefaultName())
|
|
|
|
m_owner.UnregisterInstanceSettings (this);
|
|
|
|
}
|
|
|
|
|
|
|
|
const ConstString &
|
|
|
|
InstanceSettings::GetDefaultName ()
|
|
|
|
{
|
|
|
|
static const ConstString g_default_settings_name ("[DEFAULT]");
|
|
|
|
|
|
|
|
return g_default_settings_name;
|
|
|
|
}
|
2010-09-15 13:35:14 +08:00
|
|
|
|
2010-09-17 03:05:55 +08:00
|
|
|
const ConstString &
|
|
|
|
InstanceSettings::InvalidName ()
|
|
|
|
{
|
|
|
|
static const ConstString g_invalid_name ("Invalid instance name");
|
|
|
|
|
|
|
|
return g_invalid_name;
|
|
|
|
}
|
|
|
|
|
2010-09-15 13:35:14 +08:00
|
|
|
void
|
|
|
|
InstanceSettings::ChangeInstanceName (const std::string &new_instance_name)
|
|
|
|
{
|
|
|
|
m_instance_name.SetCString (new_instance_name.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
|