winemac.drv: Don't filter non active displays out.
[wine/zf.git] / dlls / wbemprox / qualifier.c
blob1cc4087ff35421069edc21d4d85392fb32a73883
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 WCHAR *class;
38 WCHAR *member;
41 static inline struct qualifier_set *impl_from_IWbemQualifierSet(
42 IWbemQualifierSet *iface )
44 return CONTAINING_RECORD(iface, struct qualifier_set, IWbemQualifierSet_iface);
47 static ULONG WINAPI qualifier_set_AddRef(
48 IWbemQualifierSet *iface )
50 struct qualifier_set *set = impl_from_IWbemQualifierSet( iface );
51 return InterlockedIncrement( &set->refs );
54 static ULONG WINAPI qualifier_set_Release(
55 IWbemQualifierSet *iface )
57 struct qualifier_set *set = impl_from_IWbemQualifierSet( iface );
58 LONG refs = InterlockedDecrement( &set->refs );
59 if (!refs)
61 TRACE("destroying %p\n", set);
62 heap_free( set->class );
63 heap_free( set->member );
64 heap_free( set );
66 return refs;
69 static HRESULT WINAPI qualifier_set_QueryInterface(
70 IWbemQualifierSet *iface,
71 REFIID riid,
72 void **ppvObject )
74 struct qualifier_set *set = impl_from_IWbemQualifierSet( iface );
76 TRACE("%p, %s, %p\n", set, debugstr_guid( riid ), ppvObject );
78 if ( IsEqualGUID( riid, &IID_IWbemQualifierSet ) ||
79 IsEqualGUID( riid, &IID_IUnknown ) )
81 *ppvObject = set;
83 else
85 FIXME("interface %s not implemented\n", debugstr_guid(riid));
86 return E_NOINTERFACE;
88 IWbemQualifierSet_AddRef( iface );
89 return S_OK;
92 static HRESULT create_qualifier_enum( const WCHAR *class, const WCHAR *member, const WCHAR *name,
93 IEnumWbemClassObject **iter )
95 static const WCHAR fmtW[] = L"SELECT * FROM __QUALIFIERS WHERE Class='%s' AND Member='%s' AND Name='%s'";
96 static const WCHAR fmt2W[] = L"SELECT * FROM __QUALIFIERS WHERE Class='%s' AND Member='%s'";
97 static const WCHAR fmt3W[] = L"SELECT * FROM __QUALIFIERS WHERE Class='%s'";
98 WCHAR *query;
99 HRESULT hr;
100 int len;
102 if (member && name)
104 len = lstrlenW( class ) + lstrlenW( member ) + lstrlenW( name ) + ARRAY_SIZE(fmtW);
105 if (!(query = heap_alloc( len * sizeof(WCHAR) ))) return E_OUTOFMEMORY;
106 swprintf( query, len, fmtW, class, member, name );
108 else if (member)
110 len = lstrlenW( class ) + lstrlenW( member ) + ARRAY_SIZE(fmt2W);
111 if (!(query = heap_alloc( len * sizeof(WCHAR) ))) return E_OUTOFMEMORY;
112 swprintf( query, len, fmt2W, class, member );
114 else
116 len = lstrlenW( class ) + ARRAY_SIZE(fmt3W);
117 if (!(query = heap_alloc( len * sizeof(WCHAR) ))) return E_OUTOFMEMORY;
118 swprintf( query, len, fmt3W, class );
121 hr = exec_query( query, iter );
122 heap_free( query );
123 return hr;
126 static HRESULT get_qualifier_value( const WCHAR *class, const WCHAR *member, const WCHAR *name,
127 VARIANT *val, LONG *flavor )
129 IEnumWbemClassObject *iter;
130 IWbemClassObject *obj;
131 VARIANT var;
132 HRESULT hr;
134 hr = create_qualifier_enum( class, member, name, &iter );
135 if (FAILED( hr )) return hr;
137 hr = create_class_object( NULL, iter, 0, NULL, &obj );
138 IEnumWbemClassObject_Release( iter );
139 if (FAILED( hr )) return hr;
141 if (flavor)
143 hr = IWbemClassObject_Get( obj, L"Flavor", 0, &var, NULL, NULL );
144 if (hr != S_OK) goto done;
145 *flavor = V_I4( &var );
147 hr = IWbemClassObject_Get( obj, L"Type", 0, &var, NULL, NULL );
148 if (hr != S_OK) goto done;
149 switch (V_UI4( &var ))
151 case CIM_STRING:
152 hr = IWbemClassObject_Get( obj, L"StringValue", 0, val, NULL, NULL );
153 break;
154 case CIM_SINT32:
155 hr = IWbemClassObject_Get( obj, L"IntegerValue", 0, val, NULL, NULL );
156 break;
157 case CIM_BOOLEAN:
158 hr = IWbemClassObject_Get( obj, L"BoolValue", 0, val, NULL, NULL );
159 break;
160 default:
161 ERR("unhandled type %u\n", V_UI4( &var ));
162 break;
165 done:
166 IWbemClassObject_Release( obj );
167 return hr;
170 static HRESULT WINAPI qualifier_set_Get(
171 IWbemQualifierSet *iface,
172 LPCWSTR wszName,
173 LONG lFlags,
174 VARIANT *pVal,
175 LONG *plFlavor )
177 struct qualifier_set *set = impl_from_IWbemQualifierSet( iface );
179 TRACE("%p, %s, %08x, %p, %p\n", iface, debugstr_w(wszName), lFlags, pVal, plFlavor);
180 if (lFlags)
182 FIXME("flags %08x not supported\n", lFlags);
183 return E_NOTIMPL;
185 return get_qualifier_value( set->class, set->member, wszName, pVal, plFlavor );
188 static HRESULT WINAPI qualifier_set_Put(
189 IWbemQualifierSet *iface,
190 LPCWSTR wszName,
191 VARIANT *pVal,
192 LONG lFlavor )
194 FIXME("%p, %s, %p, %d\n", iface, debugstr_w(wszName), pVal, lFlavor);
195 return E_NOTIMPL;
198 static HRESULT WINAPI qualifier_set_Delete(
199 IWbemQualifierSet *iface,
200 LPCWSTR wszName )
202 FIXME("%p, %s\n", iface, debugstr_w(wszName));
203 return E_NOTIMPL;
206 static HRESULT WINAPI qualifier_set_GetNames(
207 IWbemQualifierSet *iface,
208 LONG lFlags,
209 SAFEARRAY **pNames )
211 struct qualifier_set *set = impl_from_IWbemQualifierSet( iface );
212 IEnumWbemClassObject *iter;
213 IWbemClassObject *obj;
214 HRESULT hr;
216 TRACE("%p, %08x, %p\n", iface, lFlags, pNames);
217 if (lFlags)
219 FIXME("flags %08x not supported\n", lFlags);
220 return E_NOTIMPL;
223 hr = create_qualifier_enum( set->class, set->member, NULL, &iter );
224 if (FAILED( hr )) return hr;
226 hr = create_class_object( NULL, iter, 0, NULL, &obj );
227 IEnumWbemClassObject_Release( iter );
228 if (FAILED( hr )) return hr;
230 hr = IWbemClassObject_GetNames( obj, NULL, 0, NULL, pNames );
231 IWbemClassObject_Release( obj );
232 return hr;
235 static HRESULT WINAPI qualifier_set_BeginEnumeration(
236 IWbemQualifierSet *iface,
237 LONG lFlags )
239 FIXME("%p, %08x\n", iface, lFlags);
240 return E_NOTIMPL;
243 static HRESULT WINAPI qualifier_set_Next(
244 IWbemQualifierSet *iface,
245 LONG lFlags,
246 BSTR *pstrName,
247 VARIANT *pVal,
248 LONG *plFlavor )
250 FIXME("%p, %08x, %p, %p, %p\n", iface, lFlags, pstrName, pVal, plFlavor);
251 return E_NOTIMPL;
254 static HRESULT WINAPI qualifier_set_EndEnumeration(
255 IWbemQualifierSet *iface )
257 FIXME("%p\n", iface);
258 return E_NOTIMPL;
261 static const IWbemQualifierSetVtbl qualifier_set_vtbl =
263 qualifier_set_QueryInterface,
264 qualifier_set_AddRef,
265 qualifier_set_Release,
266 qualifier_set_Get,
267 qualifier_set_Put,
268 qualifier_set_Delete,
269 qualifier_set_GetNames,
270 qualifier_set_BeginEnumeration,
271 qualifier_set_Next,
272 qualifier_set_EndEnumeration
275 HRESULT WbemQualifierSet_create( const WCHAR *class, const WCHAR *member, LPVOID *ppObj )
277 struct qualifier_set *set;
279 TRACE("%p\n", ppObj);
281 if (!(set = heap_alloc( sizeof(*set) ))) return E_OUTOFMEMORY;
283 set->IWbemQualifierSet_iface.lpVtbl = &qualifier_set_vtbl;
284 if (!(set->class = heap_strdupW( class )))
286 heap_free( set );
287 return E_OUTOFMEMORY;
289 if (!member) set->member = NULL;
290 else if (!(set->member = heap_strdupW( member )))
292 heap_free( set->class );
293 heap_free( set );
294 return E_OUTOFMEMORY;
296 set->refs = 1;
298 *ppObj = &set->IWbemQualifierSet_iface;
300 TRACE("returning iface %p\n", *ppObj);
301 return S_OK;