Show
Ignore:
Timestamp:
03/05/10 11:44:10 (6 months ago)
Author:
gm78
Message:

Added threaded loading of KML NetworkLinks?.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • FalconView/trunk/public/fvw_core/GeodataDataSources/LibkmlNetworkLink.cpp

    r2270 r2277  
    2424#include "LibkmlDataSource.h" 
    2525#include "ComErrorObject.h" 
     26#include "KMLDataLoader.h" 
    2627 
    2728// CLibkmlNetworkLink 
     
    3233   { 
    3334      PopulateWrappedDataSourceAsNecessary(); 
    34       if (m_wrappedDataSource) 
    35          return m_wrappedDataSource->get_DataSetCount(count); 
     35      const IFvDataSourcePtr& wrappedDataSource = m_networkLinkResource.GetWrappedDataSource(); 
     36      if (wrappedDataSource) 
     37         return wrappedDataSource->get_DataSetCount(count); 
    3638   } 
    3739   catch (...) 
     
    5456   { 
    5557      PopulateWrappedDataSourceAsNecessary(); 
    56       if (m_wrappedDataSource) 
    57          return m_wrappedDataSource->raw_GetDataSet(index, dataSet); 
     58      const IFvDataSourcePtr& wrappedDataSource = m_networkLinkResource.GetWrappedDataSource(); 
     59      if (wrappedDataSource) 
     60         return wrappedDataSource->raw_GetDataSet(index, dataSet); 
    5861      return E_FAIL; 
    5962   } 
     
    7275      { 
    7376         PopulateWrappedDataSourceAsNecessary(); 
    74          if (m_wrappedDataSource) 
    75             return m_wrappedDataSource->get_Name(name); 
     77         const IFvDataSourcePtr& wrappedDataSource = m_networkLinkResource.GetWrappedDataSource(); 
     78         if (wrappedDataSource) 
     79            return wrappedDataSource->get_Name(name); 
    7680         *name = _bstr_t("<NetworkLink>").Detach(); 
    7781      } 
     
    8791   { 
    8892      PopulateWrappedDataSourceAsNecessary(); 
    89       if (m_wrappedDataSource) 
    90          return m_wrappedDataSource->raw_GetDataSetByName(name, dataSet); 
     93      const IFvDataSourcePtr& wrappedDataSource = m_networkLinkResource.GetWrappedDataSource(); 
     94      if (wrappedDataSource) 
     95         return wrappedDataSource->raw_GetDataSetByName(name, dataSet); 
    9196      return E_FAIL; 
    9297   } 
     
    99104   { 
    100105      PopulateWrappedDataSourceAsNecessary(); 
    101       if (m_wrappedDataSource) 
    102          return m_wrappedDataSource->get_DataSourceCount(count); 
     106      const IFvDataSourcePtr& wrappedDataSource = m_networkLinkResource.GetWrappedDataSource(); 
     107      if (wrappedDataSource) 
     108         return wrappedDataSource->get_DataSourceCount(count); 
    103109   } 
    104110   catch (...) 
     
    121127   { 
    122128      PopulateWrappedDataSourceAsNecessary(); 
    123       if (m_wrappedDataSource) 
    124          return m_wrappedDataSource->raw_GetDataSource(index, dataSource); 
     129      const IFvDataSourcePtr& wrappedDataSource = m_networkLinkResource.GetWrappedDataSource(); 
     130      if (wrappedDataSource) 
     131         return wrappedDataSource->raw_GetDataSource(index, dataSource); 
    125132      return E_FAIL; 
    126133   } 
     
    133140   { 
    134141      PopulateWrappedDataSourceAsNecessary(); 
    135       if (m_wrappedDataSource) 
    136          return m_wrappedDataSource->raw_GetDataSourceByName(name, dataSource); 
     142      const IFvDataSourcePtr& wrappedDataSource = m_networkLinkResource.GetWrappedDataSource(); 
     143      if (wrappedDataSource) 
     144         return wrappedDataSource->raw_GetDataSourceByName(name, dataSource); 
    137145      return E_FAIL; 
    138146   } 
     
    152160      PopulateWrappedDataSourceAsNecessary(); 
    153161 
    154       if (m_wrappedDataSource) 
    155       { 
    156          ISymbolFactoryPtr symbolFactory = m_wrappedDataSource; 
     162      const IFvDataSourcePtr& wrappedDataSource = m_networkLinkResource.GetWrappedDataSource(); 
     163      if (wrappedDataSource) 
     164      { 
     165         ISymbolFactoryPtr symbolFactory = wrappedDataSource; 
    157166         if (symbolFactory) 
    158167            return symbolFactory->raw_GetImageByIdentifier(identifier, imageData); 
     
    181190   try 
    182191   { 
    183       if (!m_wrappedDataSource && m_networkLink->has_link()) 
     192      if (m_networkLinkResource.State() == Resource_Not_Loaded && m_networkLink->has_link()) 
    184193      { 
    185194         // If the regionation parameters have been set and the feature is active, 
     
    205214         { 
    206215            // get the base URL 
    207             IFvDataSourcePtr dataSource(CLSID_LibkmlDataSource); 
    208             ILibkmlDataSourcePtr libkmlDataSource = dataSource; 
    209216            kmldom::LinkPtr link = m_networkLink->get_link(); 
    210217            std::string url = CUtilityMethods::ResolveURI((char*)m_rootDS->URL, (char*)link->get_href().c_str()); 
     
    262269            } 
    263270 
    264             // populate the data source from the URL 
    265             long handle = libkmlDataSource->GetHandle(); 
    266             CLibkmlDataSource* ds = (CLibkmlDataSource*)CInternalObjectRegistry::GetObject(handle); 
    267             std::string kml_data; 
    268             ds->FetchDataRelativeToDataSource(url.c_str(), kml_data); 
    269             ds->LoadKML(kml_data, url.c_str()); 
    270  
    271             m_wrappedDataSource = dataSource.Detach(); 
    272  
    273             // register for callbacks on the wrapped data source so that changes notices get fired to anything registered 
    274             // for callbacks on the root data source 
    275             dataSource = libkmlDataSource; // reassociate the smart pointer after Detach() 
    276             dataSource->RegisterForCallbacks(this); 
    277  
    278             // indicate to the root data source that something has changed 
    279             if (!m_bFirstAttemptToLoad) 
    280                CLibkmlDataSource::FireDataSourceChanged(m_rootDS->Handle); 
     271            // Load the networklink in a background thread 
     272            m_networkLinkResource.SetResolvedUri(url); 
     273            CKMLDataLoader::GetInstance()->AddLoadRequest(this, &m_networkLinkResource); 
    281274         } 
    282275      } 
     
    284277   catch (...) 
    285278   { 
    286       m_wrappedDataSource = NULL; 
    287279      THROW_ERROR_MSG2(E_FAIL, "exception in CLibkmlNetworkLink::PopulateWrappedDataSourceAsNecessary()"); 
    288280   } 
     
    296288   { 
    297289      PopulateWrappedDataSourceAsNecessary(); 
    298       if (m_wrappedDataSource) 
    299          return m_wrappedDataSource->raw_Extent2D(minX, minY, maxX, maxY); 
     290      const IFvDataSourcePtr& wrappedDataSource = m_networkLinkResource.GetWrappedDataSource(); 
     291      if (wrappedDataSource) 
     292         return wrappedDataSource->raw_Extent2D(minX, minY, maxX, maxY); 
    300293      return E_FAIL; 
    301294   } 
     
    314307      { 
    315308         PopulateWrappedDataSourceAsNecessary(); 
    316          if (m_wrappedDataSource) 
    317             return m_wrappedDataSource->get_Description(description); 
     309         const IFvDataSourcePtr& wrappedDataSource = m_networkLinkResource.GetWrappedDataSource(); 
     310         if (wrappedDataSource) 
     311            return wrappedDataSource->get_Description(description); 
    318312         *description = _bstr_t("A KML <NetworkLink>.").Detach(); 
    319313      } 
     
    329323   { 
    330324      IFvDataSourcePtr rootDS = m_rootDS; 
    331       return rootDS->RegisterForCallbacks(fvDataSourceCallback);; 
     325      return rootDS->RegisterForCallbacks(fvDataSourceCallback); 
    332326   } 
    333327   CATCH_BLOCK_RET 
     
    339333   { 
    340334      IFvDataSourcePtr rootDS = m_rootDS; 
    341       return rootDS->UnregisterForCallbacks(fvDataSourceCallback);; 
     335      return rootDS->UnregisterForCallbacks(fvDataSourceCallback); 
    342336   } 
    343337   CATCH_BLOCK_RET 
     
    362356 
    363357      // pass the parameters on to any wrapped data source 
    364       IRegionatedKMLContainerPtr regionatedKMLContainer = m_wrappedDataSource; 
     358      IRegionatedKMLContainerPtr regionatedKMLContainer = m_networkLinkResource.GetWrappedDataSource(); 
    365359      if (regionatedKMLContainer) 
    366360         regionatedKMLContainer->SetRegionationParameters(leftLon, bottomLat, rightLon, topLat, degreesPerPixelX, degreesPerPixelY);