OW_CMPIProviderIFC.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2003-2004 Vintela, Inc., IBM Corp. All rights reserved.
00003 *
00004 * Redistribution and use in source and binary forms, with or without
00005 * modification, are permitted provided that the following conditions are met:
00006 *
00007 *  - Redistributions of source code must retain the above copyright notice,
00008 *    this list of conditions and the following disclaimer.
00009 *
00010 *  - Redistributions in binary form must reproduce the above copyright notice,
00011 *    this list of conditions and the following disclaimer in the documentation
00012 *    and/or other materials provided with the distribution.
00013 *
00014 *  - Neither the name of Vintela, Inc. nor the names of its
00015 *    contributors may be used to endorse or promote products derived from this
00016 *    software without specific prior written permission.
00017 *
00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 * ARE DISCLAIMED. IN NO EVENT SHALL Vintela, Inc. OR THE CONTRIBUTORS
00022 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00023 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00024 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00027 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00028 * POSSIBILITY OF SUCH DAMAGE.
00029 *
00030 * Author:        Markus Mueller <sedgewick_de@yahoo.de>
00031 *
00032 *******************************************************************************/
00033 #include "OW_config.h"
00034 #include "OW_CMPIProviderIFC.hpp"
00035 #include "OW_SharedLibraryException.hpp"
00036 #include "OW_SharedLibraryLoader.hpp"
00037 #include "OW_Format.hpp"
00038 #include "OW_SignalScope.hpp"
00039 #include "OW_ConfigOpts.hpp"
00040 #include "OW_FileSystem.hpp"
00041 #include "OW_NoSuchProviderException.hpp"
00042 #include "OW_CMPIInstanceProviderProxy.hpp"
00043 #include "OW_CMPIMethodProviderProxy.hpp"
00044 #ifndef OW_DISABLE_ASSOCIATION_TRAVERSAL
00045 #include "OW_CMPIAssociatorProviderProxy.hpp"
00046 #endif
00047 #include "OW_CMPIIndicationProviderProxy.hpp"
00048 
00049 #include <algorithm>
00050 using std::fill_n;
00051 
00052 namespace OW_NAMESPACE
00053 {
00054 
00055 namespace
00056 {
00057    const String COMPONENT_NAME("ow.provider.cmpi.ifc");
00058 }
00059 
00060 //typedef CMPIProviderBaseIFC* (*ProviderCreationFunc)();
00061 // the closest approximation of CMPIProviderBaseIFCRef is ::FTABLE
00062 typedef CMPIFTABLERef* (*ProviderCreationFunc)();
00063 typedef const char* (*versionFunc_t)();
00064 const char* const CMPIProviderIFC::CREATIONFUNC = "createProvider";
00065 
00067 CMPIProviderIFC::CMPIProviderIFC()
00068    : ProviderIFCBaseIFC()
00069    , m_provs()
00070    , m_guard()
00071    , m_noidProviders()
00072    , m_loadDone(false)
00073 {
00074 }
00075 
00077 CMPIProviderIFC::~CMPIProviderIFC()
00078 {
00079    try
00080    {
00081       ProviderMap::iterator it = m_provs.begin();
00082       while (it != m_provs.end())
00083       {
00084          //CMPIInstanceMI * mi = it->second->instMI;
00085          MIs miVector = it->second->miVector;
00086 
00087          // If instance provider, allow instance prov cleanup to run
00088          if (miVector.instMI)
00089          {
00090             ::CMPIOperationContext context;
00091             CMPI_ContextOnStack eCtx(context);
00092             miVector.instMI->ft->cleanup(miVector.instMI, &eCtx, true);
00093          }
00094 
00095          // If associator provider, allow associator prov cleanup to run
00096          if (miVector.assocMI)
00097          {
00098             ::CMPIOperationContext context;
00099             CMPI_ContextOnStack eCtx(context);
00100             miVector.assocMI->ft->cleanup(miVector.assocMI, &eCtx, true);
00101          }
00102 
00103          // If method provider, allow method prov cleanup to run
00104          if (miVector.methMI)
00105          {
00106             ::CMPIOperationContext context;
00107             CMPI_ContextOnStack eCtx(context);
00108             miVector.methMI->ft->cleanup(miVector.methMI, &eCtx, true);
00109          }
00110 
00111          // If property provider, allow property prov cleanup to run
00112          if (miVector.propMI)
00113          {
00114             ::CMPIOperationContext context;
00115             CMPI_ContextOnStack eCtx(context);
00116             miVector.propMI->ft->cleanup(miVector.propMI, &eCtx, true); 
00117          }
00118 
00119          // If indication provider, allow indication prov cleanup to run
00120          if (miVector.indMI)
00121          {
00122             ::CMPIOperationContext context;
00123             CMPI_ContextOnStack eCtx(context);
00124             miVector.indMI->ft->cleanup(miVector.indMI, &eCtx, true); 
00125          }
00126 
00127          it->second.setNull();
00128          it++;
00129       }
00130    
00131       m_provs.clear();
00132    
00133 // BMMU: have to cleanup polled providers
00134       for (size_t i = 0; i < m_noidProviders.size(); i++)
00135       {
00136 #if 0
00137          CMPIInstanceMI * mi = m_noidProviders[i]->instMI;
00138          ::CMPIOperationContext context;
00139          CMPI_ContextOnStack eCtx(context);
00140          mi->ft->cleanup(mi, &eCtx);
00141          m_noidProviders[i].setNull();
00142 #endif
00143       }
00144    
00145       m_noidProviders.clear();
00146    }
00147    catch (...)
00148    {
00149       // don't let exceptions escape
00150    }
00151 }
00153 void
00154 CMPIProviderIFC::doInit(const ProviderEnvironmentIFCRef&,
00155    InstanceProviderInfoArray&,
00156    SecondaryInstanceProviderInfoArray&,
00157 
00158 #ifndef OW_DISABLE_ASSOCIATION_TRAVERSAL
00159    AssociatorProviderInfoArray&,
00160 #endif
00161 
00162    MethodProviderInfoArray&,
00163    IndicationProviderInfoArray&)
00164 {
00165    return;
00166 }
00168 InstanceProviderIFCRef
00169 CMPIProviderIFC::doGetInstanceProvider(const ProviderEnvironmentIFCRef& env,
00170    const char* provIdString)
00171 {
00172    CMPIFTABLERef pProv = getProvider(env, provIdString);
00173    if (pProv)
00174    {
00175       // if the createInstance pointer is set, then assume it's an instance
00176       // provider
00177       if (pProv->miVector.instMI)
00178       {
00179          OW_LOG_DEBUG(env->getLogger(COMPONENT_NAME), Format("CMPIProviderIFC found instance"
00180             " provider %1", provIdString));
00181          return InstanceProviderIFCRef(new CMPIInstanceProviderProxy(pProv));
00182       }
00183       OW_LOG_ERROR(env->getLogger(COMPONENT_NAME), Format("Provider %1 is not an instance provider",
00184          provIdString));
00185    }
00186    OW_THROW(NoSuchProviderException, provIdString);
00187 }
00188 
00190 IndicationExportProviderIFCRefArray
00191 CMPIProviderIFC::doGetIndicationExportProviders(const ProviderEnvironmentIFCRef& env)
00192 {
00193    //loadNoIdProviders(env);
00194    IndicationExportProviderIFCRefArray rvra;
00195    //for (size_t i = 0; i < m_noidProviders.size(); i++)
00196    //{
00197    // CppProviderBaseIFCRef pProv = m_noidProviders[i];
00198    // if (pProv->isIndicationExportProvider())
00199    // {
00200    //    rvra.append(
00201    //       IndicationExportProviderIFCRef(new
00202    //          CppIndicationExportProviderProxy(
00203    //             pProv.cast_to<CppIndicationExportProviderIFC>())));
00204    // }
00205    //}
00206    return rvra;
00207 }
00208 
00210 PolledProviderIFCRefArray
00211 CMPIProviderIFC::doGetPolledProviders(const ProviderEnvironmentIFCRef& env)
00212 {
00213    //loadNoIdProviders(env);
00214    PolledProviderIFCRefArray rvra;
00215 
00216 #if 0
00217    for (size_t i = 0; i < m_noidProviders.size(); i++)
00218    {
00219       CMPIFTABLERef pProv = m_noidProviders[i];
00220       //  if (pProv->isPolledProvider())
00221       if (pProv->miVector.indMI)
00222       {
00223          rvra.append(PolledProviderIFCRef(
00224             new CMPIPolledProviderProxy(pProv)));
00225       }
00226    }
00227 #endif
00228 
00229    return rvra;
00230 }
00232 MethodProviderIFCRef
00233 CMPIProviderIFC::doGetMethodProvider(const ProviderEnvironmentIFCRef& env,
00234    const char* provIdString)
00235 {
00236    CMPIFTABLERef pProv = getProvider(env, provIdString);
00237    if (pProv)
00238    {
00239       // it's a method provider if the invokeMethod function pointer is not
00240       // NULL
00241       if (pProv->miVector.methMI)
00242       {
00243          OW_LOG_DEBUG(env->getLogger(COMPONENT_NAME), Format("CMPIProviderIFC found method provider %1",
00244             provIdString));
00245          return MethodProviderIFCRef(new CMPIMethodProviderProxy(pProv));
00246       }
00247       OW_LOG_ERROR(env->getLogger(COMPONENT_NAME), Format("Provider %1 is not a method provider",
00248          provIdString));
00249    }
00250    OW_THROW(NoSuchProviderException, provIdString);
00251 }
00252 
00253 #ifndef OW_DISABLE_ASSOCIATION_TRAVERSAL
00254 
00255 AssociatorProviderIFCRef
00256 CMPIProviderIFC::doGetAssociatorProvider(const ProviderEnvironmentIFCRef& env,
00257    const char* provIdString)
00258 {
00259    CMPIFTABLERef pProv = getProvider(env, provIdString);
00260    if (pProv)
00261    {
00262       // if the associatorNames function pointer is not 0, we know it's an
00263       // associator provider
00264       if (pProv->miVector.assocMI)
00265       {
00266          OW_LOG_DEBUG(env->getLogger(COMPONENT_NAME), Format("CMPIProviderIFC found associator provider %1",
00267             provIdString));
00268          return AssociatorProviderIFCRef(new
00269             CMPIAssociatorProviderProxy(pProv));
00270       }
00271       OW_LOG_ERROR(env->getLogger(COMPONENT_NAME), Format("Provider %1 is not an associator provider",
00272          provIdString));
00273    }
00274    OW_THROW(NoSuchProviderException, provIdString);
00275 }
00276 #endif
00277 
00279 IndicationProviderIFCRef
00280 CMPIProviderIFC::doGetIndicationProvider(const ProviderEnvironmentIFCRef& env,
00281    const char* provIdString)
00282 {
00283 #if 0
00284    CMPIFTABLERef pProv = getProvider(env, provIdString);
00285    if (pProv)
00286    {
00287       // if the indicationNames function pointer is not 0, we know it's an
00288       // indication provider
00289       if (pProv->miVector.indMI)
00290       {
00291          OW_LOG_DEBUG(env->getLogger(COMPONENT_NAME), Format("CMPIProviderIFC found indication provider %1",
00292             provIdString));
00293          return IndicationProviderIFCRef(new
00294             CMPIIndicationProviderProxy(pProv));
00295       }
00296       OW_LOG_ERROR(env->getLogger(COMPONENT_NAME), Format("Provider %1 is not an indication provider",
00297          provIdString));
00298    }
00299 #endif
00300 
00301    OW_THROW(NoSuchProviderException, provIdString);
00302 }
00303 
00305 void
00306 CMPIProviderIFC::loadNoIdProviders(const ProviderEnvironmentIFCRef& env)
00307 {
00308    MutexLock ml(m_guard);
00309 
00310    if (m_loadDone)
00311    {
00312        return;
00313    }
00314 
00315    m_loadDone = true;
00316 
00317    SharedLibraryLoaderRef ldr =
00318        SharedLibraryLoader::createSharedLibraryLoader();
00319 
00320    if (!ldr)
00321    {
00322      OW_LOG_ERROR(env->getLogger(COMPONENT_NAME), "CMPI provider ifc failed to get shared lib loader");
00323      return;
00324    }
00325 
00326    const StringArray libPaths = env->getMultiConfigItem(
00327       ConfigOpts::CMPIPROVIFC_PROV_LOCATION_opt, 
00328       String(OW_DEFAULT_CMPIPROVIFC_PROV_LOCATION).tokenize(OW_PATHNAME_SEPARATOR),
00329       OW_PATHNAME_SEPARATOR);
00330 
00331    for (size_t libIdx = 0; libIdx < libPaths.size(); ++libIdx)
00332    {
00333       String libPath(libPaths[libIdx]);
00334       StringArray dirEntries;
00335       if (!FileSystem::getDirectoryContents(libPath, dirEntries))
00336       {
00337         OW_LOG_ERROR(env->getLogger(COMPONENT_NAME), Format("CMPI provider ifc failed getting contents of "
00338           "directory: %1", libPath));
00339         return;
00340       }
00341    
00342       for (size_t i = 0; i < dirEntries.size(); i++)
00343       {
00344          if (!dirEntries[i].endsWith(OW_SHAREDLIB_EXTENSION))
00345          {
00346              continue;
00347          }
00348 #ifdef OW_DARWIN
00349          if (dirEntries[i].indexOf(OW_VERSION) != String::npos)
00350          {
00351                continue;
00352          }
00353 #endif // OW_DARWIN
00354          String libName = libPath;
00355          libName += OW_FILENAME_SEPARATOR;
00356          libName += dirEntries[i];
00357          SharedLibraryRef theLib = ldr->loadSharedLibrary(libName,
00358             env->getLogger(COMPONENT_NAME));
00359          String guessProvId = dirEntries[i].substring(3,dirEntries[i].length()-6);
00360          
00361          if (!theLib)
00362          {
00363              OW_LOG_ERROR(env->getLogger(COMPONENT_NAME), Format("CMPI provider %1 ifc failed to load"
00364                      " library: %2", guessProvId, libName));
00365              continue;
00366          }
00367       }
00368    }
00369 }
00370 
00372 CMPIFTABLERef
00373 CMPIProviderIFC::getProvider(
00374    const ProviderEnvironmentIFCRef& env, const char* provIdString)
00375 {
00376    MutexLock ml(m_guard);
00377    String provId(provIdString);
00378    ProviderMap::iterator it = m_provs.find(provId);
00379 
00380    if (it != m_provs.end())
00381    {
00382       return it->second;
00383    }
00384 
00385    SharedLibraryLoaderRef ldr =
00386       SharedLibraryLoader::createSharedLibraryLoader();
00387 
00388    if (!ldr)
00389    {
00390       OW_LOG_ERROR(env->getLogger(COMPONENT_NAME), "CMPI: provider ifc failed to get shared lib loader");
00391       return CMPIFTABLERef();
00392    }
00393 
00394    const StringArray libPaths = env->getMultiConfigItem(
00395       ConfigOpts::CMPIPROVIFC_PROV_LOCATION_opt, 
00396       String(OW_DEFAULT_CMPIPROVIFC_PROV_LOCATION).tokenize(OW_PATHNAME_SEPARATOR),
00397       OW_PATHNAME_SEPARATOR);
00398 
00399    for (size_t libIdx = 0; libIdx < libPaths.size(); ++libIdx)
00400    {
00401       String libPath(libPaths[libIdx]);
00402       String libName(libPath);
00403       libName += OW_FILENAME_SEPARATOR;
00404       libName += "lib";
00405       libName += provId;
00406       libName += OW_SHAREDLIB_EXTENSION;
00407       OW_LOG_DEBUG(env->getLogger(COMPONENT_NAME), Format("CMPIProviderIFC::getProvider loading library: %1",
00408          libName));
00409    
00410       if (!FileSystem::exists(libName))
00411       {
00412          continue;
00413       }
00414 
00415       SharedLibraryRef theLib = ldr->loadSharedLibrary(libName, env->getLogger(COMPONENT_NAME));
00416    
00417       if (!theLib)
00418       {
00419          OW_LOG_ERROR(env->getLogger(COMPONENT_NAME), Format("CMPI provider ifc failed to load library: %1 "
00420             "for provider id %2", libName, provId));
00421          return CMPIFTABLERef();
00422       }
00423       
00424       fill_n((char*)&miVector, sizeof(MIs), 0);
00425       int specificMode = 0;
00426    
00428       // find InstanceProvider entry points
00429       if (theLib->getFunctionPointer(
00430          "_Generic_Create_InstanceMI", miVector.createGenInstMI))
00431       {
00432          miVector.miTypes |= CMPI_MIType_Instance;
00433             miVector.genericMode = 1;
00434       }
00435    
00436       String creationFuncName;
00437       if ( provId.startsWith("cmpi") )
00438       {
00439          creationFuncName = provId.substring(4) + "_Create_InstanceMI";
00440       } else {
00441          creationFuncName = provId + "_Create_InstanceMI";
00442       }
00443       
00444       OW_LOG_ERROR(env->getLogger(COMPONENT_NAME),
00445          Format("CMPI provider ifc: Library %1 should contain %2",
00446             provId, creationFuncName));
00447    
00448       if (theLib->getFunctionPointer(
00449          creationFuncName, miVector.createInstMI))
00450       {
00451          miVector.miTypes |= CMPI_MIType_Instance;
00452          specificMode = 1;
00453       }
00454    
00456       // find AssociationProvider entry points
00457       if (theLib->getFunctionPointer(
00458          "_Generic_Create_AssociationMI", miVector.createGenAssocMI))
00459       {
00460          miVector.miTypes |= CMPI_MIType_Association;
00461             miVector.genericMode = 1;
00462       }
00463    
00464       if ( provId.startsWith("cmpi") )
00465       {
00466          creationFuncName = provId.substring(4) + "_Create_AssociationMI";
00467       } else {
00468          creationFuncName = provId + "_Create_AssociationMI";
00469       }
00470    
00471       if (theLib->getFunctionPointer(
00472          creationFuncName, miVector.createAssocMI))
00473       {
00474          miVector.miTypes |= CMPI_MIType_Association;
00475          specificMode = 1;
00476       }
00477    
00479       // find MethodProvider entry points
00480       if (theLib->getFunctionPointer(
00481          "_Generic_Create_MethodMI", miVector.createGenMethMI))
00482       {
00483          miVector.miTypes |= CMPI_MIType_Method;
00484             miVector.genericMode = 1;
00485       }
00486    
00487       if ( provId.startsWith("cmpi") )
00488       {
00489          creationFuncName = provId.substring(4) + "_Create_MethodMI";
00490       } else {
00491          creationFuncName = provId + "_Create_MethodMI";
00492       }
00493    
00494       if (theLib->getFunctionPointer(
00495          creationFuncName, miVector.createMethMI))
00496       {
00497          miVector.miTypes |= CMPI_MIType_Method;
00498          specificMode = 1;
00499       }
00500    
00502       // find PropertyProvider entry points
00503       if (theLib->getFunctionPointer(
00504          "_Generic_Create_PropertyMI", miVector.createGenPropMI))
00505       {
00506          miVector.miTypes |= CMPI_MIType_Property;
00507             miVector.genericMode = 1;
00508       }
00509    
00510       if ( provId.startsWith("cmpi") )
00511       {
00512          creationFuncName = provId.substring(4) + "_Create_PropertyMI";
00513       } else {
00514          creationFuncName = provId + "_Create_PropertyMI";
00515       }
00516    
00517       if (theLib->getFunctionPointer(
00518          creationFuncName, miVector.createPropMI))
00519       {
00520          miVector.miTypes |= CMPI_MIType_Property;
00521          specificMode = 1;
00522       }
00523    
00525       // find IndicationProvider entry points
00526       if (theLib->getFunctionPointer(
00527          "_Generic_Create_IndicationMI", miVector.createGenIndMI))
00528       {
00529          miVector.miTypes |= CMPI_MIType_Indication;
00530             miVector.genericMode = 1;
00531       }
00532    
00533       if ( provId.startsWith("cmpi") )
00534       {
00535          creationFuncName = provId.substring(4) + "_Create_IndicationMI";
00536       } else {
00537          creationFuncName = provId + "_Create_IndicationMI";
00538       }
00539    
00540       if (theLib->getFunctionPointer(
00541          creationFuncName, miVector.createIndMI))
00542       {
00543          miVector.miTypes |= CMPI_MIType_Indication;
00544          specificMode = 1;
00545       }
00546                
00547       if (miVector.miTypes == 0)
00548       {
00549          OW_LOG_ERROR(env->getLogger(COMPONENT_NAME), Format("CMPI provider ifc: Library %1 does not contain"
00550          " any CMPI function", libName));
00551          return CMPIFTABLERef();
00552       }
00553    
00554       if (miVector.genericMode && specificMode)
00555       {
00556          OW_LOG_ERROR(env->getLogger(COMPONENT_NAME), Format("CMPI provider ifc: Library %1 mixes generic/specific"
00557          " CMPI style provider functions", libName));
00558          return CMPIFTABLERef();
00559       }
00560    
00562       // Now it's time to initialize the providers
00563    
00564       // This is a bad hack for the broken CMPI architecture.  Even though the
00565       // _broker.hdl pointer will outlive the lifetime of nonConstEnv (or env),
00566       // it won't (shouldn't) ever be used after initialization.
00567       ProviderEnvironmentIFCRef nonConstEnv(env);
00568       _broker.hdl = &nonConstEnv;
00569       _broker.bft = CMPI_Broker_Ftab;
00570       _broker.eft = CMPI_BrokerEnc_Ftab;
00571       ::CMPIOperationContext opc;
00572       CMPI_ContextOnStack eCtx(opc);
00573    
00574       if (miVector.genericMode)
00575       {
00576          const char *mName = provId.c_str();
00577          if (miVector.miTypes & CMPI_MIType_Instance)
00578          {
00579             miVector.instMI = miVector.createGenInstMI(&_broker,&eCtx,mName);
00580          }
00581    
00582 #ifndef OW_DISABLE_ASSOCIATION_TRAVERSAL
00583          if (miVector.miTypes & CMPI_MIType_Association)
00584          {
00585             miVector.assocMI =
00586                miVector.createGenAssocMI(&_broker, &eCtx, mName);
00587          }
00588 #endif
00589    
00590          if (miVector.miTypes & CMPI_MIType_Method)
00591          {
00592             miVector.methMI =
00593                miVector.createGenMethMI(&_broker, &eCtx, mName);
00594          }
00595    
00596          if (miVector.miTypes & CMPI_MIType_Property)
00597          {
00598             miVector.propMI =
00599                miVector.createGenPropMI(&_broker, &eCtx, mName);
00600          }
00601    
00602          if (miVector.miTypes & CMPI_MIType_Indication)
00603          {
00604             miVector.indMI =
00605                miVector.createGenIndMI(&_broker, &eCtx, mName);
00606          }
00607       }
00608       else
00609       {
00610          if (miVector.miTypes & CMPI_MIType_Instance)
00611          {
00612             miVector.instMI =
00613                miVector.createInstMI(&_broker,&eCtx);
00614          }
00615    
00616 #ifndef OW_DISABLE_ASSOCIATION_TRAVERSAL
00617          if (miVector.miTypes & CMPI_MIType_Association)
00618          {
00619             miVector.assocMI =
00620                miVector.createAssocMI(&_broker,&eCtx);
00621          }
00622 #endif
00623    
00624          if (miVector.miTypes & CMPI_MIType_Method)
00625          {
00626             miVector.methMI =
00627                miVector.createMethMI(&_broker,&eCtx);
00628          }
00629          if (miVector.miTypes & CMPI_MIType_Property)
00630          {
00631             miVector.propMI =
00632                miVector.createPropMI(&_broker,&eCtx);
00633          }
00634          if (miVector.miTypes & CMPI_MIType_Indication)
00635          {
00636             miVector.indMI =
00637                miVector.createIndMI(&_broker,&eCtx);
00638          }
00639       }
00640    
00641       OW_LOG_DEBUG(env->getLogger(COMPONENT_NAME), Format("CMPI provider ifc: provider %1 loaded and initialized",
00642          provId));
00643       CMPIFTABLERef completeMI(theLib, new CompleteMI);
00644       completeMI->miVector = miVector;
00645       completeMI->broker = _broker;
00646       //MIs * _miVector = new MIs(miVector);
00647       if (completeMI->miVector.instMI != miVector.instMI)
00648       {
00649          OW_LOG_DEBUG(env->getLogger(COMPONENT_NAME), "CMPI provider ifc: WARNING Vector mismatch");
00650       }
00651       m_provs[provId] = completeMI;
00652       return m_provs[provId];
00653    }
00654    return CMPIFTABLERef();
00655 }
00656 
00658 void 
00659 CMPIProviderIFC::doUnloadProviders(
00660    const ProviderEnvironmentIFCRef& env)
00661 {
00662    String timeWindow = env->getConfigItem(ConfigOpts::CMPIPROVIFC_PROV_TTL_opt, OW_DEFAULT_CMPIPROVIFC_PROV_TTL);
00663    Int32 iTimeWindow;
00664    try
00665    {
00666       iTimeWindow = timeWindow.toInt32();
00667    }
00668    catch(const StringConversionException&)
00669    {
00670       iTimeWindow = String(OW_DEFAULT_CPPPROVIFC_PROV_TTL).toInt32();
00671    }
00672 
00673    if (iTimeWindow < 0)
00674    {
00675       return;
00676    }
00677 
00678    DateTime dt;
00679    dt.setToCurrent();
00680    CMPIStatus rc = {CMPI_RC_OK, NULL}; 
00681    MutexLock ml(m_guard);
00682    ProviderMap::iterator it = m_provs.begin();
00683    while (it != m_provs.end())
00684    {
00685       DateTime provDt = it->second->lastAccessTime;
00686       provDt.addMinutes(iTimeWindow);
00687       if(provDt < dt)
00688       {
00689          bool unload = true; 
00690          //CMPIInstanceMI * mi = it->second->instMI;
00691          MIs miVector = it->second->miVector;
00692 
00693          // If instance provider, allow instance prov cleanup to run
00694          if (miVector.instMI)
00695          {
00696             ::CMPIOperationContext context;
00697             CMPI_ContextOnStack eCtx(context);
00698             rc=miVector.instMI->ft->cleanup(miVector.instMI, &eCtx, false);
00699             if (rc.rc == CMPI_RC_ERR_NOT_SUPPORTED
00700                || rc.rc == CMPI_RC_DO_NOT_UNLOAD
00701                || rc.rc == CMPI_RC_NEVER_UNLOAD)
00702             {
00703                unload = false; 
00704             }
00705          }
00706 
00707          // If associator provider, allow associator prov cleanup to run
00708          if (miVector.assocMI)
00709          {
00710             ::CMPIOperationContext context;
00711             CMPI_ContextOnStack eCtx(context);
00712             rc=miVector.assocMI->ft->cleanup(miVector.assocMI, &eCtx, false);
00713             if (rc.rc == CMPI_RC_ERR_NOT_SUPPORTED
00714                || rc.rc == CMPI_RC_DO_NOT_UNLOAD
00715                || rc.rc == CMPI_RC_NEVER_UNLOAD)
00716             {
00717                unload = false; 
00718             }
00719          }
00720 
00721          // If method provider, allow method prov cleanup to run
00722          if (miVector.methMI)
00723          {
00724             ::CMPIOperationContext context;
00725             CMPI_ContextOnStack eCtx(context);
00726             rc=miVector.methMI->ft->cleanup(miVector.methMI, &eCtx, false); 
00727             if (rc.rc == CMPI_RC_ERR_NOT_SUPPORTED
00728                || rc.rc == CMPI_RC_DO_NOT_UNLOAD
00729                || rc.rc == CMPI_RC_NEVER_UNLOAD)
00730             {
00731                unload = false; 
00732             }
00733          }
00734 
00735          // If property provider, allow property prov cleanup to run
00736          if (miVector.propMI)
00737          {
00738             ::CMPIOperationContext context;
00739             CMPI_ContextOnStack eCtx(context);
00740             rc=miVector.propMI->ft->cleanup(miVector.propMI, &eCtx, false); 
00741             if (rc.rc == CMPI_RC_ERR_NOT_SUPPORTED
00742                || rc.rc == CMPI_RC_DO_NOT_UNLOAD
00743                || rc.rc == CMPI_RC_NEVER_UNLOAD)
00744             {
00745                unload = false; 
00746             }
00747          }
00748 
00749          // If indication provider, allow indication prov cleanup to run
00750          if (miVector.indMI)
00751          {
00752             ::CMPIOperationContext context;
00753             CMPI_ContextOnStack eCtx(context);
00754             rc=miVector.indMI->ft->cleanup(miVector.indMI, &eCtx, false); 
00755             if (rc.rc == CMPI_RC_ERR_NOT_SUPPORTED
00756                || rc.rc == CMPI_RC_DO_NOT_UNLOAD
00757                || rc.rc == CMPI_RC_NEVER_UNLOAD)
00758             {
00759                unload = false; 
00760             }
00761          }
00762 
00763          if (unload)
00764          {
00765             it->second.setNull();
00766          }
00767          else
00768          {
00769             it->second->lastAccessTime.setToCurrent(); 
00770          }
00771       }
00772       it++;
00773    }
00774 }
00775 
00776 
00777 } // end namespace OW_NAMESPACE
00778 
00779 OW_PROVIDERIFCFACTORY(OpenWBEM::CMPIProviderIFC, cmpi)
00780 

Generated on Thu Feb 9 08:47:56 2006 for openwbem by  doxygen 1.4.6