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

Diff for /pegasus/src/Pegasus/Repository/CIMRepository.cpp between version 1.50 and 1.51

version 1.50, 2001/07/17 00:49:05 version 1.51, 2001/12/13 14:54:26
Line 22 
Line 22 
 // //
 // Author: Mike Brasher (mbrasher@bmc.com) // Author: Mike Brasher (mbrasher@bmc.com)
 // //
 // Modified By:  // Modified By: Jenny Yu, Hewlett-Packard Company (jenny_yu@hp.com)
   //              Yi Zhou, Hewlett-Packard Company (yi_zhou@hp.com)
   //              Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
 // //
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
   #include <Pegasus/Common/Config.h>
 #include <cctype> #include <cctype>
 #include <cstdio> #include <cstdio>
 #include <fstream> #include <fstream>
Line 41 
Line 44 
 #include "CIMRepository.h" #include "CIMRepository.h"
 #include "RepositoryDeclContext.h" #include "RepositoryDeclContext.h"
 #include "InstanceIndexFile.h" #include "InstanceIndexFile.h"
   #include "InstanceFile.h"
 #include "AssocInstTable.h" #include "AssocInstTable.h"
 #include "AssocClassTable.h" #include "AssocClassTable.h"
  
Line 54 
Line 58 
 // //
 // _LoadObject() // _LoadObject()
 // //
 //      Loads objects (classes, instances, and qualifiers) from disk to  //      Loads objects (classes and qualifiers) from disk to
 //      memory objects. //      memory objects.
 // //
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Line 86 
Line 90 
 // //
 // _SaveObject() // _SaveObject()
 // //
 //      Saves objects (classes, instances, and qualifiers) from memory to  //      Saves objects (classes and qualifiers) from memory to
 //      disk files. //      disk files.
 // //
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Line 135 
Line 139 
 // //
 //     The following are not implemented: //     The following are not implemented:
 // //
 //         CIMRepository::setProperty()  
 //         CIMRepository::getProperty()  
 //         CIMRepository::modifyInstance()  
 //         CIMRepository::execQuery() //         CIMRepository::execQuery()
 //         CIMRepository::execQuery()  
 //         CIMRepository::associators()  
 //         CIMRepository::associatorNames()  
 //         CIMRepository::referencess()  
 //         CIMRepository::referencesNames() //         CIMRepository::referencesNames()
 //         CIMRepository::invokeMethod() //         CIMRepository::invokeMethod()
 // //
 //     Note that invokeMethod() will not never implemented since it is not //     Note that invokeMethod() will not never implemented since it is not
 //     meaningful for a repository. //     meaningful for a repository.
 // //
 //     ATTN: need to combine instances of each class into a common file to  
 //     improve disk utilization (too many i-nodes in Unix).  
 //  
 //     ATTN: make operations on files non-case-sensitive. //     ATTN: make operations on files non-case-sensitive.
 // //
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
  
 CIMRepository::CIMRepository(const String& repositoryRoot) CIMRepository::CIMRepository(const String& repositoryRoot)
     : _repositoryRoot(repositoryRoot), _nameSpaceManager(repositoryRoot)     : _repositoryRoot(repositoryRoot), _nameSpaceManager(repositoryRoot),
        _lock()
 { {
     _context = new RepositoryDeclContext(this);     _context = new RepositoryDeclContext(this);
       _isDefaultInstanceProvider = (ConfigManager::getInstance()->getCurrentValue(
           "repositoryIsDefaultInstanceProvider") == "true");
       _providerName = ConfigManager::getInstance()->getCurrentValue(
           "repositoryProviderName");
 } }
  
 CIMRepository::~CIMRepository() CIMRepository::~CIMRepository()
Line 167 
Line 166 
     delete _context;     delete _context;
 } }
  
   
   void CIMRepository::read_lock(void) throw(IPCException)
   {
      _lock.wait_read(pegasus_thread_self());
   }
   
   void CIMRepository::read_unlock(void)
   {
      _lock.unlock_read(pegasus_thread_self());
   }
   
   void CIMRepository::write_lock(void) throw(IPCException)
   {
      _lock.wait_write(pegasus_thread_self());
   }
   
   void CIMRepository::write_unlock(void)
   {
      _lock.unlock_write(pegasus_thread_self());
   }
   
 CIMClass CIMRepository::getClass( CIMClass CIMRepository::getClass(
     const String& nameSpace,     const String& nameSpace,
     const String& className,     const String& className,
     Boolean localOnly,     Boolean localOnly,
     Boolean includeQualifiers,     Boolean includeQualifiers,
     Boolean includeClassOrigin,     Boolean includeClassOrigin,
     const Array<String>& propertyList)      const CIMPropertyList& propertyList)
 { {
     // ATTN: localOnly, includeQualifiers, and includeClassOrigin are ignored     // ATTN: localOnly, includeQualifiers, and includeClassOrigin are ignored
     // for now.     // for now.
  
   
   
     String classFilePath;     String classFilePath;
     classFilePath = _nameSpaceManager.getClassFilePath(nameSpace, className);     classFilePath = _nameSpaceManager.getClassFilePath(nameSpace, className);
  
     CIMClass cimClass;     CIMClass cimClass;
   
       try
       {
     _LoadObject(classFilePath, cimClass);     _LoadObject(classFilePath, cimClass);
       }
       catch (Exception & e)
       {
           throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, className);
       }
  
     return cimClass;     return cimClass;
 } }
  
   //----------------------------------------------------------------------
   //
   // _getInstanceIndex()
   //
   //      Returns the index (or byte location) and size of the instance
   //      record in the instance file for a given instance.  Returns false
   //      if the instance cannot be found.
   //
   //----------------------------------------------------------------------
   
 Boolean CIMRepository::_getInstanceIndex( Boolean CIMRepository::_getInstanceIndex(
     const String& nameSpace,     const String& nameSpace,
     const CIMReference& instanceName,     const CIMReference& instanceName,
     String& className,     String& className,
       Uint32& size,
     Uint32& index,     Uint32& index,
     Boolean searchSuperClasses) const     Boolean searchSuperClasses) const
 { {
     // -- Get all descendent classes of this class:     // -- Get all descendent classes of this class:
  
   
     className = instanceName.getClassName();     className = instanceName.getClassName();
  
     Array<String> classNames;     Array<String> classNames;
Line 207 
Line 249 
     if (searchSuperClasses)     if (searchSuperClasses)
         _nameSpaceManager.getSuperClassNames(nameSpace, className, classNames);         _nameSpaceManager.getSuperClassNames(nameSpace, className, classNames);
  
     // -- Search each qualifying instance file for the instance:      // -- Get instance names from each qualifying instance file for the class
  
     for (Uint32 i = 0; i < classNames.size(); i++)     for (Uint32 i = 0; i < classNames.size(); i++)
     {     {
Line 218 
Line 260 
  
         String path = _getIndexFilePath(nameSpace, classNames[i]);         String path = _getIndexFilePath(nameSpace, classNames[i]);
  
         if (InstanceIndexFile::lookup(path, tmpInstanceName, index))          if (InstanceIndexFile::lookup(path, tmpInstanceName, size, index))
         {         {
             className = classNames[i];             className = classNames[i];
             return true;             return true;
Line 234 
Line 276 
     Boolean localOnly,     Boolean localOnly,
     Boolean includeQualifiers,     Boolean includeQualifiers,
     Boolean includeClassOrigin,     Boolean includeClassOrigin,
     const Array<String>& propertyList)      const CIMPropertyList& propertyList)
 { {
     // -- Get the index for this instance:     // -- Get the index for this instance:
  
     String className;     String className;
     Uint32 index;     Uint32 index;
       Uint32 size;
  
     if (!_getInstanceIndex(nameSpace, instanceName, className, index))  
       if (!_getInstanceIndex(nameSpace, instanceName, className, size, index))
     {     {
         throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, "getInstance()");          throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, instanceName.toString());
     }     }
  
     // -- Load the instance from the file:      // -- Load the instance from file:
  
     String path = _getInstanceFilePath(nameSpace, className, index);      String path = _getInstanceFilePath(nameSpace, className);
     CIMInstance cimInstance;     CIMInstance cimInstance;
     _LoadObject(path, cimInstance);      if (!_loadInstance(path, cimInstance, index, size))
       {
           throw CannotOpenFile(path);
       }
   
     return cimInstance;     return cimInstance;
 } }
  
Line 260 
Line 308 
 { {
     // -- Get the class and check to see if it is an association class:     // -- Get the class and check to see if it is an association class:
  
   
     CIMClass cimClass = getClass(nameSpace, className, false);     CIMClass cimClass = getClass(nameSpace, className, false);
     Boolean isAssociation = cimClass.isAssociation();     Boolean isAssociation = cimClass.isAssociation();
  
Line 290 
Line 339 
     const String& nameSpace,     const String& nameSpace,
     const CIMReference& instanceName)     const CIMReference& instanceName)
 { {
     // -- Lookup index of entry from index file:  
       String errMessage;
   
       // -- Lookup instance from the index file:
  
     String indexFilePath = _getIndexFilePath(     String indexFilePath = _getIndexFilePath(
         nameSpace, instanceName.getClassName());         nameSpace, instanceName.getClassName());
  
     Uint32 index;     Uint32 index;
       Uint32 size;
  
     if (!InstanceIndexFile::lookup(indexFilePath, instanceName, index))      if (!InstanceIndexFile::lookup(indexFilePath, instanceName, size, index))
         throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, instanceName.toString());         throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, instanceName.toString());
  
     // -- Attempt to remove the instance file:      // -- Remove entry from index file:
   
     String instanceFilePath = _getInstanceFilePath(  
         nameSpace, instanceName.getClassName(), index);  
  
     if (!FileSystem::removeFileNoCase(instanceFilePath))      if (!InstanceIndexFile::remove(indexFilePath, instanceName))
     {     {
         throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,          errMessage.append("Failed to delete instance ");
             "failed to remove file in CIMRepository::deleteInstance()");          errMessage.append(instanceName.toString());
           throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, errMessage);
     }     }
  
     // -- Remove entry from index file:      // -- Remove the instance from the instance file:
  
     InstanceIndexFile::remove(indexFilePath, instanceName);      String instanceFilePath = _getInstanceFilePath(
           nameSpace, instanceName.getClassName());
     // -- Delete index file if it is now empty (zero size):  
   
     Uint32 size;  
  
     if (!FileSystem::getFileSizeNoCase(indexFilePath, size))      if (!InstanceFile::removeInstance(instanceFilePath, size, index))
     {     {
         throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,          errMessage.append("Failed to delete instance ");
             "unexpected failure in CIMRepository::deleteInstance()");          errMessage.append(instanceName.toString());
           throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, errMessage);
     }     }
  
     if (size == 0 && !FileSystem::removeFileNoCase(indexFilePath))      // -- Rename the temporary index and instance files back to the original:
   
       if (!_renameTempInstanceAndIndexFiles(indexFilePath, instanceFilePath))
     {     {
         throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,          errMessage.append("Unexpected error occurred while deleting instance ");
             "unexpected failure in CIMRepository::deleteInstance()");          errMessage.append(instanceName.toString());
           throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, errMessage);
     }     }
  
     // -- Remove it from the association table (if it is really association).     // -- Remove it from the association table (if it is really association).
Line 347 
Line 399 
 { {
     // Open input file:     // Open input file:
  
   
     String assocFileName = _MakeAssocClassPath(nameSpace, _repositoryRoot);     String assocFileName = _MakeAssocClassPath(nameSpace, _repositoryRoot);
     ofstream os;     ofstream os;
  
Line 396 
Line 449 
     const String& nameSpace,     const String& nameSpace,
     const CIMClass& newClass)     const CIMClass& newClass)
 { {
   
   
     // -- Resolve the class:     // -- Resolve the class:
         CIMClass cimClass(newClass);         CIMClass cimClass(newClass);
  
Line 457 
Line 512 
 { {
     // Open input file:     // Open input file:
  
   
     String assocFileName = _MakeAssocInstPath(nameSpace, _repositoryRoot);     String assocFileName = _MakeAssocInstPath(nameSpace, _repositoryRoot);
     ofstream os;     ofstream os;
  
Line 518 
Line 574 
     }     }
 } }
  
 void CIMRepository::createInstance(  CIMReference CIMRepository::createInstance(
     const String& nameSpace,     const String& nameSpace,
     const CIMInstance& newInstance)     const CIMInstance& newInstance)
 { {
   
       String errMessage;
   
     // -- Resolve the instance (looks up class):     // -- Resolve the instance (looks up class):
         CIMInstance cimInstance(newInstance);         CIMInstance cimInstance(newInstance);
  
Line 534 
Line 593 
  
     if (!cimClass.hasKeys())     if (!cimClass.hasKeys())
     {     {
         String message = "class has no keys: ";          errMessage = "class has no keys: ";
         message += cimClass.getClassName();          errMessage += cimClass.getClassName();
         throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, message);          throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, errMessage);
     }     }
  
     // -- Be sure instance does not already exist:     // -- Be sure instance does not already exist:
  
     String className;     String className;
     Uint32 dummyIndex;     Uint32 dummyIndex;
       Uint32 dummySize;
  
     if (_getInstanceIndex(nameSpace, instanceName, className, dummyIndex, true))      if (_getInstanceIndex(nameSpace, instanceName, className, dummySize,
           dummyIndex, true))
     {     {
         throw PEGASUS_CIM_EXCEPTION(CIM_ERR_ALREADY_EXISTS, instanceName.toString());          throw PEGASUS_CIM_EXCEPTION(CIM_ERR_ALREADY_EXISTS,
               instanceName.toString());
     }     }
  
     // -- Handle if association:     // -- Handle if association:
Line 557 
Line 619 
             cimClass, cimInstance, instanceName);             cimClass, cimInstance, instanceName);
     }     }
  
     // -- Get common base (of instance file and index file):      // -- Get instance file path:
  
     String instanceFileBase = _nameSpaceManager.getInstanceFileBase(      String instanceFilePath = _getInstanceFilePath(nameSpace,
         nameSpace, cimInstance.getClassName());          cimInstance.getClassName());
   
       // -- Save instance to file:
   
       Uint32 index;
       Uint32 size;
       if (!_saveInstance(instanceFilePath, cimInstance, index, size))
       {
           errMessage.append("Failed to create instance ");
           errMessage.append(instanceName.toString());
           throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, errMessage);
       }
  
     // -- Make index file entry:     // -- Make index file entry:
  
     String indexFilePath = _getIndexFilePath(     String indexFilePath = _getIndexFilePath(
         nameSpace, cimInstance.getClassName());         nameSpace, cimInstance.getClassName());
     Uint32 index;  
   
     if (!InstanceIndexFile::insert(indexFilePath, instanceName, index))  
         throw PEGASUS_CIM_EXCEPTION(CIM_ERR_ALREADY_EXISTS, instanceName.toString());  
  
     // -- Save instance to file:      if (!InstanceIndexFile::insert(indexFilePath, instanceName, size, index))
       {
           errMessage.append("Failed to create instance ");
           errMessage.append(instanceName.toString());
           throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, errMessage);
       }
  
     String instanceFilePath = _getInstanceFilePath(nameSpace,      // -- Rename the temporary index and instance files back to the original
         cimInstance.getClassName(), index);  
  
     _SaveObject(instanceFilePath, cimInstance);      if (!_renameTempInstanceAndIndexFiles(indexFilePath, instanceFilePath))
       {
           errMessage.append("Unexpected error occurred while creating instance ");
           errMessage.append(instanceName.toString());
           throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, errMessage);
       }
       return (instanceName);
 } }
  
 void CIMRepository::modifyClass( void CIMRepository::modifyClass(
     const String& nameSpace,     const String& nameSpace,
     const CIMClass& modifiedClass)     const CIMClass& modifiedClass)
 { {
   
   
     // -- Resolve the class:     // -- Resolve the class:
         CIMClass cimClass(modifiedClass);         CIMClass cimClass(modifiedClass);
  
Line 610 
Line 691 
  
 void CIMRepository::modifyInstance( void CIMRepository::modifyInstance(
     const String& nameSpace,     const String& nameSpace,
     const CIMInstance& modifiedInstance)      const CIMNamedInstance& modifiedInstance,
       Boolean includeQualifiers,
       const CIMPropertyList& propertyList)
   {
   
   
       String errMessage;
       CIMInstance cimInstance;    // The instance that replaces the original
   
       if (propertyList.isNull())
       {
           //
           // Replace all the properties in the instance
           //
           if (includeQualifiers)
           {
               //
               // Replace the entire instance with the given instance
               // (this is the default behavior)
               //
               cimInstance = modifiedInstance.getInstance();
           }
           else
           {
               //
               // Replace all the properties in the instance, but keep the
               // original qualifiers on the instance and on the properties
               //
   
               cimInstance = getInstance(nameSpace,
                   modifiedInstance.getInstanceName(), false, true);
               CIMInstance newInstance(
                   modifiedInstance.getInstanceName().getClassName());
               CIMInstance givenInstance = modifiedInstance.getInstance();
   
               //
               // Copy over the original instance qualifiers
               //
               for (Uint32 i=0; i<cimInstance.getQualifierCount(); i++)
               {
                   newInstance.addQualifier(cimInstance.getQualifier(i));
               }
   
               //
               // Loop through the properties replacing each property in the
               // original with a new value, but keeping the original qualifiers
               //
               for (Uint32 i=0; i<givenInstance.getPropertyCount(); i++)
               {
                   // Copy the given property value (not qualifiers)
                   CIMProperty givenProperty = givenInstance.getProperty(i);
                   CIMProperty newProperty(
                       givenProperty.getName(),
                       givenProperty.getValue(),
                       givenProperty.getArraySize(),
                       givenProperty.getReferenceClassName(),
                       givenProperty.getClassOrigin(),
                       givenProperty.getPropagated());
   
                   // Copy the original property qualifiers
                   Uint32 origPos =
                       cimInstance.findProperty(newProperty.getName());
                   if (origPos != PEG_NOT_FOUND)
                   {
                       CIMProperty origProperty = cimInstance.getProperty(origPos);
                       for (Uint32 j=0; j<origProperty.getQualifierCount(); j++)
                       {
                           newProperty.addQualifier(origProperty.getQualifier(i));
                       }
                   }
   
                   // Add the newly constructed property to the new instance
                   newInstance.addProperty(newProperty);
               }
   
               // Use the newly merged instance to replace the original instance
               cimInstance = newInstance;
           }
       }
       else
       {
           //
           // Replace only the properties specified in the given instance
           //
   
           cimInstance = getInstance(nameSpace,
               modifiedInstance.getInstanceName(), false, true);
           CIMInstance givenInstance = modifiedInstance.getInstance();
   
           // NOTE: Instance qualifiers are not changed when a property list
           // is specified.  Property qualifiers are replaced with the
           // corresponding property values.
   
           //
           // Loop through the propertyList replacing each property in the original
           //
           for (Uint32 i=0; i<propertyList.getNumProperties(); i++)
           {
               Uint32 origPropPos =
                   cimInstance.findProperty(propertyList.getPropertyName(i));
               if (origPropPos != PEG_NOT_FOUND)
               {
                   // Case: Property set in original
                   CIMProperty origProperty =
                       cimInstance.getProperty(origPropPos);
   
                   // Get the given property value
                   Uint32 givenPropPos =
                       givenInstance.findProperty(propertyList.getPropertyName(i));
                   if (givenPropPos != PEG_NOT_FOUND)
                   {
                       // Case: Property set in original and given
                       CIMProperty givenProperty =
                           givenInstance.getProperty(givenPropPos);
   
                       // Copy over the property from the given to the original
                       if (includeQualifiers)
                       {
                           // Case: Total property replacement
                           cimInstance.removeProperty(origPropPos);
                           cimInstance.addProperty(givenProperty);
                       }
                       else
                       {
                           // Case: Replace only the property value (not quals)
                           origProperty.setValue(givenProperty.getValue());
                           cimInstance.removeProperty(origPropPos);
                           cimInstance.addProperty(origProperty);
                       }
                   }
                   else
                   {
                       // Case: Property set in original and not in given
                       // Just remove the property (set to null)
                       cimInstance.removeProperty(origPropPos);
                   }
               }
               else
               {
                   // Case: Property not set in original
   
                   // Get the given property value
                   Uint32 givenPropPos =
                       givenInstance.findProperty(propertyList.getPropertyName(i));
                   if (givenPropPos != PEG_NOT_FOUND)
                   {
                       // Case: Property set in given and not in original
                       CIMProperty givenProperty =
                           givenInstance.getProperty(givenPropPos);
   
                       // Copy over the property from the given to the original
                       if (includeQualifiers)
                       {
                           // Case: Total property copy
                           cimInstance.addProperty(givenProperty);
                       }
                       else
                       {
                           // Case: Copy only the property value (not qualifiers)
                           CIMProperty newProperty(
                               givenProperty.getName(),
                               givenProperty.getValue(),
                               givenProperty.getArraySize(),
                               givenProperty.getReferenceClassName(),
                               givenProperty.getClassOrigin(),
                               givenProperty.getPropagated());
                           cimInstance.addProperty(newProperty);
                       }
                   }
                   else
 { {
                       // Case: Property not set in original or in given
   
                       // Nothing to do; just make sure the property name is valid
                       // ATTN: This is not the most efficient solution
                       CIMClass cimClass = getClass(
                           nameSpace, cimInstance.getClassName(), false);
                       if (!cimClass.existsProperty(
                           propertyList.getPropertyName(i)))
                       {
                           // ATTN: This exception may be returned by setProperty
                           throw PEGASUS_CIM_EXCEPTION(
                               CIM_ERR_NO_SUCH_PROPERTY, "modifyInstance()");
                       }
                   }
               }
           }
       }
   
     // -- Resolve the instance (looks up the class):     // -- Resolve the instance (looks up the class):
         CIMInstance cimInstance(modifiedInstance);  
  
     CIMConstClass cimClass;     CIMConstClass cimClass;
     cimInstance.resolve(_context, nameSpace, cimClass);     cimInstance.resolve(_context, nameSpace, cimClass);
  
     // -- Lookup index of entry from index file:  
   
     CIMReference instanceName = cimInstance.getInstanceName(cimClass);     CIMReference instanceName = cimInstance.getInstanceName(cimClass);
  
       // -- Disallow if instance name is changed by this operation (attempt
       // -- to modify a key property.
   
       if (instanceName != modifiedInstance.getInstanceName())
       {
           throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
               "Attempted to modify a key property");
       }
   
       // -- Lookup index of entry from index file:
   
     String indexFilePath = _getIndexFilePath(     String indexFilePath = _getIndexFilePath(
         nameSpace, instanceName.getClassName());         nameSpace, instanceName.getClassName());
  
     Uint32 index;      Uint32 oldSize;
       Uint32 oldIndex;
       Uint32 newSize;
       Uint32 newIndex;
  
     if (!InstanceIndexFile::lookup(indexFilePath, instanceName, index))      if (!InstanceIndexFile::lookup(indexFilePath, instanceName, oldSize,
           oldIndex))
       {
         throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, instanceName.toString());         throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, instanceName.toString());
       }
  
     // -- Attempt to remove the instance file:      // -- modify the instance file
  
     String instanceFilePath = _getInstanceFilePath(     String instanceFilePath = _getInstanceFilePath(
         nameSpace, instanceName.getClassName(), index);          nameSpace, instanceName.getClassName());
  
     if (!FileSystem::removeFileNoCase(instanceFilePath))      if (!_modifyInstance(instanceFilePath, cimInstance, oldIndex,  oldSize,
           newIndex, newSize))
     {     {
         throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,          errMessage.append("Failed to modify instance ");
             "failed to remove file in CIMRepository::deleteInstance()");          errMessage.append(instanceName.toString());
           throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, errMessage);
     }     }
  
     // -- Save instance to file:      // -- modify the instance index file
  
     _SaveObject(instanceFilePath, cimInstance);      if (!InstanceIndexFile::modify(indexFilePath, instanceName,  newSize,
           newIndex))
       {
           errMessage.append("Failed to modify instance ");
           errMessage.append(instanceName.toString());
           throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, errMessage);
       }
   
       // -- Rename the temporary index and instance files back to the original
   
       if (!_renameTempInstanceAndIndexFiles(indexFilePath, instanceFilePath))
       {
           errMessage.append("Unexpected error occurred while modifying instance ");
           errMessage.append(instanceName.toString());
           throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, errMessage);
       }
 } }
  
 Array<CIMClass> CIMRepository::enumerateClasses( Array<CIMClass> CIMRepository::enumerateClasses(
Line 654 
Line 953 
     Boolean includeQualifiers,     Boolean includeQualifiers,
     Boolean includeClassOrigin)     Boolean includeClassOrigin)
 { {
   
   
     Array<String> classNames;     Array<String> classNames;
  
     _nameSpaceManager.getSubClassNames(     _nameSpaceManager.getSubClassNames(
Line 675 
Line 976 
     const String& className,     const String& className,
     Boolean deepInheritance)     Boolean deepInheritance)
 { {
   
   
   
     Array<String> classNames;     Array<String> classNames;
  
     _nameSpaceManager.getSubClassNames(     _nameSpaceManager.getSubClassNames(
Line 683 
Line 987 
     return classNames;     return classNames;
 } }
  
 Array<CIMInstance> CIMRepository::enumerateInstances(  Array<CIMNamedInstance> CIMRepository::enumerateInstances(
     const String& nameSpace,     const String& nameSpace,
     const String& className,     const String& className,
     Boolean deepInheritance,     Boolean deepInheritance,
     Boolean localOnly,     Boolean localOnly,
     Boolean includeQualifiers,     Boolean includeQualifiers,
     Boolean includeClassOrigin,     Boolean includeClassOrigin,
     const Array<String>& propertyList)      const CIMPropertyList& propertyList)
 { {
   
   
   
     // -- Get all descendent classes of this class:     // -- Get all descendent classes of this class:
  
     Array<String> classNames;     Array<String> classNames;
     _nameSpaceManager.getSubClassNames(      _nameSpaceManager.getSubClassNames(nameSpace, className, true, classNames);
         nameSpace, className, true, classNames);  
     classNames.prepend(className);     classNames.prepend(className);
  
     // -- Search each qualifying instance file for the instance:      // -- Get all instances for this class and all its descendent classes
  
     Array<CIMReference> instanceNames;      Array<CIMNamedInstance> namedInstances;
     Array<Uint32> indices;  
     Array<CIMInstance> instances;  
     Uint32 start = 0;  
  
     for (Uint32 i = 0; i < classNames.size(); i++)     for (Uint32 i = 0; i < classNames.size(); i++)
     {     {
         // -- Form the name of the class index file:          if (!_loadAllInstances(nameSpace, classNames[i], namedInstances))
   
         String path = _getIndexFilePath(nameSpace, classNames[i]);  
   
         // Get all instance names for that class:  
   
         InstanceIndexFile::appendInstanceNamesTo(path, instanceNames, indices);  
         PEGASUS_ASSERT(instanceNames.size() == indices.size());  
   
         // -- Load up all the instances of this class:  
   
         for (Uint32 j = start; j < instanceNames.size(); j++)  
         {         {
             String instanceFilePath = _getInstanceFilePath(              String errMessage = "Failed to load instances in class ";
                 nameSpace, classNames[i], indices[i]);              errMessage.append(classNames[i]);
               throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, errMessage);
             CIMInstance tmpInstance;  
             _LoadObject(instanceFilePath, tmpInstance);  
             instances.append(tmpInstance);  
         }         }
   
         start = instanceNames.size();  
     }     }
  
     return instances;      return namedInstances;
 } }
  
 Array<CIMReference> CIMRepository::enumerateInstanceNames( Array<CIMReference> CIMRepository::enumerateInstanceNames(
     const String& nameSpace,     const String& nameSpace,
     const String& className)     const String& className)
 { {
   
   
   
     // -- Get all descendent classes of this class:     // -- Get all descendent classes of this class:
  
     Array<String> classNames;     Array<String> classNames;
     _nameSpaceManager.getSubClassNames(nameSpace, className, true, classNames);     _nameSpaceManager.getSubClassNames(nameSpace, className, true, classNames);
     classNames.prepend(className);     classNames.prepend(className);
  
     // -- Search each qualifying instance file for the instance:      // -- Get instance names from each qualifying instance file for the class:
  
     Array<CIMReference> instanceNames;     Array<CIMReference> instanceNames;
     Array<Uint32> indices;     Array<Uint32> indices;
       Array<Uint32> sizes;
  
     for (Uint32 i = 0; i < classNames.size(); i++)     for (Uint32 i = 0; i < classNames.size(); i++)
     {     {
Line 758 
Line 1049 
  
         // Get all instances for that class:         // Get all instances for that class:
  
         InstanceIndexFile::appendInstanceNamesTo(path, instanceNames, indices);          if (!InstanceIndexFile::appendInstanceNamesTo(path, instanceNames,
               indices, sizes))
           {
               String errMessage = "Failed to load instance names in class ";
               errMessage.append(classNames[i]);
               throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, errMessage);
           }
           PEGASUS_ASSERT(instanceNames.size() == indices.size());
           PEGASUS_ASSERT(instanceNames.size() == sizes.size());
     }     }
  
     return instanceNames;     return instanceNames;
Line 770 
Line 1069 
 { {
     throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED, "execQuery()");     throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED, "execQuery()");
  
   
     return Array<CIMInstance>();     return Array<CIMInstance>();
 } }
  
Line 782 
Line 1082 
     const String& resultRole,     const String& resultRole,
     Boolean includeQualifiers,     Boolean includeQualifiers,
     Boolean includeClassOrigin,     Boolean includeClassOrigin,
     const Array<String>& propertyList)      const CIMPropertyList& propertyList)
 { {
   
   
   
     Array<CIMReference> names = associatorNames(     Array<CIMReference> names = associatorNames(
         nameSpace,         nameSpace,
         objectName,         objectName,
Line 848 
Line 1151 
     const String& role,     const String& role,
     const String& resultRole)     const String& resultRole)
 { {
   
   
   
     Array<String> associatorNames;     Array<String> associatorNames;
  
     if (objectName.isClassName())     if (objectName.isClassName())
Line 869 
Line 1175 
  
         AssocInstTable::getAssociatorNames(         AssocInstTable::getAssociatorNames(
             assocFileName,             assocFileName,
             objectName.toString(),              objectName,
             assocClass,             assocClass,
             resultClass,             resultClass,
             role,             role,
Line 902 
Line 1208 
     const String& role,     const String& role,
     Boolean includeQualifiers,     Boolean includeQualifiers,
     Boolean includeClassOrigin,     Boolean includeClassOrigin,
     const Array<String>& propertyList)      const CIMPropertyList& propertyList)
 { {
   
   
   
     Array<CIMReference> names = referenceNames(     Array<CIMReference> names = referenceNames(
         nameSpace,         nameSpace,
         objectName,         objectName,
Line 961 
Line 1270 
     const String& resultClass,     const String& resultClass,
     const String& role)     const String& role)
 { {
   
   
   
     Array<String> tmpReferenceNames;     Array<String> tmpReferenceNames;
  
     if (objectName.isClassName())     if (objectName.isClassName())
Line 1015 
Line 1327 
     const CIMReference& instanceName,     const CIMReference& instanceName,
     const String& propertyName)     const String& propertyName)
 { {
   
   
   
   
     // -- Get the index for this instance:     // -- Get the index for this instance:
  
     String className;     String className;
     Uint32 index;     Uint32 index;
       Uint32 size;
  
     if (!_getInstanceIndex(nameSpace, instanceName, className, index))      if (!_getInstanceIndex(nameSpace, instanceName, className, size, index))
         throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, "getProperty()");          throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, instanceName.toString());
  
     // -- Load the instance into memory:     // -- Load the instance into memory:
  
     String path = _getInstanceFilePath(nameSpace, className, index);      String path = _getInstanceFilePath(nameSpace, className);
     CIMInstance cimInstance;     CIMInstance cimInstance;
     _LoadObject(path, cimInstance);      if (!_loadInstance(path, cimInstance, index, size))
       {
           throw CannotOpenFile(path);
       }
  
     // -- Grab the property from the instance:     // -- Grab the property from the instance:
  
     Uint32 pos = cimInstance.findProperty(propertyName);     Uint32 pos = cimInstance.findProperty(propertyName);
  
       // ATTN: This breaks if the property is simply null
     if (pos == PEGASUS_NOT_FOUND)     if (pos == PEGASUS_NOT_FOUND)
         throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NO_SUCH_PROPERTY, "getProperty()");         throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NO_SUCH_PROPERTY, "getProperty()");
  
Line 1049 
Line 1370 
     const String& propertyName,     const String& propertyName,
     const CIMValue& newValue)     const CIMValue& newValue)
 { {
     // -- Load the instance:  
  
     CIMInstance instance = getInstance(  
         nameSpace, instanceName, false, true);  
   
     // -- Get the class:  
   
     CIMClass cimClass = getClass(nameSpace, instance.getClassName(),  
         false, true);  
   
     // -- Save instance name:  
   
     CIMReference oldRef = instance.getInstanceName(cimClass);  
   
     // -- Modify the property (disallow if property is a key):  
   
     Uint32 pos = instance.findProperty(propertyName);  
   
     if (pos == PEGASUS_NOT_FOUND)  
         throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NO_SUCH_PROPERTY, "setProperty()");  
   
     CIMProperty prop = instance.getProperty(pos);  
   
     prop.setValue(newValue);  
   
     // -- Disallow if instance name is changed by this operation (attempt  
     // -- to modify a key property.  
  
     CIMReference newRef = instance.getInstanceName(cimClass);  
  
     if (oldRef != newRef)      //
     {      // Create the instance to pass to modifyInstance()
         throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,      //
             "setProperty(): attempted to modify a key property");      CIMInstance instance(instanceName.getClassName());
     }      // ATTN: Is this the correct construction for this property?
       instance.addProperty(CIMProperty(propertyName, newValue));
       CIMNamedInstance namedInstance(instanceName, instance);
  
     // -- Modify the instance:      //
       // Create the propertyList to pass to modifyInstance()
       //
       Array<String> propertyListArray;
       propertyListArray.append(propertyName);
       CIMPropertyList propertyList(propertyListArray);
  
     modifyInstance(nameSpace, instance);      //
       // Modify the instance to set the value of the given property
       //
       modifyInstance(nameSpace, namedInstance, false, propertyList);
 } }
  
 CIMQualifierDecl CIMRepository::getQualifier( CIMQualifierDecl CIMRepository::getQualifier(
     const String& nameSpace,     const String& nameSpace,
     const String& qualifierName)     const String& qualifierName)
 { {
   
   
   
     // -- Get path of qualifier file:     // -- Get path of qualifier file:
  
     String qualifierFilePath = _nameSpaceManager.getQualifierFilePath(     String qualifierFilePath = _nameSpaceManager.getQualifierFilePath(
Line 1109 
Line 1416 
     }     }
     catch (CannotOpenFile&)     catch (CannotOpenFile&)
     {     {
         return CIMQualifierDecl();          throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, qualifierName);
     }     }
  
     return qualifierDecl;     return qualifierDecl;
Line 1119 
Line 1426 
     const String& nameSpace,     const String& nameSpace,
     const CIMQualifierDecl& qualifierDecl)     const CIMQualifierDecl& qualifierDecl)
 { {
   
   
   
     // -- Get path of qualifier file:     // -- Get path of qualifier file:
  
     String qualifierFilePath = _nameSpaceManager.getQualifierFilePath(     String qualifierFilePath = _nameSpaceManager.getQualifierFilePath(
Line 1138 
Line 1448 
     const String& nameSpace,     const String& nameSpace,
     const String& qualifierName)     const String& qualifierName)
 { {
   
   
   
     // -- Get path of qualifier file:     // -- Get path of qualifier file:
  
     String qualifierFilePath = _nameSpaceManager.getQualifierFilePath(     String qualifierFilePath = _nameSpaceManager.getQualifierFilePath(
Line 1152 
Line 1465 
 Array<CIMQualifierDecl> CIMRepository::enumerateQualifiers( Array<CIMQualifierDecl> CIMRepository::enumerateQualifiers(
     const String& nameSpace)     const String& nameSpace)
 { {
   
   
   
     String qualifiersRoot = _nameSpaceManager.getQualifiersRoot(nameSpace);     String qualifiersRoot = _nameSpaceManager.getQualifiersRoot(nameSpace);
  
     Array<String> qualifierNames;     Array<String> qualifierNames;
Line 1181 
Line 1497 
     Array<CIMValue>& outParameters)     Array<CIMValue>& outParameters)
 { {
     throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED, "invokeMethod()");     throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED, "invokeMethod()");
   
   
   
     return CIMValue();     return CIMValue();
 } }
  
 void CIMRepository::createNameSpace(const String& nameSpace) void CIMRepository::createNameSpace(const String& nameSpace)
 { {
   
   
     _nameSpaceManager.createNameSpace(nameSpace);     _nameSpaceManager.createNameSpace(nameSpace);
 } }
  
 Array<String> CIMRepository::enumerateNameSpaces() const Array<String> CIMRepository::enumerateNameSpaces() const
 { {
   
   
     Array<String> nameSpaceNames;     Array<String> nameSpaceNames;
     _nameSpaceManager.getNameSpaceNames(nameSpaceNames);     _nameSpaceManager.getNameSpaceNames(nameSpaceNames);
     return nameSpaceNames;     return nameSpaceNames;
Line 1198 
Line 1521 
  
 void CIMRepository::deleteNameSpace(const String& nameSpace) void CIMRepository::deleteNameSpace(const String& nameSpace)
 { {
   
   
   
     _nameSpaceManager.deleteNameSpace(nameSpace);     _nameSpaceManager.deleteNameSpace(nameSpace);
 } }
  
   //----------------------------------------------------------------------
   //
   // _getIndexFilePath()
   //
   //      returns the file path of the instance index file.
   //
   //----------------------------------------------------------------------
   
 String CIMRepository::_getIndexFilePath( String CIMRepository::_getIndexFilePath(
     const String& nameSpace,     const String& nameSpace,
     const String& className) const     const String& className) const
Line 1210 
Line 1544 
     return tmp;     return tmp;
 } }
  
   //----------------------------------------------------------------------
   //
   // _getInstanceFilePath()
   //
   //      returns the file path of the instance file.
   //
   //----------------------------------------------------------------------
   
 String CIMRepository::_getInstanceFilePath( String CIMRepository::_getInstanceFilePath(
     const String& nameSpace,     const String& nameSpace,
     const String& className,      const String& className) const
     Uint32 index) const  
 { {
     String tmp = _nameSpaceManager.getInstanceFileBase(nameSpace, className);     String tmp = _nameSpaceManager.getInstanceFileBase(nameSpace, className);
     char extension[32];      tmp.append(".instances");
     sprintf(extension, ".%d", index);  
     tmp += extension;  
     return tmp;     return tmp;
 } }
  
   //----------------------------------------------------------------------
   //
   // _loadInstance()
   //
   //      Loads an instance object from disk to memory.  Returns true on
   //      success.
   //
   //----------------------------------------------------------------------
   
   Boolean CIMRepository::_loadInstance(
       const String& path,
       CIMInstance& object,
       Uint32 index,
       Uint32 size)
   {
       // Load instance from instance file into memory:
   
   
       Array<Sint8> data;
       if (!InstanceFile::loadInstance(path, index, size, data))
       {
           return false;
       }
   
       XmlParser parser((char*)data.getData());
   
       XmlReader::getObject(parser, object);
   
       return true;
   }
   
   //----------------------------------------------------------------------
   //
   // _loadAllInstances()
   //
   //      Loads all the instance objects for a given class from disk to memory.
   //      Returns true on success.
   //
   //----------------------------------------------------------------------
   
   Boolean CIMRepository::_loadAllInstances(
       const String& nameSpace,
       const String& className,
       Array<CIMNamedInstance>& namedInstances)
   {
       Array<CIMReference> instanceNames;
       Array<Sint8> data;
       Array<Uint32> indices;
       Array<Uint32> sizes;
   
       //
       // Form the name of the instance index file
       //
       String indexFilePath = _getIndexFilePath(nameSpace, className);
   
       //
       // Form the name of the instance file
       //
       String instanceFilePath = _getInstanceFilePath(nameSpace, className);
   
       //
       // Get all instance names and record information from the index file
       //
       if (!InstanceIndexFile::appendInstanceNamesTo(
           indexFilePath, instanceNames, indices, sizes))
       {
           return false;
       }
       PEGASUS_ASSERT(instanceNames.size() == indices.size());
       PEGASUS_ASSERT(instanceNames.size() == sizes.size());
   
       //
       // Load all instance data from the instance file
       //
       if (instanceNames.size() > 0)
       {
           if (!InstanceFile::loadAllInstances(instanceFilePath, data))
           {
               return false;
           }
   
           //
           // for each instance loaded, call XML parser to parse the XML
           // data and create a CIMInstance object.
           //
           CIMInstance tmpInstance;
   
           Uint32 bufferSize = data.size();
           char* buffer = (char*)data.getData();
   
           for (Uint32 i = 0; i < instanceNames.size(); i++)
           {
               XmlParser parser(&(buffer[indices[i]]));
   
               XmlReader::getObject(parser, tmpInstance);
   
               namedInstances.append(CIMNamedInstance(instanceNames[i], tmpInstance));
           }
       }
   
       return true;
   }
   
   //----------------------------------------------------------------------
   //
   // _saveInstance()
   //
   //      Saves an instance object from memory to disk file.  Returns true
   //      on success.
   //
   //----------------------------------------------------------------------
   
   Boolean CIMRepository::_saveInstance(
       const String& path,
       const CIMInstance& object,
       Uint32& index,
       Uint32& size)
   {
       Array<Sint8> out;
       object.toXml(out);
   
       if (!InstanceFile::insertInstance(out, path, index, size))
       {
           return false;
       }
   
       return true;
   }
   
   //----------------------------------------------------------------------
   //
   // _modifyInstance()
   //
   //      Modifies an instance object saved in the disk file.  Returns true
   //      on success.
   //
   //----------------------------------------------------------------------
   
   Boolean CIMRepository::_modifyInstance(
       const String& path,
       const CIMInstance& object,
       Uint32 oldIndex,
       Uint32 oldSize,
       Uint32& newIndex,
       Uint32& newSize)
   {
       Array<Sint8> out;
       object.toXml(out);
   
       if (!InstanceFile::modifyInstance(out, path, oldIndex, oldSize, newIndex,
                                         newSize))
       {
           return false;
       }
   
       return true;
   }
   
   //------------------------------------------------------------------------------
   //
   // _renameTempInstanceAndIndexFiles()
   //
   //      Renames the temporary instance and instance index files back to the
   //      original files.  The temporary files were created for an insert,
   //      remove, or modify operation (to avoid data inconsistency between
   //      the two files in case of unexpected system termination or failure).
   //      This method is called after a successful insert, remove, or modify
   //      operation on BOTH the index file and the instance file.  Returns
   //      true on success.
   //
   //------------------------------------------------------------------------------
   
   Boolean CIMRepository::_renameTempInstanceAndIndexFiles(
       const String& indexFilePath,
       const String& instanceFilePath)
   {
       //
       // Rename the original files to backup files
       //
       // This is done so that we would not lose the original files if an error
       // occurs in renaming the temporary files back after the original files
       // have been removed.
       //
       String realIndexFilePath;
       if (FileSystem::existsNoCase(indexFilePath, realIndexFilePath))
       {
           if (!FileSystem::renameFile(realIndexFilePath,
                                       realIndexFilePath + ".orig"))
               return false;
       }
       else
       {
           realIndexFilePath = indexFilePath;
       }
   
       String realInstanceFilePath;
       if (FileSystem::existsNoCase(instanceFilePath, realInstanceFilePath))
       {
           if (!FileSystem::renameFile(realInstanceFilePath,
                                       realInstanceFilePath + ".orig"))
               return false;
       }
       else
       {
           realInstanceFilePath = instanceFilePath;
       }
   
       //
       // Rename the temporary instance and index files back to be the original
       // files.
       //
       // If the index file is now empty (zero size), delete the temporary
       // files instead.
       //
       Uint32 fileSize;
       String tmpIndexFilePath = realIndexFilePath + ".tmp";
       String tmpInstanceFilePath = realInstanceFilePath + ".tmp";
   
       if (!FileSystem::getFileSizeNoCase(tmpIndexFilePath, fileSize))
           return false;
   
       if (fileSize == 0)
       {
           if (!FileSystem::removeFileNoCase(tmpIndexFilePath))
               return false;
   
           if (!FileSystem::removeFileNoCase(tmpInstanceFilePath))
               return false;
       }
       else
       {
           if (!FileSystem::renameFile(tmpIndexFilePath, realIndexFilePath))
               return false;
   
           if (!FileSystem::renameFile(tmpInstanceFilePath, realInstanceFilePath))
               return false;
       }
   
       //
       // Now remove the backup files
       //
       FileSystem::removeFile(realIndexFilePath + ".orig");
       FileSystem::removeFile(realInstanceFilePath + ".orig");
   
       return true;
   }
   
 void CIMRepository::setDeclContext(RepositoryDeclContext *context) void CIMRepository::setDeclContext(RepositoryDeclContext *context)
 { {
   _context = context;   _context = context;


Legend:
Removed from v.1.50  
changed lines
  Added in v.1.51

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2