//
// Copyright: © 2009 Sierra Wireless Inc., all rights reserved
//

// SimpleCMDlg.h : header file
//

#pragma once
#include "afxwin.h"
#include <GobiConnectionMgmtAPI.h>
#include "SwiWwanCmApi.h"

// CSimpleCMDlg dialog
class CSimpleCMDlg : public CDialog
{
// Construction
public:
	CSimpleCMDlg(CWnd* pParent = NULL);	// standard constructor

// Dialog Data
	enum { IDD = IDD_SIMPLECM_DIALOG };

protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support
	

// Implementation
protected:
	HICON m_hIcon;
	
	// Handle to GobiApi DLL
	HMODULE m_hGobiApi;

	// GUI fields
	CString m_szRssi;
	CString m_szCarrier;
	CString m_szApn;
	CString m_szUsername;
	CString m_szPassword;
	CString m_szStatus;
	CComboBox m_cmbTech;

	// Connection session ID
	ULONG	m_nSessionId;

	// connect function pointer prototype
	typedef ULONG (__stdcall * tFNConnect)();

	// disconnect function pointer prototype
	typedef ULONG (__stdcall * tFNDisconnect)();

	// session state function pointer prototype
	typedef ULONG (__stdcall * tFNGetSessionState)(ULONG * pState);

	// start data sessio function pointer prototype
	typedef ULONG (__stdcall * tFNStartDataSession)(
		ULONG *	pTechnology, 
		ULONG *	pPrimaryDNS, 
		ULONG *	pSecondaryDNS, 
		ULONG *	pPrimaryNBNS, 
		ULONG *	pSecondaryNBNS, 
		CHAR *	pAPNName, 
		ULONG * pIPAddress, 
		ULONG * pAuthentication, 
		CHAR *	pUsername, 
		CHAR *	pPassword,
		ULONG * pSessionId );

	// stop data session function pointer prototype
	typedef ULONG (__stdcall * tFNStopDataSession)(ULONG sessionId);

	// set signal strength callback function pointer prototype
	typedef ULONG (__stdcall * tFNSetSignalStrengthCallback)(
		tFNSignalStrength	pCallback,
		BYTE				thresholdsSize,
		INT8 *				pThresholds );

	// set session state callback function pointer prototype
	typedef ULONG (__stdcall * tFNSetSessionStateCallback)(tFNSessionState pCallback);

	// set device removal callback function pointer prototype
	typedef ULONG (__stdcall * tFNSwiSetDeviceRemovalCallback)(tFNSwiDeviceRemoval pCallback);

	// get serving network function pointer prototype
	typedef ULONG (__stdcall * tFNGetServingNetwork)(
		ULONG *	pRegistrationState, 
		ULONG *	pCSDomain, 
		ULONG *	pPSDomain, 
		ULONG *	pRAN, 
		BYTE *	pRadioIfacesSize, 
		BYTE *	pRadioIfaces, 
		ULONG *	pRoaming, 
		WORD *	pMCC, 
		WORD *	pMNC, 
		BYTE	nameSize, 
		CHAR *	pName );

	// get signal strengths function pointer prototype
	typedef ULONG (__stdcall * tFNGetSignalStrengths)(
		ULONG *	pArraySize,
		INT8 *	pSignalStrength,
		ULONG * pRadioInterface 
		);

	// get PIN status function pointer prototype
	typedef ULONG (__stdcall * tFNUIMGetPINStatus)(
		ULONG	id, 
		ULONG*	pStatus, 
		ULONG*	pVerifyRetriesLeft, 
		ULONG*	pUnblockRetriesLeft 
		);

	// get session state function pointer prototype
	typedef ULONG (__stdcall * tFNUIMGetSessionState)(
		ULONG*	pState
		);

	// Function pointers
	tFNConnect m_pFnConnect;
	tFNDisconnect m_pFnDisconnect;
	tFNSetSignalStrengthCallback m_pFnSetSignalStrengthCb;
	tFNSetSessionStateCallback m_pFnSetSessionStateCb;
	tFNSwiSetDeviceRemovalCallback m_pFnSwiSetDeviceRemovalCb;
	tFNStartDataSession m_pFnStartDataSession;
	tFNStopDataSession m_pFnStopDataSession;
	tFNGetServingNetwork m_pFnGetServingNetwork;
	tFNGetSignalStrengths m_pFnGetSignalStrengths;
	tFNUIMGetPINStatus m_pFnUIMGetPINStatus;
	tFNGetSessionState m_pFnGetSessionState;

	// Initialize GobiApi
	BOOL Initialize();

	// Search for available device
	BOOL DeviceSearch();

	// Enable/Disable user editable controls
	void EnableControls(BOOL bEnable=TRUE);	

	// Get network information
	void GetNetworkInfo();

	// Get device state information
	void GetDeviceState();

	// Generated message map functions
	virtual BOOL OnInitDialog();
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	DECLARE_MESSAGE_MAP()

	afx_msg void OnTimer(UINT_PTR nIDEvent);
	afx_msg LRESULT OnNotifSignalStrength(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT OnNotifSessionState(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT OnNotifDeviceRemoval(WPARAM wParam, LPARAM lParam);
public:
	afx_msg void OnDestroy();
	afx_msg void OnBnClickedBtnConnect();

	
};
