Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version

CWaveForm

, 24 Feb 2006
A simple wave form API wrapper class
/*
+===========================================================================+
|				Copyright (C) Direct Line Corp. 1999-2000.					|
+---------------------------------------------------------------------------+
| File Name:																|
|																			|
|	Interface.h																|
|																			|
+---------------------------------------------------------------------------+
| Descriptions:																|
|																			|
|	Private interfaces definition and implementaion.						|
|																			|
+---------------------------------------------------------------------------+
| Developer(s):																|
|																			|
|	Xu Wen Bin.																|
|																			|
+===========================================================================+
|                         C H A N G E     L O G                             |
+---------------------------------------------------------------------------+
|																			|
|	07-20-01	1.00	Created.											|
|	09-01-01	1.01	Modified.											|
|	02-22-06	1.02	Modified.											|
|																			|
+---------------------------------------------------------------------------+
| Notes:																	|
|																			|
+===========================================================================+
*/

#ifndef _INTERFACE_H_
#define _INTERFACE_H_

/****************************************************************************
 * IIUnknown interface definition and implementation.
 ****************************************************************************
 * We use IIUnknown instead of IUnknown to prevent name space conflict.
 */
class IIUnknown
{
	virtual long AddRef() = 0;
	virtual long Release() = 0;
};

#define IMP_IIUNKNOWN() \
	long AddRef();      \
	long Release()

/****************************************************************************
 * IIStreamDevice interface definition and implementation.
 ****************************************************************************
 * Standard stream device interface.
 */
class IIStreamDevice
{
	virtual BOOL Open(UINT uDirection)         = 0;
	virtual BOOL Close(UINT uDirection)        = 0;
	virtual BOOL Start(UINT uDirection)        = 0;
	virtual BOOL Stop(UINT uDirection)         = 0;
	virtual BOOL Pause(UINT uDirection)        = 0;
	virtual BOOL Restart(UINT uDirection)      = 0;
	virtual BOOL Reset(UINT uDirection)        = 0;
	virtual UINT GetDirection()                = 0;
	virtual void SetDirection(UINT uDirection) = 0;
};

#define IMP_IISTREAMDEVICE()       \
	BOOL Open(UINT uDirection);    \
	BOOL Close(UINT uDirection);   \
	BOOL Start(UINT uDirection);   \
	BOOL Stop(UINT uDirection);    \
	BOOL Pause(UINT uDirection);   \
	BOOL Restart(UINT uDirection); \
	BOOL Reset(UINT uDirection);   \
	UINT GetDirection();           \
	void SetDirection(UINT uDirection)

/****************************************************************************
 * IIDataSource interface definition and implementation.
 ****************************************************************************
 * Standard data source interface.
 */
template<class DATATYPE>
class IIDataSource
{
	virtual BOOL Read(DATATYPE * ppData)  = 0;
	virtual BOOL ReadDone(DATATYPE pData) = 0;
};

#define IMP_IIDATASOURCE(DATATYPE) \
	BOOL Read(DATATYPE * ppData);  \
	BOOL ReadDone(DATATYPE pData)

/****************************************************************************
 * IIDataSink interface definition and implementation.
 ****************************************************************************
 * Standard data sink interface.
 */
template<class DATATYPE>
class IIDataSink
{
	virtual BOOL Write(DATATYPE * ppData) = 0;
	virtual BOOL Write(DATATYPE pData)    = 0;
};

#define IMP_IIDATASINK(DATATYPE)   \
	BOOL Write(DATATYPE * ppData); \
	BOOL Write(DATATYPE pData)

/****************************************************************************
 * IIAdvise interface definition and implementation.
 ****************************************************************************
 * Standard advise interface.
 */
#define CALLBACK_TYPEMASK   0x00070000l     /* callback type mask */
#define CALLBACK_NULL       0x00000000l     /* no callback */
#define CALLBACK_WINDOW     0x00010000l     /* dwCallback is a HWND */
#define CALLBACK_TASK       0x00020000l     /* dwCallback is a HTASK */
#define CALLBACK_FUNCTION   0x00030000l     /* dwCallback is a FARPROC */
#define CALLBACK_THREAD     (CALLBACK_TASK) /* thread ID replaces 16 bit task */
#define CALLBACK_EVENT      0x00050000l     /* dwCallback is an EVENT Handle */

typedef void (* PEVENTSINKFUNC) (DWORD, DWORD, DWORD, DWORD);

typedef struct stAdviseStructure
{
	DWORD	dwCallBack; // Represent HWDN, THREAD_ID, TAKS_ID or CALLBACK FUNCTION.
	DWORD	dwInstance;
	DWORD   dwMask;
	DWORD   dwType;
} ADVISESTRUCTURE, *PADVISESTRUCTURE;

class IIAdvise
{
	virtual void Advise(DWORD dwCallBack, DWORD dwInstance, DWORD dwMask, DWORD dwType) = 0;
	virtual void Unadvise(DWORD dwCallBack) = 0;
	virtual void Invoke(DWORD dwEvent, DWORD wParam, DWORD lParam) = 0;
};

#define IMP_IIADVISE()                                                           \
	void Advise(DWORD dwCallBack, DWORD dwInstance, DWORD dwMask, DWORD dwType); \
	void Unadvise(DWORD dwCallBack);                                             \
	void Invoke(DWORD dwEvent, DWORD wParam, DWORD lParam)

class CAdvise : public IIAdvise
{
public:

	CAdvise()
	{
		InitializeCriticalSection(&m_adviseListLock);
	}

	~CAdvise()
	{
		DeleteCriticalSection(&m_adviseListLock);

		while (!m_adviseList.IsEmpty())
		{
			PADVISESTRUCTURE stAdvise = m_adviseList.RemoveHead();

			if (stAdvise)
			{
				delete stAdvise;
			}
		}
	}

	void Advise(DWORD dwCallBack, DWORD dwInstance, DWORD dwMask, DWORD dwType)
	{
		PADVISESTRUCTURE stAdvise = new ADVISESTRUCTURE;
		stAdvise->dwCallBack = dwCallBack;
		stAdvise->dwInstance = dwInstance;
		stAdvise->dwMask     = dwMask;
		stAdvise->dwType     = dwType;

		EnterCriticalSection(&m_adviseListLock);

		m_adviseList.AddTail(stAdvise);

		LeaveCriticalSection(&m_adviseListLock);
	}

	void Unadvise(DWORD dwCallBack)
	{
		EnterCriticalSection(&m_adviseListLock);

		int count = m_adviseList.GetCount();

		for (int i = 0; i < count; i++)
		{
			PADVISESTRUCTURE stAdvise = m_adviseList.RemoveHead();

			if (stAdvise->dwCallBack == dwCallBack)
			{
				delete stAdvise;
				stAdvise = NULL;
				break;
			}
			else
			{
				m_adviseList.AddTail(stAdvise);
			}
		}

		LeaveCriticalSection(&m_adviseListLock);
	}

	void Invoke(DWORD dwEvent, DWORD wParam, DWORD lParam)
	{
		EnterCriticalSection(&m_adviseListLock);

		if (!m_adviseList.IsEmpty())
		{
			PADVISESTRUCTURE stAdvise = NULL;

			int count = m_adviseList.GetCount();

			for (int i = 0; i < count; i++)
			{
				stAdvise = m_adviseList.RemoveHead();

				if (stAdvise)
				{
					if (stAdvise->dwType == CALLBACK_EVENT)
					{
						::SetEvent((HANDLE)stAdvise->dwCallBack);
					}
					else if (stAdvise->dwType == CALLBACK_FUNCTION)
					{
						if (dwEvent & stAdvise->dwMask)
						{
							(PEVENTSINKFUNC(stAdvise->dwCallBack))(dwEvent, stAdvise->dwInstance, wParam, lParam);
						}
					}
					else if (stAdvise->dwType == CALLBACK_WINDOW)
					{
						if (dwEvent & stAdvise->dwMask)
						{
							::SendMessage((HWND)stAdvise->dwCallBack, dwEvent, wParam, lParam);
						}
					}
					else if (stAdvise->dwType == CALLBACK_THREAD)
					{
						if (dwEvent & stAdvise->dwMask)
						{
							::PostThreadMessage(stAdvise->dwCallBack, dwEvent, wParam, lParam);
						}
					}
					else
					{
						// CALLBACK_TASK.
					}

					// Add advise element back to list.
					m_adviseList.AddTail(stAdvise);
				}
			}
		}

		LeaveCriticalSection(&m_adviseListLock);
	}

private:

	// Advise list.
	CRITICAL_SECTION m_adviseListLock;
	CList<PADVISESTRUCTURE,PADVISESTRUCTURE&> m_adviseList;
};

/****************************************************************************
 * IDLEventSink interface  definition and implementation.
 ****************************************************************************
 * Standard event sink interface.
 */
class IIEventSink
{
	virtual void OnEvent(DWORD dwEvent, DWORD dwInstance, DWORD wParam, DWORD lParam) = 0;
};

#define IMP_IIEVENTSINK() \
	void OnEvent(DWORD dwEvent, DWORD dwInstance, DWORD wParam, DWORD lParam)

#endif // _INTERFACE_H_

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Skeeter
Program Manager Microsoft
China China
Graduated from Shanghai Tongji university in 1997 with bachelor degree in computer science, Wenbin got his first job as a system engineer at Bell Alcatel Mobile Shanghai office responsible for telcom-class mobile system development and deployment. Since then, Wenbin has in turn worked for Intel and Microsoft both inside and outside China, first as senior engineer, later project manager and then senior product manager.
 
With 15-year experience working with the world top IT companies, Wenbin has developed solid skill in C/C++, C#, Java, software engineering, agile development, etc, and multiple talents in product management, public presentation and speech, etc. He has always been an active member at PMI (Project Management Institution) and a regular lecture at Intel Developer Forum, Microsoft TechED conference as well as many other world-class industrial conferences. His wide-ranged industrial practice and high-level personal maturity have made him one of the best in public speech and professional training.
 
Over the years, Wenbin has cultivated his very own style in public speech, which is considered informative, engaging and refined. Since last year, Wenbin has also taken new adventure in project and product management consulting business and has proven high capacity through his work with many local emergent IT firms. Wenbin’s specialty in management consulting is on project management methodologies and processes, project management tools (e.g. MS Project), and team recruitment, build, and motivation.
 
In addition, Wenbin has received many professional qualifications including MCSE (Microsoft Certified System Engineer), MCSD (Microsoft Certified System Developer), MCDBA (Microsoft Certified Database Administrator), SCJP 2 (Sun Certified Java Programmer 2), and PMP (PMI Certified Project Management Professional). On top of that, Wenbin has got several on-duty inventions and one of them was successfully patented by United States Patent and Trademark Office.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141216.1 | Last Updated 24 Feb 2006
Article Copyright 2001 by Skeeter
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid