Esempio n. 1
0
Boolean CIMKeyBinding::equal(CIMValue value)
{
    if (value.isArray())
    {
        return false;
    }

    CIMValue kbValue;

    try
    {
        switch (value.getType())
        {
        case CIMTYPE_CHAR16:
            if (getType() != STRING) return false;
            kbValue.set(getValue()[0]);
            break;
        case CIMTYPE_DATETIME:
            if (getType() != STRING) return false;
            kbValue.set(CIMDateTime(getValue()));
            break;
        case CIMTYPE_STRING:
            if (getType() != STRING) return false;
            kbValue.set(getValue());
            break;
        case CIMTYPE_REFERENCE:
            if (getType() != REFERENCE) return false;
            kbValue.set(CIMObjectPath(getValue()));
            break;
        case CIMTYPE_BOOLEAN:
            if (getType() != BOOLEAN) return false;
            kbValue = XmlReader::stringToValue(0, getValue().getCString(),
                                               value.getType());
            break;
//      case CIMTYPE_REAL32:
//      case CIMTYPE_REAL64:
        case CIMTYPE_OBJECT:
        case CIMTYPE_INSTANCE:
            // From PEP 194: EmbeddedObjects cannot be keys.
            return false;
        default:  // Numerics
            if (getType() != NUMERIC) return false;
            kbValue = XmlReader::stringToValue(0, getValue().getCString(),
                                               value.getType());
            break;
        }
    }
    catch (Exception&)
    {
        return false;
    }

    return value.equal(kbValue);
}
Esempio n. 2
0
void
test04 (CIMClient & client)
{
  CIMObjectPath instanceName;

  instanceName.setNameSpace (providerNamespace);
  instanceName.setClassName (CLASSNAME);

  Array < CIMParamValue > inParams;
  Array < CIMParamValue > outParams;

  /*     [EmbeddedObject] String returnInstance(); */

  CIMValue retValue = client.invokeMethod (providerNamespace,
                       instanceName,
                       "returnInstance",
                       inParams,
                       outParams);

  PEGASUS_TEST_ASSERT (retValue.getType () == CIMTYPE_OBJECT);
  PEGASUS_TEST_ASSERT (!retValue.isArray ());
  PEGASUS_TEST_ASSERT (!retValue.isNull ());

  CIMObject result;
  retValue.get (result);

  CIMObjectPath objPath  = result.getPath();
  PEGASUS_TEST_ASSERT (objPath.toString() == "TestCMPI_Instance");

}
Esempio n. 3
0
    static CMPIData mbGetProperty(
        const CMPIBroker *mb,
        const CMPIContext *ctx,
        const CMPIObjectPath *cop,
        const char *name,
        CMPIStatus *rc)
    {
        PEG_METHOD_ENTER(
            TRC_CMPIPROVIDERINTERFACE,
            "CMPI_Broker:mbGetProperty()");
        mb = CM_BROKER;
        CMPIData data = {0,CMPI_nullValue,{0}};

        SCMOInstance* scmoObjPath = SCMO_ObjectPath(cop);
        CIMObjectPath qop;
        scmoObjPath->getCIMObjectPath(qop);

        try
        {
            CIMValue v = CM_CIMOM(mb)->getProperty(
                *CM_Context(ctx),
                SCMO_ObjectPath(cop)->getNameSpace(),
                qop,
                String(name));
            CIMType vType = v.getType();
            CMPIType t = type2CMPIType(vType,v.isArray());
            value2CMPIData(v,t,&data);
            CMSetStatus(rc,CMPI_RC_OK);
        }
        HandlerCatchSetStatus(rc, data);

        PEG_METHOD_EXIT();
        return data; // "data" will be valid data or nullValue (in error case)
    }
Esempio n. 4
0
void _checkUint32Property
  (CIMInstance & instance, const String & name, Uint32 value)
{
  Uint32 pos = instance.findProperty (name);
  PEGASUS_ASSERT (pos != PEG_NOT_FOUND);

  CIMProperty theProperty = instance.getProperty (pos);
  CIMValue theValue = theProperty.getValue ();

  PEGASUS_ASSERT (theValue.getType () == CIMTYPE_UINT32);
  PEGASUS_ASSERT (!theValue.isArray ());
  PEGASUS_ASSERT (!theValue.isNull ());
  Uint32 result;
  theValue.get (result);

  if (verbose)
    {
      if (result != value)
	{
	  cerr << "Property value comparison failed.  ";
	  cerr << "Expected " << value << "; ";
	  cerr << "Actual property value was " << result << "." << endl;
	}
    }

  PEGASUS_ASSERT (result == value);
}
Esempio n. 5
0
void _checkUint64Property
  (CIMInstance & instance, const String & name, Uint64 value)
{
  Uint32 pos = instance.findProperty (name);
  PEGASUS_ASSERT (pos != PEG_NOT_FOUND);

  CIMProperty theProperty = instance.getProperty (pos);
  CIMValue theValue = theProperty.getValue ();

  PEGASUS_ASSERT (theValue.getType () == CIMTYPE_UINT64);
  PEGASUS_ASSERT (!theValue.isArray ());
  PEGASUS_ASSERT (!theValue.isNull ());
  Uint64 result;
  theValue.get (result);

  if (verbose)
    {
      if (result != value)
	{
	  char buffer[32];	// Should need 21 chars max
	  sprintf (buffer, "%" PEGASUS_64BIT_CONVERSION_WIDTH "u", value);
	  cerr << "Property value comparison failed.  ";
	  cerr << "Expected " << buffer << "; ";
	  sprintf (buffer, "%" PEGASUS_64BIT_CONVERSION_WIDTH "u", result);
	  cerr << "Actual property value was " << buffer << "." << endl;
	}
    }

  PEGASUS_ASSERT (result == value);
}
Esempio n. 6
0
void _checkStringValue (CIMValue & theValue,
    const String & value,
    Boolean null = false)
{
    PEGASUS_TEST_ASSERT (theValue.getType () == CIMTYPE_STRING);
    PEGASUS_TEST_ASSERT (!theValue.isArray ());
    if (null)
    {
        PEGASUS_TEST_ASSERT (theValue.isNull ());
    }
    else
    {
        PEGASUS_TEST_ASSERT (!theValue.isNull ());
        String result;
        theValue.get (result);

        if (verbose)
        {
            if (result != value)
            {
                cerr << "Property value comparison failed.  ";
                cerr << "Expected " << value << "; ";
                cerr << "Actual property value was " << result << "." << endl;
            }
        }

        PEGASUS_TEST_ASSERT (result == value);
    }
}
Esempio n. 7
0
void _getKeyValue (
    const CIMInstance& namespaceInstance,
    CIMNamespaceName& childNamespaceName,
    Boolean& isRelativeName)

{
    //Validate key property

    Uint32 pos;
    CIMValue propertyValue;

    // [Key, MaxLen (256), Description (
    //       "A string that uniquely identifies the Namespace "
    //       "within the ObjectManager.") ]
    // string Name;

    pos = namespaceInstance.findProperty(NAMESPACE_PROPERTYNAME);
    if (pos == PEG_NOT_FOUND)
    {
        throw CIMPropertyNotFoundException
        (NAMESPACE_PROPERTYNAME.getString());
    }

    propertyValue = namespaceInstance.getProperty(pos).getValue();
    if (propertyValue.getType() != CIMTYPE_STRING)
    {
        //l10n
        //throw CIMInvalidParameterException("Invalid type for property: "
        //+ NAMESPACE_PROPERTYNAME.getString());
        throw CIMInvalidParameterException(MessageLoaderParms(
                                               "ControlProviders.NamespaceProvider.NamespaceProvider.INVALID_TYPE_FOR_PROPERTY",
                                               "Invalid type for property: $0",
                                               NAMESPACE_PROPERTYNAME.getString()));
    }

    String cnsName;
    propertyValue.get(cnsName);
    if (cnsName == String::EMPTY)
    {
        childNamespaceName = CIMNamespaceName();
    }
    else
    {
        childNamespaceName = CIMNamespaceName(cnsName);
    }

    isRelativeName = !(childNamespaceName.isNull());

}
Esempio n. 8
0
CIMPropertyRep::CIMPropertyRep(
    const CIMName& name,
    const CIMValue& value,
    Uint32 arraySize,
    const CIMName& referenceClassName,
    const CIMName& classOrigin,
    Boolean propagated)
    :
    _name(name), _value(value), _arraySize(arraySize),
    _referenceClassName(referenceClassName), _classOrigin(classOrigin),
    _propagated(propagated), _refCounter(1), _ownerCount(0)
{
    // ensure name is not null
    if (name.isNull())
    {
        throw UninitializedObjectException();
    }

    // Set the CIM name tag.
    _nameTag = generateCIMNameTag(_name);

    if ((arraySize != 0) &&
        (!value.isArray() || value.getArraySize() != arraySize))
    {
        throw TypeMismatchException();
    }

    // A CIM Property may not be of reference array type
    if (value.isArray() && (value.getType() == CIMTYPE_REFERENCE))
    {
        throw TypeMismatchException();
    }

    // if referenceClassName exists, must be CIMType REFERENCE.
    if (!referenceClassName.isNull())
    {
        if (_value.getType() != CIMTYPE_REFERENCE)
        {
            throw TypeMismatchException();
        }
    }

    // Can a property be of reference type with a null referenceClassName?
    // The DMTF says yes if it is a property of an instance; no if it is a
    // property of a class.  We'll allow it here, but check in the CIMClass
    // addProperty() method.
}
Esempio n. 9
0
void CIMPropertyRep::setValue(const CIMValue& value)
{
    // CIMType of value is immutable:

    if (!value.typeCompatible(_value))
        throw TypeMismatchException();

    if (_arraySize && _arraySize != value.getArraySize())
        throw TypeMismatchException();

    // A CIM Property may not be of reference array type
    if (value.isArray() && (value.getType() == CIMTYPE_REFERENCE))
    {
        throw TypeMismatchException();
    }

    _value = value;
}
Esempio n. 10
0
    static CMPIData mbInvokeMethod(
        const CMPIBroker *mb,
        const CMPIContext *ctx,
        const CMPIObjectPath *cop,
        const char *method,
        const CMPIArgs *in,
        CMPIArgs *out,
        CMPIStatus *rc)
    {
        PEG_METHOD_ENTER(
            TRC_CMPIPROVIDERINTERFACE,
            "CMPI_Broker:mbInvokeMethod()");
        CMPIData data = {0,CMPI_nullValue,{0}};
        mb = CM_BROKER;


        SCMOInstance* scmoObjPath = SCMO_ObjectPath(cop);
        CIMObjectPath qop;
        try
        {
            scmoObjPath->getCIMObjectPath(qop);

            CIMValue v = CM_CIMOM(mb)->invokeMethod(
                *CM_Context(ctx),
                SCMO_ObjectPath(cop)->getNameSpace(),
                qop,
                method ? String(method) : String::EMPTY,
                *CM_Args(in),
                *CM_Args(out));

            CIMType vType=v.getType();
            CMPIType t = type2CMPIType(vType,v.isArray());
            value2CMPIData(v,t,&data);

            if (rc)
            {
                CMSetStatus(rc,CMPI_RC_OK);
            }
        }
        HandlerCatchSetStatus(rc, data);

        PEG_METHOD_EXIT();
        return data; // "data" will be valid data or nullValue (in error case)
    }
Esempio n. 11
0
void _testDeliveryRetryIntervalValue(
    CIMInstance& instance)
{
    CIMValue value =
        instance.getProperty(
            instance.findProperty(
                _PROPERTY_DELIVERYRETRYINTERVAL)).getValue();
    if (value.getType() == CIMTYPE_UINT64)
    {
        // CIM Schema 2.17 experimental class
        PEGASUS_TEST_ASSERT(
            Uint64(_PROPERTY_DELIVERYRETRYINTERVAL_VALUE) == value);
    }
    else
    {
        // CIM Schema 2.22 and up
        PEGASUS_TEST_ASSERT(_PROPERTY_DELIVERYRETRYINTERVAL_VALUE == value);
    }
}
Esempio n. 12
0
void _testSubscriptionRemovalIntervalValue(
    CIMInstance& instance)
{
    CIMValue value =
        instance.getProperty(
            instance.findProperty(
                _PROPERTY_SUBSCRIPTIONREMOVALTIMEINTERVAL)).getValue();
    if (value.getType() == CIMTYPE_UINT64)
    {
        // CIM Schema 2.17 experimental class
        PEGASUS_TEST_ASSERT(
            Uint64(_PROPERTY_SUBSCRIPTIONREMOVALTIMEINTERVAL_VALUE) == value);
    }
    else
    {
        // CIM Schema 2.22 and up
        PEGASUS_TEST_ASSERT(
            _PROPERTY_SUBSCRIPTIONREMOVALTIMEINTERVAL_VALUE == value);
    }
}
Esempio n. 13
0
void _checkUint32Value (CIMValue & theValue, Uint32 value)
{
    PEGASUS_TEST_ASSERT (theValue.getType () == CIMTYPE_UINT32);
    PEGASUS_TEST_ASSERT (!theValue.isArray ());
    PEGASUS_TEST_ASSERT (!theValue.isNull ());

    Uint32 result;
    theValue.get (result);

    if (verbose)
    {
        if (result != value)
        {
            cerr << "Property value comparison failed.  ";
            cerr << "Expected " << value << "; ";
            cerr << "Actual property value was " << result << "." << endl;
        }
    }

    PEGASUS_TEST_ASSERT (result == value);
}
Esempio n. 14
0
void
test05 (CIMClient & client)
{
  CIMObjectPath instanceName;

  instanceName.setNameSpace (providerNamespace);
  instanceName.setClassName (CLASSNAME);

  Array < CIMParamValue > inParams;
  Array < CIMParamValue > outParams;

  /*     String returnDateTime(); */

  CIMValue retValue = client.invokeMethod (providerNamespace,
                       instanceName,
                       "returnDateTime",
                       inParams,
                       outParams);
  PEGASUS_TEST_ASSERT (retValue.getType () == CIMTYPE_DATETIME);
  PEGASUS_TEST_ASSERT (!retValue.isArray ());
  PEGASUS_TEST_ASSERT (!retValue.isNull ());

}
Esempio n. 15
0
CIMKeyBinding::CIMKeyBinding(const CIMName& name, const CIMValue& value)
{
    if (value.isArray())
    {
        throw TypeMismatchException();
    }

    String kbValue = value.toString();
    Type kbType;

    switch (value.getType())
    {
    case CIMTYPE_BOOLEAN:
        kbType = BOOLEAN;
        break;
    case CIMTYPE_CHAR16:
    case CIMTYPE_STRING:
    case CIMTYPE_DATETIME:
        kbType = STRING;
        break;
    case CIMTYPE_REFERENCE:
        kbType = REFERENCE;
        break;
//  case CIMTYPE_REAL32:
//  case CIMTYPE_REAL64:
    case CIMTYPE_OBJECT:
    case CIMTYPE_INSTANCE:
        // From PEP 194: EmbeddedObjects cannot be keys.
        throw TypeMismatchException();
        break;
    default:
        kbType = NUMERIC;
        break;
    }

    _rep = new CIMKeyBindingRep(name, kbValue, kbType);
}
Esempio n. 16
0
/**
 * This tests the embedded instance functionality through the CMPI Test
 * Method Provider. It first invokes the returnInstance() method to retrieve
 * an instance that can be used 
 */
void test09 (CIMClient & client)
{
  CIMObjectPath instanceName;

  instanceName.setNameSpace (providerNamespace);
  instanceName.setClassName (CLASSNAME);

  Array < CIMParamValue > inParams;
  Array < CIMParamValue > outParams;

  /*     [EmbeddedObject] String returnInstance(); */

  CIMValue retValue = client.invokeMethod (providerNamespace,
                       instanceName,
                       "returnInstance",
                       inParams,
                       outParams);

  PEGASUS_TEST_ASSERT (retValue.getType () == CIMTYPE_OBJECT);
  PEGASUS_TEST_ASSERT (!retValue.isArray ());
  PEGASUS_TEST_ASSERT (!retValue.isNull ());

  CIMObject result;
  retValue.get (result);

  CIMObjectPath objPath  = result.getPath();

  CIMInstance inputInstance(result);
  CIMInstance outputInstance;

  inParams.append(
      CIMParamValue(String("inputInstance"), CIMValue(inputInstance)));

  retValue = client.invokeMethod (providerNamespace,
      instanceName,
      "processEmbeddedInstance",
      inParams,
      outParams);

  // First test the return value
  PEGASUS_TEST_ASSERT(retValue.getType() == CIMTYPE_INSTANCE);
  PEGASUS_TEST_ASSERT(!retValue.isArray());
  PEGASUS_TEST_ASSERT(!retValue.isNull());
  retValue.get(outputInstance);
  PEGASUS_TEST_ASSERT(objPath.toString() ==
    outputInstance.getPath().toString());
  PEGASUS_TEST_ASSERT(outputInstance.getPropertyCount() ==
    inputInstance.getPropertyCount());
  for(unsigned int i = 0, n = outputInstance.getPropertyCount(); i < n; ++i)
  {
    CIMProperty outputProp(outputInstance.getProperty(i));
    CIMProperty inputProp(inputInstance.getProperty(i));

    PEGASUS_TEST_ASSERT(outputProp.getName() == inputProp.getName());
    PEGASUS_TEST_ASSERT(outputProp.getValue() == inputProp.getValue());
  }

  // Now test the output parameter
  PEGASUS_TEST_ASSERT(outParams.size() == 1);
  retValue = outParams[0].getValue();

  PEGASUS_TEST_ASSERT(retValue.getType() == CIMTYPE_INSTANCE);
  PEGASUS_TEST_ASSERT(!retValue.isArray());
  PEGASUS_TEST_ASSERT(!retValue.isNull());
  retValue.get(outputInstance);
  PEGASUS_TEST_ASSERT(objPath.toString() ==
    outputInstance.getPath().toString());
  PEGASUS_TEST_ASSERT(outputInstance.getPropertyCount() ==
    inputInstance.getPropertyCount());
  for(unsigned int i = 0, n = outputInstance.getPropertyCount(); i < n; ++i)
  {
    CIMProperty outputProp(outputInstance.getProperty(i));
    CIMProperty inputProp(inputInstance.getProperty(i));

    PEGASUS_TEST_ASSERT(outputProp.getName() == inputProp.getName());
    PEGASUS_TEST_ASSERT(outputProp.getValue() == inputProp.getValue());
  }
}
Esempio n. 17
0
void test14 (CIMClient & client)
{
    CIMObjectPath instanceName;

    instanceName.setNameSpace (providerNamespace);
    instanceName.setClassName (CLASSNAME);

    Array < CIMParamValue > inParams;
    Array < CIMInstance> eObjs;
    Array < CIMParamValue > outParams;

    CIMValue retValue = client.invokeMethod (providerNamespace,
        instanceName,
        "returnInstance",
        inParams,
        outParams);

    PEGASUS_TEST_ASSERT (retValue.getType () == CIMTYPE_OBJECT);
    PEGASUS_TEST_ASSERT (!retValue.isArray ());
    PEGASUS_TEST_ASSERT (!retValue.isNull ());

    CIMObject result;
    retValue.get (result);
    CIMObjectPath objPath  = result.getPath();
    CIMInstance inputInstance(result);
    CIMInstance outputInstance;
    eObjs.append(inputInstance);
    eObjs.append(inputInstance);
    eObjs.append(inputInstance);

    inParams.append (
        CIMParamValue(String("inputInstances"), CIMValue(eObjs)));

    retValue = client.invokeMethod (providerNamespace,
        instanceName,
        "processArrayEmbeddedInstance",
        inParams,
        outParams);

    // First test the return value
    PEGASUS_TEST_ASSERT(retValue.getType() == CIMTYPE_INSTANCE);
    PEGASUS_TEST_ASSERT(!retValue.isArray());
    PEGASUS_TEST_ASSERT(!retValue.isNull());
    retValue.get(outputInstance);
    PEGASUS_TEST_ASSERT(objPath.toString() ==
        outputInstance.getPath().toString());
    PEGASUS_TEST_ASSERT(outputInstance.getPropertyCount() ==
        inputInstance.getPropertyCount());

    for(unsigned int i = 0, n = outputInstance.getPropertyCount(); i < n; ++i)
    {
        CIMProperty outputProp(outputInstance.getProperty(i));
        CIMProperty inputProp(inputInstance.getProperty(i));

        PEGASUS_TEST_ASSERT(outputProp.getName() == inputProp.getName());
        PEGASUS_TEST_ASSERT(outputProp.getValue() == inputProp.getValue());
    }

    // Now test the output parameters
    PEGASUS_TEST_ASSERT(outParams.size() == 3);
    CIMValue outParamValue = outParams[0].getValue();
    PEGASUS_TEST_ASSERT(outParamValue.isArray());
    PEGASUS_TEST_ASSERT(!outParamValue.isNull());

    Array<CIMInstance> instances;
    outParamValue.get(instances);

    for (unsigned int j = 0; j < instances.size () ; ++j)
    {
        outputInstance = instances[j];
        PEGASUS_TEST_ASSERT(objPath.toString() ==
            outputInstance.getPath().toString());
        PEGASUS_TEST_ASSERT(outputInstance.getPropertyCount() ==
            eObjs[j].getPropertyCount());
        for(unsigned int i = 0, n = outputInstance.getPropertyCount();
            i < n; ++i)
        {
            CIMProperty outputProp(outputInstance.getProperty(i));
            CIMProperty inputProp(eObjs[j].getProperty(i));
            PEGASUS_TEST_ASSERT(outputProp.getName() == inputProp.getName());
            PEGASUS_TEST_ASSERT(outputProp.getValue() == inputProp.getValue());
        }
    }

    outParamValue = outParams[1].getValue();
    PEGASUS_TEST_ASSERT(outParamValue.isArray());
    PEGASUS_TEST_ASSERT(!outParamValue.isNull());

    Array<CIMObject> objs;
    outParamValue.get(objs);

    for (unsigned int j = 0; j < objs.size () ; ++j)
    {
        outputInstance = CIMInstance(objs[j]);
        PEGASUS_TEST_ASSERT(objPath.toString() ==
            outputInstance.getPath().toString());
        PEGASUS_TEST_ASSERT(outputInstance.getPropertyCount() ==
            eObjs[j].getPropertyCount());
        for(unsigned int i = 0, n = outputInstance.getPropertyCount();
            i < n; ++i)
        {
            CIMProperty outputProp(outputInstance.getProperty(i));
            CIMProperty inputProp(eObjs[j].getProperty(i));
            PEGASUS_TEST_ASSERT(outputProp.getName() == inputProp.getName());
            PEGASUS_TEST_ASSERT(outputProp.getValue() == inputProp.getValue());
        }
    }

    outParamValue = outParams[2].getValue();
    PEGASUS_TEST_ASSERT(outParamValue.isArray());
    PEGASUS_TEST_ASSERT(!outParamValue.isNull());

    outParamValue.get(objs);

    for (Uint32 j = 0, m = objs.size(); j < m ; ++j)
    {
        outputInstance = CIMInstance(objs[j]);
        Uint32 id;
        CIMInstance emInstance;
        CIMObject emObject;
        outputInstance.getProperty(
            outputInstance.findProperty("id")).getValue().get(id);
        outputInstance.getProperty(
            outputInstance.findProperty("emInstance")).
                getValue().get(emInstance);
        outputInstance.getProperty(
            outputInstance.findProperty("emObject")).getValue().get(emObject);
        PEGASUS_TEST_ASSERT(eObjs[j].identical(emInstance));
        PEGASUS_TEST_ASSERT(eObjs[j].identical(CIMInstance(emObject)));
        PEGASUS_TEST_ASSERT(id == j+1);
    }

}
Esempio n. 18
0
void
CIMtoXML(CIMProperty const& cp, ostream& ostr)
{
	bool isArray = false;
	bool isRef = false;
	if (cp.getName().empty())
	{
		OW_THROWCIMMSG(CIMException::FAILED, "property must have a name");
	}
	if (cp.getDataType())
	{
		isArray = cp.getDataType().isArrayType();
		isRef = cp.getDataType().isReferenceType();
		if (isArray)
		{
			ostr
				<<  "<PROPERTY.ARRAY NAME=\""
				<<  cp.getName()
				<< "\" TYPE=\"";
			CIMtoXML(cp.getDataType(), ostr);
			ostr << "\" ";
			if (cp.getDataType().getSize() != -1)
			{
				ostr
					<< "ARRAYSIZE=\""
					<< cp.getDataType().getSize()
					<< "\" ";
			}
		}
		else if (isRef)
		{
			ostr
				<< "<PROPERTY.REFERENCE NAME=\""
				<< cp.getName()
				<< "\" REFERENCECLASS=\""
				<< cp.getDataType().getRefClassName()
				<< "\" ";
		}
		else
		{
			ostr
				<< "<PROPERTY NAME=\""
				<< cp.getName()
				<< "\" TYPE=\"";
			CIMtoXML(cp.getDataType(), ostr);
			ostr << "\" ";
		}
	}
	else
	{
		String msg("Property ");
		msg += cp.getName();
		msg += " has no type defined";
		OW_THROWCIMMSG(CIMException::FAILED, msg.c_str());
	}
	if (!cp.getOriginClass().empty())
	{
		ostr
			<< "CLASSORIGIN=\""
			<< cp.getOriginClass()
			<< "\" ";
	}
	if (cp.getPropagated())
	{
		ostr << "PROPAGATED=\"true\" ";
	}
	
	CIMValue val = cp.getValue();
	if (cp.getDataType().isEmbeddedObjectType() || (val && val.getCIMDataType().isEmbeddedObjectType()))
	{
		ostr << "EmbeddedObject=\"object\" ";
	}

	ostr << '>';
	for (size_t i = 0; i < cp.getQualifiers().size(); i++)
	{
		CIMtoXML(cp.getQualifiers()[i], ostr);
	}

	if (val)
	{
		// if there isn't an EmbeddedObject qualifier on an embedded object, then output one.
		if (val.getType() == CIMDataType::EMBEDDEDINSTANCE || val.getType() == CIMDataType::EMBEDDEDCLASS)
		{
			if (!cp.getQualifier(CIMQualifier::CIM_QUAL_EMBEDDEDOBJECT))
			{
				CIMQualifier embeddedObject(CIMQualifier::CIM_QUAL_EMBEDDEDOBJECT);
				embeddedObject.setValue(CIMValue(true));
				CIMtoXML(embeddedObject, ostr);
			}
		}

		CIMtoXML(val, ostr);
	}
	if (isArray)
	{
		ostr << "</PROPERTY.ARRAY>";
	}
	else if (isRef)
	{
		ostr << "</PROPERTY.REFERENCE>";
	}
	else
	{
		ostr << "</PROPERTY>";
	}
}
Esempio n. 19
0
void CIMtoXML(CIMValue const& cv, ostream& out)
{
	if (!cv)
	{
		OW_THROWCIMMSG(CIMException::FAILED, "CIM value is NULL");
	}
	if (cv.isArray())
	{
		switch (cv.getType())
		{
			case CIMDataType::BOOLEAN:
			{
				BoolArray a;
				cv.get(a);
				raToXml(out, a);
				break;
			}
			case CIMDataType::UINT8:
			{
				UInt8Array a;
				cv.get(a);
				raToXmlNumeric(out, a);
				break;
			}
			case CIMDataType::SINT8:
			{
				Int8Array a;
				cv.get(a);
				raToXmlNumeric(out, a);
				break;
			}
			// ATTN: UTF8
			case CIMDataType::CHAR16:
			{
				Char16Array a;
				cv.get(a);
				raToXmlChar16(out, a);
				break;
			}
			case CIMDataType::UINT16:
			{
				UInt16Array a;
				cv.get(a);
				raToXml(out, a);
				break;
			}
			case CIMDataType::SINT16:
			{
				Int16Array a;
				cv.get(a);
				raToXml(out, a);
				break;
			}
			case CIMDataType::UINT32:
			{
				UInt32Array a;
				cv.get(a);
				raToXml(out, a);
				break;
			}
			case CIMDataType::SINT32:
			{
				Int32Array a;
				cv.get(a);
				raToXml(out, a);
				break;
			}
			case CIMDataType::UINT64:
			{
				UInt64Array a;
				cv.get(a);
				raToXml(out, a);
				break;
			}
			case CIMDataType::SINT64:
			{
				Int64Array a;
				cv.get(a);
				raToXml(out, a);
				break;
			}
			case CIMDataType::REAL32:
			{
				Real32Array a;
				cv.get(a);
				realArrayToXml(out, a);
				break;
			}
			case CIMDataType::REAL64:
			{
				Real64Array a;
				cv.get(a);
				realArrayToXml(out, a);
				break;
			}
			case CIMDataType::STRING:
			{
				StringArray a;
				cv.get(a);
				raToXmlSA(out, a);
				break;
			}
			case CIMDataType::DATETIME:
			{
				CIMDateTimeArray a;
				cv.get(a);
				raToXml(out, a);
				break;
			}
			case CIMDataType::REFERENCE:
			{
				CIMObjectPathArray a;
				cv.get(a);
				raToXmlCOP(out, a);
				break;
			}
			
			case CIMDataType::EMBEDDEDCLASS:
			{
				CIMClassArray ca;
				cv.get(ca);
				StringArray sa;
				for (size_t i = 0; i < ca.size(); ++i)
				{
					OStringStream ss;
					CIMtoXML(ca[i], ss);
					sa.push_back(ss.toString());
				}
				raToXmlSA(out, sa);
				break;
			}
			
			case CIMDataType::EMBEDDEDINSTANCE:
			{
				CIMInstanceArray ia;
				cv.get(ia);
				StringArray sa;
				for (size_t i = 0; i < ia.size(); ++i)
				{
					OStringStream ss;
					CIMInstancetoXML(ia[i],ss);
					sa.push_back(ss.toString());
				}
				raToXmlSA(out, sa);
				break;
			}
			default:
				OW_ASSERT(0);
		}
	}
	else if (cv.getType() == CIMDataType::REFERENCE)
	{
		out << "<VALUE.REFERENCE>";
		CIMObjectPath a(CIMNULL);
		cv.get(a);
		if (a.getFullNameSpace().isLocal())
		{
			if (a.getNameSpace().empty())
			{
				CIMInstanceNametoXML(a, out);
			}
			else
			{
				CIMLocalInstancePathtoXML(a, out);
			}
		}
		else
		{
			CIMInstancePathtoXML(a, out);
		}
		out << "</VALUE.REFERENCE>";
	}
	else
	{
		out << "<VALUE>";
		switch (cv.getType())
		{
			case CIMDataType::BOOLEAN:
			case CIMDataType::UINT8:
			case CIMDataType::SINT8:
			case CIMDataType::UINT16:
			case CIMDataType::SINT16:
			case CIMDataType::UINT32:
			case CIMDataType::SINT32:
			case CIMDataType::UINT64:
			case CIMDataType::SINT64:
			case CIMDataType::DATETIME:
			{
				out << cv.toString();
				break;
			}
			case CIMDataType::REAL32:
			{
				char tmpbuf[128];
#if FLT_RADIX == 2
#if defined(OW_REAL32_IS_FLOAT)
				::SNPRINTF(tmpbuf, sizeof(tmpbuf), "%.*e", FLT_MANT_DIG * 3 / 10 + 1, static_cast<double>(cv.toReal32()));
#elif defined(OW_REAL32_IS_DOUBLE)
				::SNPRINTF(tmpbuf, sizeof(tmpbuf), "%.*e", DBL_MANT_DIG * 3 / 10 + 1, cv.toReal32());
#endif
#else
#error "The formula for computing the number of digits of precision for a floating point needs to be implmented. It's ceiling(bits * log(FLT_RADIX) / log(10))"
#endif
				out << tmpbuf;
				break;
			}
			case CIMDataType::REAL64:
			{
				char tmpbuf[128];
#if FLT_RADIX == 2
#if defined(OW_REAL64_IS_DOUBLE)
				::SNPRINTF(tmpbuf, sizeof(tmpbuf), "%.*e", DBL_MANT_DIG * 3 / 10 + 1, cv.toReal64());
#elif defined(OW_REAL64_IS_LONG_DOUBLE)
				::SNPRINTF(tmpbuf, sizeof(tmpbuf), "%.*Le", LDBL_MANT_DIG * 3 / 10 + 1, cv.toReal64());
#endif
#else
#error "The formula for computing the number of digits of precision for a floating point needs to be implmented. It's ceiling(bits * log(FLT_RADIX) / log(10))"
#endif
				out << tmpbuf;
				break;
			}
			case CIMDataType::CHAR16:
			case CIMDataType::STRING:
			{
				out << XMLEscape(cv.toString());
				break;
			}
			
			case CIMDataType::EMBEDDEDCLASS:
			{
				CIMClass cc(CIMNULL);
				cv.get(cc);
				String s;
				OStringStream ss;
				CIMtoXML(cc, ss);
				out << XMLEscape(ss.toString());
				break;
			}
			
			case CIMDataType::EMBEDDEDINSTANCE:
			{
				CIMInstance i(CIMNULL);
				cv.get(i);
				String s;
				OStringStream ss;
				CIMInstancetoXML(i,ss);
				out << XMLEscape(ss.toString());
				break;
			}
			default:
				OW_ASSERT(0);
		}
		out << "</VALUE>";
	}
}
Esempio n. 20
0
void
CIMtoXML(CIMQualifier const& cq, ostream& ostr)
{
	CIMFlavor fv;
	
	if (cq.getName().empty())
	{
		OW_THROWCIMMSG(CIMException::FAILED, "qualifier must have a name");
	}
	CIMValue dv = cq.getDefaults().getDefaultValue();
	CIMDataType dt = cq.getDefaults().getDataType();
	CIMValue cv = cq.getValue();
	if (!cv)
	{
		cv = dv;
	}
	if (cv)
	{
		if (cv.isArray())
		{
			dt = CIMDataType(cv.getType(),cv.getArraySize());
		}
		else
		{
			dt = CIMDataType(cv.getType());
		}
	}
	OW_ASSERT(dt);
	ostr
		<< "<QUALIFIER NAME=\""
		<< cq.getName()
		<< "\" TYPE=\"";
	CIMtoXML(dt,ostr);
	ostr << "\" ";
	if (cq.getPropagated())
	{
		ostr << "PROPAGATED=\"true\" ";
	}
	//
	// Create flavors
	//
	fv = CIMFlavor(CIMFlavor::ENABLEOVERRIDE);
	if (cq.hasFlavor(fv))
	{
		//
		// Not needed, because OVERRIDABLE defaults to true!
	}
	else
	{
		fv = CIMFlavor(CIMFlavor::DISABLEOVERRIDE);
		if (cq.hasFlavor(fv))
		{
			CIMtoXML(fv, ostr);
			ostr <<  "=\"false\" ";
		}
	}
	fv = CIMFlavor(CIMFlavor::TOSUBCLASS);
	if (cq.hasFlavor(fv))
	{
		//
		// Not needed, because TOSUBCLASS defaults to true!
	}
	else
	{
		fv = CIMFlavor(CIMFlavor::RESTRICTED);
		if (cq.hasFlavor(fv))
		{
			CIMtoXML(fv, ostr);
			ostr <<  "=\"false\" ";
		}
	}
	// This is a bug in the spec, but we still support it for backward compatibility.
	//fv = CIMFlavor(CIMFlavor::TOINSTANCE);
	//if (cq.hasFlavor(fv))
	//{
	//	CIMtoXML(fv, ostr);
	//	ostr << "=\"true\" ";
	//}
	//else
	//{
		//
		// Not needed, because TOINSTANCE defaults to false!
	//}
	fv = CIMFlavor(CIMFlavor::TRANSLATE);
	if (cq.hasFlavor(fv))
	{
		CIMtoXML(fv, ostr);
		ostr << "=\"true\" ";
	}
	else
	{
		//
		// Not needed, because TRANSLATABLE defaults to false!
	}

	String lang = cq.getLanguage();
	if (!lang.empty())
	{
		ostr << " xml:lang=\"";
		ostr << lang;
		ostr << '\"';
	}

	ostr << '>';
	if (cv)
	{
		CIMtoXML(cv, ostr);
	}
	ostr << "</QUALIFIER>";
}
Esempio n. 21
0
String IndicationFormatter::_getIndPropertyValue(
    const String & specifiedPropertyName,
    const String & arrayIndexStr,
    const CIMInstance & indication,
    const ContentLanguages & contentLangs)
{
    PEG_METHOD_ENTER (TRC_IND_FORMATTER,
        "IndicationFormatter::_getIndPropertyValue");

    CIMInstance indicationInstance = indication.clone();
    String propertyName;

    Boolean canLocalize = false;

#if defined(PEGASUS_HAS_ICU) && defined(PEGASUS_INDFORMATTER_USE_ICU)
    Locale locale;
    canLocalize = _canLocalize(contentLangs, locale);
#endif

    for (Uint32 i=0; i < indicationInstance.getPropertyCount(); i++)
    {
        CIMProperty property = indicationInstance.getProperty(i);
        propertyName = property.getName().getString();

        // get specified property value
        if (String::equalNoCase(propertyName, specifiedPropertyName))
        {
            CIMValue propertyValue = property.getValue();
            Boolean valueIsNull = propertyValue.isNull();
	    CIMType type = propertyValue.getType();

            if (!valueIsNull)
            {
                Boolean isArray = propertyValue.isArray();

                if (isArray)
                {
                    PEG_METHOD_EXIT();
		    return (_getArrayValues(propertyValue, arrayIndexStr,
			                    contentLangs));
                }
                else // value is not an array
                {
#if defined(PEGASUS_HAS_ICU) && defined(PEGASUS_INDFORMATTER_USE_ICU)
		    if (canLocalize)
		    {
                        if (type == CIMTYPE_DATETIME)
		        {
			    CIMDateTime dateTimeValue;
			    propertyValue.get(dateTimeValue);
                            PEG_METHOD_EXIT();
			    return(_localizeDateTime(dateTimeValue, locale));
		        }
                        else if (type == CIMTYPE_BOOLEAN)
		        {
			    Boolean booleanValue;
			    propertyValue.get(booleanValue);
                            PEG_METHOD_EXIT();
			    return(_localizeBooleanStr(booleanValue, locale));
		        }
                        else
                        {
                            PEG_METHOD_EXIT();
                            return (propertyValue.toString());
                        }
		    }
		    else
		    {
			if (type == CIMTYPE_BOOLEAN)
			{
                            PEG_METHOD_EXIT();
                            return (_getBooleanStr(propertyValue));
			}
			else
			{
                            PEG_METHOD_EXIT();
                            return (propertyValue.toString());
			}
		    }
#else
		    if (type == CIMTYPE_BOOLEAN)
		    {
                        PEG_METHOD_EXIT();
                        return (_getBooleanStr(propertyValue));
		    }
		    else
		    {
                        PEG_METHOD_EXIT();
                        return (propertyValue.toString());
		    }
#endif
                }

            }
            else // value is NULL
            {
                PEG_METHOD_EXIT();
                return ("NULL");
            }

        }
        propertyName.clear();
    }

    PEG_METHOD_EXIT();

    return ("UNKNOWN");
}
Esempio n. 22
0
String IndicationFormatter::_getArrayValues(
    const CIMValue & propertyValue,
    const String & arrayIndexStr,
    const ContentLanguages & contentLangs)
{
    PEG_METHOD_ENTER (TRC_IND_FORMATTER,
	"IndicationFormatter::_getArrayValues");

    CIMType type = propertyValue.getType();
    String arrayValues;
    char propertyValueBuffer[2048];
    Uint32 arraySize = propertyValue.getArraySize();

    char arrayIndexBuffer[16];
    Sint32 arrayIndex = 0;
    Uint32 sizeOfArrayIndexStr = arrayIndexStr.size();

    // there is an index value enclosed in brackets (e.g. [2])
    if (sizeOfArrayIndexStr != 0)
    {
        sprintf(arrayIndexBuffer, "%s", (const char *)
	    arrayIndexStr.getCString());

	try
	{
	    _isValidIndex(arrayIndexBuffer);
            arrayIndex = atoi(arrayIndexBuffer);
	}
	catch (CIMException & c)
	{
	    arrayIndex = -1;

	    PEG_TRACE_STRING(TRC_IND_FORMATTER, Tracer::LEVEL4,c.getMessage());
	}
    }

    // Array index is out of range
    if (sizeOfArrayIndexStr != 0 &&
	((arrayIndex < 0) || ((Uint32)arrayIndex >= arraySize)))
    {
	arrayValues = "UNKNOWN";

        PEG_METHOD_EXIT();
        return (arrayValues);
    }

    switch (type)
    {
	case CIMTYPE_UINT8:
	{
	    Array<Uint8> propertyValueUint8;
	    propertyValue.get(propertyValueUint8);

	    // Empty brackets (e.g. []), gets all values of the array
	    if (sizeOfArrayIndexStr == 0)
	    {
                arrayValues.append("[");
		for (Uint32 i=0; i<arraySize; i++)
		{
		    sprintf(propertyValueBuffer, "%u",
			propertyValueUint8[i]);
		    arrayValues.append(propertyValueBuffer);

		    if ( i < arraySize-1)
		    {
			arrayValues.append(",");
		    }
		}

		arrayValues.append("]");
	    }
	    else
	    {
	        sprintf(propertyValueBuffer, "%u",
		    propertyValueUint8[arrayIndex]);
	        arrayValues = propertyValueBuffer;
	    }

            break;
	}

	case CIMTYPE_UINT16:
	{
	    Array<Uint16> propertyValueUint16;
	    propertyValue.get(propertyValueUint16);

	    // Empty brackets (e.g. []), gets all values of the array
	    if (sizeOfArrayIndexStr == 0)
	    {
                arrayValues.append("[");
		for (Uint32 i=0; i<arraySize; i++)
		{
		    sprintf(propertyValueBuffer, "%u",
			propertyValueUint16[i]);
		    arrayValues.append(propertyValueBuffer);

		    if ( i < arraySize-1)
		    {
			arrayValues.append(",");
		    }
		}

		arrayValues.append("]");
	    }
	    else
	    {
	        sprintf(propertyValueBuffer, "%u",
		    propertyValueUint16[arrayIndex]);
	        arrayValues = propertyValueBuffer;
	    }

            break;
	}

	case CIMTYPE_UINT32:
	{
	    Array<Uint32> propertyValueUint32;
	    propertyValue.get(propertyValueUint32);

	    // Empty brackets (e.g. []), gets all values of the array
	    if (sizeOfArrayIndexStr == 0)
	    {
                arrayValues.append("[");
		for (Uint32 i=0; i<arraySize; i++)
		{
		    sprintf(propertyValueBuffer, "%u",
			propertyValueUint32[i]);
		    arrayValues.append(propertyValueBuffer);

		    if ( i < arraySize-1)
		    {
			arrayValues.append(",");
		    }
		}

		arrayValues.append("]");
	    }
	    else
	    {
	        sprintf(propertyValueBuffer, "%u",
		    propertyValueUint32[arrayIndex]);
	        arrayValues = propertyValueBuffer;
	    }

            break;
	}

	case CIMTYPE_UINT64:
	{
	    Array<Uint64> propertyValueUint64;
	    propertyValue.get(propertyValueUint64);

	    // Empty brackets (e.g. []), gets all values of the array
	    if (sizeOfArrayIndexStr == 0)
	    {
                arrayValues.append("[");
		for (Uint32 i=0; i<arraySize; i++)
		{
		    sprintf(propertyValueBuffer,
			    "%" PEGASUS_64BIT_CONVERSION_WIDTH "u",
			    propertyValueUint64[i]);
		    arrayValues.append(propertyValueBuffer);

		    if ( i < arraySize-1)
		    {
			arrayValues.append(",");
		    }
		}

		arrayValues.append("]");
	    }
	    else
	    {
	        sprintf(propertyValueBuffer,
			"%" PEGASUS_64BIT_CONVERSION_WIDTH "u",
		        propertyValueUint64[arrayIndex]);
	        arrayValues = propertyValueBuffer;
	    }

            break;
	}

	case CIMTYPE_SINT8:
	{
	    Array<Sint8> propertyValueSint8;
	    propertyValue.get(propertyValueSint8);

	    // Empty brackets (e.g. []), gets all values of the array
	    if (sizeOfArrayIndexStr == 0)
	    {
                arrayValues.append("[");
		for (Uint32 i=0; i<arraySize; i++)
		{
		    sprintf(propertyValueBuffer, "%i",
			propertyValueSint8[i]);
		    arrayValues.append(propertyValueBuffer);

		    if ( i < arraySize-1)
		    {
			arrayValues.append(",");
		    }
		}

		arrayValues.append("]");
	    }
	    else
	    {
	        sprintf(propertyValueBuffer, "%i",
		    propertyValueSint8[arrayIndex]);
	        arrayValues = propertyValueBuffer;
	    }

            break;
	}

	case CIMTYPE_SINT16:
	{
	    Array<Sint16> propertyValueSint16;
	    propertyValue.get(propertyValueSint16);

	    // Empty brackets (e.g. []), gets all values of the array
	    if (sizeOfArrayIndexStr == 0)
	    {
                arrayValues.append("[");
		for (Uint32 i=0; i<arraySize; i++)
		{
		    sprintf(propertyValueBuffer, "%i",
			propertyValueSint16[i]);
		    arrayValues.append(propertyValueBuffer);

		    if ( i < arraySize-1)
		    {
			arrayValues.append(",");
		    }
		}

		arrayValues.append("]");
	    }
	    else
	    {
	        sprintf(propertyValueBuffer, "%i",
		    propertyValueSint16[arrayIndex]);
	        arrayValues = propertyValueBuffer;
	    }

            break;
	}

	case CIMTYPE_SINT32:
	{
	    Array<Sint32> propertyValueSint32;
	    propertyValue.get(propertyValueSint32);

	    // Empty brackets (e.g. []), gets all values of the array
	    if (sizeOfArrayIndexStr == 0)
	    {
                arrayValues.append("[");
		for (Uint32 i=0; i<arraySize; i++)
		{
		    sprintf(propertyValueBuffer, "%i",
			propertyValueSint32[i]);
		    arrayValues.append(propertyValueBuffer);

		    if ( i < arraySize-1)
		    {
			arrayValues.append(",");
		    }
		}

		arrayValues.append("]");
	    }
	    else
	    {
	        sprintf(propertyValueBuffer, "%i",
		    propertyValueSint32[arrayIndex]);
	        arrayValues = propertyValueBuffer;
	    }

            break;
	}

	case CIMTYPE_SINT64:
	{
	    Array<Sint64> propertyValueSint64;
	    propertyValue.get(propertyValueSint64);

	    // Empty brackets (e.g. []), gets all values of the array
	    if (sizeOfArrayIndexStr == 0)
	    {
                arrayValues.append("[");
		for (Uint32 i=0; i<arraySize; i++)
		{
		    sprintf(propertyValueBuffer,
                            "%" PEGASUS_64BIT_CONVERSION_WIDTH "d",
                            propertyValueSint64[i]);
		    arrayValues.append(propertyValueBuffer);

		    if ( i < arraySize-1)
		    {
			arrayValues.append(",");
		    }
		}

		arrayValues.append("]");
	    }
	    else
	    {
	        sprintf(propertyValueBuffer,
			"%" PEGASUS_64BIT_CONVERSION_WIDTH "d",
                        propertyValueSint64[arrayIndex]);
	        arrayValues = propertyValueBuffer;
	    }

            break;
	}

	case CIMTYPE_REAL32:
	{
	    Array<Real32> propertyValueReal32;
	    propertyValue.get(propertyValueReal32);

	    // Empty brackets (e.g. []), gets all values of the array
	    if (sizeOfArrayIndexStr == 0)
	    {
                arrayValues.append("[");
		for (Uint32 i=0; i<arraySize; i++)
		{
		    sprintf(propertyValueBuffer, "%f",
			propertyValueReal32[i]);
		    arrayValues.append(propertyValueBuffer);

		    if ( i < arraySize-1)
		    {
			arrayValues.append(",");
		    }
		}

		arrayValues.append("]");
	    }
	    else
	    {
	        sprintf(propertyValueBuffer, "%f",
		    propertyValueReal32[arrayIndex]);
	        arrayValues = propertyValueBuffer;
	    }

            break;
	}

	case CIMTYPE_REAL64:
	{
	    Array<Real64> propertyValueReal64;
	    propertyValue.get(propertyValueReal64);

	    // Empty brackets (e.g. []), gets all values of the array
	    if (sizeOfArrayIndexStr == 0)
	    {
                arrayValues.append("[");
		for (Uint32 i=0; i<arraySize; i++)
		{
		    sprintf(propertyValueBuffer, "%f",
			propertyValueReal64[i]);
		    arrayValues.append(propertyValueBuffer);

		    if ( i < arraySize-1)
		    {
			arrayValues.append(",");
		    }
		}

		arrayValues.append("]");
	    }
	    else
	    {
	        sprintf(propertyValueBuffer, "%f",
		    propertyValueReal64[arrayIndex]);
	        arrayValues = propertyValueBuffer;
	    }

            break;
	}

	case CIMTYPE_BOOLEAN:
	{
	    Array<Boolean> booleanValue;
	    propertyValue.get(booleanValue);

	    Boolean canLocalize = false;

#if defined(PEGASUS_HAS_ICU) && defined(PEGASUS_INDFORMATTER_USE_ICU)
	    Locale locale;
	    canLocalize = _canLocalize(contentLangs, locale);
#endif

	    // Empty brackets (e.g. []), gets all values of the array
	    if (sizeOfArrayIndexStr == 0)
	    {
                arrayValues.append("[");
		for (Uint32 i=0; i<arraySize; i++)
		{
#if defined(PEGASUS_HAS_ICU) && defined(PEGASUS_INDFORMATTER_USE_ICU)
		    if (canLocalize)
		    {
			arrayValues.append(_localizeBooleanStr(
			    booleanValue[i], locale));
		    }
		    else
		    {
			arrayValues.append(_getBooleanStr(booleanValue[i]));
		    }
#else
		    arrayValues.append(_getBooleanStr(booleanValue[i]));

#endif
		    if ( i < arraySize-1)
		    {
			arrayValues.append(",");
		    }
		}

		arrayValues.append("]");
	    }
	    else
	    {
#if defined(PEGASUS_HAS_ICU) && defined(PEGASUS_INDFORMATTER_USE_ICU)
                if (canLocalize)
		{
		    arrayValues = _localizeBooleanStr(
			booleanValue[arrayIndex], locale);
		}
		else
		{
		    arrayValues = _getBooleanStr(booleanValue[arrayIndex]);
		}
#else
		arrayValues = _getBooleanStr(booleanValue[arrayIndex]);
#endif
	    }

            break;
	}

	case CIMTYPE_CHAR16:
	{
	    Array<Char16> propertyValueChar16;
	    propertyValue.get(propertyValueChar16);

	    // Empty brackets (e.g. []), gets all values of the array
	    if (sizeOfArrayIndexStr == 0)
	    {
                arrayValues.append("[");
		for (Uint32 i=0; i<arraySize; i++)
		{
		    arrayValues.append(propertyValueChar16[i]);

		    if ( i < arraySize-1)
		    {
			arrayValues.append(",");
		    }
		}

		arrayValues.append("]");
	    }
	    else
	    {
	        arrayValues.append(propertyValueChar16[arrayIndex]);
	    }

            break;
	}

	case CIMTYPE_STRING:
	{
	    Array<String> propertyValueString;
	    propertyValue.get(propertyValueString);

	    // Empty brackets (e.g. []), gets all values of the array
	    if (sizeOfArrayIndexStr == 0)
	    {
                arrayValues.append("[");
		for (Uint32 i=0; i<arraySize; i++)
		{
		    arrayValues.append(propertyValueString[i]);

		    if ( i < arraySize-1)
		    {
			arrayValues.append(",");
		    }
		}

		arrayValues.append("]");
	    }
	    else
	    {
	        arrayValues.append(propertyValueString[arrayIndex]);
	    }

            break;
	}

	case CIMTYPE_DATETIME:
	{
	    Array<CIMDateTime> propertyValueDateTime;
	    propertyValue.get(propertyValueDateTime);

            Boolean canLocalize = false;

#if defined(PEGASUS_HAS_ICU) && defined(PEGASUS_INDFORMATTER_USE_ICU)
	    Locale locale;
	    canLocalize = _canLocalize(contentLangs, locale);
#endif

	    // Empty brackets (e.g. []), gets all values of the array
	    if (sizeOfArrayIndexStr == 0)
	    {
                arrayValues.append("[");
		for (Uint32 i=0; i<arraySize; i++)
		{
#if defined(PEGASUS_HAS_ICU) && defined(PEGASUS_INDFORMATTER_USE_ICU)
                    if (canLocalize)
		    {
			arrayValues.append(_localizeDateTime(
			    propertyValueDateTime[i], locale));
		    }
		    else
		    {
		        arrayValues.append(propertyValueDateTime[i].toString());
		    }
#else
		    arrayValues.append(propertyValueDateTime[i].toString());
#endif

		    if ( i < arraySize-1)
		    {
			arrayValues.append(",");
		    }
		}

		arrayValues.append("]");
	    }
	    else
	    {
#if defined(PEGASUS_HAS_ICU) && defined(PEGASUS_INDFORMATTER_USE_ICU)
		if (canLocalize)
		{
		    arrayValues.append(_localizeDateTime(
			propertyValueDateTime[arrayIndex], locale));
		}
		else
		{
		    arrayValues.append(propertyValueDateTime
			[arrayIndex].toString());
		}
#else
	        arrayValues.append(propertyValueDateTime
		    [arrayIndex].toString());
#endif
	    }

            break;
	}

	case CIMTYPE_REFERENCE:
	{
	    Array<CIMObjectPath> propertyValueRef;
	    propertyValue.get(propertyValueRef);

	    // Empty brackets (e.g. []), gets all values of the array
	    if (sizeOfArrayIndexStr == 0)
	    {
                arrayValues.append("[");
		for (Uint32 i=0; i<arraySize; i++)
		{
		    arrayValues.append(propertyValueRef[i].toString());

		    if ( i < arraySize-1)
		    {
			arrayValues.append(",");
		    }
		}

		arrayValues.append("]");
	    }
	    else
	    {
	        arrayValues.append(propertyValueRef
		    [arrayIndex].toString());
	    }

            break;
	}

	default:
	{
	    arrayValues.append("UNKNOWN");

            PEG_TRACE_STRING(TRC_IND_FORMATTER, Tracer::LEVEL4,
		"Unknown CIMType: " + type);

            break;
	}
    }

    PEG_METHOD_EXIT();
    return (arrayValues);
}
void EmailListenerDestination::handleIndication(
    const OperationContext& context,
    const String nameSpace,
    CIMInstance& indication,
    CIMInstance& handler,
    CIMInstance& subscription,
    ContentLanguages & contentLanguages)
{
    PEG_METHOD_ENTER (TRC_IND_HANDLER,
                      "EmailListenerDestination::handleIndication");

    String indicationText;

    try
    {
        // gets formatted indication message
        indicationText = IndicationFormatter::getFormattedIndText(
                             subscription, indication, contentLanguages);

        // get MailTo from handler instance
        Array<String> mailTo;
        handler.getProperty(handler.findProperty(
                                PEGASUS_PROPERTYNAME_LSTNRDST_MAILTO)).getValue().get(mailTo);

        // get MailSubject from handler instance
        String mailSubject = String::EMPTY;
        handler.getProperty(handler.findProperty(
                                PEGASUS_PROPERTYNAME_LSTNRDST_MAILSUBJECT)).getValue().get(
                                    mailSubject);

        // get MailCc from handler instance
        CIMValue mailCcValue;
        Array<String> mailCc;

        Uint32 posMailCc = handler.findProperty(
                               PEGASUS_PROPERTYNAME_LSTNRDST_MAILCC);

        if (posMailCc != PEG_NOT_FOUND)
        {
            mailCcValue = handler.getProperty(posMailCc).getValue();
        }

        if (!mailCcValue.isNull())
        {
            if ((mailCcValue.getType() == CIMTYPE_STRING) &&
                    (mailCcValue.isArray()))
            {
                mailCcValue.get(mailCc);
            }
        }

        // Sends the formatted indication to the specified recipients
        _sendViaEmail(mailTo, mailCc, mailSubject, indicationText);

    }
    catch (CIMException & c)
    {
        PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4, c.getMessage());
        PEG_METHOD_EXIT();

        throw PEGASUS_CIM_EXCEPTION (CIM_ERR_FAILED, c.getMessage());
    }
    catch (Exception& e)
    {
        PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4, e.getMessage());
        PEG_METHOD_EXIT();

        throw PEGASUS_CIM_EXCEPTION (CIM_ERR_FAILED, e.getMessage());
    }
    catch (...)
    {
        PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4,
                         "Failed to deliver indication via e-mail.");
        PEG_METHOD_EXIT();

        throw PEGASUS_CIM_EXCEPTION_L (CIM_ERR_FAILED,
                                       MessageLoaderParms("Handler.EmailListenerDestination."
                                               "EmailListenerDestination.FAILED_TO_DELIVER_INDICATION_VIA_EMAIL",
                                               "Failed to deliver indication via e-mail."));
    }

    PEG_METHOD_EXIT();
}
Esempio n. 24
0
String IndicationFormatter::getFormattedIndText(
    const CIMInstance & subscription,
    const CIMInstance & indication,
    const ContentLanguages & contentLangs)
{
    PEG_METHOD_ENTER (TRC_IND_FORMATTER,
        "IndicationFormatter::getFormattedIndText");

    String indicationText;
    String textFormat = String::EMPTY;
    CIMValue textFormatValue;
    CIMValue textFormatParamsValue;

    Array<String> textFormatParams;

        // get TextFormat from subscription
        Uint32 textFormatPos =
	    subscription.findProperty(_PROPERTY_TEXTFORMAT);

	// if the property TextFormat is not found,
	// indication is constructed with default format
        if (textFormatPos == PEG_NOT_FOUND)
        {
            indicationText = _formatDefaultIndicationText(indication,
							 contentLangs);
        }
        else
        {
            textFormatValue = subscription.getProperty(textFormatPos).
		getValue();

	    // if the value of textFormat is NULL,
	    // indication is constructed with default format
            if (textFormatValue.isNull())
            {
                indicationText = _formatDefaultIndicationText(indication,
							     contentLangs);
	    }
	    else
	    {
                // get TextFormatParameters from subscription
                Uint32 textFormatParamsPos = subscription.findProperty(
		    _PROPERTY_TEXTFORMATPARAMETERS);

	        if (textFormatParamsPos != PEG_NOT_FOUND)
	        {
                    textFormatParamsValue = subscription.getProperty(
	                textFormatParamsPos).getValue();
                }

		// constructs indication with specified format
		if ((textFormatValue.getType() == CIMTYPE_STRING) &&
		    !(textFormatValue.isArray()))
                {
		    textFormatValue.get(textFormat);
		    if (!textFormatParamsValue.isNull())
		    {
			if ((textFormatParamsValue.getType() ==
			     CIMTYPE_STRING) &&
                            (textFormatParamsValue.isArray()))
                        {
		            textFormatParamsValue.get(textFormatParams);
                        }
		    }

		    indicationText = _formatIndicationText(textFormat,
				                          textFormatParams,
				                          indication,
				                          contentLangs);
		}
		else
		{
                    indicationText = _formatDefaultIndicationText(indication,
				                                 contentLangs);
		}
	    }

        }

        PEG_METHOD_EXIT();
	return (indicationText);
}
Esempio n. 25
0
// Enumerate the instance names for the defined testclasses.
// Tests for response size and response count and displays test results
void tests::enumerateInstances(Uint32 responseSize, Uint64 responseCount)
{
    try
    {
        Stopwatch sw;
        sw.start();

        Array<CIMInstance> instances =
            client.enumerateInstances(testNamespaceName, testClass);

        sw.stop();
        Uint64 elapsed = sw.getElapsedUsec();

        Uint64 providerTime = 0;
        CIMInstance lastInstance = instances[instances.size() - 1];
        if (Uint32 pos = lastInstance.findProperty("totalTime") !=
            PEG_NOT_FOUND)
        {
            CIMProperty p = lastInstance.getProperty(pos);
            CIMValue v = p.getValue();
            if (v.getType() != CIMTYPE_UINT64)
            {
                cout << "Error:  CIMType for type totalTime Property"
                        " should be uint64." << endl;
            }
            v.get(providerTime);
        }
        else
        {
            cout << "Error: totalTime propety not found" << endl;
        }

        _displayTimes(instances.size(), responseSize,  elapsed,
                      providerTime,
                      returnedPerformanceData);

        CIMPLE_TEST_ASSERT(instances.size() == responseCount);

        // Confirm that the sequence numbers are monolithic increasing
        //
        Uint64 prevSequenceNumber = 0;
        for (Uint64 i = 0, n = instances.size() ;  i < n ; i++)
        {
            Uint32 pos;
            if ((pos = instances[i].findProperty("SequenceNumber"))
                 != PEG_NOT_FOUND )
            {
                CIMProperty p = instances[i].getProperty(pos);
                CIMValue v = p.getValue();
                Uint64 sequenceNumber;
                v.get(sequenceNumber);
                //cout << "SequenceNumber = " << sequenceNumber
                //    << " prevSequenceNumber " << prevSequenceNumber << endl;

                CIMPLE_TEST_ASSERT(sequenceNumber == (prevSequenceNumber));
                prevSequenceNumber++;
            }
        }
    }
    catch (Exception& e)
    {
        cerr << "Error: " << e.getMessage() << endl;
        exit(1);
    }
}
/*
    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;
}
Esempio n. 27
0
String IndicationFormatter::_formatDefaultIndicationText(
    const CIMInstance & indication,
    const ContentLanguages & contentLangs)
{
    PEG_METHOD_ENTER (TRC_IND_FORMATTER,
        "IndicationFormatter::_formatDefaultIndicationText");

    CIMInstance indicationInstance = indication.clone();
    String propertyName;
    String indicationStr;
    Uint32 propertyCount = indicationInstance.getPropertyCount();

    indicationStr.append("Indication (default format):");

    Boolean canLocalize = false;

#if defined(PEGASUS_HAS_ICU) && defined(PEGASUS_INDFORMATTER_USE_ICU)
    Locale locale;
    canLocalize = _canLocalize(contentLangs, locale);
#endif

    for (Uint32 i=0; i < propertyCount; i++)
    {
        CIMProperty property = indicationInstance.getProperty(i);
        propertyName = property.getName().getString();
        CIMValue propertyValue = property.getValue();
        Boolean valueIsNull = propertyValue.isNull();
        Boolean isArray = propertyValue.isArray();

        indicationStr.append(propertyName);
        indicationStr.append(" = ");

	CIMType type = propertyValue.getType();

        if (!valueIsNull)
        {
            if (isArray)
            {
		indicationStr.append(_getArrayValues(propertyValue, "",
		    contentLangs));
            }
            else // value is not an array
            {
#if defined(PEGASUS_HAS_ICU) && defined(PEGASUS_INDFORMATTER_USE_ICU)
		if (canLocalize)
		{
		    if (type == CIMTYPE_DATETIME)
		    {
			CIMDateTime dateTimeValue;
			propertyValue.get(dateTimeValue);
		        indicationStr.append(_localizeDateTime(dateTimeValue,
		    	    locale));
		    }
		    else if (type == CIMTYPE_BOOLEAN)
		    {
			Boolean booleanValue;
			propertyValue.get(booleanValue);
		        indicationStr.append(_localizeBooleanStr(booleanValue,
		    	    locale));
		    }
		    else
		    {
			indicationStr.append(propertyValue.toString());
		    }
		}
		else
		{
		    if (type == CIMTYPE_BOOLEAN)
		    {
                        indicationStr.append(_getBooleanStr(propertyValue));
		    }
		    else
		    {
                        indicationStr.append(propertyValue.toString());
		    }
		}
#else
		if (type == CIMTYPE_BOOLEAN)
		{
                    indicationStr.append(_getBooleanStr(propertyValue));
		}
		else
		{
                    indicationStr.append(propertyValue.toString());
		}
#endif
            }
        }
	else
	{
	    indicationStr.append("NULL");
	}

        if (i < propertyCount -1)
        {
            indicationStr.append(", ");
        }

        propertyName.clear();
    }

    PEG_METHOD_EXIT();

    return (indicationStr);
}
Esempio n. 28
0
int main(int argc, char** argv)
{
    try
    {
        CIMClient client;
        client.connectLocal();

        // Define instance name:

        CIMObjectPath instanceName("Methods.key=7777");

        // Define input arguments:

        Array<CIMParamValue> in;
        Array<CIMParamValue> out;

        // Invoke the method:

        const String NAMESPACE = "root/cimv2";
        const String methodName = "foo5";

        Uint32 in_arg = 234567;
        Uint32 in_out_arg = 123456;
        in.append(CIMParamValue("in_arg", in_arg));
        in.append(CIMParamValue("in_out_arg", in_out_arg));

        CIMValue value = client.invokeMethod(
            NAMESPACE,
            instanceName,
            methodName,
            in,
            out);

        {
            assert(value.getType() == CIMTYPE_UINT32);
            Uint32 t;
            value.get(t);
            assert(t == 1200);
        }

        // Check output argument:

        assert(out.size() == 2);
        {
            Uint32 pos = 0;
            assert((pos = findParam(out, "in_out_arg")) != -1);
            assert(out[pos].getParameterName() == "in_out_arg");
            CIMValue value = out[0].getValue();
            Uint32 in_out_arg_rtn;
            value.get(in_out_arg_rtn);
            assert(in_out_arg_rtn == in_out_arg);

            assert((pos = findParam(out, "out_arg")) != -1);
            assert(out[pos].getParameterName() == "out_arg");
            CIMValue value1 = out[1].getValue();
            Uint32 out_arg_rtn;
            value1.get(out_arg_rtn);
            assert(out_arg_rtn == in_arg);
        }

    }
    catch(Exception& e)
    {
        PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl);
        exit(1);
    }

    PEGASUS_STD(cout) << "+++++ passed all tests" << PEGASUS_STD(endl);

    return 0;
}
Esempio n. 29
0
/**
    GetNameSpaces
    If no nameSpace is supplied on the command line, this method looks into
    the root and test nameSpaces for the _Namespace class. The names of the 
    instances of that class are retrued by this method.
*/
Array<CIMNamespaceName> getNameSpaces(
    TestModelWalkStressClient &tmsc,
    CIMClient* client,
    OptionManager &om,
    pid_t clientPid,
    String& clientLog,
    String &clientId,
    int status,
    String &pidFile)
{
    Array<CIMNamespaceName> topNamespaceNames;
    Array<CIMNamespaceName> returnNamespaces;
    String tmpNamespace;

    om.lookupValue("namespace",tmpNamespace);
    if (tmpNamespace != String::EMPTY)
    {
        returnNamespaces.append(CIMNamespaceName (tmpNamespace));
    }
    else
    {
        //
        // Get all namespaces for display using the __Namespaces function.
        //
        CIMName className = "__NameSpace";

        //
        // We have to append any new top level root namespace if created in
        // repository.
        //
        topNamespaceNames.append("root");
        topNamespaceNames.append("test");

        Uint32 start = 0;
        Uint32 end = topNamespaceNames.size();

        //
        // for all new elements in the output array. 
        //
        for (Uint32 range = start; range < end; range ++)
        {
            //
            // Get the next increment in naming for all name element in
            // the array.
            //
            Array<CIMInstance> instances = client->enumerateInstances(
                topNamespaceNames[range], className);

            if (status != CLIENT_PASS)
            {
                status = CLIENT_PASS;
                tmsc.logInfo(clientId, clientPid, status, pidFile);
            }
            for (Uint32 i = 0 ; i < instances.size(); i++)
            {
                Uint32 pos;
                //
                // if we find the property and it is a string, use it.
                //
                if ((pos = instances[i].findProperty("name")) != PEG_NOT_FOUND)
                {
                    CIMValue value;
                    String namespaceComponent;
                    value = instances[i].getProperty(pos).getValue();
                    if (value.getType() == CIMTYPE_STRING)
                    {
                        value.get(namespaceComponent);
                        String ns = topNamespaceNames[range].getString();
                        ns.append("/");
                        ns.append(namespaceComponent);
                        returnNamespaces.append(ns);
                    }
                }
            }
        }
    }//else block ends here...

    if (verboseTest)
    {
        errorInfo.clear();
        errorInfo.append("+++++ Successfully Enumerated all Namespaces that ");
        errorInfo.append("have a _NameSpace instance defined for them in the");
        errorInfo.append(" root of test namespaces +++++");
        tmsc.errorLog(clientPid, clientLog, errorInfo);
        errorInfo.clear();
    }
    return returnNamespaces;
}
Esempio n. 30
0
void call_func()
{
    try
    {
        // Connect.

        CIMClient client;
        client.connectLocal();

        //
        // uint32 AssignSpares(
        //       [IN(false), OUT] CIM_ConcreteJob REF Job,
        //       [IN, OUT(false)] CIM_StoragePool REF InPool,
        //       [Required, IN, OUT (false)] CIM_StorageExtent REF InExtents[],
        //       [IN, OUT (false)] CIM_StorageRedundancySet REF RedundancySet);
        //

        // Build input arguments.

        Array<CIMParamValue> in;

        // InPool:

        CIMObjectPath InPool("CIM_StoragePool.InstanceID=\"1\"");
        in.append(CIMParamValue("InPool", InPool));

        // InExtents:

        CIMObjectPath StorageExtent(
            "root/cimv2:MyStorageExtent."
            "CreationClassName=\"Aristos_DiskStorageExtent\","
            "DeviceID=\"3:5000c500003ac807\","
            "SystemCreationClassName=\"Aristos_ControllerSystem\","
            "SystemName=\"500062E987654391\"");

        Array<CIMObjectPath> InExtents;
        InExtents.append(StorageExtent);
        InExtents.append(StorageExtent);
        InExtents.append(StorageExtent);

        in.append(CIMParamValue("InExtents", InExtents));

        // RedundancySet:
        CIMObjectPath RedundancySet(
            "CIM_StorageRedundancySet.InstanceID=\"1\"");
        in.append(CIMParamValue("RedundancySet", RedundancySet));

        // Invoke method.

        CIMObjectPath target("SNIA_SpareConfigurationService."
            "SystemCreationClassName=\"Mike\","
            "SystemName=\"Mike\","
            "CreationClassName=\"SNIA_SpareConfigurationService\"");

        Array<CIMParamValue> out;

        CIMValue value = client.invokeMethod(
            "root/cimv2",
            target,
            "AssignSpares",
            in,
            out);

        // Expect one output argument.
        assert(out.size() == 1);

        // Check return value.
        assert(value.getType() == CIMTYPE_UINT32);
        Uint32 return_value = 0;
        value.get(return_value);
        assert(return_value == 100);
    }
    catch(Exception& e)
    {
        cerr << "Error: " << e.getMessage() << endl;
        exit(1);
    }
}