/*
* WbemNotificationQueryAsyncApplet.h
* Copyright (c) 2012 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
// SOL9
// 2010/02/24
// 2012/\03/09 Updated.
#pragma once
#include <sol/wmi/WbemQueryApplet.h>
#include <sol/wmi/WbemObjectSink.h>
namespace SOL {
/**
* Thread for WbemServices::ExecNotificationQuery method call.
* This is a semi-ascyncronus query.
*/
class WbemNotificationQueryAsyncApplet: public WbemQueryApplet {
public:
/**
* Constructor
*/
WbemNotificationQueryAsyncApplet()
:WbemQueryApplet()
{
}
public:
/**
* Thread procedure to watch an instance creation of Win32_Process.
*/
virtual void run()
{
//ApartmentThreadedModel apartmentThreaded;
MultiThreadedModel multiThreaded;
try {
printf("1 Locator\n");
WbemLocator locator;
WbemQueryProperties& properties = getQueryProperties();
_bstr_t server = properties.getServer();
_bstr_t nspace = properties.getNamespace();
_bstr_t query = properties.getQuery();
printf("2 ConnectServer\n");
_bstr_t networkPath = L"";
if (server.length()>0) {
networkPath = L"\\\\";
networkPath = networkPath + server;
networkPath = networkPath + _bstr_t("\\");
networkPath = networkPath + nspace;
} else {
networkPath = (BSTR)nspace;
}
WbemServices services = locator.connectServer((BSTR)networkPath);
WbemObjectSink objectSink;
printf("3 ExecNotificationQueryAsync\n");
HRESULT hr = S_OK;
if (SUCCEEDED(hr = services.execNotificationQueryAsync((BSTR)query,
&objectSink))) {
bool looping = true;
while(looping) {
// The services->execNotificationQueryAsync(...) method will call the virtual
// WbemProcessSink::Indicate method when an event occurs
Sleep(500);
}
}
} catch (HRESULT hr) {
WbemErrors errors;
printf("WbemNotificationQueryAsyncApplet,Exception:HRESULT=%08x %s", hr, errors.getName(hr));
} catch (Exception ex) {
ex.printf();
WbemErrors errors;
HRESULT hr = ex.getHRESULT();
printf("WbemNotificationQueryAsyncApplet,Exception:HRESULT=%08x %s", hr, errors.getName(hr));
} catch (...) {
printf("WbemNotificationQueryAsyncApplet,Unknown Exception\n");
}
}
};
}
|