forked from salsita/passthruapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SinkPolicy.h
177 lines (138 loc) · 4.93 KB
/
SinkPolicy.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#ifndef PASSTHROUGHAPP_SINKPOLICY_H
#define PASSTHROUGHAPP_SINKPOLICY_H
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
namespace PassthroughAPP
{
// A sink policy class should implement OnStart with the prototype shown
// below, presumably by eventually forwarding to pTargetProtocol->Start,
// possibly with different parameters
class NoSinkStartPolicy
{
public:
HRESULT OnStart(LPCWSTR szUrl, IInternetProtocolSink *pOIProtSink,
IInternetBindInfo *pOIBindInfo, DWORD grfPI, HANDLE_PTR dwReserved,
IInternetProtocol* pTargetProtocol) const;
HRESULT OnStartEx(IUri *pUri, IInternetProtocolSink *pOIProtSink,
IInternetBindInfo *pOIBindInfo, DWORD grfPI, HANDLE_PTR dwReserved,
IInternetProtocolEx* pTargetProtocol) const;
};
template <class Base>
class CComObjectSharedRef : public Base
{
public:
typedef Base ContainedObject;
CComObjectSharedRef(IUnknown* punkRefCount, IUnknown* = 0);
#ifdef _ATL_DEBUG_INTERFACES
~CComObjectSharedRef();
#endif
STDMETHODIMP QueryInterface(REFIID iid, void** ppvObject);
template <class Q>
HRESULT STDMETHODCALLTYPE QueryInterface(Q** pp)
{
return QueryInterface(__uuidof(Q), (void**)pp);
}
STDMETHODIMP_(ULONG) AddRef();
STDMETHODIMP_(ULONG) Release();
Base* GetContainedObject();
static CComObjectSharedRef* GetThisObject(const Base* pBase);
private:
IUnknown* m_punkRefCount;
};
template <class Contained>
class CComPolyObjectSharedRef :
public IUnknown,
public CComObjectRootEx<typename Contained::_ThreadModel::ThreadModelNoCS>
{
public:
typedef Contained ContainedObject;
typedef typename Contained::_ThreadModel _ThreadModel;
CComPolyObjectSharedRef(IUnknown* punkRefCount, IUnknown* punkOuter);
#ifdef _ATL_DEBUG_INTERFACES
~CComPolyObjectSharedRef();
#endif
HRESULT FinalConstruct();
void FinalRelease();
STDMETHODIMP QueryInterface(REFIID iid, void** ppvObject);
template <class Q>
HRESULT STDMETHODCALLTYPE QueryInterface(Q** pp)
{
return QueryInterface(__uuidof(Q), (void**)pp);
}
STDMETHODIMP_(ULONG) AddRef();
STDMETHODIMP_(ULONG) Release();
IUnknown* GetControllingUnknown();
Contained* GetContainedObject();
static CComPolyObjectSharedRef* GetThisObject(const Contained* pContained);
CComContainedObject<Contained> m_contained;
private:
IUnknown* m_punkRefCount;
};
template <class T, class ThreadModel>
class CComObjectRefCount :
public IUnknown,
public CComObjectRootEx<typename ThreadModel::ThreadModelNoCS>
{
STDMETHODIMP QueryInterface(REFIID iid, void** ppvObject);
STDMETHODIMP_(ULONG) AddRef();
STDMETHODIMP_(ULONG) Release();
};
template <class ProtocolObject, class SinkObject>
class CComObjectProtSink :
public ProtocolObject
{
public:
typedef typename ProtocolObject::ContainedObject Protocol;
typedef typename SinkObject::ContainedObject Sink;
CComObjectProtSink(void* pv);
~CComObjectProtSink();
HRESULT FinalConstruct();
void FinalRelease();
static Protocol* GetProtocol(const Sink* pSink);
static Sink* GetSink(const Protocol* pProtocol);
SinkObject m_sink;
typedef CComObjectRefCount<CComObjectProtSink,
typename ProtocolObject::_ThreadModel> RefCountObject;
RefCountObject m_refCount;
};
#define DECLARE_NOT_AGGREGATABLE_PROTSINK(Protocol, Sink) public: \
typedef ::PassthroughAPP::CComObjectProtSink< \
::PassthroughAPP::CComObjectSharedRef<Protocol>, \
::PassthroughAPP::CComObjectSharedRef<Sink> > \
ComObjectClass; \
typedef CComCreator2<CComCreator<ComObjectClass>, \
CComFailCreator<CLASS_E_NOAGGREGATION> > _CreatorClass;
#define DECLARE_ONLY_AGGREGATABLE_PROTSINK(Protocol, Sink) public: \
typedef ::PassthroughAPP::CComObjectProtSink< \
::PassthroughAPP::CComPolyObjectSharedRef<Protocol>, \
::PassthroughAPP::CComObjectSharedRef<Sink> > \
ComObjectClass; \
typedef CComCreator2<CComFailCreator<E_FAIL>, \
CComCreator<ComObjectClass> > _CreatorClass;
#define DECLARE_AGGREGATABLE_PROTSINK(Protocol, Sink) public: \
typedef ::PassthroughAPP::CComObjectProtSink< \
::PassthroughAPP::CComPolyObjectSharedRef<Protocol>, \
::PassthroughAPP::CComObjectSharedRef<Sink> > \
ComObjectClass; \
typedef CComCreator<ComObjectClass> _CreatorClass;
template <class Protocol, class Sink>
class CustomSinkStartPolicy
{
public:
DECLARE_AGGREGATABLE_PROTSINK(Protocol, Sink)
HRESULT OnStart(LPCWSTR szUrl,
IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
DWORD grfPI, HANDLE_PTR dwReserved,
IInternetProtocol* pTargetProtocol) const;
HRESULT OnStartEx(IUri* pUri,
IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
DWORD grfPI, HANDLE_PTR dwReserved,
IInternetProtocolEx* pTargetProtocol) const;
static Sink* GetSink(const Protocol* pProtocol);
Sink* GetSink() const;
static Protocol* GetProtocol(const Sink* pSink);
};
} // end namespace PassthroughAPP
#include "SinkPolicy.inl"
#endif // PASSTHROUGHAPP_SINKPOLICY_H