Changeset 49


Ignore:
Timestamp:
Feb 11, 2012, 2:47:53 PM (12 years ago)
Author:
roman
Message:

singletons, lazy initialization singleton, free threaded marhsaler, x64

Location:
trunk/Utilities/MaxMindGeoLite
Files:
4 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Utilities/MaxMindGeoLite/Location.h

    r48 r49  
    262262};
    263263
     264////////////////////////////////////////////////////
     265// CDispatchExT
     266//
     267// TODO: IDispatch methods should take care of IID argument
     268
     269template <typename T>
     270class ATL_NO_VTABLE CDispatchExT :
     271        public IDispatchEx
     272{
     273public:
     274
     275        ////////////////////////////////////////////////////////
     276        // CDispatchData
     277
     278        class CDispatchData
     279        {
     280        public:
     281                IID m_InterfaceIdentifier;
     282                IDispatch* m_pDispatch;
     283
     284        public:
     285        // CDispatchData
     286                CDispatchData() throw() :
     287                        m_InterfaceIdentifier(IID_NULL),
     288                        m_pDispatch(NULL)
     289                {
     290                }
     291                CDispatchData(IDispatchEx* pDispatchEx, const IID& InterfaceIdentifier)
     292                {
     293                        CComPtr<IDispatch> pDispatch;
     294                        __C(pDispatchEx->QueryInterface(InterfaceIdentifier, (VOID**) &pDispatch));
     295                        m_InterfaceIdentifier = InterfaceIdentifier;
     296                        m_pDispatch = pDispatch;
     297                }
     298        };
     299
     300private:
     301        CRoArrayT<CDispatchData> m_DispatchDataArray;
     302
     303public:
     304// CDispatchExT
     305        VOID ResetDispatchInterfaceIdentifiers() throw()
     306        {
     307                m_DispatchDataArray.RemoveAll();
     308        }
     309        VOID SetDispatchInterfaceIdentifiers(const IID* pInterfaceIdentifiers, SIZE_T nInterfaceIdentifierCount)
     310        {
     311                _A(m_DispatchDataArray.IsEmpty());
     312                for(SIZE_T nIndex = 0; nIndex < nInterfaceIdentifierCount; nIndex++)
     313                        _W(m_DispatchDataArray.Add(CDispatchData(this, pInterfaceIdentifiers[nIndex])) >= 0);
     314        }
     315        VOID SetDispatchInterfaceIdentifiers(const IID& InterfaceIdentifier)
     316        {
     317                SetDispatchInterfaceIdentifiers(&InterfaceIdentifier, 1);
     318        }
     319        VOID SetDispatchInterfaceIdentifiers(SIZE_T nInterfaceIdentifierCount, ...)
     320        {
     321                _A(nInterfaceIdentifierCount);
     322                va_list Arguments;
     323                va_start(Arguments, nInterfaceIdentifierCount);
     324                CTempBufferT<IID> pInterfaceIdentifiers(nInterfaceIdentifierCount);
     325                for(SIZE_T nIndex = 0; nIndex < nInterfaceIdentifierCount; nIndex++)
     326                        pInterfaceIdentifiers[nIndex] = *va_arg(Arguments, IID*);
     327                va_end(Arguments);
     328                SetDispatchInterfaceIdentifiers(pInterfaceIdentifiers, nInterfaceIdentifierCount);
     329        }
     330        IDispatch* GetDispatch(DISPID nDispIdentifier) const throw()
     331        {
     332                const SIZE_T nDispatchIndex = (UINT) (nDispIdentifier >> 12);
     333                _A(nDispatchIndex < m_DispatchDataArray.GetCount());
     334                return m_DispatchDataArray[nDispatchIndex].m_pDispatch;
     335        }
     336
     337// IDispatchEx
     338        STDMETHOD(GetDispID)(BSTR sName, DWORD nFlags, DISPID* pid) throw()
     339        {
     340                _Z4(atlTraceCOM, 4, _T("this 0x%p, sName \"%s\", nFlags 0x%x\n"), static_cast<T*>(this), CString(sName), nFlags);
     341                _ATLTRY
     342                {
     343                        __D(pid, E_POINTER);
     344                        nFlags;
     345                        OLECHAR* ppszNames[] = { const_cast<OLECHAR*>(sName), };
     346                        const LCID nLocaleIdentifier = GetThreadLocale();
     347                        *pid = -1;
     348                        HRESULT nResult = DISP_E_UNKNOWNNAME;
     349                        for(SIZE_T nIndex = 0; nIndex < m_DispatchDataArray.GetCount(); nIndex++)
     350                        {
     351                                DISPID nDispatchDispIdentifier;
     352                                const HRESULT nDispatchResult = m_DispatchDataArray[nIndex].m_pDispatch->GetIDsOfNames(IID_NULL, ppszNames, DIM(ppszNames), nLocaleIdentifier, &nDispatchDispIdentifier);
     353                                if(SUCCEEDED(nDispatchResult))
     354                                {
     355                                        _A(!(nDispatchDispIdentifier & ~0x0FFF));
     356                                        *pid = (DISPID) (nIndex << 12) + nDispatchDispIdentifier;
     357                                        nResult = nDispatchResult;
     358                                        break;
     359                                }
     360                        }
     361                        _Z4(atlTraceGeneral, 4, _T("nResult 0x%08x, *pid %d\n"), nResult, *pid);
     362                        return nResult;
     363                }
     364                _ATLCATCH(Exception)
     365                {
     366                        _C(Exception);
     367                }
     368                return E_NOTIMPL;
     369        }
     370        STDMETHOD(InvokeEx)(DISPID id, LCID nLocaleIdentifier, WORD nFlags, DISPPARAMS* pdp, VARIANT* pvarRes, EXCEPINFO* pei, IServiceProvider* pServiceProvider) throw()
     371        {
     372                _Z4(atlTraceCOM, 4, _T("this 0x%p, id %d, nLocaleIdentifier %d, nFlags 0x%x\n"), static_cast<T*>(this), id, nLocaleIdentifier, nFlags);
     373                _ATLTRY
     374                {
     375                        pServiceProvider;
     376                        UINT nErroneousArgument;
     377                        _A((id & ~0xFFFF) == 0);
     378                        const HRESULT nResult = GetDispatch(id)->Invoke(id & 0x0FFF, IID_NULL, nLocaleIdentifier, nFlags, pdp, pvarRes, pei, &nErroneousArgument);
     379                        _Z4(atlTraceGeneral, 4, _T("nResult 0x%08x\n"), nResult);
     380                        return nResult;
     381                }
     382                _ATLCATCH(Exception)
     383                {
     384                        _C(Exception);
     385                }
     386                return E_NOTIMPL;
     387        }
     388        STDMETHOD(DeleteMemberByName)(BSTR sName, DWORD nFlags) throw()
     389        {
     390                _Z4(atlTraceCOM, 4, _T("this 0x%p, sName \"%s\", nFlags 0x%x\n"), static_cast<T*>(this), CString(sName), nFlags);
     391                return E_NOTIMPL;
     392        }
     393        STDMETHOD(DeleteMemberByDispID)(DISPID id) throw()
     394        {
     395                _Z4(atlTraceCOM, 4, _T("this 0x%p, id %d\n"), static_cast<T*>(this), id);
     396                return E_NOTIMPL;
     397        }
     398        STDMETHOD(GetMemberProperties)(DISPID id, DWORD nFlagMask, DWORD* pnFlags) throw()
     399        {
     400                _Z4(atlTraceCOM, 4, _T("this 0x%p, id %d, nFlagMask 0x%x\n"), static_cast<T*>(this), id, nFlagMask);
     401                return E_NOTIMPL;
     402        }
     403        STDMETHOD(GetMemberName)(DISPID id, BSTR* psName) throw()
     404        {
     405                _Z4(atlTraceCOM, 4, _T("this 0x%p, id %d\n"), static_cast<T*>(this), id);
     406                return E_NOTIMPL;
     407        }
     408        STDMETHOD(GetNextDispID)(DWORD nFlags, DISPID id, DISPID* pid) throw()
     409        {
     410                _Z4(atlTraceCOM, 4, _T("this 0x%p, nFlags 0x%x, id %d\n"), static_cast<T*>(this), nFlags, id);
     411                return E_NOTIMPL;
     412        }
     413        STDMETHOD(GetNameSpaceParent)(IUnknown** ppunk) throw()
     414        {
     415                _Z4(atlTraceCOM, 4, _T("this 0x%p\n"), static_cast<T*>(this));
     416                return E_NOTIMPL;
     417        }
     418
     419// IDispatch
     420        STDMETHOD(GetTypeInfoCount)(UINT* pnCount) throw()
     421        {
     422                _Z4(atlTraceCOM, 4, _T("this 0x%p\n"), static_cast<T*>(this));
     423                _ATLTRY
     424                {
     425                        const HRESULT nResult = GetDispatch(0)->GetTypeInfoCount(pnCount);
     426                        _Z4(atlTraceGeneral, 4, _T("nResult 0x%08x\n"), nResult);
     427                        return nResult;
     428                }
     429                _ATLCATCH(Exception)
     430                {
     431                        _C(Exception);
     432                }
     433                return E_NOTIMPL;
     434        }
     435        STDMETHOD(GetTypeInfo)(UINT nIndex, LCID nLocaleIdentifier, ITypeInfo** ppTypeInfo) throw()
     436        {
     437                _Z4(atlTraceCOM, 4, _T("this 0x%p, nIndex %d, nLocaleIdentifier %d\n"), static_cast<T*>(this), nIndex, nLocaleIdentifier);
     438                _ATLTRY
     439                {
     440                        const HRESULT nResult = GetDispatch(0)->GetTypeInfo(nIndex, nLocaleIdentifier, ppTypeInfo);
     441                        _Z4(atlTraceGeneral, 4, _T("nResult 0x%08x\n"), nResult);
     442                        return nResult;
     443                }
     444                _ATLCATCH(Exception)
     445                {
     446                        _C(Exception);
     447                }
     448                return E_NOTIMPL;
     449        }
     450        STDMETHOD(GetIDsOfNames)(REFIID InterfaceIdentifier, LPOLESTR* ppszNames, UINT nNameCount, LCID nLocaleIdentifier, DISPID* rgDispId) throw()
     451        {
     452                _Z4(atlTraceCOM, 4, _T("this 0x%p, nNameCount %d, nLocaleIdentifier %d\n"), static_cast<T*>(this), nNameCount, nLocaleIdentifier);
     453                _ATLTRY
     454                {
     455                        const HRESULT nResult = GetDispatch(0)->GetIDsOfNames(InterfaceIdentifier, ppszNames, nNameCount, nLocaleIdentifier, rgDispId);
     456                        _Z4(atlTraceGeneral, 4, _T("nResult 0x%08x\n"), nResult);
     457                        return nResult;
     458                }
     459                _ATLCATCH(Exception)
     460                {
     461                        _C(Exception);
     462                }
     463                return E_NOTIMPL;
     464        }
     465        STDMETHOD(Invoke)(DISPID dispIdMember, REFIID InterfaceIdentifier, LCID nLocaleIdentifier, WORD nFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr) throw()
     466        {
     467                _Z4(atlTraceCOM, 4, _T("this 0x%p, dispIdMember %d, nLocaleIdentifier %d, nFlags 0x%x\n"), static_cast<T*>(this), dispIdMember, nLocaleIdentifier, nFlags);
     468                _ATLTRY
     469                {
     470                        const HRESULT nResult = GetDispatch(0)->Invoke(dispIdMember, InterfaceIdentifier, nLocaleIdentifier, nFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
     471                        _Z4(atlTraceGeneral, 4, _T("nResult 0x%08x\n"), nResult);
     472                        return nResult;
     473                }
     474                _ATLCATCH(Exception)
     475                {
     476                        _C(Exception);
     477                }
     478                return E_NOTIMPL;
     479        }
     480};
     481
    264482////////////////////////////////////////////////////////////
    265483// CLocations
     
    558776        public CComObjectRootEx<CComMultiThreadModelNoCS>,
    559777        public CComCoClass<CLazyLocations, &__uuidof(LazyLocations)>,
    560         public IDispatchImpl<ILazyLocations>
     778        public IDispatchImpl<ILazyLocations>,
     779        public IDispatchImpl<ILocations>,
     780        public CDispatchExT<CLazyLocations>
    561781{
    562782        typedef CThreadT<CLazyLocations> CThread;
     
    573793BEGIN_COM_MAP(CLazyLocations)
    574794        COM_INTERFACE_ENTRY(ILazyLocations)
    575         COM_INTERFACE_ENTRY_IID(__uuidof(IDispatch), ILazyLocations)
    576795        COM_INTERFACE_ENTRY(ILocations)
     796        COM_INTERFACE_ENTRY_IID(__uuidof(IDispatch), ILocations)
     797        COM_INTERFACE_ENTRY(IDispatchEx)
    577798        COM_INTERFACE_ENTRY_AGGREGATE(__uuidof(IMarshal), m_FreeThreadedMarshaler)
    578799END_COM_MAP()
     
    636857                _ATLTRY
    637858                {
     859                        SetDispatchInterfaceIdentifiers(2, &__uuidof(ILazyLocations), &__uuidof(ILocations));
    638860                        CRoCriticalSectionLock ThreadLock(m_ThreadCriticalSection);
    639861                        CObjectPtr<CThread> pThread;
  • trunk/Utilities/MaxMindGeoLite/MaxMindGeoLite.idl

    r48 r49  
    4747        pointer_default(unique)
    4848]
    49 interface ILazyLocations : ILocations
     49interface ILazyLocations : IDispatch
    5050{
    5151        [propget, id(1)] HRESULT Initialized([out, retval] VARIANT_BOOL* pbInitialized);
  • trunk/Utilities/MaxMindGeoLite/MaxMindGeoLite_i.c

    r48 r49  
    77
    88 /* File created by MIDL compiler version 7.00.0555 */
    9 /* at Sun Feb 12 00:21:00 2012
     9/* at Sun Feb 12 00:46:15 2012
    1010 */
    1111/* Compiler settings for MaxMindGeoLite.idl:
  • trunk/Utilities/MaxMindGeoLite/MaxMindGeoLite_i.h

    r48 r49  
    55
    66 /* File created by MIDL compiler version 7.00.0555 */
    7 /* at Sun Feb 12 00:21:00 2012
     7/* at Sun Feb 12 00:46:15 2012
    88 */
    99/* Compiler settings for MaxMindGeoLite.idl:
     
    435435   
    436436    MIDL_INTERFACE("34BF53BB-D4C8-4002-A0EC-5BA70FE7ACA3")
    437     ILazyLocations : public ILocations
     437    ILazyLocations : public IDispatch
    438438    {
    439439    public:
     
    490490            /* [out] */ UINT *puArgErr);
    491491       
    492         /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_Item )(
    493             ILazyLocations * This,
    494             /* [in] */ VARIANT vIndex,
    495             /* [retval][out] */ ILocation **ppLocation);
    496        
    497492        /* [id][propget] */ HRESULT ( STDMETHODCALLTYPE *get_Initialized )(
    498493            ILazyLocations * This,
     
    533528#define ILazyLocations_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr)    \
    534529    ( (This)->lpVtbl -> Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) )
    535 
    536 
    537 #define ILazyLocations_get_Item(This,vIndex,ppLocation) \
    538     ( (This)->lpVtbl -> get_Item(This,vIndex,ppLocation) )
    539530
    540531
  • trunk/Utilities/MaxMindGeoLite/MaxMindGeoLite_p.c

    r48 r49  
    55
    66 /* File created by MIDL compiler version 7.00.0555 */
    7 /* at Sun Feb 12 00:21:00 2012
     7/* at Sun Feb 12 00:46:15 2012
    88 */
    99/* Compiler settings for MaxMindGeoLite.idl:
     
    407407                        0x6c,           /* Old Flags:  object, Oi2 */
    408408/* 332 */       NdrFcLong( 0x0 ),       /* 0 */
    409 /* 336 */       NdrFcShort( 0x8 ),      /* 8 */
     409/* 336 */       NdrFcShort( 0x7 ),      /* 7 */
    410410/* 338 */       NdrFcShort( 0xc ),      /* x86 Stack size/offset = 12 */
    411411/* 340 */       NdrFcShort( 0x0 ),      /* 0 */
     
    13751375    (unsigned short) -1,
    13761376    (unsigned short) -1,
    1377     288,
    13781377    330
    13791378    };
     
    14001399    0,
    14011400    0};
    1402 CINTERFACE_PROXY_VTABLE(9) _ILazyLocationsProxyVtbl =
     1401CINTERFACE_PROXY_VTABLE(8) _ILazyLocationsProxyVtbl =
    14031402{
    14041403    &ILazyLocations_ProxyInfo,
     
    14111410    0 /* IDispatch::GetIDsOfNames */ ,
    14121411    0 /* IDispatch_Invoke_Proxy */ ,
    1413     (void *) (INT_PTR) -1 /* ILocations::get_Item */ ,
    14141412    (void *) (INT_PTR) -1 /* ILazyLocations::get_Initialized */
    14151413};
     
    14221420    STUB_FORWARDING_FUNCTION,
    14231421    STUB_FORWARDING_FUNCTION,
    1424     NdrStubCall2,
    14251422    NdrStubCall2
    14261423};
     
    14301427    &IID_ILazyLocations,
    14311428    &ILazyLocations_ServerInfo,
    1432     9,
     1429    8,
    14331430    &ILazyLocations_table[-3],
    14341431    CStdStubBuffer_DELEGATING_METHODS
  • trunk/Utilities/MaxMindGeoLite/Script/LazyTest.js

    r48 r49  
    99locations = new ActiveXObject("AlaxInfo.MaxMindGeoLite.LazyLocations");
    1010
     11elapsedTime = 0;
    1112for(; ; ) {
    1213  if(locations.Initialized)
    1314    break;
    14   WScript.Echo("Initializing...");
     15  WScript.Echo("Initializing (" + elapsedTime + " seconds) ...");
    1516  //EchoLocation("alax.info", locations.Item("alax.info"));
    1617  WScript.Sleep(5000);
     18  elapsedTime += 5;
    1719}
    1820
Note: See TracChangeset for help on using the changeset viewer.