/*
    Get the value of the defined property (including looping through
    chained properties) and convert that value to an FQLOperand.
*/
Boolean FQLInstancePropertySource::getValue(
    const String& propertyName,
    FQLOperand& value) const
{
    CIMValue val;
    CIMType type;

#ifdef ENABLE_LOCAL_DIAGNOSTICS
    DCOUT << "getValue " << propertyName << " isChained "
          << boolToString(value.isChained()) << endl;
#endif
    // if dotted property, return the embedded instance or false if
    // the value is NOT an instance.
    if (value.isChained())
    {
        if (!_getPropertyValue(ci, propertyName, val))
        {
            // Property could not be found, return false.
            return false;
        }
        type=val.getType();

        if (type != CIMTYPE_INSTANCE)
        {
            return false;
        }
        else
        {
            CIMInstance ciLocal;
            val.get(ciLocal);
            if (value.isChained())
            {
                PEGASUS_ASSERT(value.chainSize() != 0);

                // If this property is chained, resolve the property chain
                FQLOperand x;
                Uint32 chainSize = value.chainSize();
                Uint32 lastEntry = chainSize - 1;

                for (Uint32 i = 0; i < chainSize; i++)
                {
                    // Get chained operand and get name from it
                    x = value.chainItem(i);
                    String pName  = x.getPropertyName();

                    // Get name from the chain item
                    if (!_getPropertyValue(ciLocal, pName, val))
                    {
                        // Property could not be found, return false.
                        return false;
                    }
                    type=val.getType();

                    if (type == CIMTYPE_INSTANCE)
                    {
                        if (i == lastEntry)
                        {
                            return false;
                        }
                        else
                        {
                            val.get(ciLocal);
                        }
                    }
                    else
                    {
                        if (i != lastEntry)
                        {
                            return false;
                        }
                    }
                }
            }
        }
    }
    else
    {
        unsigned int pos=ci.findProperty(propertyName);
        if (pos==PEG_NOT_FOUND)
        {
            // Property could not be found, return false.
            return false;
        }

        val=ci.getProperty(pos).getValue();
        type=val.getType();
    }

    if (val.isNull())
    {
        value=FQLOperand();
        return true;
    }

    if (val.isArray())
    {
        switch (type)
        {
        case CIMTYPE_UINT8:
        {
            Array<Uint8> propertyValueUint8;
            val.get(propertyValueUint8);
            Array<Sint64> propertyValueSint64;
            for (Uint32 i = 0; i < propertyValueUint8.size(); i++)
            {
                propertyValueSint64.append((Sint64)propertyValueUint8[i]);
            }
            value = FQLOperand(propertyValueSint64, FQL_INTEGER_VALUE_TAG);
        }
        break;

        case CIMTYPE_UINT16:
        {
            Array<Uint16> propertyValueUint16;
            val.get(propertyValueUint16);
            Array<Sint64> propertyValueSint64;
            for (Uint32 i = 0; i < propertyValueUint16.size(); i++)
            {
                propertyValueSint64.append((Sint64)propertyValueUint16[i]);
            }
            value=FQLOperand(propertyValueSint64, FQL_INTEGER_VALUE_TAG);
        }
        break;

        case CIMTYPE_UINT32:
        {
            Array<Uint32> propertyValueUint32;
            val.get(propertyValueUint32);
            Array<Sint64> propertyValueSint64;
            for (Uint32 i = 0; i < propertyValueUint32.size(); i++)
            {
                propertyValueSint64.append((Sint64)propertyValueUint32[i]);
            }
            value=FQLOperand(propertyValueSint64, FQL_INTEGER_VALUE_TAG);
        }
        break;

        case CIMTYPE_UINT64:
        {
            Array<Uint64> propertyValueUint64;
            val.get(propertyValueUint64);
            Array<Sint64> propertyValueSint64;
            for (Uint32 i = 0; i < propertyValueUint64.size(); i++)
            {
                propertyValueSint64.append((Sint64)propertyValueUint64[i]);
            }
            value=FQLOperand(propertyValueSint64, FQL_INTEGER_VALUE_TAG);
        }
        break;

        case CIMTYPE_SINT8:
        {
            Array<Sint8> propertyValueSint8;
            val.get(propertyValueSint8);
            Array<Sint64> propertyValueSint64;
            for (Uint32 i = 0; i < propertyValueSint8.size(); i++)
            {
                propertyValueSint64.append((Sint64)propertyValueSint8[i]);
            }
            value=FQLOperand(propertyValueSint64, FQL_INTEGER_VALUE_TAG);
        }
        break;

        case CIMTYPE_SINT16:
        {
            Array<Sint16> propertyValueSint16;
            val.get(propertyValueSint16);
            Array<Sint64> propertyValueSint64;
            for (Uint32 i = 0; i < propertyValueSint16.size(); i++)
            {
                propertyValueSint64.append((Sint64)propertyValueSint16[i]);
            }
            value=FQLOperand(propertyValueSint64, FQL_INTEGER_VALUE_TAG);
        }
        break;

        case CIMTYPE_SINT32:
        {
            Array<Sint32> propertyValueSint32;
            val.get(propertyValueSint32);
            Array<Sint64> propertyValueSint64;
            for (Uint32 i = 0; i < propertyValueSint32.size(); i++)
            {
                propertyValueSint64.append(propertyValueSint32[i]);
            }
            value=FQLOperand(propertyValueSint64, FQL_INTEGER_VALUE_TAG);
        }
        break;

        case CIMTYPE_SINT64:
        {
            Array<Sint64> propertyValueSint64;
            val.get(propertyValueSint64);
            value=FQLOperand(propertyValueSint64, FQL_INTEGER_VALUE_TAG);
        }
        break;

        case CIMTYPE_REAL32:
        {
            Array<Real32> propertyValueReal32;
            val.get(propertyValueReal32);
            Array<Real64> propertyValueReal64;
            for (Uint32 i = 0; i < propertyValueReal32.size(); i++)
            {
                propertyValueReal64.append((Real64)propertyValueReal32[i]);
            }
            value=FQLOperand(propertyValueReal64, FQL_DOUBLE_VALUE_TAG);
        }
        break;

        case CIMTYPE_REAL64:
        {
            Array<Real64> propertyValueReal64;
            val.get(propertyValueReal64);
            value=FQLOperand(propertyValueReal64, FQL_DOUBLE_VALUE_TAG);
        }
        break;

        case CIMTYPE_BOOLEAN :
        {
            Array<Boolean> booleanValues;
            val.get(booleanValues);
            value=FQLOperand(booleanValues, FQL_BOOLEAN_VALUE_TAG);
        }
        break;

        case CIMTYPE_CHAR16:
        {
            Array <Char16> char16val;
            val.get(char16val);
            String str;
            for (Uint32 i = 0 ; i < char16val.size(); i++)
            {
                str.append(char16val[i]);
            }
            value=FQLOperand(str, FQL_STRING_VALUE_TAG);
            break;
        }
        case CIMTYPE_DATETIME :
        {
            Array<CIMDateTime> datetimeValue;
            val.get(datetimeValue);
            value = FQLOperand(datetimeValue, FQL_DATETIME_VALUE_TAG);
            break;
        }
        case CIMTYPE_STRING :
        {
            Array<String> strValue;
            val.get(strValue);
            value=FQLOperand(strValue,FQL_STRING_VALUE_TAG);
            break;
        }
        case CIMTYPE_REFERENCE :
        {
            Array<CIMObjectPath> objPathValue;
            val.get(objPathValue);
            value=FQLOperand(objPathValue,FQL_REFERENCE_VALUE_TAG);
            break;
        }

        case CIMTYPE_OBJECT :
        case CIMTYPE_INSTANCE :
            PEGASUS_ASSERT(false);
        }
    }
    else
    {
        switch (type)
        {
        case CIMTYPE_UINT8:
            Uint8 propertyValueUint8;
            val.get(propertyValueUint8);
            value=FQLOperand(propertyValueUint8,FQL_INTEGER_VALUE_TAG);
            break;

        case CIMTYPE_UINT16:
            Uint16 propertyValueUint16;
            val.get(propertyValueUint16);
            value=FQLOperand(propertyValueUint16, FQL_INTEGER_VALUE_TAG);
            break;

        case CIMTYPE_UINT32:
            Uint32 propertyValueUint32;
            val.get(propertyValueUint32);
            value=FQLOperand(propertyValueUint32, FQL_INTEGER_VALUE_TAG);
            break;

        case CIMTYPE_UINT64:
            Uint64 propertyValueUint64;
            val.get(propertyValueUint64);
            value=FQLOperand(propertyValueUint64, FQL_INTEGER_VALUE_TAG);
            break;

        case CIMTYPE_SINT8:
            Sint8 propertyValueSint8;
            val.get(propertyValueSint8);
            value=FQLOperand(propertyValueSint8, FQL_INTEGER_VALUE_TAG);
            break;

        case CIMTYPE_SINT16:
            Sint16 propertyValueSint16;
            val.get(propertyValueSint16);
            value=FQLOperand(propertyValueSint16, FQL_INTEGER_VALUE_TAG);
            break;

        case CIMTYPE_SINT32:
            Sint32 propertyValueSint32;
            val.get(propertyValueSint32);
            value=FQLOperand(propertyValueSint32, FQL_INTEGER_VALUE_TAG);
            break;

        case CIMTYPE_SINT64:
            Sint64 propertyValueSint64;
            val.get(propertyValueSint64);
            value=FQLOperand(propertyValueSint64, FQL_INTEGER_VALUE_TAG);
            break;

        case CIMTYPE_REAL32:
            Real32 propertyValueReal32;
            val.get(propertyValueReal32);
            value=FQLOperand(propertyValueReal32, FQL_DOUBLE_VALUE_TAG);
            break;

        case CIMTYPE_REAL64:
            Real64 propertyValueReal64;
            val.get(propertyValueReal64);
            value=FQLOperand(propertyValueReal64, FQL_DOUBLE_VALUE_TAG);
            break;

        case CIMTYPE_BOOLEAN :
            Boolean booleanValue;
            val.get(booleanValue);
            value=FQLOperand(booleanValue, FQL_BOOLEAN_VALUE_TAG);
            break;

        case CIMTYPE_CHAR16:
        {
            Char16 char16Value;
            val.get(char16Value);
            String str;
            str.append(char16Value);
            value=FQLOperand(str, FQL_STRING_VALUE_TAG);
            break;
        }
        case CIMTYPE_DATETIME :
        {
            CIMDateTime datetimeValue;
            val.get(datetimeValue);
            value=FQLOperand(datetimeValue, FQL_DATETIME_VALUE_TAG);
            break;
        }
        case CIMTYPE_STRING :
        {
            String strValue;
            val.get(strValue);
            value=FQLOperand(strValue,FQL_STRING_VALUE_TAG);
            break;
        }
        case CIMTYPE_REFERENCE :
        {
            CIMObjectPath objPathValue;
            val.get(objPathValue);
            value = FQLOperand(objPathValue, FQL_REFERENCE_VALUE_TAG);
            break;
        }
        // The following are not valid FQL types
        case CIMTYPE_OBJECT :
        case CIMTYPE_INSTANCE :
            PEGASUS_ASSERT(false);
        }
    }
    value.setCIMType(type);
    return true;
}
예제 #2
0
static ProviderName _lookupProvider(const CIMObjectPath & cimObjectPath)
{
    String providerName;
    String moduleName;

    try
    {
        // get the PG_ProviderCapabilities instances for the specified namespace:class_name. use the matching
        // instance to gather the PG_Provider instance name (logical name).

        Array<CIMObjectPath> cimInstanceNames = _prm->enumerateInstanceNames(CIMObjectPath(String::EMPTY, "root/PG_Interop", "PG_ProviderCapabilities"));

        for(Uint32 i = 0, n = cimInstanceNames.size(); i < n; i++)
        {
            CIMInstance cimInstance = _prm->getInstance(cimInstanceNames[i]);

            // check ClassName property value
            if(String::equalNoCase(cimObjectPath.getClassName().getString(), _getPropertyValue(cimInstance, "ClassName").toString()))
            {
                // check Namespaces property value
                Array<String> nameSpaces;

                _getPropertyValue(cimInstance, "Namespaces").get(nameSpaces);

                // ATTN: need to walk the array
                if(String::equalNoCase(cimObjectPath.getNameSpace().getString(), nameSpaces[0]))
                {
                    providerName = _getPropertyValue(cimInstance, "ProviderName").toString();

                    break;
                }
            }
        }
    }
    catch(...)
    {
    }

    // ensure the provider name is valid
    if(providerName.size() == 0)
    {
        throw Exception("Could not determine PG_Provider instance for specified class.");
    }

    try
    {
        // get the PG_Provider instances associated with the specified namespace:class_name. use the matching
        // instance to gather the PG_ProviderModule instance name.

        Array<CIMObjectPath> cimInstanceNames = _prm->enumerateInstanceNames(CIMObjectPath(String::EMPTY, "root/PG_Interop", "PG_Provider"));

        for(Uint32 i = 0, n = cimInstanceNames.size(); i < n; i++)
        {
            CIMInstance cimInstance = _prm->getInstance(cimInstanceNames[i]);

            if(String::equalNoCase(providerName, _getPropertyValue(cimInstance, "Name").toString()))
            {
                moduleName = _getPropertyValue(cimInstance, "ProviderModuleName").toString();

                break;
            }
        }
    }
    catch(...)
    {
    }

    // ensure the module name is valid
    if(moduleName.size() == 0)
    {
        throw Exception("Could not determine PG_ProviderModule instance for specified class.");
    }

    String interfaceType;
    String moduleLocation;

    try
    {
        // get the PG_ProviderModule instances associated with the specified namespace:class_name. use the matching
        // instance to gather the module status and location (physical name).

        Array<CIMObjectPath> cimInstanceNames = _prm->enumerateInstanceNames(CIMObjectPath(String::EMPTY, "root/PG_Interop", "PG_ProviderModule"));

        for(Uint32 i = 0, n = cimInstanceNames.size(); i < n; i++)
        {
            CIMInstance cimInstance = _prm->getInstance(cimInstanceNames[i]);

            if(String::equalNoCase(moduleName, _getPropertyValue(cimInstance, "Name").toString()))
            {
                // ATTN: check operational status

                // get interface
                interfaceType = _getPropertyValue(cimInstance, "InterfaceType").toString();

                // get location
                moduleLocation = _getPropertyValue(cimInstance, "Location").toString();

                break;
            }
        }
    }
    catch(...)
    {
    }

    // ensure the interface and location are valid
    if((interfaceType.size() == 0) || (moduleLocation.size() == 0))
    {
        throw Exception("Could not determine PG_ProviderModule.InterfaceType or PG_ProviderModule.Location or module is disabled.");
    }

    // DEBUG
    CString s1 = interfaceType.getCString();
    const char * p1 = s1;

    CString s2 = moduleLocation.getCString();
    const char * p2 = s2;

    ProviderName temp(
        providerName,
        moduleLocation,
        interfaceType,
        0);

    return(temp);
}