-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathConnection.hpp
117 lines (86 loc) · 2.9 KB
/
Connection.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
////////////////////////////////////////////////////////////////////////////////
//! \file Connection.hpp
//! \brief The Connection class declaration.
//! \author Chris Oldwood
// Check for previous inclusion
#ifndef WMI_CONNECTION_HPP
#define WMI_CONNECTION_HPP
#if _MSC_VER > 1000
#pragma once
#endif
#include "Types.hpp"
#include <WCL/Variant.hpp>
namespace WMI
{
// Forward declarations.
class Object;
class ObjectIterator;
////////////////////////////////////////////////////////////////////////////////
//! A connection to the WMI provider on a host.
class Connection
{
public:
//! Default constructor.
Connection();
//! Open a connection to a specific host using the current credentials.
Connection(const tstring& host); // throw(WMI::Exception)
//! Destructor.
~Connection();
//
// Properties.
//
//! Query if the connection is open.
bool isOpen() const;
//! Get the underlying COM connection.
IWbemServicesPtr get() const;
//
// Methods.
//
//! Open a connection to the current host.
void open(); // throw(WMI::Exception)
//! Open a connection to a specific host using the current credentials.
void open(const tstring& host); // throw(WMI::Exception)
//! Open a connection to a specific host.
void open(const tstring& host, const tstring& login, const tstring& password); // throw(WMI::Exception)
//! Open a connection to a specific host and namespace.
void open(const tstring& host, const tstring& login, const tstring& password, const tstring& nmspace); // throw(WMI::Exception)
//! Close the connection.
void close();
//! Get a single object using it's unique path.
Object getObject(const tstring& path) const; // throw(WMI::Exception)
//! Execute the query.
ObjectIterator execQuery(const tstring& query) const; // throw(WMI::Exception)
//! Execute the query.
ObjectIterator execQuery(const tchar* query) const; // throw(WMI::Exception)
//
// Methods.
//
//! Execute a method on an object.
static void execMethod(IWbemServicesPtr connection, IWbemClassObjectPtr object,
const tchar* path, const tchar* method, WCL::Variant& returnValue); // throw(WMI::Exception)
//! Execute a method on the object.
static void execMethod(IWbemServicesPtr connection, IWbemClassObjectPtr object,
const tchar* path, const tchar* method, IWbemClassObjectPtr arguments, WCL::Variant& returnValue); // throw(WMI::Exception)
//
// Constants.
//
//! The local computer path.
static const tstring LOCALHOST;
//! The default namespace.
static const tstring DEFAULT_NAMESPACE;
private:
//
// Members.
//
IWbemLocatorPtr m_locator; //!< The underlying WMI locator.
mutable IWbemServicesPtr m_services; //!< The underlying WMI connection.
};
////////////////////////////////////////////////////////////////////////////////
//! Get the underlying COM connection.
inline IWbemServicesPtr Connection::get() const
{
return m_services;
}
//namespace WMI
}
#endif // WMI_CONNECTION_HPP