int _getProperty(const int argc, const char **argv) { // need to get class definition to find keys // first arg is name of class CIMClass cldef; try { cldef = _c.getClass( PEGASUS_NAMESPACENAME_INTEROP, argv[0] ); } catch(Exception& e) { cerr << /* "getProperty: " << */ e.getMessage() << endl; return 1; } CIMObjectPath ref; CIMInstance inst; // If next arg is "ask", prompt user for keys if (String::equalNoCase("ask",argv[1])) ref = CIMObjectPath(String::EMPTY, PEGASUS_NAMESPACENAME_INTEROP, argv[0], _inputInstanceKeys(cldef) ); // else if the next arg and is "list", enumInstNames and print // a list from which user will select else if (String::equalNoCase("list",argv[1])) { ref = _selectInstance( argv[0] ); if (ref.identical(CIMObjectPath())) return 0; } // else there's another arg but it's invalid else { return 1; } CIMProperty pDef; // if no more args, display property names and ask which if (argc < 3) { int n; for (n=0; n<cldef.getPropertyCount(); n++) cerr << n+1 << ": " << cldef.getProperty(n).getName().getString() << endl; cerr << "Property (1.." << cldef.getPropertyCount() << ")? "; cin >> n; pDef = cldef.getProperty(n-1); }
CIMClass LocalRepository::getClass( const String & nameSpace, const String & className, Boolean includeQualifiers, Boolean includeClassOrigin, const CIMPropertyList & propertyList) { // create a duplicate object before modifying CIMClass cimClass = context->lookupClass("test_namespace", className).clone(); if(!includeQualifiers) { // remove qualifiers from class for(Uint32 i = 0, n = cimClass.getQualifierCount(); i < n; i++) { cimClass.removeQualifier(i); } // remove qualifiers from properties for(Uint32 i = 0, n = cimClass.getPropertyCount(); i < n; i++) { CIMProperty cimProperty = cimClass.getProperty(i); for(Uint32 j = 0, m = cimProperty.getQualifierCount(); j < m; j++) { cimProperty.removeQualifier(j); } } } if(!includeClassOrigin) { // remove class origin for(Uint32 i = 0, n = cimClass.getPropertyCount(); i < n; i++) { cimClass.getProperty(i).setClassOrigin(CIMName()); } } cimClass.setPath(CIMObjectPath("localhost", "test_namespace", cimClass.getClassName())); return(cimClass); }
void IndicationFormatter::validateTextFormatParameters ( const CIMPropertyList & propertyList, const CIMClass & indicationClass, const Array<String> & textFormatParams) { PEG_METHOD_ENTER (TRC_IND_FORMATTER, "IndicationFormatter::validateTextFormatParameters"); Array <String> indicationClassProperties; String exceptionStr; // All the properties are selected if (propertyList.isNull ()) { for (Uint32 i = 0; i < indicationClass.getPropertyCount (); i++) { indicationClassProperties.append( indicationClass.getProperty (i).getName ().getString()); } } // partial properties are selected else { Array<CIMName> propertyNames = propertyList.getPropertyNameArray(); for (Uint32 j = 0; j < propertyNames.size(); j++) { indicationClassProperties.append(propertyNames[j].getString()); } } // check if the textFormatParams is contained in the // indicationClassProperties for (Uint32 k = 0; k < textFormatParams.size(); k++) { if (!Contains(indicationClassProperties, textFormatParams[k])) { // The property name in TextFormatParameters is not // included in the select clause of the associated filter query MessageLoaderParms parms( "IndicationFormatter.IndicationFormatter._MSG_MISS_MATCHED_PROPERTY_NAME", "The property name $0 in $1 does not match the properties in the select clause", textFormatParams[k], _PROPERTY_TEXTFORMATPARAMETERS.getString()); exceptionStr.append(MessageLoader::getMessage(parms)); PEG_METHOD_EXIT(); throw PEGASUS_CIM_EXCEPTION ( CIM_ERR_INVALID_PARAMETER, exceptionStr); } } PEG_METHOD_EXIT(); }
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; }
///////////////////////////////////////////////////////////////////////////// // WMIClassProvider::createProperties creates all properties including keys // add the qualifiers too // /////////////////////////////////////////////////////////////////////////// void WMIClassProvider::createProperties(const CIMClass& newClass, IWbemServices *pServices, IWbemClassObject *pNewClass) { HRESULT hr; PEG_METHOD_ENTER(TRC_WMIPROVIDER, "WmiClassProvider::createProperties()"); // create the properties but don't create the keys again CIMProperty prop; for (Uint32 i = 0; i < newClass.getPropertyCount(); i++) { prop = newClass.getProperty(i).clone(); // create the properties try { createProperty(prop, pNewClass); } catch (CIMException&) { throw; } // get a pointer to work with qualifiers CComPtr<IWbemQualifierSet> pQual; CComBSTR bs = prop.getName().getString().getCString(); hr = pNewClass->GetPropertyQualifierSet(bs, &pQual); bs.Empty(); if (FAILED(hr)) { CMyString msg; msg.Format("Failed get Qualifier set of [%s]. Error: 0x%X", 255, prop.getName().getString().getCString(), hr); Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3, "WMIClassProvider::createProperties() - %s", (LPCTSTR)msg); if (pQual) pQual.Release(); throw CIMException(CIM_ERR_FAILED, (LPCTSTR)msg); } // set the qualifiers to the property for (Uint32 j = 0; j < prop.getQualifierCount(); j++) { WMIQualifier qualifier(prop.getQualifier(j)); try { createQualifier(qualifier, pQual); } catch (CIMException&) { if (pQual) pQual.Release(); throw; } } // set the CLASSORIGIN qualifier if it wasn't set yet String strClassorigin = prop.getClassOrigin().getString(); if (strClassorigin.size() == 0) { strClassorigin = newClass.getClassName().getString(); } WMIFlavor flavor(CIMFlavor::DEFAULTS); /* v.vt = VT_BSTR; v.bstrVal = strClassorigin.getCString(); */ CComVariant v; v = strClassorigin.getCString(); hr = pQual->Put(L"CLASSORIGIN", &v, flavor.getAsWMIValue()); v.Clear(); if (pQual) pQual.Release(); if (FAILED(hr)) { CMyString msg; msg.Format("Failed to add CLASSORIGIN qualifier in [%s]. Error: 0x%X", 255, prop.getName().getString().getCString(), hr); Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3, "WMIClassProvider::createProperties () - %s", (LPCTSTR)msg); throw CIMException(CIM_ERR_FAILED, (LPCTSTR)msg); } } PEG_METHOD_EXIT(); return; }
void IndicationFormatter::_validatePropertyType ( const CIMClass & indicationClass, const String & propertyParam, const String & typeStr, const Boolean & isArray) { PEG_METHOD_ENTER (TRC_IND_FORMATTER, "IndicationFormatter::_validatePropertyType"); String exceptionStr; char propertyTypeBuffer[32]; char * providedPropertyType; Array <String> validPropertyTypes; String propertyTypeStr = typeStr; validPropertyTypes.append ( "boolean"); validPropertyTypes.append ( "uint8"); validPropertyTypes.append ( "sint8"); validPropertyTypes.append ( "uint16"); validPropertyTypes.append ( "sint16"); validPropertyTypes.append ( "uint32"); validPropertyTypes.append ( "sint32"); validPropertyTypes.append ( "uint64"); validPropertyTypes.append ( "sint64"); validPropertyTypes.append ( "real32"); validPropertyTypes.append ( "real64"); validPropertyTypes.append ( "char16"); validPropertyTypes.append ( "string"); validPropertyTypes.append ( "datetime"); validPropertyTypes.append ( "reference"); propertyTypeStr.toLower(); sprintf(propertyTypeBuffer, "%s", (const char *)propertyTypeStr.getCString()); // skip white space providedPropertyType = propertyTypeBuffer; while (*providedPropertyType && isspace(*providedPropertyType)) { providedPropertyType++; } String providedTypeStr = providedPropertyType; Uint32 space = providedTypeStr.find(" "); if (space != PEG_NOT_FOUND) { // skip the appended space from the providedTypeStr // e.g {1, string } String restTypeStr = providedTypeStr.subString(space, PEG_NOT_FOUND); Uint32 i = 0; while (restTypeStr[i] == ' ') { i++; } restTypeStr = restTypeStr.subString(i, PEG_NOT_FOUND); if (strlen(restTypeStr.getCString()) == 0) { providedTypeStr = providedTypeStr.subString(0, space); } else { // the provided property type is not a valid type // e.g. {1, string xxx} MessageLoaderParms parms( "IndicationFormatter.IndicationFormatter._MSG_INVALID_TYPE_OF_FOR_PROPERTY", "Invalid property type of $0 in property $1", providedPropertyType, _PROPERTY_TEXTFORMAT.getString()); } } // // Checks if the provided property type is a valid type // if (!(Contains (validPropertyTypes, providedTypeStr))) { // the provided property type is not valid type MessageLoaderParms parms( "IndicationFormatter.IndicationFormatter._MSG_INVALID_TYPE_OF_FOR_PROPERTY", "Invalid property type of $0 in property $1", providedPropertyType, _PROPERTY_TEXTFORMAT.getString()); exceptionStr.append(MessageLoader::getMessage(parms)); PEG_METHOD_EXIT(); throw PEGASUS_CIM_EXCEPTION ( CIM_ERR_INVALID_PARAMETER, exceptionStr); } for (Uint32 i = 0; i < indicationClass.getPropertyCount (); i++) { CIMName propertyName = indicationClass.getProperty (i).getName (); if (String::equalNoCase(propertyParam, (propertyName.getString()))) { // get the property type; CIMType propertyType = indicationClass.getProperty (i).getType(); // Check if the property is an array type if ((isArray && !(indicationClass.getProperty(i).isArray())) || (!isArray && indicationClass.getProperty(i).isArray())) { MessageLoaderParms parms( "IndicationFormatter.IndicationFormatter._MSG_PROPERTY_IS_NOT_AN_ARRAY_TYPE", "The property $0 is not an array type", propertyName.getString()); exceptionStr.append(MessageLoader::getMessage(parms)); PEG_METHOD_EXIT(); throw PEGASUS_CIM_EXCEPTION ( CIM_ERR_INVALID_PARAMETER, exceptionStr); } // property type matchs if (String::equalNoCase(providedTypeStr, cimTypeToString(propertyType))) { break; } else { MessageLoaderParms parms( "IndicationFormatter.IndicationFormatter._MSG_MISS_MATCHED_TYPE_OF_FOR_PROPERTY", "The provided property type of $0 in $1 does not match the property type $2", providedPropertyType, cimTypeToString(propertyType), _PROPERTY_TEXTFORMAT.getString()); exceptionStr.append(MessageLoader::getMessage(parms)); PEG_METHOD_EXIT(); throw PEGASUS_CIM_EXCEPTION ( CIM_ERR_INVALID_PARAMETER, exceptionStr); } } } PEG_METHOD_EXIT(); }