Changeset 48 for trunk/Utilities/MaxMindGeoLite/Location.h
- Timestamp:
- Feb 11, 2012, 2:26:24 PM (11 years ago)
- Location:
- trunk/Utilities/MaxMindGeoLite
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Utilities/MaxMindGeoLite
- Property svn:ignore
-
old new 3 3 *.suo 4 4 *.sdf 5 *.opensdf
-
- Property svn:ignore
-
trunk/Utilities/MaxMindGeoLite/Location.h
r47 r48 230 230 231 231 //////////////////////////////////////////////////////////// 232 // CFreeThreadedMarshaler 233 234 class CFreeThreadedMarshaler 235 { 236 private: 237 CComPtr<IUnknown> m_pMarshalerUnknown; 238 CComPtr<IMarshal> m_pMarshalerMarshal; 239 240 public: 241 // CFreeThreadedMarshaler 242 const CComPtr<IMarshal>& operator -> () const throw() 243 { 244 return GetMarshal(); 245 } 246 VOID Initialize() 247 { 248 _A(!m_pMarshalerUnknown && !m_pMarshalerMarshal); 249 __C(CoCreateFreeThreadedMarshaler(NULL, &m_pMarshalerUnknown)); 250 m_pMarshalerMarshal = m_pMarshalerUnknown; 251 __D(m_pMarshalerMarshal, E_NOINTERFACE); 252 } 253 VOID Terminate() throw() 254 { 255 m_pMarshalerMarshal = NULL; 256 m_pMarshalerUnknown = NULL; 257 } 258 const CComPtr<IMarshal>& GetMarshal() const throw() 259 { 260 return m_pMarshalerMarshal; 261 } 262 }; 263 264 //////////////////////////////////////////////////////////// 232 265 // CLocations 233 266 … … 235 268 public CComObjectRootEx<CComMultiThreadModelNoCS>, 236 269 public CComCoClass<CLocations, &__uuidof(Locations)>, 237 public CBasePersistT<CLocations>,238 //public IRoPersistStreamInitT<CLocations>,239 //public IRoPersistStorageT<CLocations>,240 //public IRoPersistPropertyBagT<CLocations>,241 //public IRoSpecifyPropertyPagesT<CLocations>,242 270 public IDispatchImpl<ILocations> 243 271 { … … 247 275 //DECLARE_REGISTRY_RESOURCEID(IDR) 248 276 277 DECLARE_CLASSFACTORY_SINGLETON(CLocations) 278 249 279 DECLARE_PROTECT_FINAL_CONSTRUCT() 250 280 251 281 BEGIN_COM_MAP(CLocations) 252 //COM_INTERFACE_ENTRY_IID(__uuidof(IPersist), IPersistStreamInit)253 //COM_INTERFACE_ENTRY_IID(__uuidof(IPersistStream), IPersistStreamInit)254 //COM_INTERFACE_ENTRY(IPersistStreamInit)255 //COM_INTERFACE_ENTRY(IPersistStorage)256 //COM_INTERFACE_ENTRY(IPersistPropertyBag)257 //COM_INTERFACE_ENTRY(ISpecifyPropertyPages)258 282 COM_INTERFACE_ENTRY(ILocations) 259 283 COM_INTERFACE_ENTRY(IDispatch) 284 COM_INTERFACE_ENTRY_AGGREGATE(__uuidof(IMarshal), m_FreeThreadedMarshaler) 260 285 END_COM_MAP() 261 262 BEGIN_PROP_MAP(CLocations)263 END_PROP_MAP()264 286 265 287 public: … … 427 449 private: 428 450 CWindowsSockets2 m_Sockets; 429 C RequiresSave m_bRequiresSave;430 mutable CRoCriticalSection m_DataCriticalSection;451 CFreeThreadedMarshaler m_FreeThreadedMarshaler; 452 //mutable CRoCriticalSection m_DataCriticalSection; 431 453 GeoLiteCity::CLocationArray m_LocationArray; 432 454 GeoLiteCity::CBlockArray m_BlockArray; … … 451 473 return S_OK; 452 474 } 453 CLocations() throw() : 454 CBasePersistT<CLocations>(m_DataCriticalSection), 455 m_bRequiresSave(m_DataCriticalSection) 475 CLocations() throw() 456 476 { 457 477 _Z4(atlTraceRefcount, 4, _T("this 0x%p\n"), this); … … 466 486 { 467 487 __C(m_Sockets.GetStartupResult()); 488 m_FreeThreadedMarshaler.Initialize(); 468 489 Initialize(); 469 490 } … … 476 497 VOID FinalRelease() throw() 477 498 { 499 m_FreeThreadedMarshaler.Terminate(); 478 500 } 479 501 VOID Initialize() … … 490 512 } 491 513 492 // ILocation 514 // ILocations 493 515 STDMETHOD(get_Item)(VARIANT vIndex, ILocation** ppLocation) throw() 494 516 { … … 529 551 530 552 OBJECT_ENTRY_AUTO(__uuidof(Locations), CLocations) 553 554 //////////////////////////////////////////////////////////// 555 // CLazyLocations 556 557 class ATL_NO_VTABLE CLazyLocations : 558 public CComObjectRootEx<CComMultiThreadModelNoCS>, 559 public CComCoClass<CLazyLocations, &__uuidof(LazyLocations)>, 560 public IDispatchImpl<ILazyLocations> 561 { 562 typedef CThreadT<CLazyLocations> CThread; 563 564 public: 565 enum { IDR = IDR_LAZYLOCATIONS }; 566 567 //DECLARE_REGISTRY_RESOURCEID(IDR) 568 569 DECLARE_CLASSFACTORY_SINGLETON(CLazyLocations) 570 571 DECLARE_PROTECT_FINAL_CONSTRUCT() 572 573 BEGIN_COM_MAP(CLazyLocations) 574 COM_INTERFACE_ENTRY(ILazyLocations) 575 COM_INTERFACE_ENTRY_IID(__uuidof(IDispatch), ILazyLocations) 576 COM_INTERFACE_ENTRY(ILocations) 577 COM_INTERFACE_ENTRY_AGGREGATE(__uuidof(IMarshal), m_FreeThreadedMarshaler) 578 END_COM_MAP() 579 580 private: 581 CFreeThreadedMarshaler m_FreeThreadedMarshaler; 582 mutable CRoCriticalSection m_ThreadCriticalSection; 583 CObjectPtr<CThread> m_pThread; 584 mutable CRoCriticalSection m_DataCriticalSection; 585 CObjectPtr<CLocations> m_pLocations; 586 587 DWORD ThreadProc(CThread* pThread, CEvent& InitializationEvent, CEvent& TerminationEvent) 588 { 589 CMultiThreadedApartment MultiThreadedApartment; 590 _W(InitializationEvent.Set()); 591 CComPtr<ILocations> pLocations; 592 __C(pLocations.CoCreateInstance(__uuidof(Locations))); 593 const CObjectPtr<CLocations> pNativeLocations = static_cast<CLocations*>((ILocations*) pLocations); 594 _A(pNativeLocations); 595 { 596 CRoCriticalSectionLock DataLock(m_DataCriticalSection); 597 _A(!m_pLocations); 598 m_pLocations = pNativeLocations; 599 } 600 TerminationEvent; 601 CRoCriticalSectionLock ThreadLock(m_ThreadCriticalSection); 602 _A(m_pThread == pThread || !m_pThread && WaitForSingleObject(TerminationEvent, 0) == WAIT_OBJECT_0); 603 m_pThread.Release(); 604 return 0; 605 } 606 607 public: 608 // CLazyLocations 609 static CString GetObjectFriendlyName() 610 { 611 return _StringHelper::GetLine(IDR, 2); 612 } 613 static HRESULT WINAPI UpdateRegistry(BOOL bRegister) throw() 614 { 615 _Z2(atlTraceRegistrar, 2, _T("bRegister %d\n"), bRegister); 616 _ATLTRY 617 { 618 UpdateRegistryFromResource<CLazyLocations>(bRegister); 619 } 620 _ATLCATCH(Exception) 621 { 622 _C(Exception); 623 } 624 return S_OK; 625 } 626 CLazyLocations() throw() 627 { 628 _Z4(atlTraceRefcount, 4, _T("this 0x%p\n"), this); 629 } 630 ~CLazyLocations() throw() 631 { 632 _Z4(atlTraceRefcount, 4, _T("this 0x%p\n"), this); 633 } 634 HRESULT FinalConstruct() throw() 635 { 636 _ATLTRY 637 { 638 CRoCriticalSectionLock ThreadLock(m_ThreadCriticalSection); 639 CObjectPtr<CThread> pThread; 640 __E(pThread.Construct()->Initialize(this, &CLazyLocations::ThreadProc)); 641 m_pThread = pThread; 642 } 643 _ATLCATCH(Exception) 644 { 645 _C(Exception); 646 } 647 return S_OK; 648 } 649 VOID FinalRelease() throw() 650 { 651 CObjectPtr<CThread> pThread; 652 { 653 CRoCriticalSectionLock ThreadLock(m_ThreadCriticalSection); 654 m_pThread.Swap(pThread); 655 } 656 } 657 CObjectPtr<CLocations> GetLocations() const throw() 658 { 659 CRoCriticalSectionLock DataLock(m_DataCriticalSection); 660 return m_pLocations; 661 } 662 663 // ILazyLocations 664 STDMETHOD(get_Initialized)(VARIANT_BOOL* pbInitialized) throw() 665 { 666 _Z4(atlTraceCOM, 4, _T("...\n")); 667 _ATLTRY 668 { 669 __D(pbInitialized, E_POINTER); 670 //ObjectLock Lock(this); 671 //CRoCriticalSectionLock DataLock(m_DataCriticalSection); 672 *pbInitialized = GetLocations() ? ATL_VARIANT_TRUE : ATL_VARIANT_FALSE; 673 } 674 _ATLCATCH(Exception) 675 { 676 _C(Exception); 677 } 678 return S_OK; 679 } 680 681 // ILocations 682 STDMETHOD(get_Item)(VARIANT vIndex, ILocation** ppLocation) throw() 683 { 684 _Z4(atlTraceCOM, 4, _T("vIndex.vt 0x%x\n"), vIndex.vt); 685 _ATLTRY 686 { 687 __D(ppLocation, E_POINTER); 688 __D(vIndex.vt == VT_BSTR, E_INVALIDARG); 689 //ObjectLock Lock(this); 690 //CRoCriticalSectionLock DataLock(m_DataCriticalSection); 691 CComPtr<ILocation> pLocation; 692 const CObjectPtr<CLocations> pLocations = GetLocations(); 693 if(pLocations) 694 __C(pLocations->get_Item(vIndex, &pLocation)); 695 *ppLocation = pLocation.Detach(); 696 } 697 _ATLCATCH(Exception) 698 { 699 _C(Exception); 700 } 701 return S_OK; 702 } 703 }; 704 705 OBJECT_ENTRY_AUTO(__uuidof(LazyLocations), CLazyLocations)
Note: See TracChangeset
for help on using the changeset viewer.