#pragma once

#include "ApiHelper.h"
#include "FuncList.h"

class CGobiApiDev;
class CGobiApiDms;
class CGobiApiNas;
class CGobiApiWds;
class CGobiApiWms;
class CGobiApiFwMgmt;
class CGobiApiOma;
class CGobiApiPds;
class CGobiApiRms;
class CGobiApiCat;
class CGobiApiSwiOma;
class CGobiApiSar;

class CFuncList;

class CApiHelperGobi : public CApiHelper
{
public:
	CApiHelperGobi(void);
	~CApiHelperGobi(void);

	///////////////////////////////////////////////////////////////////////////////
	///
	///	Initialize API helper.  Will attempt to connect to the first detected
	/// Qualcomm device.
	///
	///	\param	[IN] pParent
	///			Handle to parent window
	///
	///	\return	TRUE if initialization successful and device detected, 
	///			FALSE otherwise			
	///
	///////////////////////////////////////////////////////////////////////////////
	BOOL Initialize(CWnd* pParent);

	///////////////////////////////////////////////////////////////////////////////
	///
	///	Uninitialize API helper and disconnect from device
	///
	///	\return	TRUE if un-initialization successful, FALSE otherwise			
	///
	///////////////////////////////////////////////////////////////////////////////
	BOOL Uninitialize();

	///////////////////////////////////////////////////////////////////////////////
	///
	///	Get list of available functions
	///
	///	\param	[OUT] pFuncList
	///			List of available functions
	///
	///	\return	TRUE if successfully retrieve list of available functions, 
	///			FALSE otherwise			
	///
	///////////////////////////////////////////////////////////////////////////////
	BOOL GetAvailFuncList(CFuncList* pFuncList);

	///////////////////////////////////////////////////////////////////////////////
	///
	///	Copies list of functions to execute and signal worker thread to begin
	/// execution.  Caller thread is not blocked.  Completion of API calls is
	/// signaled by posting WM_USER_ExecutionComplete message to parent window
	/// previously provided with the Initialize call.
	///
	///	\param	[IN] pFuncList
	///			List of functions to execute
	///
	///	\return	TRUE if functions successfully copied and worker thread successfully
	///			signaled, FALSE otherwise			
	///
	///////////////////////////////////////////////////////////////////////////////
	BOOL ExecuteFunctions(CFuncList* pFuncList);

	static void __stdcall DeviceRemovalCallback(ULONG nStatus);

protected:
	CGobiApiDev* m_pDev;	// pointer to Device Connectivity object
	CGobiApiNas* m_pNas;	// pointer to NAS service object
	CGobiApiDms* m_pDms;	// pointer to DMS service object
	CGobiApiWds* m_pWds;	// pointer to WDS service object
	CGobiApiWms* m_pWms;    // pointer to WMS service object
	CGobiApiFwMgmt* m_pFwm;	// pointer to Firmware Management service object
	CGobiApiOma* m_pOma;    // pointer to OMA-DM service object
	CGobiApiPds* m_pPds;    // pointer to PDS service object
	CGobiApiRms* m_pRms;    // pointer to RMS service object
	CGobiApiCat* m_pCat;    // pointer to CAT service object
	CGobiApiSwiOma* m_pSwiOma; // pointer to SWI-OMA-DM service object
	CGobiApiSar* m_pSar;	// pointer to SAR service object

	HMODULE m_hQCApiDll;	// handle to Qualcomm API DLL

	///////////////////////////////////////////////////////////////////////////////
	///
	///	Execute list of functions
	///
	///	\param	None
	///
	///	\return	TRUE if successfully executed list of functions, 
	///			FALSE otherwise			
	///
	///////////////////////////////////////////////////////////////////////////////
	BOOL Execute();
};
