_IRobotEventEvents_CP.h 1.6 KB
Newer Older
L
ljc545w 已提交
1
#pragma once
2 3 4 5 6 7 8 9
#include <map>
#include <set>

/**
 * 微信PID与客户端事件ConnectionPoint的cookie的映射,客户端使用自己关心的微信PID和cookie进行注册,
 * 服务端根据PID向订阅该PID的客户端发起事件调用
 */
map<DWORD, set<DWORD>> WxPidToEventCookie;
L
ljc545w 已提交
10 11 12 13 14 15

template<class T>
class CProxy_IRobotEventEvents :
	public ATL::IConnectionPointImpl<T, &__uuidof(_IRobotEventEvents)>
{
public:
16
    HRESULT Fire_OnGetMessageEvent(DWORD pid, VARIANT* msg)
L
ljc545w 已提交
17 18 19
    {
        HRESULT hr = S_OK;
        T* pThis = static_cast<T*>(this);
20 21 22 23 24 25
        if (WxPidToEventCookie.count(pid)==0)
        {
            return hr;
        }
        const set<DWORD> cookies = WxPidToEventCookie[pid];
        for (DWORD cookie:cookies)
L
ljc545w 已提交
26 27
        {
            pThis->Lock();
28
            ATL::CComPtr<IUnknown> punkConnection=this->m_vec.GetUnknown(cookie);
L
ljc545w 已提交
29
            pThis->Unlock();
30
            if (punkConnection)
L
ljc545w 已提交
31
            {
32 33 34 35
                IDispatch* pConnection = static_cast<IDispatch*>(punkConnection.p);
                if (pConnection)
                {
                    ATL::CComVariant varResult;
L
ljc545w 已提交
36

37 38 39 40 41 42 43 44 45 46 47
                    DISPPARAMS params = { msg, nullptr, 1, 0 };
                    hr = pConnection->Invoke(1, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &params, &varResult, nullptr, nullptr);
                }
                else
                {
                    WxPidToEventCookie[pid].erase(cookie);
                }
            }
            else
            {
                WxPidToEventCookie[pid].erase(cookie);
L
ljc545w 已提交
48 49 50 51 52
            }
        }
        return hr;
    }
};