Esempio n. 1
0
bool CVariableStorage::add( const wxString& varName, const wxString& value, uint8_t type, bool bPersistent )
{
    // Name is always upper case
    wxString name = varName.Upper();
  name.Trim( true );
  name.Trim( false );

    CVSCPVariable *pVar = new CVSCPVariable;
  if ( NULL == pVar ) return false;

  pVar->setType( type );			// Store the type

    // Store persistence
    if ( bPersistent ) {
        pVar->setPersistent( true );
    }
    else {
        pVar->setPersistent( false );
    }

    pVar->setName( name );

    // Store value
    if ( !pVar->setValueFromString( type, value ) ) return false;

    // If persistent store persistant value
    if ( bPersistent ) {
        pVar->setPersistatValue( value );
    }

    if ( NULL != find( name ) ) {
        
        // The variable is there already - just change value
        m_hashVariable[ name ]->setValueFromString( m_hashVariable[ name ]->getType(), value );

        delete pVar;	// No use for the variable

    }
    else {
        // New variable
        m_hashVariable[ name ] = pVar;
        m_listVariable.Append( pVar );
    }

    return true;
}
Esempio n. 2
0
bool CVariableStorage::load( void )
{
    bool bArray;
    wxXmlDocument doc;

#ifdef BUILD_VSCPD_SERVICE
    wxStandardPaths stdPath;

    // Set the default dm configuration path
#ifdef WIN32	
    m_configPath = stdPath.GetConfigDir();
    m_configPath += _("/vscp/variables.xml");
#else
	m_configPath = _("/srv/vscp/variables.xml");
#endif	
#endif

    if (!doc.Load( m_configPath ) ) {
        return false;
    }

    //::wxLogDebug ( _("Loading variables from: \n\t") + m_configPath );

    // start processing the XML file
    if ( doc.GetRoot()->GetName() != wxT("persistent") ) {
        return false;
    }

    wxXmlNode *child = doc.GetRoot()->GetChildren();
    while (child) {

        if (child->GetName() == wxT("variable")) {

            CVSCPVariable *pVar = new CVSCPVariable;
            pVar->setPersistent( true );     // Loaded variables are persistent
            bArray = false;

            // Get variable type - String is default
#if wxCHECK_VERSION(3,0,0)            
            pVar->setType( pVar->getVariableTypeFromString( child->GetAttribute( wxT("type"), wxT("string") ) ) );  
#else
            pVar->setType( pVar->getVariableTypeFromString( child->GetPropVal( wxT("type"), wxT("string") ) ) );
#endif             

            wxXmlNode *subchild = child->GetChildren();
            while (subchild) {

                if (subchild->GetName() == wxT("name")) {
                    wxString strName = subchild->GetNodeContent();
                    strName.Trim();
                    strName.Trim(false);
                    // Replace spaces in name with underscore
                    int pos;
                    while (wxNOT_FOUND != ( pos = strName.Find(_(" ")))){
                        strName.SetChar(pos,wxChar('_'));
                    }
                    pVar->setName( strName );
                }
                else if (subchild->GetName() == wxT("value")) {
                    pVar->setValueFromString( pVar->getType(), subchild->GetNodeContent() );
                    pVar->setPersistatValue( subchild->GetNodeContent() );
                }
                else if (subchild->GetName() == wxT("note")) {
                    pVar->setNote( subchild->GetNodeContent() );
                }

                subchild = subchild->GetNext();

            }

            // Add the variable (always persistent if from file storage)
            add( pVar );

        }

        child = child->GetNext();

    }

    return true;
}