WidgetInfo ImportManagerView::widgetInfo() { if (m_importsWidget == 0) { m_importsWidget = new ImportsWidget; connect(m_importsWidget, SIGNAL(removeImport(Import)), this, SLOT(removeImport(Import))); connect(m_importsWidget, SIGNAL(addImport(Import)), this, SLOT(addImport(Import))); if (model()) m_importsWidget->setImports(model()->imports()); } return createWidgetInfo(m_importsWidget, 0, "ImportManager", WidgetInfo::LeftPane, 1); }
static void createImportList(SmiModule *smiModule) { SmiNode *smiNode; SmiType *smiType; SmiModule *smiTypeModule; SmiNodekind kind = SMI_NODEKIND_SCALAR | SMI_NODEKIND_COLUMN; SmiImport *smiImport; for (smiNode = smiGetFirstNode(smiModule, kind); smiNode; smiNode = smiGetNextNode(smiNode, kind)) { smiType = smiGetNodeType(smiNode); if (smiType && (smiType->decl == SMI_DECL_IMPLICIT_TYPE)) { smiType = smiGetParentType(smiType); } if (smiType) { smiTypeModule = smiGetTypeModule(smiType); if (smiTypeModule && strcmp(smiTypeModule->name, smiModule->name)) { if (strlen(smiTypeModule->name)) { addImport(smiTypeModule->name, smiType->name); } } if (smiType->basetype == SMI_BASETYPE_INTEGER32) { addImport("SNMPv2-SMI", "Integer32"); } } } for (smiImport = smiGetFirstImport(smiModule); smiImport; smiImport = smiGetNextImport(smiImport)) { if (islower((int) smiImport->name[0]) || (smiImport->module && !strcmp(smiImport->module, "SNMPv2-SMI")) || (smiImport->module && !strcmp(smiImport->module, "SNMPv2-TC"))) { addImport(smiImport->module, smiImport->name); } } }
////////////////////////////////////////////////////////////////////////// // import BcBool CsPackageImporter::import( const BcName& Name ) { Name_ = Name; BcPath Path = CsCore::pImpl()->getPackageImportPath( Name ); PSY_LOGSCOPEDCATEGORY( "Import" ); PSY_LOG( "Importing %s...\n", (*Path).c_str() ); PSY_LOGSCOPEDINDENT; BcTimer TotalTimer; TotalTimer.mark(); // Store source file info. FsStats Stats; if( FsCore::pImpl()->fileStats( (*Path).c_str(), Stats ) ) { Header_.SourceFileStatsHash_ = BcHash( reinterpret_cast< BcU8* >( &Stats ), sizeof( Stats ) ); } else { Header_.SourceFileStatsHash_ = 0; } beginImport(); Header_.SourceFile_ = addString( (*Path).c_str() ); endImport(); Json::Value Root; if( loadJsonFile( (*Path).c_str(), Root ) ) { // Add as dependency. beginImport(); addDependency( (*Path).c_str() ); // Get resource list. Json::Value Resources( Root.get( "resources", Json::Value( Json::arrayValue ) ) ); // Add all package cross refs. addAllPackageCrossRefs( Resources ); // Set resource id to zero. ResourceIds_.store( 0 ); // Import everything. for( const auto& ResourceObject : Resources ) { addImport( ResourceObject, BcFalse ); } endImport(); // Sort importers. std::sort( Resources_.begin(), Resources_.end() ); // Iterate over all resources and import (import calls can append to the list) size_t CurrResourceIdx = 0; while( CurrResourceIdx < Resources_.size() ) { // Grab first resource in the list. auto ResourceEntry = std::move( Resources_[ CurrResourceIdx++ ] ); // Import resource. BcTimer ResourceTimer; ResourceTimer.mark(); try { PSY_LOGSCOPEDINDENT; beginImport(); if( importResource( std::move( ResourceEntry.Importer_ ), ResourceEntry.Resource_ ) ) { PSY_LOG( "SUCCEEDED: Time: %.2f seconds.\n", ResourceTimer.time() ); } else { PSY_LOG( "FAILED: Time: %.2f seconds.\n", ResourceTimer.time() ); BcBreakpoint; endImport(); return BcFalse; } endImport(); } catch( CsImportException ImportException ) { PSY_LOG( "FAILED: Time: %.2f seconds.\n", ResourceTimer.time() ); PSY_LOG( "ERROR: in file %s:\n%s\n", ImportException.file().c_str(), ImportException.what() ); endImport(); return BcFalse; } } // Save and return. BcPath PackedPackage( CsCore::pImpl()->getPackagePackedPath( Name ) ); BcBool SaveSuccess = save( PackedPackage ); if( SaveSuccess ) { PSY_LOG( "SUCCEEDED: Time: %.2f seconds.\n", TotalTimer.time() ); // Write out dependencies. std::string OutputDependencies = *CsCore::pImpl()->getPackageIntermediatePath( Name ) + "/deps.json"; CsSerialiserPackageObjectCodec ObjectCodec( nullptr, (BcU32)bcRFF_ALL, (BcU32)bcRFF_TRANSIENT, 0 ); SeJsonWriter Writer( &ObjectCodec ); Writer << Dependencies_; Writer.save( OutputDependencies.c_str() ); } else { PSY_LOG( "FAILED: Time: %.2f seconds.\n", TotalTimer.time() ); BcBreakpoint; } return SaveSuccess; } return BcFalse; }
////////////////////////////////////////////////////////////////////////// // addImport BcU32 CsPackageImporter::addImport( const Json::Value& Resource, BcBool IsCrossRef ) { PSY_LOGSCOPEDINDENT; std::lock_guard< std::recursive_mutex > Lock( BuildingLock_ ); BcAssert( BuildingBeginCount_ > 0 ); // Validate it's an object. BcAssertMsg( Resource.type() == Json::objectValue, "Can't import a value that isn't an object." ); // Validate name and type. Json::Value Name( Resource.get( "name", Json::nullValue ) ); Json::Value Type( Resource.get( "$Class", Json::nullValue ) ); if( Type == Json::nullValue ) { Type = Resource.get( "type", Json::nullValue ); } BcAssertMsg( Name.type() == Json::stringValue, "Name not specified for resource.\n" ); BcAssertMsg( Type.type() == Json::stringValue, "Type not specified for resource.\n" ) // Check if there is a resource with matching name already, as long as it isn't a cross ref. if( !IsCrossRef ) { auto AlreadyExisting = std::find_if( Resources_.begin(), Resources_.end(), [ this, &Name ]( const TResourceImport& ResourceImport ) { return ResourceImport.Importer_->getResourceName() == Name.asCString(); } ); BcAssertMsg( AlreadyExisting == Resources_.end(), "Resource \"%s\" already exists in package \"%s\"", Name.asCString(), (*Name_).c_str() ); } // Grab class, create importer. const ReClass* ResourceClass = ReManager::GetClass( Type.asCString() ); CsResourceImporterUPtr ResourceImporter; if( ResourceClass != nullptr ) { CsResourceImporterAttribute* ResourceImporterAttr = nullptr; do { ResourceImporterAttr = ResourceClass->getAttribute< CsResourceImporterAttribute >(); // Check on a parent to see if there is a valid importer attached to it. if( ResourceImporterAttr == nullptr ) { ResourceClass = ResourceClass->getSuper(); } } while( ResourceImporterAttr == nullptr && ResourceClass != nullptr ); if( ResourceImporterAttr != nullptr ) { ResourceImporter = ResourceImporterAttr->getImporter(); } } // BcAssertMsg( ResourceImporter != nullptr, "Can't create resource importer for \"%s\"", Type.asCString() ); // Serialise resource onto importer. CsSerialiserPackageObjectCodec ObjectCodec( nullptr, bcRFF_IMPORTER, bcRFF_NONE, bcRFF_IMPORTER ); SeJsonReader Reader( &ObjectCodec ); Reader.serialiseClassMembers( ResourceImporter.get(), ResourceImporter->getClass(), Resource, 0 ); // Add import with importer. return addImport( std::move( ResourceImporter ), Resource, IsCrossRef ); }