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 #include "wbemprox_private.h"
23 IWbemQualifierSet IWbemQualifierSet_iface
;
29 static inline struct qualifier_set
*impl_from_IWbemQualifierSet(
30 IWbemQualifierSet
*iface
)
32 return CONTAINING_RECORD(iface
, struct qualifier_set
, IWbemQualifierSet_iface
);
35 static ULONG WINAPI
qualifier_set_AddRef(
36 IWbemQualifierSet
*iface
)
38 struct qualifier_set
*set
= impl_from_IWbemQualifierSet( iface
);
39 return InterlockedIncrement( &set
->refs
);
42 static ULONG WINAPI
qualifier_set_Release(
43 IWbemQualifierSet
*iface
)
45 struct qualifier_set
*set
= impl_from_IWbemQualifierSet( iface
);
46 LONG refs
= InterlockedDecrement( &set
->refs
);
49 TRACE("destroying %p\n", set
);
50 heap_free( set
->class );
51 heap_free( set
->member
);
57 static HRESULT WINAPI
qualifier_set_QueryInterface(
58 IWbemQualifierSet
*iface
,
62 struct qualifier_set
*set
= impl_from_IWbemQualifierSet( iface
);
64 TRACE("%p, %s, %p\n", set
, debugstr_guid( riid
), ppvObject
);
66 if ( IsEqualGUID( riid
, &IID_IWbemQualifierSet
) ||
67 IsEqualGUID( riid
, &IID_IUnknown
) )
73 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
76 IWbemQualifierSet_AddRef( iface
);
80 static HRESULT
create_qualifier_enum( const WCHAR
*class, const WCHAR
*member
, const WCHAR
*name
,
81 IEnumWbemClassObject
**iter
)
83 static const WCHAR fmtW
[] =
84 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','_','_','Q','U','A','L',
85 'I','F','I','E','R','S',' ','W','H','E','R','E',' ','C','l','a','s','s','=',
86 '\'','%','s','\'',' ','A','N','D',' ','M','e','m','b','e','r','=','\'','%','s','\'',' ',
87 'A','N','D',' ','N','a','m','e','=','\'','%','s','\'',0};
88 static const WCHAR fmt2W
[] =
89 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','_','_','Q','U','A','L',
90 'I','F','I','E','R','S',' ','W','H','E','R','E',' ','C','l','a','s','s','=',
91 '\'','%','s','\'',' ','A','N','D',' ','M','e','m','b','e','r','=','\'','%','s','\'',0};
92 static const WCHAR noneW
[] = {'_','_','N','O','N','E',0};
97 if (!member
) member
= noneW
;
98 len
= strlenW( class ) + strlenW( member
);
99 if (name
) len
+= strlenW( name
) + SIZEOF(fmtW
);
100 else len
+= SIZEOF(fmt2W
);
102 if (!(query
= heap_alloc( len
* sizeof(WCHAR
) ))) return E_OUTOFMEMORY
;
103 if (name
) sprintfW( query
, fmtW
, class, member
, name
);
104 else sprintfW( query
, fmt2W
, class, member
);
106 hr
= exec_query( query
, iter
);
111 static HRESULT
get_qualifier_value( const WCHAR
*class, const WCHAR
*member
, const WCHAR
*name
,
112 VARIANT
*val
, LONG
*flavor
)
114 static const WCHAR qualifiersW
[] = {'_','_','Q','U','A','L','I','F','I','E','R','S',0};
115 static const WCHAR intvalueW
[] = {'I','n','t','e','g','e','r','V','a','l','u','e',0};
116 static const WCHAR strvalueW
[] = {'S','t','r','i','n','g','V','a','l','u','e',0};
117 static const WCHAR flavorW
[] = {'F','l','a','v','o','r',0};
118 static const WCHAR typeW
[] = {'T','y','p','e',0};
119 IEnumWbemClassObject
*iter
;
120 IWbemClassObject
*obj
;
124 hr
= create_qualifier_enum( class, member
, name
, &iter
);
125 if (FAILED( hr
)) return hr
;
127 hr
= create_class_object( qualifiersW
, iter
, 0, NULL
, &obj
);
128 IEnumWbemClassObject_Release( iter
);
129 if (FAILED( hr
)) return hr
;
133 hr
= IWbemClassObject_Get( obj
, flavorW
, 0, &var
, NULL
, NULL
);
134 if (hr
!= S_OK
) goto done
;
135 *flavor
= V_I4( &var
);
137 hr
= IWbemClassObject_Get( obj
, typeW
, 0, &var
, NULL
, NULL
);
138 if (hr
!= S_OK
) goto done
;
139 switch (V_UI4( &var
))
142 hr
= IWbemClassObject_Get( obj
, strvalueW
, 0, val
, NULL
, NULL
);
145 hr
= IWbemClassObject_Get( obj
, intvalueW
, 0, val
, NULL
, NULL
);
148 ERR("unhandled type %u\n", V_UI4( &var
));
153 IWbemClassObject_Release( obj
);
157 static HRESULT WINAPI
qualifier_set_Get(
158 IWbemQualifierSet
*iface
,
164 struct qualifier_set
*set
= impl_from_IWbemQualifierSet( iface
);
166 FIXME("%p, %s, %08x, %p, %p\n", iface
, debugstr_w(wszName
), lFlags
, pVal
, plFlavor
);
167 return get_qualifier_value( set
->class, set
->member
, wszName
, pVal
, plFlavor
);
170 static HRESULT WINAPI
qualifier_set_Put(
171 IWbemQualifierSet
*iface
,
176 FIXME("%p, %s, %p, %d\n", iface
, debugstr_w(wszName
), pVal
, lFlavor
);
180 static HRESULT WINAPI
qualifier_set_Delete(
181 IWbemQualifierSet
*iface
,
184 FIXME("%p, %s\n", iface
, debugstr_w(wszName
));
188 static HRESULT WINAPI
qualifier_set_GetNames(
189 IWbemQualifierSet
*iface
,
193 FIXME("%p, %08x, %p\n", iface
, lFlags
, pNames
);
197 static HRESULT WINAPI
qualifier_set_BeginEnumeration(
198 IWbemQualifierSet
*iface
,
201 FIXME("%p, %08x\n", iface
, lFlags
);
205 static HRESULT WINAPI
qualifier_set_Next(
206 IWbemQualifierSet
*iface
,
212 FIXME("%p, %08x, %p, %p, %p\n", iface
, lFlags
, pstrName
, pVal
, plFlavor
);
216 static HRESULT WINAPI
qualifier_set_EndEnumeration(
217 IWbemQualifierSet
*iface
)
219 FIXME("%p\n", iface
);
223 static const IWbemQualifierSetVtbl qualifier_set_vtbl
=
225 qualifier_set_QueryInterface
,
226 qualifier_set_AddRef
,
227 qualifier_set_Release
,
230 qualifier_set_Delete
,
231 qualifier_set_GetNames
,
232 qualifier_set_BeginEnumeration
,
234 qualifier_set_EndEnumeration
237 HRESULT
WbemQualifierSet_create(
238 IUnknown
*pUnkOuter
, const WCHAR
*class, const WCHAR
*member
, LPVOID
*ppObj
)
240 struct qualifier_set
*set
;
242 TRACE("%p, %p\n", pUnkOuter
, ppObj
);
244 if (!(set
= heap_alloc( sizeof(*set
) ))) return E_OUTOFMEMORY
;
246 set
->IWbemQualifierSet_iface
.lpVtbl
= &qualifier_set_vtbl
;
247 if (!(set
->class = heap_strdupW( class )))
250 return E_OUTOFMEMORY
;
252 if (!member
) set
->member
= NULL
;
253 else if (!(set
->member
= heap_strdupW( member
)))
255 heap_free( set
->class );
257 return E_OUTOFMEMORY
;
261 *ppObj
= &set
->IWbemQualifierSet_iface
;
263 TRACE("returning iface %p\n", *ppObj
);