2 * Web Services on Devices
4 * Copyright 2017 Owen Rudge for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(wsdapi
);
32 typedef struct IWSDMessageParametersImpl
{
33 IWSDMessageParameters IWSDMessageParameters_iface
;
35 IWSDAddress
*localAddress
;
36 IWSDAddress
*remoteAddress
;
37 } IWSDMessageParametersImpl
;
39 typedef struct IWSDUdpMessageParametersImpl
{
40 IWSDMessageParametersImpl base
;
41 WSDUdpRetransmitParams retransmitParams
;
42 } IWSDUdpMessageParametersImpl
;
44 static inline IWSDMessageParametersImpl
*impl_from_IWSDMessageParameters(IWSDMessageParameters
*iface
)
46 return CONTAINING_RECORD(iface
, IWSDMessageParametersImpl
, IWSDMessageParameters_iface
);
49 static inline IWSDUdpMessageParametersImpl
*impl_from_IWSDUdpMessageParameters(IWSDUdpMessageParameters
*iface
)
51 return CONTAINING_RECORD(iface
, IWSDUdpMessageParametersImpl
, base
.IWSDMessageParameters_iface
);
54 /* IWSDMessageParameters implementation */
56 static ULONG
IWSDMessageParametersImpl_AddRef(IWSDMessageParameters
*iface
)
58 IWSDMessageParametersImpl
*This
= impl_from_IWSDMessageParameters(iface
);
59 ULONG ref
= InterlockedIncrement(&This
->ref
);
61 TRACE("(%p) ref=%d\n", This
, ref
);
65 static ULONG
IWSDMessageParametersImpl_Release(IWSDMessageParameters
*iface
)
67 IWSDMessageParametersImpl
*This
= impl_from_IWSDMessageParameters(iface
);
68 ULONG ref
= InterlockedDecrement(&This
->ref
);
70 TRACE("(%p) ref=%d\n", This
, ref
);
74 if (This
->localAddress
!= NULL
)
76 IWSDAddress_Release(This
->localAddress
);
79 if (This
->remoteAddress
!= NULL
)
81 IWSDAddress_Release(This
->remoteAddress
);
84 HeapFree(GetProcessHeap(), 0, This
);
90 static HRESULT
IWSDMessageParametersImpl_GetLocalAddress(IWSDMessageParameters
*This
, IWSDAddress
**ppAddress
)
92 IWSDMessageParametersImpl
*impl
= impl_from_IWSDMessageParameters(This
);
94 TRACE("(%p, %p)\n", impl
, ppAddress
);
96 if (ppAddress
== NULL
)
101 if (impl
->localAddress
== NULL
)
106 *ppAddress
= impl
->localAddress
;
107 IWSDAddress_AddRef(*ppAddress
);
112 static HRESULT
IWSDMessageParametersImpl_SetLocalAddress(IWSDMessageParameters
*This
, IWSDAddress
*pAddress
)
114 IWSDMessageParametersImpl
*impl
= impl_from_IWSDMessageParameters(This
);
116 TRACE("(%p, %p)\n", impl
, pAddress
);
118 if (pAddress
== NULL
)
123 if (impl
->localAddress
!= NULL
)
125 IWSDAddress_Release(impl
->localAddress
);
128 impl
->localAddress
= pAddress
;
129 IWSDAddress_AddRef(pAddress
);
134 static HRESULT
IWSDMessageParametersImpl_GetRemoteAddress(IWSDMessageParameters
*This
, IWSDAddress
**ppAddress
)
136 IWSDMessageParametersImpl
*impl
= impl_from_IWSDMessageParameters(This
);
138 TRACE("(%p, %p)\n", impl
, ppAddress
);
140 if (ppAddress
== NULL
)
145 if (impl
->remoteAddress
== NULL
)
150 *ppAddress
= impl
->remoteAddress
;
151 IWSDAddress_AddRef(*ppAddress
);
156 static HRESULT
IWSDMessageParametersImpl_SetRemoteAddress(IWSDMessageParameters
*This
, IWSDAddress
*pAddress
)
158 IWSDMessageParametersImpl
*impl
= impl_from_IWSDMessageParameters(This
);
160 TRACE("(%p, %p)\n", impl
, pAddress
);
162 if (pAddress
== NULL
)
167 if (impl
->remoteAddress
!= NULL
)
169 IWSDAddress_Release(impl
->remoteAddress
);
172 impl
->remoteAddress
= pAddress
;
173 IWSDAddress_AddRef(pAddress
);
178 static HRESULT
IWSDMessageParametersImpl_GetLowerParameters(IWSDMessageParameters
*This
, IWSDMessageParameters
**ppTxParams
)
180 FIXME("(%p, %p)\n", This
, ppTxParams
);
184 /* IWSDUdpMessageParameters implementation */
185 static HRESULT WINAPI
IWSDUdpMessageParametersImpl_QueryInterface(IWSDUdpMessageParameters
*iface
, REFIID riid
, void **ppv
)
187 IWSDUdpMessageParametersImpl
*This
= impl_from_IWSDUdpMessageParameters(iface
);
189 TRACE("(%p, %s, %p)\n", This
, debugstr_guid(riid
), ppv
);
193 WARN("Invalid parameter\n");
199 if (IsEqualIID(riid
, &IID_IUnknown
) ||
200 IsEqualIID(riid
, &IID_IWSDMessageParameters
) ||
201 IsEqualIID(riid
, &IID_IWSDUdpMessageParameters
))
203 *ppv
= &This
->base
.IWSDMessageParameters_iface
;
207 WARN("Unknown IID %s\n", debugstr_guid(riid
));
208 return E_NOINTERFACE
;
211 IUnknown_AddRef((IUnknown
*)*ppv
);
215 static ULONG WINAPI
IWSDUdpMessageParametersImpl_AddRef(IWSDUdpMessageParameters
*iface
)
217 return IWSDMessageParametersImpl_AddRef((IWSDMessageParameters
*)iface
);
220 static ULONG WINAPI
IWSDUdpMessageParametersImpl_Release(IWSDUdpMessageParameters
*iface
)
222 return IWSDMessageParametersImpl_Release((IWSDMessageParameters
*)iface
);
225 static HRESULT WINAPI
IWSDUdpMessageParametersImpl_GetLocalAddress(IWSDUdpMessageParameters
*This
, IWSDAddress
**ppAddress
)
227 return IWSDMessageParametersImpl_GetLocalAddress((IWSDMessageParameters
*)This
, ppAddress
);
230 static HRESULT WINAPI
IWSDUdpMessageParametersImpl_SetLocalAddress(IWSDUdpMessageParameters
*This
, IWSDAddress
*pAddress
)
232 return IWSDMessageParametersImpl_SetLocalAddress((IWSDMessageParameters
*)This
, pAddress
);
235 static HRESULT WINAPI
IWSDUdpMessageParametersImpl_GetRemoteAddress(IWSDUdpMessageParameters
*This
, IWSDAddress
**ppAddress
)
237 return IWSDMessageParametersImpl_GetRemoteAddress((IWSDMessageParameters
*)This
, ppAddress
);
240 static HRESULT WINAPI
IWSDUdpMessageParametersImpl_SetRemoteAddress(IWSDUdpMessageParameters
*This
, IWSDAddress
*pAddress
)
242 return IWSDMessageParametersImpl_SetRemoteAddress((IWSDMessageParameters
*)This
, pAddress
);
245 static HRESULT WINAPI
IWSDUdpMessageParametersImpl_GetLowerParameters(IWSDUdpMessageParameters
*This
, IWSDMessageParameters
**ppTxParams
)
247 return IWSDMessageParametersImpl_GetLowerParameters((IWSDMessageParameters
*)This
, ppTxParams
);
250 static HRESULT WINAPI
IWSDUdpMessageParametersImpl_SetRetransmitParams(IWSDUdpMessageParameters
*This
, const WSDUdpRetransmitParams
*pParams
)
252 IWSDUdpMessageParametersImpl
*impl
= impl_from_IWSDUdpMessageParameters(This
);
254 TRACE("(%p, %p)\n", impl
, pParams
);
261 impl
->retransmitParams
= *pParams
;
265 static HRESULT WINAPI
IWSDUdpMessageParametersImpl_GetRetransmitParams(IWSDUdpMessageParameters
*This
, WSDUdpRetransmitParams
*pParams
)
267 IWSDUdpMessageParametersImpl
*impl
= impl_from_IWSDUdpMessageParameters(This
);
269 TRACE("(%p, %p)\n", impl
, pParams
);
276 * pParams
= impl
->retransmitParams
;
280 static const IWSDUdpMessageParametersVtbl udpMsgParamsVtbl
=
283 IWSDUdpMessageParametersImpl_QueryInterface
,
284 IWSDUdpMessageParametersImpl_AddRef
,
285 IWSDUdpMessageParametersImpl_Release
,
287 /* IWSDMessageParameters */
288 IWSDUdpMessageParametersImpl_GetLocalAddress
,
289 IWSDUdpMessageParametersImpl_SetLocalAddress
,
290 IWSDUdpMessageParametersImpl_GetRemoteAddress
,
291 IWSDUdpMessageParametersImpl_SetRemoteAddress
,
292 IWSDUdpMessageParametersImpl_GetLowerParameters
,
294 /* IWSDUdpMessageParameters */
295 IWSDUdpMessageParametersImpl_SetRetransmitParams
,
296 IWSDUdpMessageParametersImpl_GetRetransmitParams
299 HRESULT WINAPI
WSDCreateUdpMessageParameters(IWSDUdpMessageParameters
**ppTxParams
)
301 IWSDUdpMessageParametersImpl
*obj
;
303 TRACE("(%p)\n", ppTxParams
);
305 if (ppTxParams
== NULL
)
307 WARN("Invalid parameter: ppTxParams == NULL\n");
313 obj
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*obj
));
314 if (!obj
) return E_OUTOFMEMORY
;
316 obj
->base
.IWSDMessageParameters_iface
.lpVtbl
= (IWSDMessageParametersVtbl
*)&udpMsgParamsVtbl
;
319 /* Populate default retransmit parameters */
320 obj
->retransmitParams
.ulSendDelay
= 0;
321 obj
->retransmitParams
.ulRepeat
= 1;
322 obj
->retransmitParams
.ulRepeatMinDelay
= 50;
323 obj
->retransmitParams
.ulRepeatMaxDelay
= 250;
324 obj
->retransmitParams
.ulRepeatUpperDelay
= 450;
326 *ppTxParams
= (IWSDUdpMessageParameters
*)&obj
->base
.IWSDMessageParameters_iface
;
327 TRACE("Returning iface %p\n", *ppTxParams
);