Changeset 2277

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

Added threaded loading of KML NetworkLinks?.

Location:
FalconView/trunk/public/fvw_core/GeodataDataSources
Files:
5 added
6 modified

Legend:

Unmodified
Added
Removed
  • FalconView/trunk/public/fvw_core/GeodataDataSources/GeodataDataSources.vcproj

    r2214 r2277  
    546546            </File> 
    547547            <File 
     548                RelativePath=".\KMLDataLoader.cpp" 
     549                > 
     550            </File> 
     551            <File 
     552                RelativePath=".\KMLNetworkLinkResource.cpp" 
     553                > 
     554            </File> 
     555            <File 
    548556                RelativePath=".\LibkmlContainerBase.cpp" 
    549557                > 
     
    732740            </File> 
    733741            <File 
     742                RelativePath=".\KMLDataLoader.h" 
     743                > 
     744            </File> 
     745            <File 
     746                RelativePath=".\KMLNetworkLinkResource.h" 
     747                > 
     748            </File> 
     749            <File 
     750                RelativePath=".\KMLResource.h" 
     751                > 
     752            </File> 
     753            <File 
    734754                RelativePath=".\LibkmlContainerBase.h" 
    735755                > 
  • FalconView/trunk/public/fvw_core/GeodataDataSources/LibkmlDataSource.cpp

    r2267 r2277  
    387387      std::string resolved_path(path); 
    388388 
    389       if (m_kml_file_path) 
     389      if (m_kml_file_path.size()) 
    390390      { 
    391391         // path is possibly relative to the path / URL of the file from which this was loaded 
    392          resolved_path = CUtilityMethods::ResolveURI(m_kml_file_path, path); 
     392         resolved_path = CUtilityMethods::ResolveURI(m_kml_file_path.c_str(), path); 
    393393      } 
    394394       
     
    441441 
    442442      // return a cached image, if there is one 
    443       STRING_TO_VARIANT_MAP::iterator iter = m_imageCache.find(identifierAsChar); 
     443      STRING_TO_VARIANT_MAP::iterator iter = m_imageCache.begin(); //find(identifierAsChar); 
    444444      if (iter != m_imageCache.end()) 
    445445      { 
     
    528528 
    529529      // load the KML into this object 
    530       LoadKML(file_data, url_cstr); 
     530      WrapKMLFile(LoadKML(file_data, url_cstr)); 
    531531   } 
    532532   CATCH_BLOCK_RET 
     
    563563   __ensure_not_released(); 
    564564 
    565    if (m_kml_file_path) 
    566    { 
    567       _bstr_t u(m_kml_file_path); 
    568       *url = u.Detach(); 
     565   if (m_kml_file_path.size()) 
     566   { 
     567      *url = _bstr_t(m_kml_file_path.c_str()).Detach(); 
    569568   } 
    570569   else 
     
    607606} 
    608607 
    609 void CLibkmlDataSource::LoadKML(std::string &kml, const char* path) // path may be a URL, if this was opened from a URL 
     608kmlengine::KmlFilePtr CLibkmlDataSource::LoadKML(std::string &kml, const char* path) // path may be a URL, if this was opened from a URL 
    610609{ 
    611610   // CreateFromParse creates some pseudo-memory leaks.  These "leaks" do not grow and are not a problem. 
     
    652651   // save the path to the file 
    653652 
    654    if (m_kml_file_path) 
    655       delete[] m_kml_file_path; 
    656  
    657653   if (path) 
    658    { 
    659       size_t s = strlen(path) + 1; 
    660       m_kml_file_path = new char[s]; 
    661       memcpy(m_kml_file_path, path, s); 
    662    } 
    663  
     654      m_kml_file_path = path; 
     655 
     656   return kml_file; 
     657} 
     658 
     659void CLibkmlDataSource::WrapKMLFile(const kmlengine::KmlFilePtr& kml_file) 
     660{ 
    664661   // wrap the root element (must be a data source type) 
    665662   kmldom::ElementPtr root = kml_file->get_root(); 
     
    923920         (*iter)->DataSourceChanged(); 
    924921      } 
    925       catch (...) 
     922      catch (_com_error& ) 
    926923      { 
    927924         std::string msg("an exception was caught in making a callback on IFvDataSourceCallback"); 
  • FalconView/trunk/public/fvw_core/GeodataDataSources/LibkmlDataSource.h

    r2267 r2277  
    4747{ 
    4848public: 
    49    CLibkmlDataSource() : m_root_element(NULL), m_kml_file_path(NULL), m_internalRefs(0), m_factory(NULL), m_b_objectFinalReleased(false), 
     49   CLibkmlDataSource() : m_root_element(NULL), m_internalRefs(0), m_factory(NULL), m_b_objectFinalReleased(false), 
    5050      m_visible(VARIANT_TRUE), m_expanded(VARIANT_TRUE) {} 
    5151 
     
    8787      __ensure_not_released(); 
    8888      CInternalObjectRegistry::UnregisterObject(m_handle); 
    89       if (m_kml_file_path) 
    90          delete[] m_kml_file_path; 
    9189      m_b_objectFinalReleased = true; 
    9290    } 
     
    120118 
    121119   void FetchDataRelativeToDataSource(const char* path, std::string& out_string); 
    122    void LoadKML(std::string &kml, const char* path); 
     120   kmlengine::KmlFilePtr LoadKML(std::string &kml, const char* path); 
     121   void WrapKMLFile(const kmlengine::KmlFilePtr& kml_file); 
     122 
     123   void SetKmlFilePath(const std::string& path) { m_kml_file_path = path; } 
    123124 
    124125   // ILibkmlDataSource Methods 
     
    181182   LONG m_handle; 
    182183   IFvDataSourcePtr m_root_element; 
    183    char *m_kml_file_path; // this may be a file path our a URL, may be NULL if KMZ 
     184   std::string m_kml_file_path; // this may be a file path our a URL, may be NULL if KMZ 
    184185   kmlengine::KmzFilePtr m_kmz_file; // populate this if KMZ 
    185186   ULONG m_internalRefs; 
  • 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); 
  • FalconView/trunk/public/fvw_core/GeodataDataSources/LibkmlNetworkLink.h

    r2270 r2277  
    2525#include "InternalObjectRegistry.h" 
    2626#include "ComErrorHandler.h" 
     27#include "KMLNetworkLinkResource.h" 
    2728 
    2829#include "kml/dom.h" 
     
    4748{ 
    4849public: 
    49    CLibkmlNetworkLink() : m_wrappedDataSource(NULL), m_bFirstAttemptToLoad(TRUE), 
     50   CLibkmlNetworkLink() : m_bFirstAttemptToLoad(TRUE), 
    5051      m_leftLon(-180.0), m_bottomLat(-90.0), m_rightLon(180.0), m_topLat(90.0), 
    51       m_degreesPerPixelX(-1.0), m_degreesPerPixelY(-1.0) {} 
     52      m_degreesPerPixelX(-1.0), m_degreesPerPixelY(-1.0), m_networkLinkResource(this) {} 
    5253 
    5354DECLARE_REGISTRY_RESOURCEID(IDR_LIBKMLNETWORKLINK) 
     
    126127   void PopulateWrappedDataSourceAsNecessary(); 
    127128 
     129   CKMLNetworkLinkResource m_networkLinkResource; 
     130 
    128131   LONG m_handle; 
    129132   ILibkmlDataSourcePtr m_rootDS; 
    130133   kmldom::NetworkLinkPtr m_networkLink; 
    131    IFvDataSourcePtr m_wrappedDataSource; 
     134    
    132135   BOOL m_bFirstAttemptToLoad; // used to prevent firing data source changed notice the first time it's loaded 
    133136 
  • FalconView/trunk/public/fvw_core/GeodataDataSources/stdafx.h

    r2268 r2277  
    8282typedef std::vector<ILinearRingPtr> LINEAR_RING_VECTOR; 
    8383 
     84#include <queue> 
     85 
    8486#define MEM_FILE_NAME_MAX_LENGTH 40 
    8587