www.pudn.com > GEOPC_modified_2005621145656299.rar > I_BSAS.CPP, change:2005-03-24,size:5916b


// I_BSAS.cpp 
// 
//  This file contains the sample implementation of  
//  the IOPCBrowseServerAddressSpace interface for the XXX server. 
// 
// 
//	(c) COPYRIGHT 1997, INTELLUTION INC. 
// ALL RIGHTS RESERVED 
// 
// Original Author: Al Chisholm 
// 
// Modification Log: 
//	Vers    Date   By    Notes 
//	----  -------- ---   ----- 
//	0.00  08/01/97 ACC 
// 
// 
// 
// NOTE: at present this code does not support any filtering 
// and works only for a 'flat' address space. 
// 
 
#define WIN32_LEAN_AND_MEAN 
 
#include "OPCXXX.h" 
 
 
///////////////////////////////////////////////////////////////////////////// 
// Constructor /Destructor functions 
// 
 
/////////////////////////////////////// 
// IXXXBSAS() 
//   Constructor for this Interface 
/////////////////////////////////////// 
/* 
 * IXXXBSAS::IXXXBSAS 
 * IXXXBSAS::~IXXXBSAS 
 * 
 * Parameters (Constructor): 
 *  pUnkRef		'parent' LPUNKNOWN to use for reference counting. 
 zzz 
 *  cstr			ULONG number of OPCITEMATTRIBTESs in pIA 
 *  pIA		  ptr to IAs 
 *  pmem       IMalloc memory allocator to use for returned data 
 */ 
 
IXXXBSAS::IXXXBSAS( 
	LPUNKNOWN pUnkRef,IMalloc * pmem) 
{ 
	 
	m_cRef = 0; 
	m_pUnkRef = pUnkRef; 
	m_Parent =(XXXServer *)pUnkRef; 
	m_pmem = pmem; 
 
	return; 
} 
 
 
/////////////////////////////////////// 
// ~IXXXBSAS() 
//   Destructor for this Interface 
/////////////////////////////////////// 
IXXXBSAS::~IXXXBSAS(void) 
{ 
	return; 
} 
 
 
 
 
 
 
///////////////////////////////////////////////////////////////////////////// 
// IUnknown functions 
///////////////////////////////////////////////////////////////////////////// 
 
/////////////////////////////////////// 
// IXXXBSAS:: 
/////////////////////////////////////// 
STDMETHODIMP IXXXBSAS::QueryInterface(REFIID riid 
	, LPVOID *ppv) 
{ 
	*ppv=NULL; 
 
	if (IID_IUnknown==riid || IID_IOPCBrowseServerAddressSpace==riid) 
		*ppv=(LPVOID)this; 
 
	if (NULL!=*ppv) 
	{ 
		((LPUNKNOWN)*ppv)->AddRef(); 
		return S_OK; 
	} 
 
	return E_NOINTERFACE; 
} 
 
 
/////////////////////////////////////// 
// IXXXBSAS:: 
/////////////////////////////////////// 
STDMETHODIMP_(ULONG) IXXXBSAS::AddRef(void) 
{ 
	// Addref this object and also the 'parent' if any 
	// 
	++m_cRef; 
	if(m_pUnkRef != NULL)  
		m_pUnkRef->AddRef(); 
	return m_cRef; 
} 
 
/////////////////////////////////////// 
// IXXXBSAS:: 
/////////////////////////////////////// 
STDMETHODIMP_(ULONG) IXXXBSAS::Release(void) 
{ 
	// Release this object and also the 'parent' if any 
	// 
	if(m_pUnkRef != NULL)  
		m_pUnkRef->Release(); 
 
	if (0L!=--m_cRef) 
		return m_cRef; 
 
	delete this; 
	return 0; 
} 
 
 
 
///////////////////////////////////////////////////////////////////////////// 
// IOPCBrowseServerAddressSpace functions 
///////////////////////////////////////////////////////////////////////////// 
 
/////////////////////////////////////// 
// IXXXBSAS:: 
/////////////////////////////////////// 
STDMETHODIMP IXXXBSAS::QueryOrganization(  
    /* [out] */ OPCNAMESPACETYPE  *pNameSpaceType) 
{ 
	if(!pNameSpaceType) return E_INVALIDARG; 
	*pNameSpaceType = OPC_NS_FLAT; 
	return S_OK; 
} 
 
 
         
/////////////////////////////////////// 
// IXXXBSAS:: 
/////////////////////////////////////// 
STDMETHODIMP IXXXBSAS::ChangeBrowsePosition(  
    /* [in] */ OPCBROWSEDIRECTION dwBrowseDirection, 
    /* [string][in] */ LPCWSTR szString) 
{ 
	return E_FAIL; 
} 
 
 
         
/////////////////////////////////////// 
// IXXXBSAS:: 
/////////////////////////////////////// 
STDMETHODIMP IXXXBSAS::BrowseOPCItemIDs(  
    /* [in] */ OPCBROWSETYPE dwBrowseFilterType, 
    /* [string][in] */ LPCWSTR szFilterCriteria, 
    /* [in] */ VARTYPE vtDataTypeFilter, 
    /* [in] */ DWORD dwAccessRightsFilter, 
    /* [out] */ LPENUMSTRING  *ppIEnumString) 
{ 
	IXXXEnumString *temp; 
	LPOLESTR * AddressList; 
	int	AddressCount=9; 
	HRESULT hr; 
 
	// Get a snapshot of the address list  
	// Note that the filtering will be server specific 
	// 
//	m_Parent->GetAddressList(dwBrowseFilterType, szFilterCriteria, vtDataTypeFilter, 
//	 dwAccessRightsFilter,&AddressList, &AddressCount); 
 
	// Create the Enumerator using the snapshot 
	// Note that the enumerator will AddRef the server  
	// 
//	zzz check Parent - is that right? or should it be 'this' 
//	should pIMalloc be pmem? 
	temp = new IXXXEnumString(m_Parent, AddressCount, AddressList, pIMalloc); 
//	m_Parent->FreeAddressList(AddressList, AddressCount); 
 
	if ( temp == NULL) 
		return E_OUTOFMEMORY; 
 
	// Then QI for the interface. 
	// Note 'temp' actually is the interface 
	// but QI is the 'proper' way to get it. 
	// Note QI will do an AddRef of the Enum which will also do 
	// an AddRef of the 'parent' - i.e. the 'this' pointer passed above. 
	// 
	hr = temp->QueryInterface( IID_IEnumString, (LPVOID*)ppIEnumString); 
	if ( FAILED( hr)) 
	{ 
		delete temp; 
		return hr; 
	} 
 
	return S_OK; 
} 
 
 
         
/////////////////////////////////////// 
// IXXXBSAS:: 
/////////////////////////////////////// 
STDMETHODIMP IXXXBSAS::GetItemID(  
    /* [in] */ LPWSTR szItemDataID, 
    /* [string][out] */ LPWSTR  *szItemID) 
{ 
	if(!szItemID) return E_INVALIDARG; 
	*szItemID = WSTRClone(szItemDataID, m_pmem); 
	return S_OK; 
} 
 
 
         
/////////////////////////////////////// 
// IXXXBSAS:: 
/////////////////////////////////////// 
STDMETHODIMP IXXXBSAS::BrowseAccessPaths(  
    /* [string][in] */ LPCWSTR szItemID, 
    /* [out] */ LPENUMSTRING  *ppIEnumString) 
{ 
	return E_NOTIMPL; 
} 
         
 
// Define a sample list of available ITEMIDs for BrowseAddressSpace. 
// Note that in this sample code, AddItems and ValidateItems do NOT 
// check against this list. In a 'real' server they would need to do so. 
// 
 
 
 
//zzz move to server.cpp later 
/////////////////////////////////////// 
// XXXServer::GetAddressList() 
// Create a list of all the group names 
//