d3d11: Report D3D11_FORMAT_SUPPORT_TYPED_UNORDERED_ACCESS_VIEW in CheckFormatSupport().
[wine.git] / dlls / msado15 / connection.c
blob5d8f78f53e87edc19828f05988cf47c3825489df
1 /*
2 * Copyright 2019 Hans Leidekker for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <stdarg.h>
20 #include "windef.h"
21 #include "winbase.h"
22 #define COBJMACROS
23 #include "initguid.h"
24 #include "ocidl.h"
25 #include "objbase.h"
26 #include "olectl.h"
27 #include "msado15_backcompat.h"
29 #include "wine/debug.h"
30 #include "wine/heap.h"
32 #include "msado15_private.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(msado15);
36 struct connection;
38 struct connection_point
40 IConnectionPoint IConnectionPoint_iface;
41 struct connection *conn;
42 const IID *riid;
43 IUnknown **sinks;
44 ULONG sinks_size;
47 struct connection
49 _Connection Connection_iface;
50 ISupportErrorInfo ISupportErrorInfo_iface;
51 IConnectionPointContainer IConnectionPointContainer_iface;
52 LONG refs;
53 ObjectStateEnum state;
54 LONG timeout;
55 WCHAR *datasource;
56 struct connection_point cp_connev;
59 static inline struct connection *impl_from_Connection( _Connection *iface )
61 return CONTAINING_RECORD( iface, struct connection, Connection_iface );
64 static inline struct connection *impl_from_ISupportErrorInfo( ISupportErrorInfo *iface )
66 return CONTAINING_RECORD( iface, struct connection, ISupportErrorInfo_iface );
69 static inline struct connection *impl_from_IConnectionPointContainer( IConnectionPointContainer *iface )
71 return CONTAINING_RECORD( iface, struct connection, IConnectionPointContainer_iface );
74 static inline struct connection_point *impl_from_IConnectionPoint( IConnectionPoint *iface )
76 return CONTAINING_RECORD( iface, struct connection_point, IConnectionPoint_iface );
79 static ULONG WINAPI connection_AddRef( _Connection *iface )
81 struct connection *connection = impl_from_Connection( iface );
82 return InterlockedIncrement( &connection->refs );
85 static ULONG WINAPI connection_Release( _Connection *iface )
87 struct connection *connection = impl_from_Connection( iface );
88 LONG refs = InterlockedDecrement( &connection->refs );
89 ULONG i;
90 if (!refs)
92 TRACE( "destroying %p\n", connection );
93 for (i = 0; i < connection->cp_connev.sinks_size; ++i)
95 if (connection->cp_connev.sinks[i])
96 IUnknown_Release( connection->cp_connev.sinks[i] );
98 heap_free( connection->cp_connev.sinks );
99 heap_free( connection->datasource );
100 heap_free( connection );
102 return refs;
105 static HRESULT WINAPI connection_QueryInterface( _Connection *iface, REFIID riid, void **obj )
107 struct connection *connection = impl_from_Connection( iface );
108 TRACE( "%p, %s, %p\n", connection, debugstr_guid(riid), obj );
110 *obj = NULL;
112 if (IsEqualGUID( riid, &IID__Connection ) || IsEqualGUID( riid, &IID_IDispatch ) ||
113 IsEqualGUID( riid, &IID_IUnknown ))
115 *obj = iface;
117 else if(IsEqualGUID( riid, &IID_ISupportErrorInfo ))
119 *obj = &connection->ISupportErrorInfo_iface;
121 else if (IsEqualGUID( riid, &IID_IConnectionPointContainer ))
123 *obj = &connection->IConnectionPointContainer_iface;
125 else if (IsEqualGUID( riid, &IID_IRunnableObject ))
127 TRACE("IID_IRunnableObject not supported returning NULL\n");
128 return E_NOINTERFACE;
130 else
132 FIXME( "interface %s not implemented\n", debugstr_guid(riid) );
133 return E_NOINTERFACE;
135 connection_AddRef( iface );
136 return S_OK;
139 static HRESULT WINAPI connection_GetTypeInfoCount( _Connection *iface, UINT *count )
141 FIXME( "%p, %p\n", iface, count );
142 return E_NOTIMPL;
145 static HRESULT WINAPI connection_GetTypeInfo( _Connection *iface, UINT index, LCID lcid, ITypeInfo **info )
147 FIXME( "%p, %u, %u, %p\n", iface, index, lcid, info );
148 return E_NOTIMPL;
151 static HRESULT WINAPI connection_GetIDsOfNames( _Connection *iface, REFIID riid, LPOLESTR *names, UINT count,
152 LCID lcid, DISPID *dispid )
154 FIXME( "%p, %s, %p, %u, %u, %p\n", iface, debugstr_guid(riid), names, count, lcid, dispid );
155 return E_NOTIMPL;
158 static HRESULT WINAPI connection_Invoke( _Connection *iface, DISPID member, REFIID riid, LCID lcid, WORD flags,
159 DISPPARAMS *params, VARIANT *result, EXCEPINFO *excep_info, UINT *arg_err )
161 FIXME( "%p, %d, %s, %d, %d, %p, %p, %p, %p\n", iface, member, debugstr_guid(riid), lcid, flags, params,
162 result, excep_info, arg_err );
163 return E_NOTIMPL;
166 static HRESULT WINAPI connection_get_Properties( _Connection *iface, Properties **obj )
168 FIXME( "%p, %p\n", iface, obj );
169 return E_NOTIMPL;
172 static HRESULT WINAPI connection_get_ConnectionString( _Connection *iface, BSTR *str )
174 struct connection *connection = impl_from_Connection( iface );
175 BSTR source = NULL;
177 TRACE( "%p, %p\n", connection, str );
179 if (connection->datasource && !(source = SysAllocString( connection->datasource ))) return E_OUTOFMEMORY;
180 *str = source;
181 return S_OK;
184 static HRESULT WINAPI connection_put_ConnectionString( _Connection *iface, BSTR str )
186 struct connection *connection = impl_from_Connection( iface );
187 WCHAR *source = NULL;
189 TRACE( "%p, %s\n", connection, debugstr_w( !wcsstr( str, L"Password" ) ? L"<hidden>" : str ) );
191 if (str && !(source = strdupW( str ))) return E_OUTOFMEMORY;
192 heap_free( connection->datasource );
193 connection->datasource = source;
194 return S_OK;
197 static HRESULT WINAPI connection_get_CommandTimeout( _Connection *iface, LONG *timeout )
199 struct connection *connection = impl_from_Connection( iface );
200 TRACE( "%p, %p\n", connection, timeout );
201 *timeout = connection->timeout;
202 return S_OK;
205 static HRESULT WINAPI connection_put_CommandTimeout( _Connection *iface, LONG timeout )
207 struct connection *connection = impl_from_Connection( iface );
208 TRACE( "%p, %d\n", connection, timeout );
209 connection->timeout = timeout;
210 return S_OK;
213 static HRESULT WINAPI connection_get_ConnectionTimeout( _Connection *iface, LONG *timeout )
215 FIXME( "%p, %p\n", iface, timeout );
216 return E_NOTIMPL;
219 static HRESULT WINAPI connection_put_ConnectionTimeout( _Connection *iface, LONG timeout )
221 FIXME( "%p, %d\n", iface, timeout );
222 return E_NOTIMPL;
225 static HRESULT WINAPI connection_get_Version( _Connection *iface, BSTR *str )
227 FIXME( "%p, %p\n", iface, str );
228 return E_NOTIMPL;
231 static HRESULT WINAPI connection_Close( _Connection *iface )
233 struct connection *connection = impl_from_Connection( iface );
235 TRACE( "%p\n", connection );
237 if (connection->state == adStateClosed) return MAKE_ADO_HRESULT( adErrObjectClosed );
239 connection->state = adStateClosed;
240 return S_OK;
243 static HRESULT WINAPI connection_Execute( _Connection *iface, BSTR command, VARIANT *records_affected,
244 LONG options, _Recordset **record_set )
246 FIXME( "%p, %s, %p, %08x, %p\n", iface, debugstr_w(command), records_affected, options, record_set );
247 return E_NOTIMPL;
250 static HRESULT WINAPI connection_BeginTrans( _Connection *iface, LONG *transaction_level )
252 FIXME( "%p, %p\n", iface, transaction_level );
253 return E_NOTIMPL;
256 static HRESULT WINAPI connection_CommitTrans( _Connection *iface )
258 FIXME( "%p\n", iface );
259 return E_NOTIMPL;
262 static HRESULT WINAPI connection_RollbackTrans( _Connection *iface )
264 FIXME( "%p\n", iface );
265 return E_NOTIMPL;
268 static HRESULT WINAPI connection_Open( _Connection *iface, BSTR connect_str, BSTR userid, BSTR password,
269 LONG options )
271 struct connection *connection = impl_from_Connection( iface );
272 FIXME( "%p, %s, %s, %p, %08x\n", iface, debugstr_w(connect_str), debugstr_w(userid),
273 password, options );
275 if (connection->state == adStateOpen) return MAKE_ADO_HRESULT( adErrObjectOpen );
277 connection->state = adStateOpen;
278 return S_OK;
281 static HRESULT WINAPI connection_get_Errors( _Connection *iface, Errors **obj )
283 FIXME( "%p, %p\n", iface, obj );
284 return E_NOTIMPL;
287 static HRESULT WINAPI connection_get_DefaultDatabase( _Connection *iface, BSTR *str )
289 FIXME( "%p, %p\n", iface, str );
290 return E_NOTIMPL;
293 static HRESULT WINAPI connection_put_DefaultDatabase( _Connection *iface, BSTR str )
295 FIXME( "%p, %s\n", iface, debugstr_w(str) );
296 return E_NOTIMPL;
299 static HRESULT WINAPI connection_get_IsolationLevel( _Connection *iface, IsolationLevelEnum *level )
301 FIXME( "%p, %p\n", iface, level );
302 return E_NOTIMPL;
305 static HRESULT WINAPI connection_put_IsolationLevel( _Connection *iface, IsolationLevelEnum level )
307 FIXME( "%p, %d\n", iface, level );
308 return E_NOTIMPL;
311 static HRESULT WINAPI connection_get_Attributes( _Connection *iface, LONG *attr )
313 FIXME( "%p, %p\n", iface, attr );
314 return E_NOTIMPL;
317 static HRESULT WINAPI connection_put_Attributes( _Connection *iface, LONG attr )
319 FIXME( "%p, %d\n", iface, attr );
320 return E_NOTIMPL;
323 static HRESULT WINAPI connection_get_CursorLocation( _Connection *iface, CursorLocationEnum *cursor_loc )
325 FIXME( "%p, %p\n", iface, cursor_loc );
326 return E_NOTIMPL;
329 static HRESULT WINAPI connection_put_CursorLocation( _Connection *iface, CursorLocationEnum cursor_loc )
331 FIXME( "%p, %u\n", iface, cursor_loc );
332 return E_NOTIMPL;
335 static HRESULT WINAPI connection_get_Mode( _Connection *iface, ConnectModeEnum *mode )
337 FIXME( "%p, %p\n", iface, mode );
338 return E_NOTIMPL;
341 static HRESULT WINAPI connection_put_Mode( _Connection *iface, ConnectModeEnum mode )
343 FIXME( "%p, %u\n", iface, mode );
344 return E_NOTIMPL;
347 static HRESULT WINAPI connection_get_Provider( _Connection *iface, BSTR *str )
349 FIXME( "%p, %p\n", iface, str );
350 return E_NOTIMPL;
353 static HRESULT WINAPI connection_put_Provider( _Connection *iface, BSTR str )
355 FIXME( "%p, %s\n", iface, debugstr_w(str) );
356 return E_NOTIMPL;
359 static HRESULT WINAPI connection_get_State( _Connection *iface, LONG *state )
361 struct connection *connection = impl_from_Connection( iface );
362 TRACE( "%p, %p\n", connection, state );
363 *state = connection->state;
364 return S_OK;
367 static HRESULT WINAPI connection_OpenSchema( _Connection *iface, SchemaEnum schema, VARIANT restrictions,
368 VARIANT schema_id, _Recordset **record_set )
370 FIXME( "%p, %d, %s, %s, %p\n", iface, schema, debugstr_variant(&restrictions),
371 debugstr_variant(&schema_id), record_set );
372 return E_NOTIMPL;
375 static HRESULT WINAPI connection_Cancel( _Connection *iface )
377 FIXME( "%p\n", iface );
378 return E_NOTIMPL;
381 static const struct _ConnectionVtbl connection_vtbl =
383 connection_QueryInterface,
384 connection_AddRef,
385 connection_Release,
386 connection_GetTypeInfoCount,
387 connection_GetTypeInfo,
388 connection_GetIDsOfNames,
389 connection_Invoke,
390 connection_get_Properties,
391 connection_get_ConnectionString,
392 connection_put_ConnectionString,
393 connection_get_CommandTimeout,
394 connection_put_CommandTimeout,
395 connection_get_ConnectionTimeout,
396 connection_put_ConnectionTimeout,
397 connection_get_Version,
398 connection_Close,
399 connection_Execute,
400 connection_BeginTrans,
401 connection_CommitTrans,
402 connection_RollbackTrans,
403 connection_Open,
404 connection_get_Errors,
405 connection_get_DefaultDatabase,
406 connection_put_DefaultDatabase,
407 connection_get_IsolationLevel,
408 connection_put_IsolationLevel,
409 connection_get_Attributes,
410 connection_put_Attributes,
411 connection_get_CursorLocation,
412 connection_put_CursorLocation,
413 connection_get_Mode,
414 connection_put_Mode,
415 connection_get_Provider,
416 connection_put_Provider,
417 connection_get_State,
418 connection_OpenSchema,
419 connection_Cancel
422 static HRESULT WINAPI supporterror_QueryInterface( ISupportErrorInfo *iface, REFIID riid, void **obj )
424 struct connection *connection = impl_from_ISupportErrorInfo( iface );
425 return connection_QueryInterface( &connection->Connection_iface, riid, obj );
428 static ULONG WINAPI supporterror_AddRef( ISupportErrorInfo *iface )
430 struct connection *connection = impl_from_ISupportErrorInfo( iface );
431 return connection_AddRef( &connection->Connection_iface );
434 static ULONG WINAPI supporterror_Release( ISupportErrorInfo *iface )
436 struct connection *connection = impl_from_ISupportErrorInfo( iface );
437 return connection_Release( &connection->Connection_iface );
440 static HRESULT WINAPI supporterror_InterfaceSupportsErrorInfo( ISupportErrorInfo *iface, REFIID riid )
442 struct connection *connection = impl_from_ISupportErrorInfo( iface );
443 FIXME( "%p, %s\n", connection, debugstr_guid(riid) );
444 return S_FALSE;
447 static const struct ISupportErrorInfoVtbl support_error_vtbl =
449 supporterror_QueryInterface,
450 supporterror_AddRef,
451 supporterror_Release,
452 supporterror_InterfaceSupportsErrorInfo
455 static HRESULT WINAPI connpointcontainer_QueryInterface( IConnectionPointContainer *iface,
456 REFIID riid, void **obj )
458 struct connection *connection = impl_from_IConnectionPointContainer( iface );
459 return connection_QueryInterface( &connection->Connection_iface, riid, obj );
462 static ULONG WINAPI connpointcontainer_AddRef( IConnectionPointContainer *iface )
464 struct connection *connection = impl_from_IConnectionPointContainer( iface );
465 return connection_AddRef( &connection->Connection_iface );
468 static ULONG WINAPI connpointcontainer_Release( IConnectionPointContainer *iface )
470 struct connection *connection = impl_from_IConnectionPointContainer( iface );
471 return connection_Release( &connection->Connection_iface );
474 static HRESULT WINAPI connpointcontainer_EnumConnectionPoints( IConnectionPointContainer *iface,
475 IEnumConnectionPoints **points )
477 struct connection *connection = impl_from_IConnectionPointContainer( iface );
478 FIXME( "%p, %p\n", connection, points );
479 return E_NOTIMPL;
482 static HRESULT WINAPI connpointcontainer_FindConnectionPoint( IConnectionPointContainer *iface,
483 REFIID riid, IConnectionPoint **point )
485 struct connection *connection = impl_from_IConnectionPointContainer( iface );
487 TRACE( "%p, %s %p\n", connection, debugstr_guid( riid ), point );
489 if (!point) return E_POINTER;
491 if (IsEqualIID( riid, connection->cp_connev.riid ))
493 *point = &connection->cp_connev.IConnectionPoint_iface;
494 IConnectionPoint_AddRef( *point );
495 return S_OK;
498 FIXME( "unsupported connection point %s\n", debugstr_guid( riid ) );
499 return CONNECT_E_NOCONNECTION;
502 static const struct IConnectionPointContainerVtbl connpointcontainer_vtbl =
504 connpointcontainer_QueryInterface,
505 connpointcontainer_AddRef,
506 connpointcontainer_Release,
507 connpointcontainer_EnumConnectionPoints,
508 connpointcontainer_FindConnectionPoint
511 static HRESULT WINAPI connpoint_QueryInterface( IConnectionPoint *iface, REFIID riid, void **obj )
513 struct connection_point *connpoint = impl_from_IConnectionPoint( iface );
515 if (IsEqualGUID( &IID_IUnknown, riid ) || IsEqualGUID( &IID_IConnectionPoint, riid ))
517 *obj = &connpoint->IConnectionPoint_iface;
519 else
521 FIXME( "interface %s not implemented\n", debugstr_guid( riid ) );
522 return E_NOINTERFACE;
525 connection_AddRef( &connpoint->conn->Connection_iface );
526 return S_OK;
529 static ULONG WINAPI connpoint_AddRef( IConnectionPoint *iface )
531 struct connection_point *connpoint = impl_from_IConnectionPoint( iface );
532 return IConnectionPointContainer_AddRef( &connpoint->conn->IConnectionPointContainer_iface );
535 static ULONG WINAPI connpoint_Release( IConnectionPoint *iface )
537 struct connection_point *connpoint = impl_from_IConnectionPoint( iface );
538 return IConnectionPointContainer_Release( &connpoint->conn->IConnectionPointContainer_iface );
541 static HRESULT WINAPI connpoint_GetConnectionInterface( IConnectionPoint *iface, IID *iid )
543 struct connection_point *connpoint = impl_from_IConnectionPoint( iface );
544 FIXME( "%p, %p\n", connpoint, iid );
545 return E_NOTIMPL;
548 static HRESULT WINAPI connpoint_GetConnectionPointContainer( IConnectionPoint *iface,
549 IConnectionPointContainer **container )
551 struct connection_point *connpoint = impl_from_IConnectionPoint( iface );
552 FIXME( "%p, %p\n", connpoint, container );
553 return E_NOTIMPL;
556 static HRESULT WINAPI connpoint_Advise( IConnectionPoint *iface, IUnknown *unk_sink,
557 DWORD *cookie )
559 struct connection_point *connpoint = impl_from_IConnectionPoint( iface );
560 IUnknown *sink, **tmp;
561 ULONG new_size;
562 HRESULT hr;
563 DWORD i;
565 TRACE( "%p, %p, %p\n", iface, unk_sink, cookie );
567 if (!unk_sink || !cookie) return E_FAIL;
569 if (FAILED(hr = IUnknown_QueryInterface( unk_sink, &IID_ConnectionEventsVt, (void**)&sink )))
571 *cookie = 0;
572 return E_FAIL;
575 if (connpoint->sinks)
577 for (i = 0; i < connpoint->sinks_size; ++i)
579 if (!connpoint->sinks[i])
580 break;
583 if (i == connpoint->sinks_size)
585 new_size = connpoint->sinks_size * 2;
586 if (!(tmp = heap_realloc_zero( connpoint->sinks, new_size * sizeof(*connpoint->sinks) )))
587 return E_OUTOFMEMORY;
588 connpoint->sinks = tmp;
589 connpoint->sinks_size = new_size;
592 else
594 if (!(connpoint->sinks = heap_alloc_zero( sizeof(*connpoint->sinks) ))) return E_OUTOFMEMORY;
595 connpoint->sinks_size = 1;
596 i = 0;
599 connpoint->sinks[i] = sink;
600 *cookie = i + 1;
601 return S_OK;
604 static HRESULT WINAPI connpoint_Unadvise( IConnectionPoint *iface, DWORD cookie )
606 struct connection_point *connpoint = impl_from_IConnectionPoint( iface );
607 TRACE( "%p, %u\n", connpoint, cookie );
609 if (!cookie || cookie > connpoint->sinks_size || !connpoint->sinks || !connpoint->sinks[cookie - 1])
610 return E_FAIL;
612 IUnknown_Release( connpoint->sinks[cookie - 1] );
613 connpoint->sinks[cookie - 1] = NULL;
614 return S_OK;
617 static HRESULT WINAPI connpoint_EnumConnections( IConnectionPoint *iface,
618 IEnumConnections **points )
620 struct connection_point *connpoint = impl_from_IConnectionPoint( iface );
621 FIXME( "%p, %p\n", connpoint, points );
622 return E_NOTIMPL;
625 static const IConnectionPointVtbl connpoint_vtbl =
627 connpoint_QueryInterface,
628 connpoint_AddRef,
629 connpoint_Release,
630 connpoint_GetConnectionInterface,
631 connpoint_GetConnectionPointContainer,
632 connpoint_Advise,
633 connpoint_Unadvise,
634 connpoint_EnumConnections
637 HRESULT Connection_create( void **obj )
639 struct connection *connection;
641 if (!(connection = heap_alloc( sizeof(*connection) ))) return E_OUTOFMEMORY;
642 connection->Connection_iface.lpVtbl = &connection_vtbl;
643 connection->ISupportErrorInfo_iface.lpVtbl = &support_error_vtbl;
644 connection->IConnectionPointContainer_iface.lpVtbl = &connpointcontainer_vtbl;
645 connection->refs = 1;
646 connection->state = adStateClosed;
647 connection->timeout = 30;
648 connection->datasource = NULL;
650 connection->cp_connev.conn = connection;
651 connection->cp_connev.riid = &DIID_ConnectionEvents;
652 connection->cp_connev.IConnectionPoint_iface.lpVtbl = &connpoint_vtbl;
653 connection->cp_connev.sinks = NULL;
654 connection->cp_connev.sinks_size = 0;
656 *obj = &connection->Connection_iface;
657 TRACE( "returning iface %p\n", *obj );
658 return S_OK;