Changeset 2279

Show
Ignore:
Timestamp:
03/05/10 14:16:21 (5 months ago)
Author:
gm78
Message:

Added threaded loading of KML images.

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

Legend:

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

    r2277 r2279  
    550550            </File> 
    551551            <File 
     552                RelativePath=".\KMLImageDataResource.cpp" 
     553                > 
     554            </File> 
     555            <File 
    552556                RelativePath=".\KMLNetworkLinkResource.cpp" 
    553557                > 
     
    744748            </File> 
    745749            <File 
     750                RelativePath=".\KMLImageDataResource.h" 
     751                > 
     752            </File> 
     753            <File 
    746754                RelativePath=".\KMLNetworkLinkResource.h" 
    747755                > 
  • FalconView/trunk/public/fvw_core/GeodataDataSources/KMLResource.h

    r2277 r2279  
    1515 
    1616   IStream* m_pMarshalingStream; 
    17    IFvDataSourceCallbackPtr m_marshaledCallback; 
    1817 
    1918public: 
     
    3635      { 
    3736         // create IStream used for marshalling 
    38          m_marshaledCallback = NULL; 
     37         m_pMarshalingStream = NULL; 
    3938         THROW_IF_NOT_OK(::CoMarshalInterThreadInterfaceInStream(IID_IFvDataSourceCallback,  
    4039            pDataSourceCallback, &m_pMarshalingStream)); 
     
    5150       try 
    5251       { 
    53           // marshall the IDisplayChangeNotifyEvents interface to this thread 
    54           HRESULT hr = ::CoGetInterfaceAndReleaseStream(m_pMarshalingStream,  
    55              IID_IFvDataSourceCallback, reinterpret_cast<void **>(&m_marshaledCallback)); 
     52          if (m_pMarshalingStream != NULL) 
     53          { 
     54             // marshall the IDisplayChangeNotifyEvents interface to this thread 
     55             IFvDataSourceCallbackPtr marshaledCallback; 
    5656 
    57           if (m_marshaledCallback != NULL) 
    58              m_marshaledCallback->DataSourceChanged(); 
     57             HRESULT hr = ::CoGetInterfaceAndReleaseStream(m_pMarshalingStream,  
     58                IID_IFvDataSourceCallback, reinterpret_cast<void **>(&marshaledCallback)); 
     59 
     60             if (marshaledCallback != NULL) 
     61                marshaledCallback->DataSourceChanged(); 
     62          } 
    5963       } 
    6064       catch(_com_error &) 
  • FalconView/trunk/public/fvw_core/GeodataDataSources/LibkmlDataSource.cpp

    r2277 r2279  
    3838#include "kml/base/file.h" 
    3939#include "kml/base/uri_parser.h" 
     40#include "KMLImageDataResource.h" 
     41#include "KMLDataLoader.h" 
    4042 
    4143// CLibkmlDataSource 
    42  
    43 /* static */ ULONG CLibkmlDataSource::s_nextMemFile = 0; 
    4444 
    4545STDMETHODIMP CLibkmlDataSource::raw_Open(BSTR file) 
     
    441441 
    442442      // return a cached image, if there is one 
    443       STRING_TO_VARIANT_MAP::iterator iter = m_imageCache.begin(); //find(identifierAsChar); 
    444       if (iter != m_imageCache.end()) 
    445       { 
    446          // return the cached image 
    447          *imageData = _variant_t(iter->second).Detach(); // copies buffer to imageData 
     443      CKMLImageDataResource* pCachedImage = m_imageCache.Find(identifierAsChar); 
     444      if (pCachedImage != NULL) 
     445      { 
     446         pCachedImage->GetImageData(imageData); 
    448447         return S_OK; 
    449448      } 
    450449 
    451       // no image cached 
    452  
    453       // fetch the image data 
    454       std::string file_contents; 
    455       FetchDataRelativeToDataSource(identifierAsChar, file_contents); 
    456       char mem_file_name[MEM_FILE_NAME_MAX_LENGTH]; 
    457       sprintf_s(mem_file_name, MEM_FILE_NAME_MAX_LENGTH, "/vsimem/LibkmlDSMemFile%u", s_nextMemFile++); 
    458       VSIFCloseL(VSIFileFromMemBuffer(mem_file_name, (GByte*)file_contents.c_str(), file_contents.length(), FALSE)); 
    459  
    460       // use GDAL to interpret the raw data 
    461       IFvGDALDataSetPtr GDALDataset(CLSID_FvGDALDataSet); 
    462       GDALDataset->Open(_bstr_t(mem_file_name)); 
    463       IRasterDataSetPtr raster = GDALDataset; 
    464       *imageData = raster->InterpretAsImage().Detach(); 
    465       VSIUnlink(mem_file_name); 
    466  
    467       // cache the image 
    468       m_imageCache[identifierAsChar] = _variant_t(imageData); // copies imageData to buffer 
    469    } 
    470    CATCH_BLOCK_RET 
    471  
     450      // no image cached.  we'll create a resource for the image and 
     451      // load it in a background thread 
     452      CKMLImageDataResource* imageDataResource = new CKMLImageDataResource(this, identifierAsChar); 
     453      m_imageCache.Insert(identifierAsChar, imageDataResource); 
     454      CKMLDataLoader::GetInstance()->AddLoadRequest(this, imageDataResource); 
     455 
     456      imageDataResource->GetImageData(imageData); 
     457   } 
     458   CATCH_BLOCK_RET 
     459 
     460   return S_OK; 
     461} 
     462 
     463STDMETHODIMP CLibkmlDataSource::raw_DataSourceChanged() 
     464{ 
     465   FireDataSourceChanged(m_handle); 
    472466   return S_OK; 
    473467} 
     
    956950   return S_OK; 
    957951} 
     952 
     953 
     954void CKmlImageCache::Insert(const std::string& imageId, CKMLImageDataResource *pResource) 
     955{ 
     956   // add smarts here to manage resource quotas in the cache  
     957   // 
     958 
     959   m_imageCache[imageId] = pResource; 
     960} 
     961 
     962CKMLImageDataResource* CKmlImageCache::Find(const std::string& imageId) 
     963{ 
     964   std::map<std::string, CKMLImageDataResource*>::iterator it = m_imageCache.find(imageId); 
     965   if (it == m_imageCache.end()) 
     966      return NULL; 
     967 
     968   return it->second; 
     969} 
     970 
     971void CKmlImageCache::Clear() 
     972{ 
     973   std::map<std::string, CKMLImageDataResource*>::iterator it = m_imageCache.begin(); 
     974   for(; it != m_imageCache.end(); ++it) 
     975      delete it->second; 
     976} 
  • FalconView/trunk/public/fvw_core/GeodataDataSources/LibkmlDataSource.h

    r2277 r2279  
    3131#error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms." 
    3232#endif 
     33 
     34class CKMLImageDataResource; 
     35 
     36class CKmlImageCache 
     37{ 
     38   std::map<std::string, CKMLImageDataResource*> m_imageCache; 
     39    
     40public: 
     41   void Insert(const std::string& imageId, CKMLImageDataResource *pResource); 
     42   CKMLImageDataResource* Find(const std::string& imageId); 
     43   void Clear(); 
     44}; 
    3345 
    3446// CLibkmlDataSource 
     
    4456   public IDispatchImpl<IFvDataSourceEdit, &__uuidof(IFvDataSourceEdit), &LIBID_FvDataSourcesLib, /* wMajor = */ 1, /* wMinor = */ 0>, 
    4557   public IDispatchImpl<IUIState, &__uuidof(IUIState), &LIBID_FvDataSourcesLib, /* wMajor = */ 1, /* wMinor = */ 0>, 
     58   public IDispatchImpl<IFvDataSourceCallback, &__uuidof(IUIState), &LIBID_FvDataSourcesLib, /* wMajor = */ 1, /* wMinor = */ 0>, 
    4659   public CComErrorHandler 
    4760{ 
     
    7184   COM_INTERFACE_ENTRY(IRegionatedKMLContainer) 
    7285    COM_INTERFACE_ENTRY(IUIState) 
     86   COM_INTERFACE_ENTRY(IFvDataSourceCallback) 
    7387END_COM_MAP() 
    7488 
     
    88102      CInternalObjectRegistry::UnregisterObject(m_handle); 
    89103      m_b_objectFinalReleased = true; 
     104 
     105      m_imageCache.Clear(); 
    90106    } 
    91107 
     
    157173   STDMETHOD(raw_GetImageByIdentifier)(BSTR identifier, VARIANT* imageData); 
    158174 
     175   // IFvDataSourceCallback Methods 
     176public: 
     177   STDMETHOD(raw_DataSourceChanged)(); 
     178 
    159179   // IFvDataSourceEdit Methods 
    160180public: 
     
    185205   kmlengine::KmzFilePtr m_kmz_file; // populate this if KMZ 
    186206   ULONG m_internalRefs; 
    187    STRING_TO_VARIANT_MAP m_imageCache; 
     207   CKmlImageCache m_imageCache; 
    188208   DATA_SOURCE_CALLBACK_VECTOR m_callbacks; 
    189209   bool m_b_objectFinalReleased; 
     
    200220   static std::string s_dumpFile; 
    201221   static void MaybeDumpKML(std::string& kml); 
    202  
    203    static ULONG s_nextMemFile; 
    204222}; 
    205223 
  • FalconView/trunk/public/fvw_core/GeodataDataSources/UtilityMethods.h

    r2242 r2279  
    146146   STDMETHOD(raw_GetLeakData)(VARIANT* leakData); 
    147147 
    148    static ULONG s_nextMemFile; 
    149  
    150148   static OGRPoint* Copy2OGR(IPoint* point); 
    151149   static OGRLineString* Copy2OGR(ILineString* lineString);