📄 cmpi_brokerenc.cpp
字号:
String logString = id; Uint32 logSeverity = Logger::INFORMATION; logString.append(":"); if (string) { logString.append( ( char*)CMGetCharsPtr(string,NULL)); } else { logString.append( text ); } // There are no notion in CMPI spec about what 'severity' means. // So we are going to try to map if (severity <= 1) logSeverity = Logger::INFORMATION; else if (severity == 2) logSeverity = Logger::WARNING; else if (severity == 3) logSeverity = Logger::SEVERE; else if (severity == 4) logSeverity = Logger::FATAL; Logger::put(Logger::STANDARD_LOG, id, logSeverity, logString); CMReturn ( CMPI_RC_OK); } CMPIStatus mbEncTracer (const CMPIBroker*,int level,const char *component,const char *text, const CMPIString *string) { if ( !component || !(text || string)) CMReturn(CMPI_RC_ERR_INVALID_PARAMETER); String traceString = String::EMPTY; Uint32 traceComponent = TRC_PROVIDERMANAGER; Uint32 traceLevel = Tracer::LEVEL1; // There are no notion in CMPI spec about what 'level' means. // So we are going to try to map . We don't want to map to LEVEL1 // as it requires the PEG_METHOD_ENTER and PEG_METHOD_EXIT macros. if (level <= 2) traceLevel = Tracer::LEVEL2; else if (level == 3) traceLevel = Tracer::LEVEL3; else if (level == 4) traceLevel = Tracer::LEVEL4; // Next is figuring if 'component' maps to the Pegasus types; { Uint32 i =0; Uint32 m =sizeof(TRACE_COMPONENT_LIST)/sizeof(TRACE_COMPONENT_LIST[0]); for (; i < m; i++) { if (System::strcasecmp(component, TRACE_COMPONENT_LIST[i]) == 0) { traceComponent = i; break; } } // if not found, just use TRC_PROVIDERMANAGER and put the // 'component' in the traceString. if ((m = i) && (traceComponent == TRC_PROVIDERMANAGER)) { traceString=String(component); traceString.append(":"); } } if (string) { traceString.append( ( char*)CMGetCharsPtr(string,NULL)); } else { traceString.append( text ); } Tracer::trace(traceComponent, traceLevel, traceString.getCString()); CMReturn ( CMPI_RC_OK); }#endif static CMPISelectExp *mbEncNewSelectExp (const CMPIBroker * mb, const char *query, const char *lang, CMPIArray ** projection, CMPIStatus * st) { int exception = 1; int useShortNames = 0; CMPIStatus rc = { CMPI_RC_OK, NULL }; if (strncmp (lang, CALL_SIGN_WQL, CALL_SIGN_WQL_SIZE) == 0) { WQLSelectStatement *stmt = new WQLSelectStatement (); try { WQLParser::parse (query, *stmt); exception = 0; } catch (const ParseError &) { if (st) CMSetStatus (st, CMPI_RC_ERR_INVALID_QUERY); } catch (const MissingNullTerminator &) { if (st) CMSetStatus (st, CMPI_RC_ERR_INVALID_QUERY); } if (exception) { delete stmt; if (projection) *projection = NULL; return NULL; } if (projection) { if (stmt->getAllProperties ()) { *projection = NULL; } else { *projection = mbEncNewArray (mb, stmt->getSelectPropertyNameCount (), CMPI_string, NULL); for (int i = 0, m = stmt->getSelectPropertyNameCount (); i < m; i++) { const CIMName & n = stmt->getSelectPropertyName (i); //cerr << "Property: " << n.getString() << endl; // Since the array and the CIMName disappear when this function // exits we use CMPI data storage - the CMPI_Object keeps a list of // data and cleans it up when the provider API function is exited. CMPIString *str_data = reinterpret_cast < CMPIString * >(new CMPI_Object (n.getString())); CMPIValue value; value.string = str_data; rc = CMSetArrayElementAt (*projection, i, &value, CMPI_string); if (rc.rc != CMPI_RC_OK) { if (st) CMSetStatus (st, rc.rc); return NULL; } } } } stmt->hasWhereClause (); if (st) CMSetStatus (st, CMPI_RC_OK); return (CMPISelectExp *) new CMPI_SelectExp (stmt); }#ifndef PEGASUS_DISABLE_CQL if ((strncmp (lang, CALL_SIGN_CQL, CALL_SIGN_CQL_SIZE) == 0) || (strncmp (lang, "CIMxCQL", 7) == 0) || (strncmp (lang, "CIM:CQL", 7) == 0)) { /* IBMKR: This will have to be removed when the CMPI spec is updated with a clear explanation of what properties array can have as strings. For right now, if useShortNames is set to true, _only_ the last chained identifier is used. */ if (strncmp (lang, CALL_SIGN_CQL, CALL_SIGN_CQL_SIZE) == 0) { useShortNames = 1; } // Get the namespace. const CMPIContext *ctx = CMPI_ThreadContext::getContext (); CMPIData data = ctx->ft->getEntry (ctx, CMPIInitNameSpace, &rc); if (rc.rc != CMPI_RC_OK) { if (st) CMSetStatus (st, CMPI_RC_ERR_FAILED); return NULL; } // Create the CIMOMHandle wrapper. CIMOMHandle *cm_handle = CM_CIMOM (mb); CIMOMHandleQueryContext qcontext (CIMNamespaceName (CMGetCharPtr (data.value.string)), *cm_handle); String sLang (lang); String sQuery (query); CQLSelectStatement *selectStatement = new CQLSelectStatement (sLang, sQuery, qcontext); try { CQLParser::parse (query, *selectStatement); selectStatement->validate (); exception = 0; } catch (...) { if (st) CMSetStatus (st, CMPI_RC_ERR_INVALID_QUERY); } if (exception) { delete selectStatement; if (projection) *projection = NULL; return NULL; } else { if (projection) { Array < CQLChainedIdentifier > select_Array = selectStatement->getSelectChainedIdentifiers (); // Special check. Remove it when useShortNames is not neccessary if ((select_Array.size() == 1) && (useShortNames) && (select_Array[0].getLastIdentifier().getName().getString() == String::EMPTY)) { *projection= NULL; } else { *projection = mbEncNewArray (mb, select_Array.size (), CMPI_string, NULL); CQLIdentifier identifier; String name; for (Uint32 i = 0; i < select_Array.size (); i++) { if (useShortNames) { identifier = select_Array[i].getLastIdentifier (); name = identifier.getName ().getString (); } else { name = select_Array[i].toString (); } // Since the array and the CIMName disappear when this function // exits we use CMPI data storage - the CMPI_Object keeps a list of // data and cleans it up when the provider API function is exited. //cerr << "Property: " << name << endl; CMPIString *str_data = reinterpret_cast < CMPIString * >(new CMPI_Object (name)); CMPIValue value; value.string = str_data; rc = CMSetArrayElementAt (*projection, i, &value, CMPI_string); if (rc.rc != CMPI_RC_OK) { if (st) CMSetStatus (st, rc.rc); return NULL; } } } } } if (st) CMSetStatus (st, CMPI_RC_OK); return (CMPISelectExp *) new CMPI_SelectExp (selectStatement); }#endif if (st) CMSetStatus (st, CMPI_RC_ERR_QUERY_LANGUAGE_NOT_SUPPORTED); return NULL; }#if defined (CMPI_VER_90) && !defined(CMPI_VER_100) static CMPIArray * mbEncGetKeyList(CMPIBroker *mb, CMPIContext *ctx, CMPIObjectPath *cop, CMPIStatus *rc) { if ((cop==NULL) || (ctx==NULL)) { if (rc) CMSetStatus(rc, CMPI_RC_ERR_INVALID_PARAMETER); return NULL; } CIMObjectPath *op=(CIMObjectPath*)cop->hdl; if (!op) { if (rc) CMSetStatus(rc, CMPI_RC_ERR_INVALID_PARAMETER); return NULL; } CIMClass *cls=mbGetClass(mb,*op); Array<String> keys; for (int i=0,m=cls->getPropertyCount(); i<m; i++) { CIMConstProperty p=cls->getProperty(i); Uint32 k=p.findQualifier("key"); if (k!=PEG_NOT_FOUND) { keys.append(p.getName().getString()); } } CMPIArray *ar=mb->eft->newArray(mb,keys.size(),CMPI_string,NULL); for (Uint32 i=0,m=keys.size(); i<m; i++) { String s=keys[i]; CMPIString *str=string2CMPIString(s); ar->ft->setElementAt(ar,i,(CMPIValue*)&str,CMPI_string); } if (rc) CMSetStatus(rc,CMPI_RC_OK); return ar; } #endif}static CMPIBrokerEncFT brokerEnc_FT={ CMPICurrentVersion ,mbEncNewInstance ,mbEncNewObjectPath ,mbEncNewArgs ,mbEncNewString ,mbEncNewArray ,mbEncNewDateTime ,mbEncNewDateTimeFromBinary ,mbEncNewDateTimeFromString ,mbEncNewSelectExp ,mbEncClassPathIsA ,mbEncToString ,mbEncIsOfType ,mbEncGetType#if defined (CMPI_VER_85) ,mbEncGetMessage#endif#if defined (CMPI_VER_90) && !defined(CMPI_VER_100) ,mbEncGetKeyList#endif#if defined (CMPI_VER_100) ,mbEncLogMessage ,mbEncTracer#endif#if defined (CMPI_VER_200) ,mbEncNewCMPIError ,mbEncOpenMessageFile ,mbEncCloseMessageFile ,mbEncGetMessage2#endif};CMPIBrokerEncFT *CMPI_BrokerEnc_Ftab=&brokerEnc_FT;PEGASUS_NAMESPACE_END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -