]>
git.proxmox.com Git - mirror_smartmontools-debian.git/blob - os_win32/wmiquery.h
4 * Home page of code is: http://smartmontools.sourceforge.net
6 * Copyright (C) 2011 Christian Franke <smartmontools-support@lists.sourceforge.net>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
13 * You should have received a copy of the GNU General Public License
14 * (for example COPYING); If not, see <http://www.gnu.org/licenses/>.
21 #define WMIQUERY_H_CVSID "$Id: wmiquery.h 3475 2011-11-10 21:43:40Z chrfranke $"
26 #include "wbemcli_small.h"
32 #define __attribute_format_printf(x, y) /**/
33 #elif defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO
34 // Check format of __mingw_*printf() instead of MSVCRT.DLL:*printf()
35 #define __attribute_format_printf(x, y) __attribute__((format (gnu_printf, x, y)))
37 #define __attribute_format_printf(x, y) __attribute__((format (printf, x, y)))
40 /////////////////////////////////////////////////////////////////////////////
43 /// Wrapper class for COM BSTR
47 /// Construct from string.
48 com_bstr(const char * str
);
50 /// Destructor frees BSTR.
52 { SysFreeString(m_bstr
); }
54 /// Implicit conversion to BSTR.
58 /// Convert BSTR back to std::string.
59 static bool to_str(const BSTR
& bstr
, std::string
& str
);
64 com_bstr(const com_bstr
&);
65 void operator=(const com_bstr
&);
69 /////////////////////////////////////////////////////////////////////////////
72 /// Wrapper class for COM Interface pointer
77 /// Construct empty object
81 /// Destructor releases the interface.
85 /// Release interface and clear the pointer.
89 m_ptr
->Release(); m_ptr
= 0;
93 /// Return the pointer.
97 /// Pointer dereferencing.
101 /// Return address of pointer for replacement.
103 { reset(); return &m_ptr
; }
105 /// For (ptr != 0) check.
106 operator bool() const
109 /// For (ptr == 0) check.
110 bool operator!() const
116 com_intf_ptr(const com_intf_ptr
&);
117 void operator=(const com_intf_ptr
&);
121 /////////////////////////////////////////////////////////////////////////////
124 class wbem_enumerator
;
126 /// Wrapper class for IWbemClassObject
130 /// Get string representation.
131 std::string
get_str(const char * name
) /*const*/;
134 /// Contents is set by wbem_enumerator.
135 friend class wbem_enumerator
;
136 com_intf_ptr
<IWbemClassObject
> m_intf
;
140 /////////////////////////////////////////////////////////////////////////////
145 /// Wrapper class for IEnumWbemClassObject
146 class wbem_enumerator
149 /// Get next object, return false if none or error.
150 bool next(wbem_object
& obj
);
153 /// Contents is set by wbem_services.
154 friend class wbem_services
;
155 com_intf_ptr
<IEnumWbemClassObject
> m_intf
;
159 /////////////////////////////////////////////////////////////////////////////
162 /// Wrapper class for IWbemServices
166 /// Connect to service, return false on error.
169 /// Execute query, get result list.
170 /// Return false on error.
171 bool vquery(wbem_enumerator
& result
, const char * qstr
, va_list args
) /*const*/;
173 /// Execute query, get single result object.
174 /// Return false on error or result size != 1.
175 bool vquery1(wbem_object
& obj
, const char * qstr
, va_list args
) /*const*/;
177 /// Version of vquery() with printf() formatting.
178 bool query(wbem_enumerator
& result
, const char * qstr
, ...) /*const*/
179 __attribute_format_printf(3, 4);
181 /// Version of vquery1() with printf() formatting.
182 bool query1(wbem_object
& obj
, const char * qstr
, ...) /*const*/
183 __attribute_format_printf(3, 4);
186 com_intf_ptr
<IWbemServices
> m_intf
;