Confdump Agent
1.4.0
|
00001 /* 00002 * Confdump-Agent - Dump static and runtime system configuration 00003 * Copyright (C) 2009-2012 Straton IT, SAS 00004 * 00005 * This program is free software: you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 3 as 00007 * published by the Free Software Foundation. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 */ 00017 00018 #ifndef INCLUDED_CONFDUMP_SYSTEM_WMI_CHECKEDCALLS_HPP 00019 #define INCLUDED_CONFDUMP_SYSTEM_WMI_CHECKEDCALLS_HPP 00020 00021 #include <comdef.h> 00022 00023 #include "boost/shared_ptr.hpp" 00024 #include "boost/bind.hpp" 00025 #include "QString" 00026 00027 #include "Confdump/RuntimeError.hpp" 00028 00029 struct IErrorInfo; 00030 00031 namespace Confdump 00032 { 00033 namespace System 00034 { 00035 namespace Wmi 00036 { 00037 00073 template<class T> 00074 boost::shared_ptr<T> guardComObject( T *ptr ) 00075 { 00076 /* Exception safety notes: shared_ptr may throw a bad_alloc, in that case 00077 * Release is called. 00078 */ 00079 return boost::shared_ptr<T>( ptr, boost::bind( &T::Release, _1 ) ); 00080 } 00081 00082 00088 class Win32Error : public RuntimeError 00089 { 00090 public: 00091 Win32Error( QString message, HRESULT hr ); 00092 virtual ~Win32Error(); 00093 00095 HRESULT hresult() const; 00097 QString hresultAsHex() const; 00098 00099 public: 00100 Win32Error(); 00101 00102 HRESULT hresult_; 00103 }; 00104 00112 class ComError : public Win32Error 00113 { 00114 public: 00118 ComError( HRESULT hr, QString action ); 00119 virtual ~ComError(); 00120 00122 QString errorMessage() const; 00123 00124 private: 00125 ComError(); 00126 00127 _com_error comError_; 00128 }; 00129 00138 class WmiError : public Win32Error 00139 { 00140 public: 00147 WmiError( QString statusDump, HRESULT hr, QString action ); 00148 virtual ~WmiError(); 00149 00150 private: 00151 WmiError(); 00152 }; 00153 00177 void throwOnComError( HRESULT hr, QString action ); 00178 00187 void throwOnWmiError( HRESULT hr, QString action, QString element = QString() ); 00188 00191 class WmiDiagnostics 00192 { 00193 HRESULT hr_; 00194 QString cause_; 00195 00196 WmiDiagnostics(); 00197 00198 public: 00199 WmiDiagnostics( HRESULT hr ); 00200 bool knownError() const; 00202 QString toString() const; 00203 }; 00204 00206 00207 } 00208 } 00209 } 00210 00211 #endif /* INCLUDED_CONFDUMP_SYSTEM_WMI_CHECKEDCALLS_HPP */