|
From: Frank V. C. <fr...@us...> - 2000-11-19 05:19:56
|
Update of /cvsroot/corelinux/clfw/src/libs/LibLoad In directory slayer.i.sourceforge.net:/tmp/cvs-serv5509/src/libs/LibLoad Modified Files: LibraryInstance.cpp LibraryObjectRegistry.cpp Log Message: 122753 LibraryLoader refit Index: LibraryInstance.cpp =================================================================== RCS file: /cvsroot/corelinux/clfw/src/libs/LibLoad/LibraryInstance.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -r1.3 -r1.4 *** LibraryInstance.cpp 2000/11/19 03:18:28 1.3 --- LibraryInstance.cpp 2000/11/19 05:19:52 1.4 *************** *** 26,33 **** --- 26,41 ---- #endif + #if !defined(__METASPACE_HPP) + #include <MetaSpace.hpp> + #endif + #if !defined(__LIBRARYINSTANCE_HPP) #include INCL_LibraryInstance #endif + #if !defined(__LIBRARYOBJECT_HPP) + #include INCL_LibraryObject + #endif + #if !defined(__LIBRARYOBJECTREGISTRY_HPP) #include INCL_LibraryObjectRegistry *************** *** 129,132 **** --- 137,149 ---- // + // This is the default + // + + MetaClassPtr LibraryInstance::getObjectClassParent( void ) const + { + return MetaSpace::getClassForType( LibraryObject::getTypeDescriptor() ); + } + + // // Fetch the individual from the registry // *************** *** 138,142 **** throw ( NullPointerException ) { ! return LibraryObjectRegistry::createObject(this,aObjectName); } --- 155,159 ---- throw ( NullPointerException ) { ! return LibraryObjectRegistry::getObject(this,aObjectName); } *************** *** 148,152 **** throw ( NullPointerException ) { ! return LibraryObjectRegistry::destroyObject(this,aObject); } } --- 165,169 ---- throw ( NullPointerException ) { ! return LibraryObjectRegistry::returnObject(this,aObject); } } Index: LibraryObjectRegistry.cpp =================================================================== RCS file: /cvsroot/corelinux/clfw/src/libs/LibLoad/LibraryObjectRegistry.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -r1.3 -r1.4 *** LibraryObjectRegistry.cpp 2000/11/19 03:18:28 1.3 --- LibraryObjectRegistry.cpp 2000/11/19 05:19:52 1.4 *************** *** 37,40 **** --- 37,50 ---- #endif + #if !defined(__METASPACE_HPP) + #include <MetaSpace.hpp> + #endif + + #if !defined(__METACLASS_HPP) + #include <MetaClass.hpp> + #endif + + #include <cstring> + namespace corelinux { *************** *** 43,46 **** --- 53,127 ---- // + // Local function to find the metaclass that is of type + // and has the required method + // + + static CharPtr gCreateInstanceMethod( "create" ); + static CharPtr gDestroyInstanceMethod( "destroy" ); + + static LibraryObjectPtr fetchObject( CharCptr aName, MetaClassPtr aClass ) + { + LibraryObjectPtr aPtr( NULLPTR ); + + // + // Check this for name and matching method + // + + if( strcmp( aName, aClass->getInstanceTypeName() ) == 0 ) + { + Iterator<DispatchDescriptorPtr> *aMethodIterator + ( + aClass->createMethodIterator() + ); + + while( aMethodIterator->isValid() == true ) + { + if( strcmp + ( + gCreateInstanceMethod, + aMethodIterator->getElement()->theClassMethodName + ) == 0 ) + { + aClass->dispatch + ( + gCreateInstanceMethod, + (void **)NULLPTR, + (void *) &aPtr + ); + break; + } + else + { + aMethodIterator->setNext(); + } + } + aClass->destroyIterator( aMethodIterator ); + } + + // + // If we have no luck, we dig deeper + // + + if( aPtr == NULLPTR ) + { + Iterator<MetaClassPtr> *aChildIterator( aClass->createIterator() ); + while( aPtr == NULLPTR && aChildIterator->isValid() == true ) + { + aPtr = fetchObject( aName, aChildIterator->getElement() ); + aChildIterator->setNext(); + } + aClass->destroyIterator( aChildIterator ); + + } + else + { + ; // do nothing + } + + return aPtr; + } + + + // // Constructor // *************** *** 89,93 **** // ! LibraryObjectPtr LibraryObjectRegistry::createObject ( LibraryInstancePtr aLibraryInstance, --- 170,174 ---- // ! LibraryObjectPtr LibraryObjectRegistry::getObject ( LibraryInstancePtr aLibraryInstance, *************** *** 98,108 **** LibraryObjectPtr aLibraryObject( NULLPTR ); ! if( aLibraryInstance != NULLPTR && ! aName != NULLPTR ) { LibraryObjectRegistryPtr aLORPtr( theRegistry.instance() ); Guard myGuard( aLORPtr->access() ); ! } else --- 179,188 ---- LibraryObjectPtr aLibraryObject( NULLPTR ); ! if( aLibraryInstance != NULLPTR && aName != NULLPTR ) { LibraryObjectRegistryPtr aLORPtr( theRegistry.instance() ); Guard myGuard( aLORPtr->access() ); ! aLibraryObject = aLORPtr->resolveObject( aLibraryInstance, aName ); } else *************** *** 118,122 **** // ! void LibraryObjectRegistry::destroyObject ( LibraryInstancePtr aLibraryInstance, --- 198,202 ---- // ! void LibraryObjectRegistry::returnObject ( LibraryInstancePtr aLibraryInstance, *************** *** 129,134 **** LibraryObjectRegistryPtr aLORPtr( theRegistry.instance() ); Guard myGuard( aLORPtr->access() ); - } else --- 209,214 ---- LibraryObjectRegistryPtr aLORPtr( theRegistry.instance() ); Guard myGuard( aLORPtr->access() ); + aLORPtr->disgardObject( aLibraryInstance, aLibraryObject ); } else *************** *** 143,174 **** // ! // ! // Determine if the library name is registered as a key to definitions // ! bool LibraryObjectRegistry::isLibraryDefined ( ! CharCptr aLibrary ! ) const { ! GUARD; ! bool found(false); ! ObjectInstanceMapConstIterator begin( theInstances.begin() ); ! ObjectInstanceMapConstIterator end( theInstances.end() ); ! while( begin != end && found == false ) { ! if( strcmp( (*begin).first->getLibraryName(), aLibrary ) == 0 ) { ! found = true; } else { ! ++begin; } } ! return found; } } --- 223,355 ---- // ! ! // ! // Resolve using the cache or the ontology // ! LibraryObjectPtr LibraryObjectRegistry::resolveObject ( ! LibraryInstancePtr aInstance, ! CharCptr aObjectName ! ) { ! LibraryInstanceMapIterator aFItr( theInstances.find(aInstance) ); ! LibObjectReference aObjCache = {NULLPTR,1}; ! ! // ! // If the instance is found in cache, and the object ! // fetch and increment reference ! // ! if( aFItr != theInstances.end() ) { ! ObjectInstanceMapIterator aFOItr ! ( ! (*aFItr).second.find( aObjectName ) ! ); ! ! if( aFOItr != (*aFItr).second.end() ) { ! aObjCache.theLibObj = (*aFOItr).second.theLibObj; ! (*aFOItr).second.theCount += 1; } else { ! aObjCache.theLibObj = fetchObject ! ( ! aObjectName, ! aInstance->getObjectClassParent() ! ); ! if( aObjCache.theLibObj != NULLPTR ) ! { ! (*aFItr).second[aObjectName] = aObjCache; ! } ! else ! { ! ; // do nothing ! } } } ! ! // ! // Otherwise fetch an instance ! // ! else ! { ! aObjCache.theLibObj = fetchObject ! ( ! aObjectName, ! aInstance->getObjectClassParent() ! ); ! ! if( aObjCache.theLibObj != NULLPTR ) ! { ! ObjectInstanceMap aMap; ! ! aMap[aObjectName] = aObjCache; ! theInstances[aInstance] = aMap; ! } ! else ! { ! ; // do nothing ! } ! } ! ! return aObjCache.theLibObj; } + // + // Either keep it or let it go based on the references + // + + void LibraryObjectRegistry::disgardObject + ( + LibraryInstancePtr aInstance, + LibraryObjectPtr aObject + ) + { + LibraryInstanceMapIterator aFItr( theInstances.find(aInstance) ); + + if( aFItr != theInstances.end() ) + { + ObjectInstanceMapIterator aFOItr + ( + (*aFItr).second.find + ( + aObject->getType()->getInstanceTypeName() + ) + ); + + if( aFOItr != (*aFItr).second.end() ) + { + if( (*aFOItr).second.theCount == 1 ) + { + aObject->getType()->dispatch + ( + aObject, + gDestroyInstanceMethod, + (void **) NULLPTR, + (void *) NULLPTR + ); + + (*aFItr).second.erase( aFOItr ); + } + else + { + (*aFOItr).second.theCount -= 1; + } + + } + else + { + ; // exception ? + } + + } + else + { + ; // do nothing + } + } } |