Commit 044881e3 authored by Cory Quammen's avatar Cory Quammen Committed by Utkarsh Ayachit

Settings now stored internally exclusively as a Json::Value tree

This avoids the need to synchronize the Json::Value and JSON
string member variables.

Made member names for setting/getting settings from/to strings
more accurate.

Change-Id: Ic499a27cc0c12b4e97a0b32ddb975318b23593aa
parent 0e38716a
......@@ -29,8 +29,8 @@ settingsString = """
""" % (trueRadius, trueThetaResolution, trueCenter[0], trueCenter[1], trueCenter[2])
settings = paraview.servermanager.vtkSMSettings.GetInstance()
settings.SetUserSettingsString(settingsString)
settings.SetSiteSettingsString("{}")
settings.SetUserSettingsFromString(settingsString)
settings.SetSiteSettingsFromString("{}")
# Check the setting directly
settingPath = ".sources.SphereSource.Radius"
......@@ -76,8 +76,38 @@ if radius != trueRadius:
# Now clear out the settings and test setting values
#
#
settings.SetUserSettingsString("{}")
settings.SetSiteSettingsString("{}")
settings.SetUserSettingsFromString(None)
settingsString = settings.GetUserSettingsAsString()
if settingsString != "{}\n":
print "User settings set from None should be {}"
sys.exit(-1)
settings.SetSiteSettingsFromString(None)
settingsString = settings.GetSiteSettingsAsString()
if settingsString != "{}\n":
print "Site settings set from None should be {}"
sys.exit(-1)
settings.SetUserSettingsFromString("")
settingsString = settings.GetUserSettingsAsString()
if settingsString != "{}\n":
print "User settings set from empty string should be {}"
sys.exit(-1)
settings.SetSiteSettingsFromString("")
settingsString = settings.GetSiteSettingsAsString()
if settingsString != "{}\n":
print "Site settings set from empty string should be {}"
sys.exit(-1)
settings.SetUserSettingsFromString("{}")
settingsString = settings.GetUserSettingsAsString()
if settingsString != "{}\n":
print "User settings set from {} should be {}"
sys.exit(-1)
settings.SetSiteSettingsFromString("{}")
settingsString = settings.GetSiteSettingsAsString()
if settingsString != "{}\n":
print "Site settings set from {} should be {}"
sys.exit(-1)
if settings.HasSetting(".sources.SphereSource"):
print "Setting '.sources.SphereSource' should have been cleared"
......
......@@ -529,8 +529,6 @@ vtkStandardNewMacro(vtkSMSettings);
//----------------------------------------------------------------------------
vtkSMSettings::vtkSMSettings()
{
this->UserSettingsString = NULL;
this->SiteSettingsString = NULL;
this->Internal = new vtkSMSettingsInternal();
}
......@@ -599,7 +597,7 @@ bool vtkSMSettings::LoadUserSettings(const char* fileName)
userSettingsString[stringSize] = '\0';
userSettingsFile.close();
this->SetUserSettingsString( userSettingsString );
this->SetUserSettingsFromString( userSettingsString );
delete[] userSettingsString;
}
else
......@@ -611,36 +609,19 @@ bool vtkSMSettings::LoadUserSettings(const char* fileName)
}
//----------------------------------------------------------------------------
void vtkSMSettings::SetUserSettingsString(const char* settings)
void vtkSMSettings::SetUserSettingsFromString(const char* settings)
{
vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting UserSettingsString to "
<< (settings ? settings :"(null)") );
if ( this->UserSettingsString == NULL && settings == NULL) { return;}
if ( this->UserSettingsString && settings && (!strcmp(this->UserSettingsString,settings))) { return;}
delete [] this->UserSettingsString;
// Blank out the settings
this->Internal->UserSettingsJSONRoot.clear();
if (settings)
{
size_t n = strlen(settings) + 1;
char *cp1 = new char[n];
const char *cp2 = settings;
this->UserSettingsString = cp1;
do { *cp1++ = *cp2++; } while ( --n );
}
else
{
this->UserSettingsString = NULL;
}
this->Modified();
if (!this->UserSettingsString)
if (settings == NULL || strcmp(settings, "") == 0)
{
return;
}
// Parse the user settings
Json::Reader reader;
bool success = reader.parse(std::string( settings ), this->Internal->UserSettingsJSONRoot, false);
bool success = reader.parse(std::string(settings), this->Internal->UserSettingsJSONRoot, false);
if (!success)
{
vtkErrorMacro(<< "Could not parse user settings JSON");
......@@ -648,6 +629,12 @@ void vtkSMSettings::SetUserSettingsString(const char* settings)
}
}
//----------------------------------------------------------------------------
std::string vtkSMSettings::GetUserSettingsAsString()
{
return this->Internal->UserSettingsJSONRoot.toStyledString();
}
//----------------------------------------------------------------------------
bool vtkSMSettings::LoadSiteSettings()
{
......@@ -694,7 +681,7 @@ bool vtkSMSettings::LoadSiteSettings(const char* fileName)
siteSettingsString[stringSize] = '\0';
siteSettingsFile.close();
this->SetSiteSettingsString( siteSettingsString );
this->SetSiteSettingsFromString( siteSettingsString );
delete[] siteSettingsString;
}
else
......@@ -706,36 +693,19 @@ bool vtkSMSettings::LoadSiteSettings(const char* fileName)
}
//----------------------------------------------------------------------------
void vtkSMSettings::SetSiteSettingsString(const char* settings)
void vtkSMSettings::SetSiteSettingsFromString(const char* settings)
{
vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting SiteSettingsString to "
<< (settings ? settings :"(null)") );
if ( this->SiteSettingsString == NULL && settings == NULL) { return;}
if ( this->SiteSettingsString && settings && (!strcmp(this->SiteSettingsString,settings))) { return;}
delete [] this->SiteSettingsString;
// Blank out the settings
this->Internal->SiteSettingsJSONRoot.clear();
if (settings)
{
size_t n = strlen(settings) + 1;
char *cp1 = new char[n];
const char *cp2 = settings;
this->SiteSettingsString = cp1;
do { *cp1++ = *cp2++; } while ( --n );
}
else
{
this->SiteSettingsString = NULL;
}
this->Modified();
if ( !this->SiteSettingsString )
if (settings == NULL || strcmp(settings, "") == 0)
{
return;
}
// Parse the user settings
Json::Reader reader;
bool success = reader.parse(std::string( settings ), this->Internal->SiteSettingsJSONRoot, false);
bool success = reader.parse(std::string(settings), this->Internal->SiteSettingsJSONRoot, false);
if (!success)
{
vtkErrorMacro(<< "Could not parse site settings JSON");
......@@ -743,6 +713,12 @@ void vtkSMSettings::SetSiteSettingsString(const char* settings)
}
}
//----------------------------------------------------------------------------
std::string vtkSMSettings::GetSiteSettingsAsString()
{
return this->Internal->SiteSettingsJSONRoot.toStyledString();
}
//----------------------------------------------------------------------------
bool vtkSMSettings::HasSetting(const char* settingName)
{
......@@ -977,29 +953,9 @@ bool vtkSMSettings::GetProxySettings(vtkSMProxy* proxy, const char* jsonPrefix)
//----------------------------------------------------------------------------
void vtkSMSettings::PrintSelf(ostream& os, vtkIndent indent)
{
os << indent << "UserSettingsString: ";
if ( this->UserSettingsString )
{
os << "\n" << this->UserSettingsString << "\n";
}
else
{
os << "(null)";
}
os << indent << "UserSettings:\n";
os << this->Internal->UserSettingsJSONRoot.toStyledString();
os << indent << "SiteSettingsString: ";
if ( this->SiteSettingsString )
{
os << "\n" << this->SiteSettingsString << "\n";
}
else
{
os << "(null)";
}
os << indent << "SiteSettings:\n";
os << this->Internal->SiteSettingsJSONRoot.toStyledString();
}
......@@ -55,8 +55,8 @@ public:
// Description:
// Set user-specific settings. These are stored in a home directory.
virtual void SetUserSettingsString(const char* settings);
vtkGetStringMacro(UserSettingsString);;
virtual void SetUserSettingsFromString(const char* settings);
virtual std::string GetUserSettingsAsString();
// Description:
// Load site settings from default location TBD. Returns true on success,
......@@ -70,8 +70,8 @@ public:
// Description:
// Set site-specific settings. These are stored in a location TBD.
virtual void SetSiteSettingsString(const char* settings);
vtkGetStringMacro(SiteSettingsString);
virtual void SetSiteSettingsFromString(const char* settings);
virtual std::string GetSiteSettingsAsString();
// Description:
// Check whether a setting is defined for the requested names.
......@@ -130,12 +130,6 @@ private:
vtkSMSettings(const vtkSMSettings&); // Purposely not implemented
void operator=(const vtkSMSettings&); // Purposely not implemented
// User-specified settings
char* UserSettingsString;
// Site-specific settings
char* SiteSettingsString;
class vtkSMSettingsInternal;
vtkSMSettingsInternal * Internal;
};
......
......@@ -205,20 +205,20 @@ void vtkInitializationHelper::Initialize(int argc, char**argv,
unsigned int stringSize;
if (controller->GetLocalProcessId() == 0)
{
char* siteSettingsString = settings->GetSiteSettingsString();
stringSize = siteSettingsString ? (strlen(siteSettingsString)+1) : 0;
std::string siteSettingsString = settings->GetSiteSettingsAsString().c_str();
stringSize = static_cast<unsigned int>(siteSettingsString.size())+1;
controller->Broadcast(&stringSize, 1, 0);
if (stringSize > 0)
{
controller->Broadcast(siteSettingsString, stringSize, 0);
controller->Broadcast(const_cast<char*>(siteSettingsString.c_str()), stringSize, 0);
}
char* userSettingsString = settings->GetUserSettingsString();
stringSize = userSettingsString ? (strlen(userSettingsString)+1) : 0;
std::string userSettingsString = settings->GetUserSettingsAsString();
stringSize = static_cast<unsigned int>(userSettingsString.size())+1;
controller->Broadcast(&stringSize, 1, 0);
if (stringSize > 0)
{
controller->Broadcast(userSettingsString, stringSize, 0);
controller->Broadcast(const_cast<char*>(userSettingsString.c_str()), stringSize, 0);
}
}
else // Satellites
......@@ -228,26 +228,24 @@ void vtkInitializationHelper::Initialize(int argc, char**argv,
{
char* siteSettingsString = new char[stringSize];
controller->Broadcast(siteSettingsString, stringSize, 0);
std::cout << "siteSettings: " << siteSettingsString << std::endl;
settings->SetSiteSettingsString(siteSettingsString);
settings->SetSiteSettingsFromString(siteSettingsString);
delete[] siteSettingsString;
}
else
{
settings->SetSiteSettingsString(NULL);
settings->SetSiteSettingsFromString(NULL);
}
controller->Broadcast(&stringSize, 1, 0);
if (stringSize > 0)
{
char* userSettingsString = new char[stringSize];
controller->Broadcast(userSettingsString, stringSize, 0);
std::cout << "userSettings: " << userSettingsString << std::endl;
settings->SetUserSettingsString(userSettingsString);
settings->SetUserSettingsFromString(userSettingsString);
delete[] userSettingsString;
}
else
{
settings->SetUserSettingsString(NULL);
settings->SetUserSettingsFromString(NULL);
}
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment