/*
* UPnPDevice.h
* Copyright (c) 2011 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
// SOL9
// 2009/12/02
#pragma once
#include <sol/upnp/UPnPObject.h>
#include <sol/upnp/UPnPServices.h>
namespace SOL {
class UPnPDevice :public UPnPObject {
public:
UPnPDevice(IDispatch* pDev=NULL)
:UPnPObject(pDev)
{
}
public:
~UPnPDevice()
{
}
public:
IUPnPDevice* get()
{
return (IUPnPDevice*)getIDispatch();
}
public:
const wchar_t* getUniqueDeviceName(StringT<wchar_t>& string)
{
BSTR name = NULL;
IUPnPDevice* pDevice = get();
if (SUCCEEDED(pDevice->get_UniqueDeviceName(&name))) {
string = name;
SysFreeString(name);
}
return (const wchar_t*)string;
}
public:
const wchar_t* getModelName(StringT<wchar_t>& string)
{
BSTR name = NULL;
IUPnPDevice* pDevice = get();
if (SUCCEEDED(pDevice->get_ModelName(&name))) {
string = name;
SysFreeString(name);
}
return (const wchar_t*)string;
}
public:
const wchar_t* getDescription(StringT<wchar_t>& string)
{
BSTR name = NULL;
IUPnPDevice* pDevice = get();
if (SUCCEEDED(pDevice->get_Description(&name))) {
string = name;
SysFreeString(name);
}
return (const wchar_t*)string;
}
public:
const wchar_t* getFriendlyName(StringT<wchar_t>& string)
{
BSTR name = NULL;
IUPnPDevice* pDevice = get();
if (SUCCEEDED(pDevice->get_FriendlyName(&name))) {
string = name;
SysFreeString(name);
}
return (const wchar_t*)string;
}
public:
const wchar_t* getManufacturerURL(StringT<wchar_t>& string)
{
BSTR name = NULL;
IUPnPDevice* pDevice = get();
if (SUCCEEDED(pDevice->get_ManufacturerURL(&name))) {
string = name;
SysFreeString(name);
}
return (const wchar_t*)string;
}
public:
const wchar_t* getType(StringT<wchar_t>& string)
{
BSTR name = NULL;
IUPnPDevice* pDevice = get();
if (SUCCEEDED(pDevice->get_Type(&name))) {
string = name;
SysFreeString(name);
}
return (const wchar_t*)string;
}
public:
const wchar_t* getModelNumber(StringT<wchar_t>& string)
{
BSTR name = NULL;
IUPnPDevice* pDevice = get();
if (SUCCEEDED(pDevice->get_ModelNumber(&name))) {
string = name;
SysFreeString(name);
}
return (const wchar_t*)string;
}
public:
const wchar_t* getModelURL(StringT<wchar_t>& string)
{
BSTR name = NULL;
IUPnPDevice* pDevice = get();
if (SUCCEEDED(pDevice->get_ModelURL(&name))) {
string = name;
SysFreeString(name);
}
return (const wchar_t*)string;
}
public:
const wchar_t* getManufacturerName(StringT<wchar_t>& string)
{
BSTR name = NULL;
IUPnPDevice* pDevice = get();
if (SUCCEEDED(pDevice->get_ManufacturerName(&name))) {
string = name;
SysFreeString(name);
}
return (const wchar_t*)string;
}
public:
const wchar_t* getSerialNumber(StringT<wchar_t>& string)
{
BSTR name = NULL;
IUPnPDevice* pDevice = get();
if (SUCCEEDED(pDevice->get_SerialNumber(&name))) {
string = name;
SysFreeString(name);
}
return (const wchar_t*)string;
}
public:
HRESULT getServices(UPnPServices& services)
{
HRESULT hr = E_FAIL;
IUPnPServices* pServices;
printf(".......Services\n");
IUPnPDevice* pDevice = get();
if (SUCCEEDED(hr=pDevice->get_Services(&pServices)) )
{
services.set(pServices);
//services.display();
}
return hr;
}
public:
HRESULT getServices(IUPnPServices** ppServices)
{
HRESULT hr = E_FAIL;
//IUPnPServices* pServices;
printf(".......Services\n");
IUPnPDevice* pDevice = get();
if (ppServices) {
hr = pDevice->get_Services(ppServices);
} else {
throw E_POINTER;
}
return hr;
}
public:
HRESULT getChildren(IUPnPDevices** children)
{
HRESULT hr = E_FAIL;
IUPnPDevice* pDevice = get();
if (children) {
hr = pDevice->get_Children(children);
} else {
throw E_POINTER;
}
return hr;
}
public:
bool hasChildren()
{
bool rc = false;
IUPnPDevice* pDevice = get();
VARIANT_BOOL variant_bool = VARIANT_FALSE;
if (SUCCEEDED(pDevice->get_HasChildren(&variant_bool))) {
if (variant_bool == VARIANT_TRUE) {
rc = true;
}
}
return rc;
}
public:
void display()
{
printf("UPnPDevice \n");
StringT<wchar_t> devName;
wprintf(L"UniqueDeviceName: %s\n", getUniqueDeviceName(devName));
StringT<wchar_t> modelName;
wprintf(L"ModelName: %s\n", getModelName(modelName));
StringT<wchar_t> desc;
wprintf(L"Description: %s\n", getDescription(desc));
StringT<wchar_t> fname;
wprintf(L"FriendlyName: %s\n", getFriendlyName(fname));
StringT<wchar_t> murl;
wprintf(L"ManufacturerURL: %s\n", getManufacturerURL(murl));
StringT<wchar_t> mname;
wprintf(L"ManufacturerName: %s\n", getManufacturerName(mname));
StringT<wchar_t> serialNumber;
wprintf(L"SerialNumber: %s\n", getSerialNumber(serialNumber));
// IUPnPServices* pServices;
printf("Services\n");
UPnPServices services;
// if (SUCCEEDED(pDevice->get_Services(&pServices)) ){
if (SUCCEEDED(getServices(services)) ){
services.display();
}
}
};
}
|