-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathObject.hpp
168 lines (125 loc) · 4.19 KB
/
Object.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
////////////////////////////////////////////////////////////////////////////////
//! \file Object.hpp
//! \brief The Object class declaration.
//! \author Chris Oldwood
// Check for previous inclusion
#ifndef WMI_OBJECT_HPP
#define WMI_OBJECT_HPP
#if _MSC_VER > 1000
#pragma once
#endif
#include "Types.hpp"
#include <set>
#include <WCL/Variant.hpp>
#include "Connection.hpp"
namespace WMI
{
////////////////////////////////////////////////////////////////////////////////
//! An instance of a WMI Class.
class Object
{
public:
//! A set of property names.
typedef std::set<tstring> PropertyNames;
//! The property type query flags.
enum PropertyTypes
{
ALL_PROPERTIES = 0,
NONSYSTEM_PROPERTIES = WBEM_FLAG_NONSYSTEM_ONLY,
LOCAL_PROPERTIES = WBEM_FLAG_LOCAL_ONLY,
PROPAGATED_PROPERTIES = WBEM_FLAG_PROPAGATED_ONLY,
SYSTEM_PROPERTIES = WBEM_FLAG_SYSTEM_ONLY,
};
public:
//! Default constructor.
Object();
//! Construction from the underlying COM object and connection.
Object(IWbemClassObjectPtr object, const Connection& connection);
//! Destructor.
virtual ~Object();
//
// Properties.
//
//! Get the underlying COM object.
IWbemClassObjectPtr get() const;
//! Get the underlying COM connection.
const Connection& connection() const;
//
// WMI Object properties.
//
//! Query if the object has the named property.
bool hasProperty(const tstring& name) const; // throw(WMI::Exception)
//! Get the names of the supported properties.
size_t getPropertyNames(PropertyNames& names, PropertyTypes types = NONSYSTEM_PROPERTIES) const; // throw(WMI::Exception)
//! Get the value for a property.
void getProperty(const tstring& name, WCL::Variant& value) const; // throw(WMI::Exception)
//! Get the property value for an object as a typed value.
template<typename T>
T getProperty(const tstring& name) const; // throw(WMI::Exception, ComException)
//
// WMI Object property short-hands.
//
//! Full path to the class or instance - including server and namespace.
tstring absolutePath() const;
//! Relative path to the class or instance.
tstring relativePath() const;
//
// WMI Object methods.
//
//! Create the object used to pass arguments to a method.
IWbemClassObjectPtr createArgumentsObject(const tstring& className, const tstring& methodName) const; // throw(WMI::Exception)
//! Execute a method on the object.
void execMethod(const tchar* method, WCL::Variant& returnValue); // throw(WMI::Exception)
//! Execute a method on the object.
void execMethod(const tchar* method, IWbemClassObjectPtr arguments, WCL::Variant& returnValue); // throw(WMI::Exception)
//! Set an argument's value.
static void setArgument(IWbemClassObjectPtr arguments, const tstring& name, const WCL::Variant& value);
//
// Methods.
//
//! Refresh the state of the object.
void refresh();
private:
//
// Members.
// NB: mutable as COM interfaces are always non-const.
//
mutable IWbemClassObjectPtr m_object; //! The underlying COM object.
Connection m_connection; //! The object's connection.
};
////////////////////////////////////////////////////////////////////////////////
//! Get the underlying COM object.
inline IWbemClassObjectPtr Object::get() const
{
return m_object;
}
////////////////////////////////////////////////////////////////////////////////
//! Get the underlying COM connection.
inline const Connection& Object::connection() const
{
return m_connection;
}
////////////////////////////////////////////////////////////////////////////////
//! Get the property value for an object as a typed value.
template<typename T>
inline T Object::getProperty(const tstring& name) const
{
WCL::Variant value;
getProperty(name, value);
return WCL::getValue<T>(value);
}
////////////////////////////////////////////////////////////////////////////////
//! Full path to the class or instance - including server and namespace.
inline tstring Object::absolutePath() const
{
return getProperty<tstring>(TXT("__Path"));
}
////////////////////////////////////////////////////////////////////////////////
//! Relative path to the class or instance.
inline tstring Object::relativePath() const
{
return getProperty<tstring>(TXT("__RelPath"));
}
//namespace WMI
}
#endif // WMI_OBJECT_HPP