www.pudn.com > Ge_opc_Server_v1.rar > I_BSAS.CPP


// I_BSAS.cpp 
// 
//  This file contains the sample implementation of 
//  the IOPCBrowseServerAddressSpace interface for the LHEpipeview 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 "OPCLHEpipeview.h" 
 
 
///////////////////////////////////////////////////////////////////////////// 
// Constructor /Destructor functions 
// 
 
/////////////////////////////////////// 
// ILHEpipeviewBSAS() 
//   Constructor for this Interface 
/////////////////////////////////////// 
/* 
 * ILHEpipeviewBSAS::ILHEpipeviewBSAS 
 * ILHEpipeviewBSAS::~ILHEpipeviewBSAS 
 * 
 * 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 
 */ 
 
ILHEpipeviewBSAS::ILHEpipeviewBSAS( 
	LPUNKNOWN pUnkRef, 
	IMalloc * pmem) 
{ 
	UINT		i; 
 
	m_cRef = 0; 
	m_pUnkRef = pUnkRef; 
 
	m_pmem = pmem; 
 
	return; 
} 
 
 
/////////////////////////////////////// 
// ~ILHEpipeviewBSAS() 
//   Destructor for this Interface 
/////////////////////////////////////// 
ILHEpipeviewBSAS::~ILHEpipeviewBSAS(void) 
{ 
	return; 
} 
 
 
 
 
 
 
///////////////////////////////////////////////////////////////////////////// 
// IUnknown functions 
///////////////////////////////////////////////////////////////////////////// 
 
/////////////////////////////////////// 
// ILHEpipeviewBSAS:: 
/////////////////////////////////////// 
STDMETHODIMP ILHEpipeviewBSAS::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; 
} 
 
 
/////////////////////////////////////// 
// ILHEpipeviewBSAS:: 
/////////////////////////////////////// 
STDMETHODIMP_(ULONG) ILHEpipeviewBSAS::AddRef(void) 
{ 
	// Addref this object and also the 'parent' if any 
	// 
	++m_cRef; 
	if(m_pUnkRef != NULL) 
		m_pUnkRef->AddRef(); 
	return m_cRef; 
} 
 
/////////////////////////////////////// 
// ILHEpipeviewBSAS:: 
/////////////////////////////////////// 
STDMETHODIMP_(ULONG) ILHEpipeviewBSAS::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 
///////////////////////////////////////////////////////////////////////////// 
 
/////////////////////////////////////// 
// ILHEpipeviewBSAS:: 
/////////////////////////////////////// 
STDMETHODIMP QueryOrganization( 
    /* [out] */ OPCNAMESPACETYPE  *pNameSpaceType) 
{ 
	if(!pNameSpaceType) return E_INVALIDARG; 
	*pNameSpaceType = OPC_FLAT; 
	return S_OK; 
} 
 
 
 
/////////////////////////////////////// 
// ILHEpipeviewBSAS:: 
/////////////////////////////////////// 
STDMETHODIMP ChangeBrowsePosition( 
    /* [in] */ OPCBROWSEDIRECTION dwBrowseDirection, 
    /* [string][in] */ LPCWSTR szString) 
{ 
	return E_FAIL; 
} 
 
 
 
/////////////////////////////////////// 
// ILHEpipeviewBSAS:: 
/////////////////////////////////////// 
STDMETHODIMP BrowseOPCItemIDs( 
    /* [in] */ OPCBROWSETYPE dwBrowseFilterType, 
    /* [string][in] */ LPCWSTR szFilterCriteria, 
    /* [in] */ VARTYPE vtDataTypeFilter, 
    /* [in] */ DWORD dwAccessRightsFilter, 
    /* [out] */ LPENUMSTRING  *ppIEnumString) 
{ 
	ILHEpipeviewEnumString *temp; 
	LPOLESTR * AddressList; 
	int	AddressCount; 
	HRESULT hr; 
 
	// Get a snapshot of the address list 
	// Note that the filtering will be server specific 
	// 
	m_Parent->GetAddressList( dwScope, 
	 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 ILHEpipeviewEnumString(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( riid, (LPVOID*)ppIEnumString); 
	if ( FAILED( hr)) 
	{ 
		delete temp; 
		return hr; 
	} 
 
	return S_OK; 
} 
 
 
 
/////////////////////////////////////// 
// ILHEpipeviewBSAS:: 
/////////////////////////////////////// 
STDMETHODIMP GetItemID( 
    /* [in] */ LPWSTR szItemDataID, 
    /* [string][out] */ LPWSTR  *szItemID) 
{ 
	if(!szItemID) return E_INVALIDARG; 
	szItemID = WSTRClone(szItemDataID, m_pmem); 
	return S_OK; 
} 
 
 
 
/////////////////////////////////////// 
// ILHEpipeviewBSAS:: 
/////////////////////////////////////// 
STDMETHODIMP BrowseAccessPaths( 
    /* [string][in] */ LPCWSTR szItemID, 
    /* [out] */ LPENUMSTRING  *ppIEnumString) 
{ 
	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. 
// 
static LPOLESTR tags[] = 
{ 
	l"FIC101", 
	l"FIC102", 
	l"FIC103", 
	l"FIC104", 
	l"FIC105", 
	l"FIC106", 
	l"FIC107", 
	l"FIC108", 
	l"FIC109", 
}; 
 
 
zzz move to server.cpp later 
/////////////////////////////////////// 
// LHEpipeviewServer::GetAddressList() 
// Create a list of all the group names 
// 
void LHEpipeviewServer::GetAddressList( 
	OPCBROWSETYPE dwBrowseFilterType, 
	LPCWSTR szFilterCriteria, 
	VARTYPE vtDataTypeFilter, 
	DWORD dwAccessRightsFilter, 
	LPOLESTR**AddressList, 
	int *AddressCount) 
{ 
	int	j, count = sizeof(tags); 
	LPOLESTR *mylist; 
 
	// Defaults... 
	*AddressList = NULL; 
	*AddressCount = 0; 
 
	*AddressList = mylist = new LPOLESTR[count];	// Caller must free this! 
	if (*mylist == NULL) 
	{ 
		return; 
	} 
	for (j=0; j