wined3d: Don't use persistent BOs from the client thread if we might need to do verte...
[wine.git] / dlls / wbemprox / qualifier.c
blob826c48e9d932feb9ca23b5b50484a71ca94dc29b
1 /*
2 * Copyright 2013 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 #define COBJMACROS
21 #include <stdarg.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "objbase.h"
26 #include "wbemcli.h"
28 #include "wine/debug.h"
29 #include "wbemprox_private.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
33 struct qualifier_set
35 IWbemQualifierSet IWbemQualifierSet_iface;
36 LONG refs;
37 enum wbm_namespace ns;
38 WCHAR *class;
39 WCHAR *member;
42 static inline struct qualifier_set *impl_from_IWbemQualifierSet(
43 IWbemQualifierSet *iface )
45 return CONTAINING_RECORD(iface, struct qualifier_set, IWbemQualifierSet_iface);
48 static ULONG WINAPI qualifier_set_AddRef(
49 IWbemQualifierSet *iface )
51 struct qualifier_set *set = impl_from_IWbemQualifierSet( iface );
52 return InterlockedIncrement( &set->refs );
55 static ULONG WINAPI qualifier_set_Release(
56 IWbemQualifierSet *iface )
58 struct qualifier_set *set = impl_from_IWbemQualifierSet( iface );
59 LONG refs = InterlockedDecrement( &set->refs );
60 if (!refs)
62 TRACE("destroying %p\n", set);
63 free( set->class );
64 free( set->member );
65 free( set );
67 return refs;
70 static HRESULT WINAPI qualifier_set_QueryInterface(
71 IWbemQualifierSet *iface,
72 REFIID riid,
73 void **ppvObject )
75 struct qualifier_set *set = impl_from_IWbemQualifierSet( iface );
77 TRACE("%p, %s, %p\n", set, debugstr_guid( riid ), ppvObject );
79 if ( IsEqualGUID( riid, &IID_IWbemQualifierSet ) ||
80 IsEqualGUID( riid, &IID_IUnknown ) )
82 *ppvObject = set;
84 else
86 FIXME("interface %s not implemented\n", debugstr_guid(riid));
87 return E_NOINTERFACE;
89 IWbemQualifierSet_AddRef( iface );
90 return S_OK;
93 static HRESULT create_qualifier_enum( enum wbm_namespace ns, const WCHAR *class, const WCHAR *member,
94 const WCHAR *name, IEnumWbemClassObject **iter )
96 static const WCHAR fmtW[] = L"SELECT * FROM __QUALIFIERS WHERE Class='%s' AND Member='%s' AND Name='%s'";
97 static const WCHAR fmt2W[] = L"SELECT * FROM __QUALIFIERS WHERE Class='%s' AND Member='%s'";
98 static const WCHAR fmt3W[] = L"SELECT * FROM __QUALIFIERS WHERE Class='%s'";
99 WCHAR *query;
100 HRESULT hr;
101 int len;
103 if (member && name)
105 len = lstrlenW( class ) + lstrlenW( member ) + lstrlenW( name ) + ARRAY_SIZE(fmtW);
106 if (!(query = malloc( len * sizeof(WCHAR) ))) return E_OUTOFMEMORY;
107 swprintf( query, len, fmtW, class, member, name );
109 else if (member)
111 len = lstrlenW( class ) + lstrlenW( member ) + ARRAY_SIZE(fmt2W);
112 if (!(query = malloc( len * sizeof(WCHAR) ))) return E_OUTOFMEMORY;
113 swprintf( query, len, fmt2W, class, member );
115 else
117 len = lstrlenW( class ) + ARRAY_SIZE(fmt3W);
118 if (!(query = malloc( len * sizeof(WCHAR) ))) return E_OUTOFMEMORY;
119 swprintf( query, len, fmt3W, class );
122 hr = exec_query( ns, query, iter );
123 free( query );
124 return hr;
127 static HRESULT get_qualifier_value( enum wbm_namespace ns, const WCHAR *class, const WCHAR *member, const WCHAR *name,
128 VARIANT *val, LONG *flavor )
130 IEnumWbemClassObject *iter;
131 IWbemClassObject *obj;
132 VARIANT var;
133 HRESULT hr;
135 hr = create_qualifier_enum( ns, class, member, name, &iter );
136 if (FAILED( hr )) return hr;
138 hr = create_class_object( ns, NULL, iter, 0, NULL, &obj );
139 IEnumWbemClassObject_Release( iter );
140 if (FAILED( hr )) return hr;
142 if (flavor)
144 hr = IWbemClassObject_Get( obj, L"Flavor", 0, &var, NULL, NULL );
145 if (hr != S_OK) goto done;
146 *flavor = V_I4( &var );
148 hr = IWbemClassObject_Get( obj, L"Type", 0, &var, NULL, NULL );
149 if (hr != S_OK) goto done;
150 switch (V_UI4( &var ))
152 case CIM_STRING:
153 hr = IWbemClassObject_Get( obj, L"StringValue", 0, val, NULL, NULL );
154 break;
155 case CIM_SINT32:
156 hr = IWbemClassObject_Get( obj, L"IntegerValue", 0, val, NULL, NULL );
157 break;
158 case CIM_BOOLEAN:
159 hr = IWbemClassObject_Get( obj, L"BoolValue", 0, val, NULL, NULL );
160 break;
161 default:
162 ERR( "unhandled type %lu\n", V_UI4( &var ) );
163 break;
166 done:
167 IWbemClassObject_Release( obj );
168 return hr;
171 static HRESULT WINAPI qualifier_set_Get(
172 IWbemQualifierSet *iface,
173 LPCWSTR wszName,
174 LONG lFlags,
175 VARIANT *pVal,
176 LONG *plFlavor )
178 struct qualifier_set *set = impl_from_IWbemQualifierSet( iface );
180 TRACE( "%p, %s, %#lx, %p, %p\n", iface, debugstr_w(wszName), lFlags, pVal, plFlavor );
181 if (lFlags)
183 FIXME( "flags %#lx not supported\n", lFlags );
184 return E_NOTIMPL;
186 return get_qualifier_value( set->ns, set->class, set->member, wszName, pVal, plFlavor );
189 static HRESULT WINAPI qualifier_set_Put(
190 IWbemQualifierSet *iface,
191 LPCWSTR wszName,
192 VARIANT *pVal,
193 LONG lFlavor )
195 FIXME( "%p, %s, %p, %ld\n", iface, debugstr_w(wszName), pVal, lFlavor );
196 return E_NOTIMPL;
199 static HRESULT WINAPI qualifier_set_Delete(
200 IWbemQualifierSet *iface,
201 LPCWSTR wszName )
203 FIXME("%p, %s\n", iface, debugstr_w(wszName));
204 return E_NOTIMPL;
207 static HRESULT WINAPI qualifier_set_GetNames(
208 IWbemQualifierSet *iface,
209 LONG lFlags,
210 SAFEARRAY **pNames )
212 struct qualifier_set *set = impl_from_IWbemQualifierSet( iface );
213 IEnumWbemClassObject *iter;
214 IWbemClassObject *obj;
215 HRESULT hr;
217 TRACE( "%p, %#lx, %p\n", iface, lFlags, pNames );
218 if (lFlags)
220 FIXME( "flags %#lx not supported\n", lFlags );
221 return E_NOTIMPL;
224 hr = create_qualifier_enum( set->ns, set->class, set->member, NULL, &iter );
225 if (FAILED( hr )) return hr;
227 hr = create_class_object( set->ns, NULL, iter, 0, NULL, &obj );
228 IEnumWbemClassObject_Release( iter );
229 if (FAILED( hr )) return hr;
231 hr = IWbemClassObject_GetNames( obj, NULL, 0, NULL, pNames );
232 IWbemClassObject_Release( obj );
233 return hr;
236 static HRESULT WINAPI qualifier_set_BeginEnumeration(
237 IWbemQualifierSet *iface,
238 LONG lFlags )
240 FIXME( "%p, %#lx\n", iface, lFlags );
241 return E_NOTIMPL;
244 static HRESULT WINAPI qualifier_set_Next(
245 IWbemQualifierSet *iface,
246 LONG lFlags,
247 BSTR *pstrName,
248 VARIANT *pVal,
249 LONG *plFlavor )
251 FIXME( "%p, %#lx, %p, %p, %p\n", iface, lFlags, pstrName, pVal, plFlavor );
252 return E_NOTIMPL;
255 static HRESULT WINAPI qualifier_set_EndEnumeration(
256 IWbemQualifierSet *iface )
258 FIXME("%p\n", iface);
259 return E_NOTIMPL;
262 static const IWbemQualifierSetVtbl qualifier_set_vtbl =
264 qualifier_set_QueryInterface,
265 qualifier_set_AddRef,
266 qualifier_set_Release,
267 qualifier_set_Get,
268 qualifier_set_Put,
269 qualifier_set_Delete,
270 qualifier_set_GetNames,
271 qualifier_set_BeginEnumeration,
272 qualifier_set_Next,
273 qualifier_set_EndEnumeration
276 HRESULT WbemQualifierSet_create( enum wbm_namespace ns, const WCHAR *class, const WCHAR *member, LPVOID *ppObj )
278 struct qualifier_set *set;
280 TRACE("%p\n", ppObj);
282 if (!(set = malloc( sizeof(*set) ))) return E_OUTOFMEMORY;
284 set->IWbemQualifierSet_iface.lpVtbl = &qualifier_set_vtbl;
285 if (!(set->class = heap_strdupW( class )))
287 free( set );
288 return E_OUTOFMEMORY;
290 if (!member) set->member = NULL;
291 else if (!(set->member = heap_strdupW( member )))
293 free( set->class );
294 free( set );
295 return E_OUTOFMEMORY;
297 set->ns = ns;
298 set->refs = 1;
300 *ppObj = &set->IWbemQualifierSet_iface;
302 TRACE("returning iface %p\n", *ppObj);
303 return S_OK;