(file) Return to ProviderModule.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / ProviderManager

File: [Pegasus] / pegasus / src / Pegasus / ProviderManager / Attic / ProviderModule.cpp (download)
Revision: 1.31, Sun Oct 17 19:39:58 2004 UTC (19 years, 8 months ago) by karl
Branch: MAIN
CVS Tags: RELEASE_2_4_3, RELEASE_2_4_2, RELEASE_2_4_1-BETA3, RELEASE_2_4_1-BETA2, RELEASE_2_4_1-BETA1, RELEASE_2_4_1, RELEASE_2_4_0-RC3, RELEASE_2_4_0-RC2, RELEASE_2_4_0, RELEASE_2_4-root, RELEASE_2_4-branch, IBM_241_April1405, CHUNKTESTDONE_PEP140
Changes since 1.30: +6 -4 lines
BUG#: 2196
TITLE: Copyright update

DESCRIPTION: Update all .cpp and .h files for new license and
update the doc/license.txt file.  Note that there were also
a couple of files that had to be fixed because they had violated
the comments rules (ex. blank line at head of file or in the case of
xmlwriter.cpp a comment line //=========  which drove the strip
function nuts.  These were fixed.  This has been compiled and tested
on windows.

//%2004////////////////////////////////////////////////////////////////////////
//
// 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.
//
// 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.
//
//==============================================================================
//
// Author: Chip Vincent (cvincent@us.ibm.com)
//
// Modified By:
//      Nag Boranna, Hewlett-Packard Company(nagaraja_boranna@hp.com)
//		Yi Zhou, Hewlett-Packard Company(yi_zhou@hp.com)
//     Mike Day, IBM (mdday@us.ibm.com)
//     Adrian Schuur, IBM (schuur@de.ibm.com)
//     Amit K Arora (amita@in.ibm.com) for PEP101
//
//%/////////////////////////////////////////////////////////////////////////////
#include "ProviderModule.h"

#include <Pegasus/Common/FileSystem.h>
#include <Pegasus/Provider/CIMInstanceProvider.h>
#include <Pegasus/Common/MessageLoader.h> //l10n

#ifdef PEGASUS_OS_OS400
#include "CreateProviderOS400SystemState.h"
#endif

PEGASUS_NAMESPACE_BEGIN

ProviderModule::ProviderModule(const String & fileName, const String & interfaceName)
   : _fileName(fileName),
     _ref_count(0),
     _library(0)
{
    setInterfaceName(interfaceName);
}

ProviderModule::ProviderModule(const ProviderModule & pm)
    : _fileName(pm._fileName),
      _library(pm._library),
      _interfaceName(pm._interfaceName),
      _interfaceFileName(pm._interfaceFileName),
      _provider(pm._provider),
      _refCount(pm._refCount)
{
}




ProviderModule::~ProviderModule(void)
{ 
    _provider.release();
    _adapter.release();


}

void ProviderModule::setInterfaceName(const String & interfaceName)
{
    _interfaceName = interfaceName;
    _interfaceFileName=String::EMPTY;

    if (_interfaceName.size()>0)
    {
#ifdef PEGASUS_OS_TYPE_WINDOWS
        _interfaceFileName=_interfaceName+String("Adapter.dll");
#elif defined(PEGASUS_OS_HPUX)
        // ATTN: Fix this for IA64.
        _interfaceFileName=
		 String("lib")+interfaceName+String("Adapter.sl");
#elif defined(PEGASUS_OS_OS400)
        _interfaceFileName=interfaceName+String("Adapter");
#elif defined(PEGASUS_OS_DARWIN)
        _interfaceFileName=
            String("lib")+interfaceName+String("Adapter.dylib");
#else
        _interfaceFileName=
            String("lib")+interfaceName+String("Adapter.so");
#endif
                                                                                
    	_interfaceFileName = FileSystem::getAbsoluteFileName(
		ConfigManager::getHomedPath(ConfigManager::getInstance()->getCurrentValue("providerDir")), _interfaceFileName);

     }
}

CIMProvider *ProviderModule::load(const String & providerName)
{


    // get the interface adapter library first
    CIMProvider *provider = 0;

    if (_interfaceFileName.size()>0) {
      _adapter.reset(ProviderAdapterManager::get_pamgr()->addAdapter(
	      _interfaceName,_interfaceFileName,_fileName,providerName));
      provider=dynamic_cast<CIMProvider*>(_adapter.get());
      if (provider==NULL) {
      	//l10n
	//throw Exception("ProviderLoadFailure ("+providerName+
			//"Provider is not a BaseProvider");
	throw Exception(MessageLoaderParms("ProviderManager.ProviderModule.IS_NOT_A",
					   "ProviderLoadFailure ($0" \
					   "Provider is not a BaseProvider",
					   providerName));
        }
      _ref_count++;
      return provider;
    }

    // dynamically load the provider library

    if(_library == 0)
    {
       _library = System::loadDynamicLibrary((const char *)_fileName.getCString());
    }
    
    if(_library == 0)
    {

        // ATTN: does unload() need to be called?
		//l10n
        //String errorString = "Cannot load library, error: " + System::dynamicLoadError();
        //throw Exception("ProviderLoadFailure (" + _fileName + ":" + providerName + "):" + errorString);
        throw Exception(MessageLoaderParms("ProviderManager.ProviderModule.CANNOT_LOAD_LIBRARY",
        								   "ProviderLoadFailure ($0:$1):Cannot load library, error: $2",
        								   _fileName,
        								   providerName,
        								   System::dynamicLoadError()));
    }

    // find libray entry point
    CIMProvider * (*createProvider)(const String &) = 0;

    createProvider = (CIMProvider * (*)(const String &))System::loadDynamicSymbol(
        _library, "PegasusCreateProvider");

    if(createProvider == 0)
    {
    	//l10n
        //String errorString = "entry point not found.";
        //throw Exception("ProviderLoadFailure (" + _fileName + ":" + providerName + "):" + errorString);

        throw Exception(MessageLoaderParms("ProviderManager.ProviderModule.ENTRY_POINT_NOT_FOUND",
					   "ProviderLoadFailure ($0:$1):entry point not found.",
					   _fileName,
					   providerName));
    }

    // invoke the provider entry point
#ifndef PEGASUS_OS_OS400
    provider = createProvider(providerName);
#else
    // On OS/400, need to call a layer of code that does platform-specific
    // checks before calling the provider
    provider = OS400_CreateProvider(providerName.getCString(), createProvider, _fileName);
#endif
    

    // test for the appropriate interface
    if(dynamic_cast<CIMProvider *>(provider) == 0)
    {
    	//l10n
           //String errorString = "provider is not a CIMProvider.";
        //throw Exception("ProviderLoadFailure (" + _fileName + ":" + providerName + "):" + errorString);
        throw Exception(MessageLoaderParms("ProviderManager.ProviderModule.PROVIDER_IS_NOT_A",
        								   "ProviderLoadFailure ($0:$1):provider is not a CIMProvider.",
        								   _fileName,
        								   providerName));
    }
    _ref_count++;
    return provider;
}

void ProviderModule::unloadModule(void)
{
  _ref_count--;
   if( _ref_count.value() > 0)
      return;
   _ref_count = 0;
   if(_library != 0)
     {
       System::unloadDynamicLibrary(_library);
       _library = 0;
     }
}

Boolean ProviderModule::operator == (const void *key) const 
{
   String *prov = reinterpret_cast<String *>(const_cast<void *>(key));
   if(String::equalNoCase(_fileName, *prov))
      return true;
   return false;
}

Boolean ProviderModule::operator == (const ProviderModule &pm) const
{
   if(String::equalNoCase(_fileName, pm._fileName))
      return true;
   return false;
}

PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2