www.pudn.com > GEOPC_modified_2005621145656299.rar > OPCXXX.H, change:2005-06-15,size:26518b


// OPCXXX.h 
// 
// This file contains OBJECT definitions which are SPECFIC 
// to the OPC server for XXX 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, XXXItem 
//  0.02  03/01/97 acc   add GetValue(), SetValue() to XXXItem 
//  0.90  04/01/97 acc   add Async Support 
// 
// 
 
 
#ifndef OPCXXX_H 
#define OPCXXX_H 
 
 
#include "OPC.h"	//The 'standard' OPC custom interface defintions 
#include "OLECTL.h"	// For ConnectionPoint Stuff 
#include "I_BSAS.H" 
#include "ENUMHELP.h"	//Some enumerator helper classes 
 
// Define the unique classID that represents Vendor ZZZ's 
// OPC Server for product XXX 
// 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); 
 
 
// Implementation specific definitions. 
#define N_GRPS	5		// max number of groups supported per server 
#define N_ITEMS	1000		// 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	XXXServer;	// The server object itself 
class	IXXXServer;	// The IOPCServer Interface 
class	IXXXEnum;	// The IEnumUnknown Interface 
class	IXXXSPG;	// The optional IOPCServerPublicGroups interface 
class	IXXXBSAS;	// The optional IOPCBrowseServerAddressSpace interface 
class	IXXXPF;		// The optional IPersistFile interface 
 
class	XXXGroup;	// The Group Object itself 
class	IXXXGSM;	// The IOPCGroupStateMgt interface 
class	IXXXPGSM;	// The optional IOPCPublicGroupStateMgt interface 
class	IXXXSIO;	// The IOPCSyncIO interface 
class	IXXXASIO;	// The IOPCAsynIO interface 
class	IXXXASIO2;	// The IOPCAsynIO2 interface 
class	IXXXIM;		// The IOPCItemMgt interface 
class	IXXXDO;		// The IDataObject interface 
 
class	IXXXEnumIA;	// enum item attrs is returned from an itemmgt method 
 
class	XXXItem;	// A 'local' Item Class 
 
class CImpIConnectionPointContainer; 
class CImpIConnectionPoint; 
 
///////////////////////////////////////////////////////////////////////////// 
// 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 
 
#define QUALITY_BAD				0 
#define QUALITY_UNCERTAIN		1 
#define QUALITY_GOOD			3 
typedef struct 
{ 
    unsigned short nLimit     : 2;		// 0..3   (2 bits) 
    unsigned short nSubStatus : 4;		// 0..15  (4 bits) 
    unsigned short nQuality   : 2;		// 0..3   (2 bits) 
	unsigned short nLeftOver  : 8; 
} QUALITY_STATE; 
 
//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); 
 
 
///////////////////////////////////////////////////////////////////////////// 
// XXXServer 
//   This class is an implementation of a XXX specific version of the 
//   OPCServer class. 
// There is no standard OPC Server 'object', only vendor specific objects 
//   so this derives from IUnKnown.  
// The other XXX sepcific implementations of the OPC interfaces for this  
//   will derive from the OPC interface classes in OPC.H (see below) 
// 
///////////////////////////////////////////////////////////////////////////// 
class XXXServer : public IUnknown 
{ 
  public: 
    XXXServer( LPUNKNOWN, void (*pfn)(void)); 
    ~XXXServer( 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); 
 
		void   GetAddressList(  
	OPCBROWSETYPE dwBrowseFilterType, 
	LPCWSTR szFilterCriteria, 
	VARTYPE vtDataTypeFilter, 
	DWORD dwAccessRightsFilter, 
	LPOLESTR**AddressList,  
	int *AddressCount); 
	void FreeAddressList( LPOLESTR*AddressList, int count); 
  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 IXXXServer; 
  friend class IXXXPF; 
  friend class IXXXGSM; 
	friend class CImpIConnectionPointContainer; 
	friend class CImpIConnectionPoint; 
 
  private: 
	// Member Variables 
	IXXXServer		*m_pIServer;	// ptr to 'tear-off' IOPCServer i/f 
	IXXXSPG 		*m_pISPG;		// public groups (optional) 
	IXXXBSAS 		*m_pIBSAS;		// browse address space (optional) 
	IXXXPF			*m_pIPF;		// persistfile (optional) 
	CImpIConnectionPointContainer	*m_pCImpIConnPointContainer;// IConnectionPointContainer implementation 
	CImpIConnectionPoint		*m_pCImpIConnPoint;			// IConnectionPoint implementation 
 
    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; 
	 XXXGroup	* pGroup; 
    } m_groups[N_GRPS]; 
 
}; 
 
 
///////////////////////////////////////////////////////////////////////////// 
// XXX specific implementation of an IOPCServer Interface 
// 
class IXXXServer : public IOPCServer 
{ 
  public: 
    IXXXServer( LPUNKNOWN ); 
    ~IXXXServer( 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 
	XXXServer	*m_Parent;	// ptr to 'owning' XXXServer 
}; 
 
///////////////////////////////////////////////////////////////////////////// 
// XXX specific implementation of an IPersistFile Interface for the Server 
// 
class IXXXPF: public IPersistFile 
{ 
  public: 
    IXXXPF( LPUNKNOWN ); 
    ~IXXXPF( 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 
	XXXServer	*m_Parent;	// ptr to 'owning' XXXServer 
}; 
 
 
///////////////////////////////////////////////////////////////////////////// 
// XXXGroup 
//   This class is an implementation of a XXX specific version of the 
//   OPC Group class. 
// 
///////////////////////////////////////////////////////////////////////////// 
class XXXGroup : public IUnknown 
{ 
  public: 
    XXXGroup( LPUNKNOWN ); 
    ~XXXGroup( 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) 
	XXXItem		*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, XXXItem * 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); 
	HRESULT		SendDataChange(IN DWORD			dwTransID, 
											IN HRESULT			hrMasterQuality, 
											IN HRESULT			hrMasterError, 
											IN DWORD			dwCount, 
											IN OPCHANDLE	*	pdwHandleList, 
											IN VARIANT		*	pvDataList, 
											IN WORD			*	pwQualityList, 
											IN FILETIME		*	pftTimeList, 
											OUT HRESULT		*	pErrors); 
  friend class IXXXServer; 
  friend class XXXServer; 
  friend class IXXXIM; 
  friend class IXXXSIO; 
  friend class IXXXASIO; 
  friend class IXXXASIO2; 
  friend class IXXXGSM; 
  friend class IXXXPGSM; 
  friend class IXXXDO; 
  friend class IXXXEnumIA; 
  friend class CImpIConnectionPointContainer; 
	friend class CImpIConnectionPoint; 
  private: 
	// Member Variables 
    ULONG		mRefCount; 
	XXXServer	*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; 
 
	IXXXGSM		*m_pIXXXGSM;	//Group State Mgt 
	IXXXPGSM	*m_pIXXXPGSM;	// Public Group State Mgt (optional) 
	IXXXSIO		*m_pIXXXSIO;	// SyncIO 
	IXXXASIO	*m_pIXXXASIO;	// ASynioIO 
	IXXXASIO2	*m_pIXXXASIO2; 
	IXXXIM		*m_pIXXXIM;		// Item Mgt 
	IXXXDO		*m_pIXXXDO;		// Data Object 
	CImpIConnectionPointContainer	*m_pCImpIConnPointContainer;// IConnectionPointContainer implementation 
	CImpIConnectionPoint		*m_pCImpIConnPoint;			// IConnectionPoint implementation 
 
	// 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; 
	 XXXItem	*pItem; 
    } m_items[N_ITEMS]; 
}; 
 
 
 
///////////////////////////////////////////////////////////////////////////// 
// IXXXIM 
//   This class is an implementation of a XXX specific version of the 
//   OPC ItemMgt Interface 
// 
class IXXXIM : public IOPCItemMgt 
{ 
  public: 
    IXXXIM( LPUNKNOWN ); 
    ~IXXXIM( 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 
	XXXGroup	*m_Parent;	// ptr to owning 'XXXGroup' 
 
}; 
 
 
///////////////////////////////////////////////////////////////////////////// 
// IXXXSIO 
//   This class is an implementation of a XXX specific version of the 
//   OPC AsyncIO Interface 
// 
class IXXXSIO : public IOPCSyncIO 
{ 
  public: 
    IXXXSIO( LPUNKNOWN ); 
    ~IXXXSIO( 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 
	XXXGroup	*m_Parent;	// ptr to owning 'XXXGroup' 
}; 
 
 
///////////////////////////////////////////////////////////////////////////// 
// IXXXASIO 
//   This class is an implementation of a XXX specific version of the 
//   OPC AsyncIO Interface 
// 
class IXXXASIO : public IOPCAsyncIO 
{ 
  public: 
    IXXXASIO( LPUNKNOWN ); 
    ~IXXXASIO( 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 
	XXXGroup	*m_Parent;	// ptr to owning 'XXXGroup' 
}; 
 
class IXXXASIO2 : public IOPCAsyncIO2 
{ 
  public: 
    IXXXASIO2( LPUNKNOWN ); 
    ~IXXXASIO2( void); 
 
	// the IUnknown Functions 
	STDMETHODIMP         QueryInterface( REFIID iid, LPVOID* ppInterface); 
	STDMETHODIMP_(ULONG) AddRef( void); 
	STDMETHODIMP_(ULONG) Release( void); 
 
	 
/*	STDMETHODIMP Read(  
            DWORD dwCount, 
            OPCHANDLE  *phServer, 
            DWORD dwTransactionID, 
            DWORD  *pdwCancelID, 
            HRESULT  *ppErrors); 
*/ 
	STDMETHODIMP	Read(  
            /* [in] */ DWORD dwCount, 
            /* [size_is][in] */ OPCHANDLE __RPC_FAR *phServer, 
            /* [in] */ DWORD dwTransactionID, 
            /* [out] */ DWORD __RPC_FAR *pdwCancelID, 
            /* [size_is][size_is][out] */ HRESULT __RPC_FAR *__RPC_FAR *ppErrors); 
         
     /*   STDMETHODIMP Write(  
            DWORD dwCount, 
			OPCHANDLE *phServer, 
            VARIANT *pItemValues, 
            DWORD dwTransactionID, 
            DWORD *pdwCancelID, 
            HRESULT *ppErrors); 
       */ 
	   STDMETHODIMP Write(  
            /* [in] */ DWORD dwCount, 
            /* [size_is][in] */ OPCHANDLE __RPC_FAR *phServer, 
            /* [size_is][in] */ VARIANT __RPC_FAR *pItemValues, 
            /* [in] */ DWORD dwTransactionID, 
            /* [out] */ DWORD __RPC_FAR *pdwCancelID, 
            /* [size_is][size_is][out] */ HRESULT __RPC_FAR *__RPC_FAR *ppErrors); 
        STDMETHODIMP Refresh2(  
            OPCDATASOURCE dwSource, 
            DWORD dwTransactionID, 
            DWORD *pdwCancelID); 
         
        STDMETHODIMP Cancel2(  
             DWORD dwCancelID); 
         
        STDMETHODIMP SetEnable(  
            BOOL bEnable); 
         
        STDMETHODIMP GetEnable(  
             BOOL *pbEnable); 
	 
 
 
 
  private: 
	// Member Variables 
	XXXGroup	*m_Parent;	// ptr to owning 'XXXGroup' 
}; 
 
///////////////////////////////////////////////////////////////////////////// 
// IXXXPGSM 
//   This class is an implementation of a XXX specific version of the 
//   Optional OPC PublicGroupStateMgt Interface 
// 
class IXXXPGSM : public IOPCPublicGroupStateMgt 
{ 
  public: 
    IXXXPGSM( LPUNKNOWN ); 
    ~IXXXPGSM( 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 
	XXXGroup	*m_Parent;	// ptr to owning 'XXXGroup' 
}; 
 
 
///////////////////////////////////////////////////////////////////////////// 
// IXXXGSM 
//   This class is an implementation of a XXX specific version of the 
//   OPC PublicGroupStateMgt Interface 
// 
class IXXXGSM : public IOPCGroupStateMgt 
{ 
  public: 
    IXXXGSM( LPUNKNOWN ); 
    ~IXXXGSM( 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 
	XXXGroup	*m_Parent;	// ptr to owning 'XXXGroup' 
}; 
 
 
///////////////////////////////////////////////////////////////////////////// 
// IXXXDO 
//   This class is an implementation of a XXX specific version of the 
//   OPC PublicGroupStateMgt Interface 
// 
class IXXXDO : public IDataObject 
{ 
  public: 
    IXXXDO( LPUNKNOWN ); 
    ~IXXXDO( 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 
	XXXGroup	*m_Parent;	// ptr to owning 'XXXGroup' 
	IAdviseSink	*m_dataCallback; 
	IAdviseSink	*m_datatimeCallback; 
	IAdviseSink	*m_writeCallback; 
	UINT m_data; 
	UINT m_datatime; 
	UINT m_write; 
 
  friend class XXXGroup; 
 
}; 
 
 
 
///////////////////////////////////////////////////////////////////////////// 
// IXXXEnumIA 
//   This class is an implementation of a XXX specific version of the 
//   OPC IEnumOPCItemAttributes Interface 
// 
class IXXXEnumIA : public IEnumOPCItemAttributes 
{ 
  public: 
	IXXXEnumIA(LPUNKNOWN parent, ULONG c, OPCITEMATTRIBUTES* ia, IMalloc* m); 
    IXXXEnumIA( LPUNKNOWN ); 
    ~IXXXEnumIA( 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 
}; 
 
 
///////////////////////////////////////////////////////////////////////////// 
// XXXItem 
//   This class is an implementation of an XXX 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 XXXGroup. 
// 
///////////////////////////////////////////////////////////////////////////// 
// 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 XXXItem : public IUnknown 
{ 
  public: 
    XXXItem( XXXGroup *ParentGroup); 
    ~XXXItem( void); 
	BOOL	m_bValue; 
 
	// 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); 
	XXXItem 	* Clone(XXXGroup * 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 IXXXSIO; 
  friend class IXXXASIO; 
  friend class IXXXASIO2; 
  friend class IXXXDO; 
  friend class XXXGroup; 
  private: 
	// Member Variables 
    ULONG		mRefCount; 
	XXXGroup	*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