www.pudn.com > Ge_opc_Server_v1.rar > OPCLHEpipeview.H


// OPCLHEpipeview.h 
// 
// This file contains OBJECT definitions which are SPECFIC 
// to the OPC server for LHEpipeview provided by vendor ZZZ. 
// (The OPC.H file contains common interface base classes that 
//  each vendor derives from) 
// 
// 
//	(C) COPYRIGHT 1996 INTELLUTION INC. 
// ALL RIGHTS RESERVED 
// 
// Original Author: Al Chisholm 
// 
// Modification Log: 
//	Vers    Date   By    Notes 
//	----  -------- ---   ----- 
//	0.00  11/18/96 ACC 
//        12/10/96 acc   add Enumerators, LHEpipeviewItem 
//  0.02  03/01/97 acc   add GetValue(), SetValue() to LHEpipeviewItem 
//  0.90  04/01/97 acc   add Async Support 
// 
// 
 
 
#ifndef OPCLHEpipeview_H 
#define OPCLHEpipeview_H 
 
 
#include "OPC.h"	//The 'standard' OPC custom interface defintions 
#include "OLECTL.h"	// For ConnectionPoint Stuff 
#include "ENUMHELP.h"	//Some enumerator helper classes 
 
// Define the unique classID that represents Vendor ZZZ's 
// OPC Server for product LHEpipeview 
// This ID also appears in the REG file 
// 
// *** EVERY IMPLEMENTATION MUST USE A DIFFERENT GUID ***. 
/* 
// CLSID_OPCSampleServer == {4210FF60-D373-11ce-B4B5-C46F03C10000} 
DEFINE_GUID( CLSID_OPCSampleServer, 0x4210ff60, 0xd373, 0x11ce, 0xb4, 0xb5, 0xc4, 0x6f, 0x3, 0xc1, 0x0, 0x0); 
*/ 
// CLSID_OPCSampleServer =={09C0FE36-4191-4a70-9954-91D12ADA008D} 
DEFINE_GUID( CLSID_OPCSampleServer, 0x9c0fe36, 0x4191, 0x4a70, 0x99, 0x54, 0x91, 0xd1, 0x2a, 0xda, 0x0, 0x8d); 
 
 
// Implementation specific definitions. 
#define N_GRPS	10		// max number of groups supported per server 
#define N_ITEMS	100		// max number of items supported per group 
 
// Special Quality flag for Inactive groups and items 
// 
#define QUAL_NOTACTIVE 0x1c	// Bad/Out of Service 
 
///////////////////////////////////////////////////////////////////////////// 
// Forward type definitions of the vendor specific classes 
 
class	LHEpipeviewServer;	// The server object itself 
class	ILHEpipeviewServer;	// The IOPCServer Interface 
class	ILHEpipeviewEnum;	// The IEnumUnknown Interface 
class	ILHEpipeviewSPG;	// The optional IOPCServerPublicGroups interface 
class	ILHEpipeviewBSAS;	// The optional IOPCBrowseServerAddressSpace interface 
class	ILHEpipeviewPF;		// The optional IPersistFile interface 
 
class	LHEpipeviewGroup;	// The Group Object itself 
class	ILHEpipeviewGSM;	// The IOPCGroupStateMgt interface 
class	ILHEpipeviewPGSM;	// The optional IOPCPublicGroupStateMgt interface 
class	ILHEpipeviewSIO;	// The IOPCSyncIO interface 
class	ILHEpipeviewASIO;	// The IOPCAsynIO interface 
class	ILHEpipeviewIM;		// The IOPCItemMgt interface 
class	ILHEpipeviewDO;		// The IDataObject interface 
 
class	ILHEpipeviewEnumIA;	// enum item attrs is returned from an itemmgt method 
 
class	LHEpipeviewItem;	// A 'local' Item Class 
 
 
///////////////////////////////////////////////////////////////////////////// 
// Global server variables. 
// These variables keep track of state information which is global to the server process. 
// The common memory allocator is required so that the server 
//   can allocate items to be returned to the client. 
// The client must be able to access and to free these items 
//   so they need to be in common memory. 
///////////////////////////////////////////////////////////////////////////// 
 
extern FILETIME		serverStartTime; 
extern IMalloc		*pIMalloc;		// Common memory allocator 
 
 
 
///////////////////////////////////////////////////////////////////////////// 
// From OPCUtil.cpp 
// Utility and convenience functions 
// 
#define WCHAR	wchar_t 
 
//zzz use my hdr file! 
BSTR BSTRFromWSTR(const WCHAR * s, IMalloc *pmem);	// Aloc BSTR and copy WSTR into it 
void BSTRFree(BSTR bstr, IMalloc *pmem);			// Free a BSTR 
WCHAR * WSTRFromBSTR(const BSTR bstr, IMalloc *pmem);		// Aloc a WSTR and copy a BSTR into it 
WCHAR * WSTRClone(const WCHAR *oldstr, IMalloc *pmem); 
void WSTRFree(WCHAR * c, IMalloc *pmem); 
 
///////////////////////////////////////////////////////////////////////////// 
// From ItemUtil.cpp 
// Utility and convenience functions 
// 
void IAClone(OPCITEMATTRIBUTES * pNewIA, const OPCITEMATTRIBUTES*pOldIA, IMalloc *pmem); 
void IAFree(OPCITEMATTRIBUTES *pIA, IMalloc *pmem); 
 
 
///////////////////////////////////////////////////////////////////////////// 
// LHEpipeviewServer 
//   This class is an implementation of a LHEpipeview specific version of the 
//   OPCServer class. 
// There is no standard OPC Server 'object', only vendor specific objects 
//   so this derives from IUnKnown. 
// The other LHEpipeview sepcific implementations of the OPC interfaces for this 
//   will derive from the OPC interface classes in OPC.H (see below) 
// 
///////////////////////////////////////////////////////////////////////////// 
class LHEpipeviewServer : public IUnknown 
{ 
  public: 
    LHEpipeviewServer( LPUNKNOWN, void (*pfn)(void)); 
    ~LHEpipeviewServer( void); 
 
	// the IUnknown Functions 
	STDMETHODIMP         QueryInterface( REFIID iid, LPVOID* ppInterface); 
	STDMETHODIMP_(ULONG) AddRef( void); 
	STDMETHODIMP_(ULONG) Release( void); 
 
	// Public (non-OPC) Functions 
	void			UpdateData(DWORD tics); 
	void			GenerateTransaction(DWORD *pTransactionID); 
 
  private: 
	// Some private (non-opc) utility functions to help with Enumeration 
	void 			GetUnkList( OPCENUMSCOPE scope, 
						LPUNKNOWN ** GroupList, int *GroupCount); 
	void 			GetNameList( OPCENUMSCOPE scope, 
						LPOLESTR ** GroupList, int *GroupCount); 
	void			FreeNameList( LPOLESTR*GroupList, int GroupCount); 
	void			FreeUnkList( LPUNKNOWN*GroupList, int GroupCount); 
 
  friend class ILHEpipeviewServer; 
  friend class ILHEpipeviewPF; 
  friend class ILHEpipeviewGSM; 
  private: 
	// Member Variables 
	ILHEpipeviewServer		*m_pIServer;	// ptr to 'tear-off' IOPCServer i/f 
	ILHEpipeviewSPG 		*m_pISPG;		// public groups (optional) 
	ILHEpipeviewBSAS 		*m_pIBSAS;		// browse address space (optional) 
	ILHEpipeviewPF			*m_pIPF;		// persistfile (optional) 
 
    ULONG			mRefCount; 
    FILETIME		mLastUpdate; 
    void			(*m_pfnDestroy)(void); 
 
	DWORD			m_tid;			// transaction ID 
	int				m_Slot;			// Asnyc helper thread slot 
 
	// A Real server might use an OBJLIST here 
    struct { 
	 int		inuse; 
	 LHEpipeviewGroup	* pGroup; 
    } m_groups[N_GRPS]; 
 
}; 
 
 
///////////////////////////////////////////////////////////////////////////// 
// LHEpipeview specific implementation of an IOPCServer Interface 
// 
class ILHEpipeviewServer : public IOPCServer 
{ 
  public: 
    ILHEpipeviewServer( LPUNKNOWN ); 
    ~ILHEpipeviewServer( void); 
 
	// the IUnknown Functions 
	STDMETHODIMP         QueryInterface( REFIID iid, LPVOID* ppInterface); 
	STDMETHODIMP_(ULONG) AddRef( void); 
	STDMETHODIMP_(ULONG) Release( void); 
 
	// the IOPCServer Functions 
	STDMETHODIMP         GetStatus( 
		OPCSERVERSTATUS** ppServerStatus); 
	STDMETHODIMP         GetErrorString( 
		HRESULT hr, 
		LCID locale, 
		LPWSTR *ppstring); 
	STDMETHODIMP         AddGroup( 
		LPCWSTR szName, 
		BOOL bActive, 
		DWORD dwRequestedUpdateRate, 
		OPCHANDLE hClientGroup, 
		LONG *pTimeBias, 
		FLOAT *pPercentDeadband, 
		DWORD dwLCID, 
		OPCHANDLE *phServerGroup, 
		DWORD *pRevisedUpdateRate, 
		REFIID riid, 
		LPUNKNOWN *ppUnk 
		); 
	STDMETHODIMP         GetGroupByName( 
		LPCWSTR szGroupName, 
		REFIID riid, LPUNKNOWN *ppUnk); 
	STDMETHODIMP         RemoveGroup( 
		OPCHANDLE groupHandleID, 
		BOOL bForce); 
 
	STDMETHODIMP CreateGroupEnumerator( 
		OPCENUMSCOPE dwScope, 
		REFIID riid, 
		LPUNKNOWN *ppUnk 
		); 
 
  private: 
	// Member Variables 
	LHEpipeviewServer	*m_Parent;	// ptr to 'owning' LHEpipeviewServer 
}; 
 
///////////////////////////////////////////////////////////////////////////// 
// LHEpipeview specific implementation of an IPersistFile Interface for the Server 
// 
class ILHEpipeviewPF: public IPersistFile 
{ 
  public: 
    ILHEpipeviewPF( LPUNKNOWN ); 
    ~ILHEpipeviewPF( void); 
 
	// the IUnknown Functions 
	STDMETHODIMP         QueryInterface( REFIID iid, LPVOID* ppInterface); 
	STDMETHODIMP_(ULONG) AddRef( void); 
	STDMETHODIMP_(ULONG) Release( void); 
 
	// the IPersist Functions 
	STDMETHODIMP         GetClassID( 
		CLSID *pClassID 
		); 
 
	// the IPersistFile Functions 
	STDMETHODIMP         IsDirty( void); 
 
	STDMETHODIMP         Load( 
		LPCOLESTR pszFileName, 
		DWORD dwMode 
		); 
 
	STDMETHODIMP         Save( 
		LPCOLESTR pszFileName, 
		BOOL fRemember 
		); 
 
	STDMETHODIMP         SaveCompleted( 
		LPCOLESTR pszFileName 
		); 
 
	STDMETHODIMP         GetCurFile( 
		LPOLESTR *ppszFileName 
		); 
 
  private: 
	// Member Variables 
	LHEpipeviewServer	*m_Parent;	// ptr to 'owning' LHEpipeviewServer 
}; 
 
 
///////////////////////////////////////////////////////////////////////////// 
// LHEpipeviewGroup 
//   This class is an implementation of a LHEpipeview specific version of the 
//   OPC Group class. 
// 
///////////////////////////////////////////////////////////////////////////// 
class LHEpipeviewGroup : public IUnknown 
{ 
  public: 
    LHEpipeviewGroup( LPUNKNOWN ); 
    ~LHEpipeviewGroup( void); 
 
	// the IUnknown Functions 
	STDMETHODIMP         QueryInterface( REFIID iid, LPVOID* ppInterface); 
	STDMETHODIMP_(ULONG) AddRef( void); 
	STDMETHODIMP_(ULONG) Release( void); 
 
  private: 
	// Some private (non-opc) utility functions to help with Enumeration 
	void		GetItemList( OPCITEMATTRIBUTES **AttrList, int *ItemCount); 
	void		FreeItemList( OPCITEMATTRIBUTES *AttrList, int ItemCount); 
 
	// Item List Management Functions 
	BOOL		ItemValid(OPCHANDLE h);	// Validate Item Handle (see if in use) 
	LHEpipeviewItem		*ItemPtr(OPCHANDLE h);	// Given handle, return pointer 
	int			ItemHandles(void);		// Total # item handles (some may be empty) 
	HRESULT		ItemAlloc(OPCHANDLE *h);		// Alloc next avaialable Handle 
	HRESULT		ItemReAlloc(OPCHANDLE h);		// Alloc a specific Handle (used by Clone) 
	void		ItemSet(OPCHANDLE h, LHEpipeviewItem * p);		// Assign an item to a slot 
	void		ItemFree(OPCHANDLE h); 
 
	void		AsyncHelper( DWORD tics ); 
	void		Scan( void ); 
 
	void		CheckDOOnDataTimeChange( void ); 
	void		CheckDOOnDataChange( void ); 
	void		CheckDORefresh( void ); 
	void		CheckDOAsyncRead( void ); 
	void		CheckDOAsyncWrite( void ); 
	void		SendStreamWithTime(int Count, OPCHANDLE *ItemHandleList, DWORD size, WORD mask, DWORD tid); 
	void		SendStream(int Count, OPCHANDLE *ItemHandleList, DWORD size, WORD mask, DWORD tid); 
	void		SendWriteStream(int Count, OPCHANDLE *ItemHandleList, DWORD tid); 
	long		ComputeSize(int Count, OPCHANDLE *ItemHandleList); 
 
  friend class ILHEpipeviewServer; 
  friend class LHEpipeviewServer; 
  friend class ILHEpipeviewIM; 
  friend class ILHEpipeviewSIO; 
  friend class ILHEpipeviewASIO; 
  friend class ILHEpipeviewGSM; 
  friend class ILHEpipeviewPGSM; 
  friend class ILHEpipeviewDO; 
  friend class ILHEpipeviewEnumIA; 
  private: 
	// Member Variables 
    ULONG		mRefCount; 
	LHEpipeviewServer	*m_ParentServer; 
	DWORD		m_dwRevisedRate; 
	FLOAT		m_Deadband; 
	DWORD		m_LCID; 
	LONG		m_TimeBias; 
	BOOL		m_bActive; 
	WCHAR		*m_szName; 
	OPCHANDLE	m_ServerGroupHandle; 
	OPCHANDLE	m_ClientGroupHandle; 
 
	ILHEpipeviewGSM		*m_pILHEpipeviewGSM;	//Group State Mgt 
	ILHEpipeviewPGSM	*m_pILHEpipeviewPGSM;	// Public Group State Mgt (optional) 
	ILHEpipeviewSIO		*m_pILHEpipeviewSIO;	// SyncIO 
	ILHEpipeviewASIO	*m_pILHEpipeviewASIO;	// ASynioIO 
	ILHEpipeviewIM		*m_pILHEpipeviewIM;		// Item Mgt 
	ILHEpipeviewDO		*m_pILHEpipeviewDO;		// Data Object 
 
	// For manageing updaterate 
	// 
	long		m_scan; 
 
	// And related Async Flags	// 2.0 
	// 
	BOOL		m_AsyncReadActive; 
	BOOL		m_AsyncReadCancel; 
	DWORD		m_AsyncReadTID; 
	OPCDATASOURCE	m_AsyncReadSource; 
	OPCHANDLE	*m_AsyncReadList; 
 
	BOOL		m_AsyncWriteActive; 
	BOOL		m_AsyncWriteCancel; 
	DWORD		m_AsyncWriteTID; 
	OPCHANDLE	*m_AsyncWriteList; 
 
	BOOL		m_RefreshActive; 
	BOOL		m_RefreshCancel; 
	DWORD		m_RefreshTID; 
	OPCDATASOURCE	m_RefreshSource; 
	OPCHANDLE	*m_RefreshList; 
 
	// A Real server might use an OBJLIST here 
    struct { 
	 int		inuse; 
	 LHEpipeviewItem	*pItem; 
    } m_items[N_ITEMS]; 
}; 
 
 
 
///////////////////////////////////////////////////////////////////////////// 
// ILHEpipeviewIM 
//   This class is an implementation of a LHEpipeview specific version of the 
//   OPC ItemMgt Interface 
// 
class ILHEpipeviewIM : public IOPCItemMgt 
{ 
  public: 
    ILHEpipeviewIM( LPUNKNOWN ); 
    ~ILHEpipeviewIM( void); 
 
	// the IUnknown Functions 
	STDMETHODIMP         QueryInterface( REFIID iid, LPVOID* ppInterface); 
	STDMETHODIMP_(ULONG) AddRef( void); 
	STDMETHODIMP_(ULONG) Release( void); 
 
	// the IOPCItemMgt Functions 
	STDMETHODIMP AddItems( 
		DWORD            dwNumItems, 
		OPCITEMDEF     * pItemArray, 
		OPCITEMRESULT ** ppAddResults, 
		HRESULT       ** ppErrors 
	    ); 
 
	STDMETHODIMP ValidateItems( 
		DWORD             dwNumItems, 
		OPCITEMDEF      * pItemArray, 
		BOOL              bBlobUpdate, 
		OPCITEMRESULT  ** ppValidationResults, 
		HRESULT        ** ppErrors 
	    ); 
 
	STDMETHODIMP RemoveItems( 
		DWORD        dwNumItems, 
		OPCHANDLE  * phServer, 
		HRESULT   ** ppErrors 
	    ); 
 
	STDMETHODIMP SetActiveState( 
		DWORD        dwNumItems, 
		OPCHANDLE  * phServer, 
		BOOL         bActive, 
		HRESULT   ** ppErrors 
		); 
 
	STDMETHODIMP SetClientHandles( 
		DWORD        dwNumItems, 
		OPCHANDLE  * phServer, 
		OPCHANDLE  * phClient, 
		HRESULT   ** ppErrors 
		); 
 
	STDMETHODIMP SetDatatypes( 
		DWORD        dwNumItems, 
		OPCHANDLE  * phServer, 
		VARTYPE    * pRequestedDatatypes, 
		HRESULT   ** ppErrors 
	    ); 
 
	STDMETHODIMP CreateEnumerator( 
		REFIID      riid, 
		LPUNKNOWN * ppUnk 
	    ); 
 
  private: 
	// Member Variables 
	LHEpipeviewGroup	*m_Parent;	// ptr to owning 'LHEpipeviewGroup' 
 
}; 
 
 
///////////////////////////////////////////////////////////////////////////// 
// ILHEpipeviewSIO 
//   This class is an implementation of a LHEpipeview specific version of the 
//   OPC AsyncIO Interface 
// 
class ILHEpipeviewSIO : public IOPCSyncIO 
{ 
  public: 
    ILHEpipeviewSIO( LPUNKNOWN ); 
    ~ILHEpipeviewSIO( void); 
 
	// the IUnknown Functions 
	STDMETHODIMP         QueryInterface( REFIID iid, LPVOID* ppInterface); 
	STDMETHODIMP_(ULONG) AddRef( void); 
	STDMETHODIMP_(ULONG) Release( void); 
 
	// the IOPCSyncIO Functions 
	STDMETHODIMP Read( 
		OPCDATASOURCE   dwSource, 
		DWORD           dwNumItems, 
		OPCHANDLE     * phServer, 
		OPCITEMSTATE ** ppItemValues, 
		HRESULT      ** ppErrors 
	    ); 
 
	STDMETHODIMP Write( 
		DWORD        dwNumItems, 
		OPCHANDLE  * phServer, 
		VARIANT    * pItemValues, 
		HRESULT   ** ppErrors 
	    ); 
 
  private: 
	// Member Variables 
	LHEpipeviewGroup	*m_Parent;	// ptr to owning 'LHEpipeviewGroup' 
}; 
 
 
///////////////////////////////////////////////////////////////////////////// 
// ILHEpipeviewASIO 
//   This class is an implementation of a LHEpipeview specific version of the 
//   OPC AsyncIO Interface 
// 
class ILHEpipeviewASIO : public IOPCAsyncIO 
{ 
  public: 
    ILHEpipeviewASIO( LPUNKNOWN ); 
    ~ILHEpipeviewASIO( void); 
 
	// the IUnknown Functions 
	STDMETHODIMP         QueryInterface( REFIID iid, LPVOID* ppInterface); 
	STDMETHODIMP_(ULONG) AddRef( void); 
	STDMETHODIMP_(ULONG) Release( void); 
 
  	// the IOPCAsyncIO Functions 
	STDMETHODIMP Read( 
		DWORD           dwConnection, 
		OPCDATASOURCE   dwSource, 
		DWORD           dwNumItems, 
		OPCHANDLE     * phServer, 
		DWORD         * pTransactionID, 
		HRESULT      ** ppErrors 
	    ); 
 
	STDMETHODIMP Write( 
		DWORD       dwConnection, 
		DWORD       dwNumItems, 
		OPCHANDLE * phServer, 
		VARIANT   * pItemValues, 
		DWORD     * pTransactionID, 
		HRESULT ** ppErrors 
	    ); 
 
	STDMETHODIMP Refresh( 
		DWORD           dwConnection, 
		OPCDATASOURCE   dwSource, 
		DWORD         * pTransactionID 
	    ); 
 
	STDMETHODIMP Cancel( 
		DWORD dwTransactionID 
	    ); 
 
  private: 
	// Member Variables 
	LHEpipeviewGroup	*m_Parent;	// ptr to owning 'LHEpipeviewGroup' 
}; 
 
///////////////////////////////////////////////////////////////////////////// 
// ILHEpipeviewPGSM 
//   This class is an implementation of a LHEpipeview specific version of the 
//   Optional OPC PublicGroupStateMgt Interface 
// 
class ILHEpipeviewPGSM : public IOPCPublicGroupStateMgt 
{ 
  public: 
    ILHEpipeviewPGSM( LPUNKNOWN ); 
    ~ILHEpipeviewPGSM( void); 
 
	// the IUnknown Functions 
	STDMETHODIMP         QueryInterface( REFIID iid, LPVOID* ppInterface); 
	STDMETHODIMP_(ULONG) AddRef( void); 
	STDMETHODIMP_(ULONG) Release( void); 
 
	// the IOPCPublicGroupStateMgt Functions 
	STDMETHODIMP GetState( 
		BOOL * pPublic 
		); 
 
	STDMETHODIMP MoveToPublic( 
		void 
		); 
 
  private: 
	// Member Variables 
	LHEpipeviewGroup	*m_Parent;	// ptr to owning 'LHEpipeviewGroup' 
}; 
 
 
///////////////////////////////////////////////////////////////////////////// 
// ILHEpipeviewGSM 
//   This class is an implementation of a LHEpipeview specific version of the 
//   OPC PublicGroupStateMgt Interface 
// 
class ILHEpipeviewGSM : public IOPCGroupStateMgt 
{ 
  public: 
    ILHEpipeviewGSM( LPUNKNOWN ); 
    ~ILHEpipeviewGSM( void); 
 
	// the IUnknown Functions 
	STDMETHODIMP         QueryInterface( REFIID iid, LPVOID* ppInterface); 
	STDMETHODIMP_(ULONG) AddRef( void); 
	STDMETHODIMP_(ULONG) Release( void); 
 
	// the IOPCGroupStateMgt Functions 
	STDMETHODIMP GetState( 
		DWORD     * pUpdateRate, 
		BOOL      * pActive, 
		LPWSTR    * ppName, 
		LONG      * pTimeBias, 
		FLOAT     * pPercentDeadband, 
		DWORD     * pLCID, 
		OPCHANDLE * phClientGroup, 
		OPCHANDLE * phServerGroup 
		); 
 
	STDMETHODIMP SetState( 
		DWORD     * pRequestedUpdateRate, 
		DWORD     * pRevisedUpdateRate, 
		BOOL      * pActive, 
		LONG      * pTimeBias, 
		FLOAT     * pPercentDeadband, 
		DWORD     * pLCID, 
		OPCHANDLE * phClientGroup 
	    ); 
 
	STDMETHODIMP SetName( 
		LPCWSTR szName 
	    ); 
 
	STDMETHODIMP CloneGroup( 
		LPCWSTR     szName, 
		REFIID      riid, 
		LPUNKNOWN * ppUnk 
	    ); 
 
  private: 
	// Member Variables 
	LHEpipeviewGroup	*m_Parent;	// ptr to owning 'LHEpipeviewGroup' 
}; 
 
 
///////////////////////////////////////////////////////////////////////////// 
// ILHEpipeviewDO 
//   This class is an implementation of a LHEpipeview specific version of the 
//   OPC PublicGroupStateMgt Interface 
// 
class ILHEpipeviewDO : public IDataObject 
{ 
  public: 
    ILHEpipeviewDO( LPUNKNOWN ); 
    ~ILHEpipeviewDO( void); 
 
	// the IUnknown Functions 
	STDMETHODIMP         QueryInterface( REFIID iid, LPVOID* ppInterface); 
	STDMETHODIMP_(ULONG) AddRef( void); 
	STDMETHODIMP_(ULONG) Release( void); 
 
	// the IDataObject Functions 
	STDMETHODIMP GetData( 
			FORMATETC *pformatetcIn, 
			STGMEDIUM *pmedium) ; 
 
	STDMETHODIMP GetDataHere( 
			FORMATETC *pformatetc, 
			STGMEDIUM *pmedium) ; 
 
	STDMETHODIMP QueryGetData( 
			FORMATETC *pformatetc) ; 
 
	STDMETHODIMP GetCanonicalFormatEtc( 
			FORMATETC *pformatectIn, 
			FORMATETC *pformatetcOut) ; 
 
	STDMETHODIMP SetData( 
			FORMATETC *pformatetc, 
			STGMEDIUM *pmedium, 
			BOOL fRelease) ; 
 
	STDMETHODIMP EnumFormatEtc( 
			DWORD dwDirection, 
			IEnumFORMATETC **ppenumFormatEtc) ; 
 
	STDMETHODIMP DAdvise( 
			FORMATETC *pformatetc, 
			DWORD advf, 
			IAdviseSink *pAdvSink, 
			DWORD *pdwConnection) ; 
 
	STDMETHODIMP DUnadvise( 
			DWORD dwConnection) ; 
 
	STDMETHODIMP EnumDAdvise( 
			IEnumSTATDATA **ppenumAdvise) ; 
 
  private: 
	// Member Variables 
	LHEpipeviewGroup	*m_Parent;	// ptr to owning 'LHEpipeviewGroup' 
	IAdviseSink	*m_dataCallback; 
	IAdviseSink	*m_datatimeCallback; 
	IAdviseSink	*m_writeCallback; 
	UINT m_data; 
	UINT m_datatime; 
	UINT m_write; 
 
  friend class LHEpipeviewGroup; 
 
}; 
 
 
 
///////////////////////////////////////////////////////////////////////////// 
// ILHEpipeviewEnumIA 
//   This class is an implementation of a LHEpipeview specific version of the 
//   OPC IEnumOPCItemAttributes Interface 
// 
class ILHEpipeviewEnumIA : public IEnumOPCItemAttributes 
{ 
  public: 
	ILHEpipeviewEnumIA(LPUNKNOWN parent, ULONG c, OPCITEMATTRIBUTES* ia, IMalloc* m); 
    ILHEpipeviewEnumIA( LPUNKNOWN ); 
    ~ILHEpipeviewEnumIA( void); 
 
	// the IUnknown Functions 
	STDMETHODIMP         QueryInterface( REFIID iid, LPVOID* ppInterface); 
	STDMETHODIMP_(ULONG) AddRef( void); 
	STDMETHODIMP_(ULONG) Release( void); 
 
	// the IEnum Functions 
	STDMETHODIMP         Next ( 
		ULONG celt, 
		OPCITEMATTRIBUTES **rgelt, 
		ULONG *pceltFetched 
		); 
 
	STDMETHODIMP         Skip ( 
		ULONG celt 
		); 
 
	STDMETHODIMP         Reset( 
		void 
		); 
 
	STDMETHODIMP         Clone( 
		IEnumOPCItemAttributes **ppenum 
		); 
 
  private: 
	// Member Variables 
	ULONG           m_cRef;     //Enum Object reference count 
	LPUNKNOWN       m_pUnkRef;  //'parent' IUnknown for ref counting 
	ULONG           m_iCur;     //Current element 
	ULONG           m_cIA;     //Number of item attribues in us 
	OPCITEMATTRIBUTES       *m_pIA;  //List of item attributes 
	IMalloc			*m_pmem;	// memory allocator to use 
}; 
 
 
///////////////////////////////////////////////////////////////////////////// 
// LHEpipeviewItem 
//   This class is an implementation of an LHEpipeview specific Item Class. 
//   This implementation is PURELY for the sake of this sample code 
//   and does NOT represent a required OPC object or interface. 
//   It is intended to show a very simple example of a working item implementation. 
//   You can implement your Items any way you chose - you can even 
//   embed them as structures in the LHEpipeviewGroup. 
// 
///////////////////////////////////////////////////////////////////////////// 
// Cached Data Change Flags 
#define OPC_ODC_CP	1		// ConnectionPoint Object 
#define OPC_ODC_DO	2		// Data Object without time 
#define OPC_ODC_DOT	4		// Data Object with time 
#define OPC_ODC_ANY	(4+2+1) 
 
// for use by QueDeviceRead() 
// 
#define DEVICE_READ	1 
#define DEVICE_REFRESH	2 
 
class LHEpipeviewItem : public IUnknown 
{ 
  public: 
    LHEpipeviewItem( LHEpipeviewGroup *ParentGroup); 
    ~LHEpipeviewItem( void); 
 
	// the IUnknown Functions 
	STDMETHODIMP         QueryInterface( REFIID iid, LPVOID* ppInterface); 
	STDMETHODIMP_(ULONG) AddRef( void); 
	STDMETHODIMP_(ULONG) Release( void); 
 
	// Member Utility Functions (Note these are NOT an OPC required interface!) 
	HRESULT 	Init(int j, OPCITEMDEF *def, OPCITEMRESULT *ir); 
	void		SetActive(BOOL a); 
	BOOL		GetActive(void); 
	void		SetHandle(OPCHANDLE h); 
	OPCHANDLE	GetHandle(void); 
	HRESULT		SetDatatype(VARTYPE v); 
	VARTYPE		GetDatatype(void); 
	LHEpipeviewItem 	* Clone(LHEpipeviewGroup * newparent, OPCHANDLE newserveritemhandle); 
	void		IAGet(OPCITEMATTRIBUTES * pIA); 
	HRESULT		GetValue(OPCDATASOURCE ds, VARIANT * v, WORD *q, FILETIME*t); 
	HRESULT		SetValue(VARIANT * v); 
	void		Simulate( void ); 
	void		QueDeviceRead( short mask );	// 2.0 
	BOOL		CheckDeviceRead( HRESULT *r ); 
	void		QueDeviceWrite( VARIANT * v); 
	BOOL		CheckDeviceWrite( HRESULT *r ); 
	void		MarkAsChanged( WORD flg ); 
	void		ClearChanged( WORD flg ); 
	BOOL		Changed(WORD flg); 
 
  friend class ILHEpipeviewSIO; 
  friend class ILHEpipeviewASIO; 
  friend class ILHEpipeviewDO; 
  private: 
	// Member Variables 
    ULONG		mRefCount; 
	LHEpipeviewGroup	*m_Parent;		// The group that owns this item 
 
	OPCHANDLE	m_hServerItem; 
	VARTYPE		m_vtCanonical; 
 
	OPCHANDLE	m_hClientItem; 
	WCHAR		* m_szItemID; 
	WCHAR		* m_szAccessPath; 
	VARTYPE		m_vtRequested; 
	BOOL		m_bActive; 
 
	// Simulated Server supplied Dynamic Data for testing... 
	FLOAT		m_SimValue;		// used by the sample code's data simulator logic 
	FLOAT		m_Value; 
	WORD		m_Quality; 
	FILETIME	m_TimeStamp; 
 
	HRESULT		m_LastWriteError;	// Place to save result of Async Write 
	BOOL		m_GenData;		// set to generate sine wave simulation 
								// this flag is cleared by any WRITE 
	WORD		m_AsyncMask;	// bit mask used by Async operations 	V2.0 
 
}; 
 
 
#endif