Ejemplo n.º 1
0
////////////////////////////////////////////////////////////////
//
// addWMIParametersToCIMMethod
//
// Add parameters from a WMI class to a CIMMethod.
//
///////////////////////////////////////////////////////////////
void addWMIParametersToCIMMethod(
        const CComPtr<IWbemClassObject>& wmiParameters, 
        CIMMethod& method,
        Boolean includeQualifiers)
{
    // Check if wmiParameters is NULL (this will ocurr when there are none)
    HRESULT hr;
    if (wmiParameters)
    {
        // Enumerate all output parameters
        hr = wmiParameters->BeginEnumeration(WBEM_FLAG_LOCAL_ONLY);
        while(true)
        {
            // Get current parameter name and value
            CComBSTR bstrParamName;
            CComVariant vParamValue;
            CIMTYPE wmiType;
            hr = wmiParameters->Next(0, &bstrParamName, 
                &vParamValue, &wmiType, NULL);

            // Check errors
            if (WBEM_S_NO_MORE_DATA == hr) 
            {
                break;
            }
            if (FAILED(hr)) 
            {
                bstrParamName.Empty();
                vParamValue.Clear();
                throw CIMException(CIM_ERR_FAILED);
            }
            
            // Convert to CIMParameter
            BSTR tmpBstr = (BSTR)bstrParamName.Copy();
            String parameterName(_bstr_t(tmpBstr, FALSE));
            SysFreeString(tmpBstr);

            // Add the parameter to this method if it is not the return value
            // and it does not already exist in the method.
            // If the parameter already exists (i.e., an in & out parameter), 
            // then there is no need to re-add or modify it here
            // (the in version is an exact copy of the out version):
            String strRetVal("ReturnValue");
            if (!(String::equalNoCase(parameterName, strRetVal)) &&
                method.findParameter(parameterName) == PEG_NOT_FOUND)
            {
                // Get the qualifier list for this param from WMI:
                CComPtr<IWbemQualifierSet> pParamQualifiers;
                HRESULT hr = 
                    wmiParameters->GetPropertyQualifierSet(bstrParamName, 
                                                           &pParamQualifiers);
                
                // create the CIMParameter
                CIMParameter cimParam = 
                    cimParamFromWMIParam(parameterName,
                                         wmiType,
                                         pParamQualifiers,
                                         includeQualifiers);

                // Now, add the new parameter to the CIMMethod:
                method.addParameter(cimParam);

                if (pParamQualifiers)
                    pParamQualifiers.Release();
            }

            bstrParamName.Empty();
            vParamValue.Clear();
        }
        hr = wmiParameters->EndEnumeration();    
    }
}
Ejemplo n.º 2
0
int _getClass(const int argc, const char **argv)
{
  CIMClass cldef;
  try
  {
    cldef = _c.getClass( PEGASUS_NAMESPACENAME_INTEROP, argv[0] );
  }
  catch (Exception& e)
  {
    cerr << /* "getClass: " << */ e.getMessage() << endl;
    return 1;
  }

  // Display the class definition
  // without qualifiers, for the moment

  // First the class name and superclass
  cout << "class " << cldef.getClassName().getString() << " : "
    << cldef.getSuperClassName().getString() << endl;
  cout << "{" << endl;
  
  // Now the properties
  // No qualifiers except [key], but specify type, array
  for (int i=0; i<cldef.getPropertyCount(); i++)
  {
    CIMProperty p = cldef.getProperty(i);
    cout << "  ";
    // output key, if required
    if (_isKey(p)) cout << "[ Key ] ";
    // prepare to output type, but
    // first, if type is "reference", find target class
    if (p.getType() == CIMTYPE_REFERENCE)
      cout << p.getReferenceClassName().getString() << " REF ";
    // output type
    else cout << cimTypeToString(p.getType()) << " ";
    // output name
    cout << p.getName().getString();
    // output array, if required
    if (p.isArray()) cout << "[]";
    // final eol
    cout << ";" << endl;
  }
  
  // need to do methods
  for (int i=0; i<cldef.getMethodCount(); i++)
  {
    CIMMethod m = cldef.getMethod(i);
    // output type
    cout << "  " << cimTypeToString(m.getType()) << " ";
    // output name
    cout << m.getName().getString() << "(";
    // output parameters
    // new line if there are any parameters
    for (int j=0; j<m.getParameterCount(); j++)
    {
      CIMParameter p = m.getParameter(j);
      // output IN/OUT qualifiers on a fresh line
      cout << endl << "    [ ";
      // loop through qualifiers looking for IN, OUT
      for (int k=0; k<p.getQualifierCount(); k++)
      {
        // when one found, output its value
        CIMQualifier q = p.getQualifier(k);
        if (q.getName().equal("in") ||
            q.getName().equal("out"))
        {
          cout << q.getName().getString() << " ";
        }
      }
      // Now the type
      cout << "] " << cimTypeToString(p.getType()) << " ";
      // finally the name
      cout << p.getName().getString();
      // array brackets
      if (p.isArray()) cout << "[]";
      // closing , on parameter if not last
      if (j != m.getParameterCount()-1) cout << ",";
    }
    // after last param, indent before closing paren

    // close paren
    cout << ")";
    // if (m.isArray()) cout << "[]";
    // finish output
    cout << ";" << endl;
  }
  
  // final brace and done
  cout << "};" << endl;

  return 0; 
}
Ejemplo n.º 3
0
void
CIMtoXML(CIMMethod const& cm, ostream& ostr)
{
	ostr << "<METHOD ";
	if (cm.getName().empty())
	{
		OW_THROWCIMMSG(CIMException::FAILED, "method must have a name");
	}
	ostr
		<< "NAME=\""
		<< cm.getName()
		<< "\" ";
	if (cm.getReturnType())
	{
		ostr << "TYPE=\"";
		CIMtoXML(cm.getReturnType(),ostr);
		ostr << "\" ";
	}
	if (!cm.getOriginClass().empty())
	{
		ostr
			<< "CLASSORIGIN=\""
			<< cm.getOriginClass()
			<< "\" ";
	}
	if (cm.getPropagated())
	{
		ostr << "PROPAGATED=\"true\" ";
	}
	ostr << '>';
	for (size_t i = 0; i < cm.getQualifiers().size(); i++)
	{
		CIMtoXML(cm.getQualifiers()[i], ostr);
	}
	for (size_t i = 0; i < cm.getParameters().size(); i++)
	{
		CIMtoXML(cm.getParameters()[i], ostr);
	}
	ostr << "</METHOD>";
}