⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmpi_selectexp.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//%2006//////////////////////////////////////////////////////////////////////////// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation, The Open Group.// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; Symantec Corporation; The Open Group.//// Permission is hereby granted, free of charge, to any person obtaining a copy// of this software and associated documentation files (the "Software"), to// deal in the Software without restriction, including without limitation the// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or// sell copies of the Software, and to permit persons to whom the Software is// furnished to do so, subject to the following conditions:// // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.////==============================================================================////%/////////////////////////////////////////////////////////////////////////////#include "CMPI_Version.h"#include "CMPI_SelectExp.h"#include "CMPI_Ftabs.h"#include "CMPI_Value.h"#include "CMPI_String.h"#include "CMPI_SelectExpAccessor_WQL.h"#ifndef PEGASUS_DISABLE_CQL#include "CMPI_SelectExpAccessor_CQL.h"#include <Pegasus/CQL/CQLSelectStatement.h>#include <Pegasus/CQL/CQLParser.h>#endif#include <Pegasus/WQL/WQLInstancePropertySource.h>#include <Pegasus/Provider/CIMOMHandleQueryContext.h>#include <Pegasus/WQL/WQLParser.h>PEGASUS_USING_STD;PEGASUS_NAMESPACE_BEGIN#define DDD(X)   if (_cmpi_trace) X;extern int _cmpi_trace;extern "C"{  PEGASUS_STATIC CMPIStatus selxRelease (CMPISelectExp * eSx)  { 	CMPI_SelectExp *se = (CMPI_SelectExp*)eSx;        if (!se->persistent) {		// Do not call unlinkAndDelete - b/c the CMPI_Object::unlinkAndDelete		// casts the structure to a CMPI_Object and deletes it. But this is a                // CMPI_SelectExp structure so not all of the variables get deleted. Hence                // we delete them here.         	//((CMPI_Object*)se)->unlinkAndDelete();                (reinterpret_cast<CMPI_Object*>(se))->unlink();        }	delete se;    CMReturn (CMPI_RC_OK);  }  // This will not clone all the CMPISelectExp objects. It clones only when  // original object has either CQLSelectStatement or WQLSelectStatement.  // Any other properties of original object may cause clone to retun error  // CMPI_RC_ERR_NOT_SUPPORTED. Use this only when you have just created  // CMPISelectExp object with CMNewselectExp (broker,query,lang,projection,rc)  PEGASUS_STATIC CMPISelectExp *selxClone (const CMPISelectExp * eSx, CMPIStatus * rc)  {      CMPI_SelectExp *new_se;      CMPI_SelectExp *se = (CMPI_SelectExp*) eSx;      if (#ifndef PEGASUS_DISABLE_CQL          !se->cql_stmt &&#endif          !se->wql_stmt || se->_context || se->hdl)      {    if (rc)      CMSetStatus (rc, CMPI_RC_ERR_NOT_SUPPORTED);    return NULL;  }#ifndef PEGASUS_DISABLE_CQL      CQLSelectStatement *cql_stmt;#endif      WQLSelectStatement *wql_stmt;      Boolean  disable_cql = true;#ifndef PEGASUS_DISABLE_CQL      if (se->cql_stmt)      {          cql_stmt = new CQLSelectStatement (*se->cql_stmt);          new_se = new CMPI_SelectExp (cql_stmt, true);          disable_cql = false;      }#endif      if (disable_cql)      {          wql_stmt = new WQLSelectStatement (*se->wql_stmt);          new_se = new CMPI_SelectExp (wql_stmt, true);      }      return (CMPISelectExp*) new_se;  }  /* Helper functions */  PEGASUS_STATIC CMPIBoolean _check_WQL (CMPI_SelectExp * sx, CMPIStatus * rc)  {    if (sx->wql_stmt == NULL)      {        WQLSelectStatement *stmt = new WQLSelectStatement ();        try        {          WQLParser::parse (sx->cond, *stmt);        }        catch (const Exception &e) 	{	   DDD(cout<<"### exception: _check_WQL - msg: "<<e.getMessage()<<endl);           if (rc) CMSetStatusWithString(rc,CMPI_RC_ERR_INVALID_QUERY,            	(CMPIString*)string2CMPIString(e.getMessage()));           delete stmt;	   return false;	}        catch (...)        {	  DDD(cout<<"### exception: _check_WQL - ... " <<endl);          delete stmt;          if (rc) CMSetStatus (rc, CMPI_RC_ERR_INVALID_QUERY);          return false;        }        /* Only set it for success */        sx->wql_stmt = stmt;      }                         /* sx->wql_stmt ... */    return true;  }#ifndef PEGASUS_DISABLE_CQL  PEGASUS_STATIC CMPIBoolean _check_CQL (CMPI_SelectExp * sx, CMPIStatus * rc)  {    Boolean fail = false;    if (sx->cql_stmt == NULL)      {        /* The constructor should set this to a valid pointer. */        if (sx->_context == NULL)          {            CMSetStatus (rc, CMPI_RC_ERROR_SYSTEM);            return false;          }        CQLSelectStatement *selectStatement =          new CQLSelectStatement (sx->lang, sx->cond, *sx->_context);        try        {          CQLParser::parse (sx->cond, *selectStatement);          selectStatement->validate ();        }        catch (const Exception &e)  	{	    DDD(cout<<"### exception: _check_CQL - msg: "<<e.getMessage()<<endl);            if (rc) CMSetStatusWithString(rc,CMPI_RC_ERR_INVALID_QUERY,            		(CMPIString*)string2CMPIString(e.getMessage()));            fail = true;        }        catch (...)        {	  DDD(cout<<"### exception: _check_CQL - ... " <<endl);          if (rc) CMSetStatus (rc, CMPI_RC_ERR_INVALID_QUERY);	  fail = true;        }	if (fail) 	{          delete selectStatement;          return false;        }        sx->cql_stmt = selectStatement;      }    return true;  }#endif  PEGASUS_STATIC CMPIBoolean selxEvaluate (const CMPISelectExp * eSx, const CMPIInstance * inst,                                   CMPIStatus * rc)  {    CMPI_SelectExp *sx = (CMPI_SelectExp *) eSx;    if (!inst)      {        if (rc)          CMSetStatus (rc, CMPI_RC_ERR_INVALID_PARAMETER);        return false;      }    if (!inst->hdl)      {        if (rc)          CMSetStatus (rc, CMPI_RC_ERR_INVALID_PARAMETER);        return false;      }    CIMInstance *instance = (CIMInstance *) inst->hdl;    /* WQL */    if (strncmp (sx->lang.getCString (), CALL_SIGN_WQL, CALL_SIGN_WQL_SIZE) ==        0)      {        if (_check_WQL (sx, rc))          {            try            {              return sx->wql_stmt->evaluate (*(CIMInstance *) inst->hdl);            } catch (const Exception &e)	    {		        DDD(cout<<"### exception: selxEvaluate - msg: "<<e.getMessage()<<endl);                if (rc) CMSetStatusWithString(rc,CMPI_RC_ERR_FAILED,            		(CMPIString*)string2CMPIString(e.getMessage()));                return false;	    }            catch (...)            {	      DDD(cout<<"### exception: selxEvaluate - ... " <<endl);              if (rc) CMSetStatus (rc, CMPI_RC_ERR_FAILED);              return false;            }          }        else          return false;      }    /* CIM:CQL */#ifndef PEGASUS_DISABLE_CQL    if ((strncmp (sx->lang.getCString(),                  CALL_SIGN_CQL, CALL_SIGN_CQL_SIZE) == 0) ||        (strncmp (sx->lang.getCString(),                  "CIM:CQL", 7) == 0))      {        if (_check_CQL (sx, rc))          {            try            {              return sx->cql_stmt->evaluate (*instance);            }            catch (const Exception &e)             {	        DDD(cout<<"### exception: selxEvaluate - msg: "<<e.getMessage()<<endl);                if (rc) CMSetStatusWithString(rc,CMPI_RC_ERR_FAILED,            		(CMPIString*)string2CMPIString(e.getMessage()));		return false;            }            catch (...)            {	      DDD(cout<<"### exception: selxEvaluate - ... " <<endl);              if (rc) CMSetStatus (rc, CMPI_RC_ERR_FAILED);              return false;            }          }        else          return false;      }#endif    /* Tried some other weird query language which we don't support */    if (rc)      CMSetStatus (rc, CMPI_RC_ERR_NOT_SUPPORTED);    return false;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -