cmpiprovider.cpp

来自「Pegasus is an open-source implementation」· C++ 代码 · 共 610 行 · 第 1/2 页

CPP
610
字号
//%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 "CMPIProvider.h"#include "CMPI_Object.h"#include "CMPI_Broker.h"#include "CMPI_ContextArgs.h"#include "CMPI_Ftabs.h"#include <Pegasus/Common/Tracer.h>#include <Pegasus/Common/Time.h>#include <Pegasus/ProviderManager2/CMPI/CMPIProvider.h>#include <Pegasus/ProviderManager2/CMPI/CMPIProviderModule.h>#include <Pegasus/ProviderManager2/CMPI/CMPILocalProviderManager.h>PEGASUS_USING_STD;PEGASUS_NAMESPACE_BEGIN// set current operations to 1 to prevent an unload// until the provider has had a chance to initializeCMPIProvider::CMPIProvider(const String & name,		   CMPIProviderModule *module,		   ProviderVector *mv)   : _status(UNINITIALIZED), _module(module), _cimom_handle(0), _name(name),     _no_unload(0), _rm(0), _threadWatchList(), _cleanedThreads(){   _current_operations = 1;   _currentSubscriptions = 0;   broker.hdl =0;   broker.provider = this;   if (mv) miVector=*mv;   noUnload=false;   Time::gettimeofday(&_idleTime);}CMPIProvider::CMPIProvider(CMPIProvider *pr)  : _status(UNINITIALIZED), _module(pr->_module), _cimom_handle(0), _name(pr->_name),    _no_unload(0), _rm(0), _threadWatchList(), _cleanedThreads(){   _current_operations = 1;   _currentSubscriptions = 0;   miVector=pr->miVector;   broker.hdl =0;   broker.provider = this;   _cimom_handle=new CIMOMHandle();   noUnload=pr->noUnload;   Time::gettimeofday(&_idleTime);}CMPIProvider::~CMPIProvider(void){    delete (CIMOMHandle*)broker.hdl;	PEGASUS_ASSERT ( _threadWatchList.size () == 0 );	PEGASUS_ASSERT ( _cleanedThreads.size () == 0 );}CMPIProvider::Status CMPIProvider::getStatus(void){    AutoMutex lock(_statusMutex);    return(_status);}void CMPIProvider::set(CMPIProviderModule *&module,                    ProviderVector cmpiProvider,                    CIMOMHandle *&cimomHandle){    _module = module;    miVector = cmpiProvider;    _cimom_handle = cimomHandle;}void CMPIProvider::reset(){    _module = 0;    _cimom_handle = 0;    _no_unload = 0;    _status = UNINITIALIZED;}CMPIProviderModule *CMPIProvider::getModule(void) const{    return(_module);}String CMPIProvider::getName(void) const{    return(_name.subString(1,PEG_NOT_FOUND));}void setError(ProviderVector &miVector,                String &error,		const String &realProviderName,                  const char *generic,                  const char *spec){   if (miVector.genericMode)           error.append(generic);   else      {           error.append(realProviderName);           error.append(spec);      }  error.append(", ");}void CMPIProvider::initialize(CIMOMHandle & cimom,                              ProviderVector & miVector,			      String & name,                              CMPI_Broker & broker){        broker.hdl=new CIMOMHandle(cimom);        broker.bft=CMPI_Broker_Ftab;        broker.eft=CMPI_BrokerEnc_Ftab;        broker.xft=CMPI_BrokerExt_Ftab;        broker.mft=NULL;    // CMPI memory services not supported        {            WriteLock writeLock (broker.rwsemClassCache);            broker.clsCache=new ClassCache();        }        broker.name=name;        const OperationContext opc;        CMPI_ContextOnStack eCtx(opc);        CMPI_ThreadContext thr(&broker,&eCtx);	    CMPIStatus rc = {CMPI_RC_OK, NULL};		String error = String::EMPTY;  	    String realProviderName(name);        if (miVector.genericMode) {           CString mName=realProviderName.getCString();           if (miVector.miTypes & CMPI_MIType_Instance)              miVector.instMI=miVector.createGenInstMI(&broker,&eCtx,mName, &rc);           if (miVector.miTypes & CMPI_MIType_Association)              miVector.assocMI=miVector.createGenAssocMI(&broker,&eCtx,mName, &rc);           if (miVector.miTypes & CMPI_MIType_Method)              miVector.methMI=miVector.createGenMethMI(&broker,&eCtx,mName, &rc);           if (miVector.miTypes & CMPI_MIType_Property)              miVector.propMI=miVector.createGenPropMI(&broker,&eCtx,mName, &rc);           if (miVector.miTypes & CMPI_MIType_Indication)              miVector.indMI=miVector.createGenIndMI(&broker,&eCtx,mName, &rc);        }        else {           if (miVector.miTypes & CMPI_MIType_Instance)              miVector.instMI=miVector.createInstMI(&broker,&eCtx, &rc);           if (miVector.miTypes & CMPI_MIType_Association)              miVector.assocMI=miVector.createAssocMI(&broker,&eCtx, &rc);           if (miVector.miTypes & CMPI_MIType_Method)              miVector.methMI=miVector.createMethMI(&broker,&eCtx, &rc);           if (miVector.miTypes & CMPI_MIType_Property)              miVector.propMI=miVector.createPropMI(&broker,&eCtx, &rc);           if (miVector.miTypes & CMPI_MIType_Indication)              miVector.indMI=miVector.createIndMI(&broker,&eCtx, &rc);        }           if (miVector.miTypes & CMPI_MIType_Instance)              if (miVector.instMI == NULL || rc.rc != CMPI_RC_OK)			setError(miVector, error, realProviderName, _Generic_Create_InstanceMI, _Create_InstanceMI);           if (miVector.miTypes & CMPI_MIType_Association)              if (miVector.assocMI == NULL || rc.rc != CMPI_RC_OK)			setError(miVector, error, realProviderName, _Generic_Create_AssociationMI, _Create_AssociationMI);           if (miVector.miTypes & CMPI_MIType_Method)              if (miVector.methMI == NULL || rc.rc != CMPI_RC_OK)			setError(miVector, error, realProviderName, _Generic_Create_MethodMI, _Create_MethodMI);           if (miVector.miTypes & CMPI_MIType_Property)			 if (miVector.propMI == NULL || rc.rc != CMPI_RC_OK)			setError(miVector, error, realProviderName, _Generic_Create_PropertyMI, _Create_PropertyMI);           if (miVector.miTypes & CMPI_MIType_Indication)              if (miVector.indMI == NULL || rc.rc != CMPI_RC_OK)			setError(miVector, error, realProviderName, _Generic_Create_IndicationMI, _Create_IndicationMI);		if (error.size() != 0)		 {			delete (CIMOMHandle*)broker.hdl;			broker.hdl =0;		    	throw Exception(MessageLoaderParms("ProviderManager.CMPI.CMPIProvider.CANNOT_INIT_API",            			"ProviderInitFailure: Error initializing $0 the following API(s): $1",				realProviderName,				error.subString(0, error.size()-2)));		  }}void CMPIProvider::initialize(CIMOMHandle & cimom){    String providername(getName());    if(_status == UNINITIALIZED)  {      String compoundName;      if (_location.size() == 0)			compoundName= providername;      else			compoundName=_location+":"+providername;      try {	 // yield before a potentially lengthy operation.        Threads::yield();	 CMPIProvider::initialize(cimom,miVector,compoundName,broker);	      if (miVector.miTypes & CMPI_MIType_Method) {	        if (miVector.methMI->ft->miName==NULL) noUnload=true;	      }      }      catch(...) {        _current_operations = 0;	      throw;      }      _status = INITIALIZED;      _current_operations = 0;  }}Boolean CMPIProvider::tryTerminate(void){  Boolean terminated = false;  if(_status == INITIALIZED)  {   if(false == unload_ok())   {      return false;   }   Status savedStatus=_status;      // yield before a potentially lengthy operation.      Threads::yield();      try      {	if (noUnload==false) {		// False means that the CIMServer is not shutting down.	   _terminate(false);	   if (noUnload==true) {	      _status=savedStatus;	      return false;	   }	   terminated=true;	 }      }      catch(...)      {	 PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4,			  "Exception caught in CMPIProviderFacade::tryTerminate() for " +			  getName());	 terminated = false;      }   if(terminated == true)   {    _status = UNINITIALIZED;   }  }  return terminated;}/* Terminates the CMPIProvider by cleaning its class cache and calling its cleanup funtions. @argument terminating When set to false, the provider may resist terminating.  	If true, provider MUST clean up.*/void CMPIProvider::_terminate(Boolean terminating){    const OperationContext opc;    CMPIStatus rc={CMPI_RC_OK,NULL};    CMPI_ContextOnStack eCtx(opc);    CMPI_ThreadContext thr(&broker,&eCtx);/* @param terminating When true, the terminating argument indicates that the MB is in the process of     terminating and that cleanup must be done. When set to false, the MI may respond with     CMPI_IRC_DO_NOT_UNLOAD, or CMPI_IRC_NEVER_UNLOAD, indicating that unload will     interfere with current MI processing.

⌨️ 快捷键说明

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