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
29 #include "wine/debug.h"
30 #include "wbemprox_private.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
36 IWbemQualifierSet IWbemQualifierSet_iface;
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 );
62 TRACE("destroying %p\n", set);
63 heap_free( set->class );
64 heap_free( set->member );
70 static HRESULT WINAPI qualifier_set_QueryInterface(
71 IWbemQualifierSet *iface,
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 ) )
86 FIXME("interface %s not implemented\n", debugstr_guid(riid));
89 IWbemQualifierSet_AddRef( iface );
93 static HRESULT create_qualifier_enum( const WCHAR *class, const WCHAR *member, const WCHAR *name,
94 IEnumWbemClassObject **iter )
96 static const WCHAR fmtW[] =
97 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','_','_','Q','U','A','L',
98 'I','F','I','E','R','S',' ','W','H','E','R','E',' ','C','l','a','s','s','=',
99 '\'','%','s','\'',' ','A','N','D',' ','M','e','m','b','e','r','=','\'','%','s','\'',' ',
100 'A','N','D',' ','N','a','m','e','=','\'','%','s','\'',0};
101 static const WCHAR fmt2W[] =
102 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','_','_','Q','U','A','L',
103 'I','F','I','E','R','S',' ','W','H','E','R','E',' ','C','l','a','s','s','=',
104 '\'','%','s','\'',' ','A','N','D',' ','M','e','m','b','e','r','=','\'','%','s','\'',0};
105 static const WCHAR noneW[] = {'_','_','N','O','N','E',0};
110 if (!member) member = noneW;
111 len = strlenW( class ) + strlenW( member );
112 if (name) len += strlenW( name ) + SIZEOF(fmtW);
113 else len += SIZEOF(fmt2W);
115 if (!(query = heap_alloc( len * sizeof(WCHAR) ))) return E_OUTOFMEMORY;
116 if (name) sprintfW( query, fmtW, class, member, name );
117 else sprintfW( query, fmt2W, class, member );
119 hr = exec_query( query, iter );
124 static HRESULT get_qualifier_value( const WCHAR *class, const WCHAR *member, const WCHAR *name,
125 VARIANT *val, LONG *flavor )
127 static const WCHAR qualifiersW[] = {'_','_','Q','U','A','L','I','F','I','E','R','S',0};
128 static const WCHAR intvalueW[] = {'I','n','t','e','g','e','r','V','a','l','u','e',0};
129 static const WCHAR strvalueW[] = {'S','t','r','i','n','g','V','a','l','u','e',0};
130 static const WCHAR flavorW[] = {'F','l','a','v','o','r',0};
131 static const WCHAR typeW[] = {'T','y','p','e',0};
132 IEnumWbemClassObject *iter;
133 IWbemClassObject *obj;
137 hr = create_qualifier_enum( class, member, name, &iter );
138 if (FAILED( hr )) return hr;
140 hr = create_class_object( qualifiersW, iter, 0, NULL, &obj );
141 IEnumWbemClassObject_Release( iter );
142 if (FAILED( hr )) return hr;
146 hr = IWbemClassObject_Get( obj, flavorW, 0, &var, NULL, NULL );
147 if (hr != S_OK) goto done;
148 *flavor = V_I4( &var );
150 hr = IWbemClassObject_Get( obj, typeW, 0, &var, NULL, NULL );
151 if (hr != S_OK) goto done;
152 switch (V_UI4( &var ))
155 hr = IWbemClassObject_Get( obj, strvalueW, 0, val, NULL, NULL );
158 hr = IWbemClassObject_Get( obj, intvalueW, 0, val, NULL, NULL );
161 ERR("unhandled type %u\n", V_UI4( &var ));
166 IWbemClassObject_Release( obj );
170 static HRESULT WINAPI qualifier_set_Get(
171 IWbemQualifierSet *iface,
177 struct qualifier_set *set = impl_from_IWbemQualifierSet( iface );
179 FIXME("%p, %s, %08x, %p, %p\n", iface, debugstr_w(wszName), lFlags, pVal, plFlavor);
180 return get_qualifier_value( set->class, set->member, wszName, pVal, plFlavor );
183 static HRESULT WINAPI qualifier_set_Put(
184 IWbemQualifierSet *iface,
189 FIXME("%p, %s, %p, %d\n", iface, debugstr_w(wszName), pVal, lFlavor);
193 static HRESULT WINAPI qualifier_set_Delete(
194 IWbemQualifierSet *iface,
197 FIXME("%p, %s\n", iface, debugstr_w(wszName));
201 static HRESULT WINAPI qualifier_set_GetNames(
202 IWbemQualifierSet *iface,
206 FIXME("%p, %08x, %p\n", iface, lFlags, pNames);
210 static HRESULT WINAPI qualifier_set_BeginEnumeration(
211 IWbemQualifierSet *iface,
214 FIXME("%p, %08x\n", iface, lFlags);
218 static HRESULT WINAPI qualifier_set_Next(
219 IWbemQualifierSet *iface,
225 FIXME("%p, %08x, %p, %p, %p\n", iface, lFlags, pstrName, pVal, plFlavor);
229 static HRESULT WINAPI qualifier_set_EndEnumeration(
230 IWbemQualifierSet *iface )
232 FIXME("%p\n", iface);
236 static const IWbemQualifierSetVtbl qualifier_set_vtbl =
238 qualifier_set_QueryInterface,
239 qualifier_set_AddRef,
240 qualifier_set_Release,
243 qualifier_set_Delete,
244 qualifier_set_GetNames,
245 qualifier_set_BeginEnumeration,
247 qualifier_set_EndEnumeration
250 HRESULT WbemQualifierSet_create(
251 IUnknown *pUnkOuter, const WCHAR *class, const WCHAR *member, LPVOID *ppObj )
253 struct qualifier_set *set;
255 TRACE("%p, %p\n", pUnkOuter, ppObj);
257 if (!(set = heap_alloc( sizeof(*set) ))) return E_OUTOFMEMORY;
259 set->IWbemQualifierSet_iface.lpVtbl = &qualifier_set_vtbl;
260 if (!(set->class = heap_strdupW( class )))
263 return E_OUTOFMEMORY;
265 if (!member) set->member = NULL;
266 else if (!(set->member = heap_strdupW( member )))
268 heap_free( set->class );
270 return E_OUTOFMEMORY;
274 *ppObj = &set->IWbemQualifierSet_iface;
276 TRACE("returning iface %p\n", *ppObj);