1 /* WinRT Windows.Devices.Geolocation.Geolocator Implementation
3 * Copyright 2023 Fabian Maurer
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/debug.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(geolocator
);
27 struct geolocator_statics
29 IActivationFactory IActivationFactory_iface
;
35 IGeolocator IGeolocator_iface
;
36 IWeakReferenceSource IWeakReferenceSource_iface
;
37 IWeakReference IWeakReference_iface
;
42 static inline struct geolocator
*impl_from_IGeolocator(IGeolocator
*iface
)
44 return CONTAINING_RECORD(iface
, struct geolocator
, IGeolocator_iface
);
47 static HRESULT WINAPI
geolocator_QueryInterface(IGeolocator
*iface
, REFIID iid
, void **out
)
49 struct geolocator
*impl
= impl_from_IGeolocator(iface
);
51 TRACE("iface %p, iid %s, out %p.\n", iface
, debugstr_guid(iid
), out
);
53 if (IsEqualGUID(iid
, &IID_IUnknown
) ||
54 IsEqualGUID(iid
, &IID_IInspectable
) ||
55 IsEqualGUID(iid
, &IID_IAgileObject
) ||
56 IsEqualGUID(iid
, &IID_IGeolocator
))
58 *out
= &impl
->IGeolocator_iface
;
59 IInspectable_AddRef(*out
);
63 if (IsEqualGUID(iid
, &IID_IWeakReferenceSource
))
65 *out
= &impl
->IWeakReferenceSource_iface
;
66 IInspectable_AddRef(*out
);
70 FIXME("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid
));
75 static ULONG WINAPI
geolocator_AddRef(IGeolocator
*iface
)
77 struct geolocator
*impl
= impl_from_IGeolocator(iface
);
78 ULONG ref
= InterlockedIncrement(&impl
->ref_public
);
79 TRACE("iface %p increasing refcount to %lu.\n", iface
, ref
);
80 IWeakReference_AddRef(&impl
->IWeakReference_iface
);
84 static ULONG WINAPI
geolocator_Release(IGeolocator
*iface
)
86 struct geolocator
*impl
= impl_from_IGeolocator(iface
);
87 ULONG ref
= InterlockedDecrement(&impl
->ref_public
);
88 TRACE("iface %p decreasing refcount to %lu.\n", iface
, ref
);
89 IWeakReference_Release(&impl
->IWeakReference_iface
);
93 static HRESULT WINAPI
geolocator_GetIids(IGeolocator
*iface
, ULONG
*iid_count
, IID
**iids
)
95 FIXME("iface %p, iid_count %p, iids %p stub!\n", iface
, iid_count
, iids
);
99 static HRESULT WINAPI
geolocator_GetRuntimeClassName(IGeolocator
*iface
, HSTRING
*class_name
)
101 FIXME("iface %p, class_name %p stub!\n", iface
, class_name
);
105 static HRESULT WINAPI
geolocator_GetTrustLevel(IGeolocator
*iface
, TrustLevel
*trust_level
)
107 FIXME("iface %p, trust_level %p stub!\n", iface
, trust_level
);
111 HRESULT WINAPI
geolocator_get_DesiredAccuracy(IGeolocator
*iface
, PositionAccuracy
*value
)
113 FIXME("iface %p, value %p stub.\n", iface
, value
);
117 HRESULT WINAPI
geolocator_set_DesiredAccuracy(IGeolocator
*iface
, PositionAccuracy value
)
119 FIXME("iface %p, value %d stub.\n", iface
, value
);
123 HRESULT WINAPI
geolocator_get_MovementThreshold(IGeolocator
*iface
, DOUBLE
*value
)
125 FIXME("iface %p, value %p stub.\n", iface
, value
);
129 HRESULT WINAPI
geolocator_set_MovementThreshold(IGeolocator
*iface
, DOUBLE value
)
131 FIXME("iface %p, value %f stub.\n", iface
, value
);
135 HRESULT WINAPI
geolocator_get_ReportInterval(IGeolocator
*iface
, UINT32
*value
)
137 FIXME("iface %p, value %p stub.\n", iface
, value
);
141 HRESULT WINAPI
geolocator_set_ReportInterval(IGeolocator
*iface
, UINT32 value
)
143 FIXME("iface %p, value %u stub.\n", iface
, value
);
147 HRESULT WINAPI
geolocator_LocationStatus(IGeolocator
*iface
, PositionStatus
*value
)
149 FIXME("iface %p, value %p stub.\n", iface
, value
);
153 HRESULT WINAPI
geolocator_GetGeopositionAsync(IGeolocator
*iface
, IAsyncOperation_Geoposition
**value
)
155 FIXME("iface %p, value %p stub.\n", iface
, value
);
159 HRESULT WINAPI
geolocator_GetGeopositionAsyncWithAgeAndTimeout(IGeolocator
*iface
, TimeSpan maximum_age
, TimeSpan timeout
, IAsyncOperation_Geoposition
**value
)
161 FIXME("iface %p, maximum_age %#I64x, timeout %#I64x, value %p stub.\n", iface
, maximum_age
.Duration
, timeout
.Duration
, value
);
165 HRESULT WINAPI
geolocator_add_PositionChanged(IGeolocator
*iface
, ITypedEventHandler_Geolocator_PositionChangedEventArgs
*handler
, EventRegistrationToken
*token
)
167 FIXME("iface %p, handler %p, token %p stub.\n", iface
, handler
, token
);
171 HRESULT WINAPI
geolocator_remove_PositionChanged(IGeolocator
*iface
, EventRegistrationToken token
)
173 FIXME("iface %p, token %#I64x stub.\n", iface
, token
.value
);
177 HRESULT WINAPI
geolocator_add_StatusChanged(IGeolocator
*iface
, ITypedEventHandler_Geolocator_StatusChangedEventArgs
*handler
, EventRegistrationToken
*token
)
179 FIXME("iface %p, handler %p, token %p stub.\n", iface
, handler
, token
);
183 HRESULT WINAPI
geolocator_remove_StatusChanged(IGeolocator
*iface
, EventRegistrationToken token
)
185 FIXME("iface %p, token %#I64x stub.\n", iface
, token
.value
);
189 static const struct IGeolocatorVtbl geolocator_vtbl
=
191 geolocator_QueryInterface
,
194 /* IInspectable methods */
196 geolocator_GetRuntimeClassName
,
197 geolocator_GetTrustLevel
,
198 /* IGeolocator methods */
199 geolocator_get_DesiredAccuracy
,
200 geolocator_set_DesiredAccuracy
,
201 geolocator_get_MovementThreshold
,
202 geolocator_set_MovementThreshold
,
203 geolocator_get_ReportInterval
,
204 geolocator_set_ReportInterval
,
205 geolocator_LocationStatus
,
206 geolocator_GetGeopositionAsync
,
207 geolocator_GetGeopositionAsyncWithAgeAndTimeout
,
208 geolocator_add_PositionChanged
,
209 geolocator_remove_PositionChanged
,
210 geolocator_add_StatusChanged
,
211 geolocator_remove_StatusChanged
,
214 static inline struct geolocator
*impl_from_IWeakReference(IWeakReference
*iface
)
216 return CONTAINING_RECORD(iface
, struct geolocator
, IWeakReference_iface
);
219 static HRESULT WINAPI
weak_reference_QueryInterface(IWeakReference
*iface
, REFIID iid
, void **out
)
221 struct geolocator
*impl
= impl_from_IWeakReference(iface
);
223 TRACE("iface %p, iid %s, out %p.\n", iface
, debugstr_guid(iid
), out
);
225 if (IsEqualGUID(iid
, &IID_IUnknown
) ||
226 IsEqualGUID(iid
, &IID_IWeakReference
))
228 *out
= &impl
->IWeakReference_iface
;
229 IInspectable_AddRef(*out
);
233 FIXME("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid
));
235 return E_NOINTERFACE
;
238 static ULONG WINAPI
weak_reference_AddRef(IWeakReference
*iface
)
240 struct geolocator
*impl
= impl_from_IWeakReference(iface
);
241 ULONG ref
= InterlockedIncrement(&impl
->ref_weak
);
242 TRACE("iface %p increasing refcount to %lu.\n", iface
, ref
);
246 static ULONG WINAPI
weak_reference_Release(IWeakReference
*iface
)
248 struct geolocator
*impl
= impl_from_IWeakReference(iface
);
249 ULONG ref
= InterlockedDecrement(&impl
->ref_weak
);
255 static HRESULT WINAPI
weak_reference_Resolve(IWeakReference
*iface
, REFIID iid
, IInspectable
**out
)
257 struct geolocator
*impl
= impl_from_IWeakReference(iface
);
261 TRACE("iface %p, iid %s, out %p stub.\n", iface
, debugstr_guid(iid
), out
);
267 if (!(ref
= ReadNoFence(&impl
->ref_public
)))
269 } while (ref
!= InterlockedCompareExchange(&impl
->ref_public
, ref
+ 1, ref
));
271 hr
= IGeolocator_QueryInterface(&impl
->IGeolocator_iface
, iid
, (void **)out
);
272 InterlockedDecrement(&impl
->ref_public
);
276 static const struct IWeakReferenceVtbl weak_reference_vtbl
=
278 weak_reference_QueryInterface
,
279 weak_reference_AddRef
,
280 weak_reference_Release
,
281 /* IWeakReference methods */
282 weak_reference_Resolve
,
285 static inline struct geolocator
*impl_from_IWeakReferenceSource(IWeakReferenceSource
*iface
)
287 return CONTAINING_RECORD(iface
, struct geolocator
, IWeakReferenceSource_iface
);
290 static HRESULT WINAPI
weak_reference_source_QueryInterface(IWeakReferenceSource
*iface
, REFIID iid
, void **out
)
292 struct geolocator
*impl
= impl_from_IWeakReferenceSource(iface
);
293 return geolocator_QueryInterface(&impl
->IGeolocator_iface
, iid
, out
);
296 static ULONG WINAPI
weak_reference_source_AddRef(IWeakReferenceSource
*iface
)
298 struct geolocator
*impl
= impl_from_IWeakReferenceSource(iface
);
299 return geolocator_AddRef(&impl
->IGeolocator_iface
);
302 static ULONG WINAPI
weak_reference_source_Release(IWeakReferenceSource
*iface
)
304 struct geolocator
*impl
= impl_from_IWeakReferenceSource(iface
);
305 return geolocator_Release(&impl
->IGeolocator_iface
);
308 static HRESULT WINAPI
weak_reference_source_GetWeakReference(IWeakReferenceSource
*iface
, IWeakReference
**ref
)
310 struct geolocator
*impl
= impl_from_IWeakReferenceSource(iface
);
312 TRACE("iface %p, ref %p stub.\n", iface
, ref
);
313 *ref
= &impl
->IWeakReference_iface
;
314 IWeakReference_AddRef(*ref
);
318 static const struct IWeakReferenceSourceVtbl weak_reference_source_vtbl
=
320 weak_reference_source_QueryInterface
,
321 weak_reference_source_AddRef
,
322 weak_reference_source_Release
,
323 /* IWeakReferenceSource methods */
324 weak_reference_source_GetWeakReference
,
327 static inline struct geolocator_statics
*impl_from_IActivationFactory(IActivationFactory
*iface
)
329 return CONTAINING_RECORD(iface
, struct geolocator_statics
, IActivationFactory_iface
);
332 static HRESULT WINAPI
factory_QueryInterface(IActivationFactory
*iface
, REFIID iid
, void **out
)
334 struct geolocator_statics
*impl
= impl_from_IActivationFactory(iface
);
336 TRACE("iface %p, iid %s, out %p.\n", iface
, debugstr_guid(iid
), out
);
338 if (IsEqualGUID(iid
, &IID_IUnknown
) ||
339 IsEqualGUID(iid
, &IID_IInspectable
) ||
340 IsEqualGUID(iid
, &IID_IAgileObject
) ||
341 IsEqualGUID(iid
, &IID_IActivationFactory
))
343 *out
= &impl
->IActivationFactory_iface
;
344 IInspectable_AddRef(*out
);
348 FIXME("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid
));
350 return E_NOINTERFACE
;
353 static ULONG WINAPI
factory_AddRef(IActivationFactory
*iface
)
355 struct geolocator_statics
*impl
= impl_from_IActivationFactory(iface
);
356 ULONG ref
= InterlockedIncrement(&impl
->ref
);
357 TRACE("iface %p increasing refcount to %lu.\n", iface
, ref
);
361 static ULONG WINAPI
factory_Release(IActivationFactory
*iface
)
363 struct geolocator_statics
*impl
= impl_from_IActivationFactory(iface
);
364 ULONG ref
= InterlockedDecrement(&impl
->ref
);
365 TRACE("iface %p decreasing refcount to %lu.\n", iface
, ref
);
369 static HRESULT WINAPI
factory_GetIids(IActivationFactory
*iface
, ULONG
*iid_count
, IID
**iids
)
371 FIXME("iface %p, iid_count %p, iids %p stub!\n", iface
, iid_count
, iids
);
375 static HRESULT WINAPI
factory_GetRuntimeClassName(IActivationFactory
*iface
, HSTRING
*class_name
)
377 FIXME("iface %p, class_name %p stub!\n", iface
, class_name
);
381 static HRESULT WINAPI
factory_GetTrustLevel(IActivationFactory
*iface
, TrustLevel
*trust_level
)
383 FIXME("iface %p, trust_level %p stub!\n", iface
, trust_level
);
387 static const struct IActivationFactoryVtbl factory_vtbl
;
389 static HRESULT WINAPI
factory_ActivateInstance(IActivationFactory
*iface
, IInspectable
**instance
)
391 struct geolocator
*impl
;
393 TRACE("iface %p, instance %p.\n", iface
, instance
);
395 if (!(impl
= calloc(1, sizeof(*impl
))))
398 return E_OUTOFMEMORY
;
401 impl
->IGeolocator_iface
.lpVtbl
= &geolocator_vtbl
;
402 impl
->IWeakReferenceSource_iface
.lpVtbl
= &weak_reference_source_vtbl
;
403 impl
->IWeakReference_iface
.lpVtbl
= &weak_reference_vtbl
;
404 impl
->ref_public
= 1;
407 *instance
= (IInspectable
*)&impl
->IGeolocator_iface
;
411 static const struct IActivationFactoryVtbl factory_vtbl
=
413 factory_QueryInterface
,
416 /* IInspectable methods */
418 factory_GetRuntimeClassName
,
419 factory_GetTrustLevel
,
420 /* IActivationFactory methods */
421 factory_ActivateInstance
,
424 static struct geolocator_statics geolocator_statics
=
430 static IActivationFactory
*geolocator_factory
= &geolocator_statics
.IActivationFactory_iface
;
432 HRESULT WINAPI
DllGetClassObject(REFCLSID clsid
, REFIID riid
, void **out
)
434 FIXME("clsid %s, riid %s, out %p stub!\n", debugstr_guid(clsid
), debugstr_guid(riid
), out
);
435 return CLASS_E_CLASSNOTAVAILABLE
;
438 HRESULT WINAPI
DllGetActivationFactory(HSTRING classid
, IActivationFactory
**factory
)
440 const WCHAR
*name
= WindowsGetStringRawBuffer(classid
, NULL
);
442 TRACE("classid %s, factory %p.\n", debugstr_hstring(classid
), factory
);
446 if (!wcscmp(name
, RuntimeClass_Windows_Devices_Geolocation_Geolocator
))
447 IActivationFactory_QueryInterface(geolocator_factory
, &IID_IActivationFactory
, (void **)factory
);
449 if (*factory
) return S_OK
;
450 return CLASS_E_CLASSNOTAVAILABLE
;