// BluetoothManagerDlg.h : header file
//

#pragma once
#include "afxwin.h"
#include "afxcmn.h"

#include "..\..\..\..\Source\Common\wclPowerevents.h"
#include "..\..\..\..\Source\Bluetooth\wclBluetooth.h"

using namespace wclCommon;
using namespace wclBluetooth;


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

// Dialog Data
	enum { IDD = IDD_BLUETOOTHMANAGER_DIALOG };

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


// Implementation
protected:
	HICON m_hIcon;

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

private:
	CEdit edName;
	CListCtrl lvRadios;
	CEdit edTimeout;
	CEdit edPIN;
	CListCtrl lvDevices;
	CListCtrl lvServices;
	CListCtrl lvEvents;
	CListCtrl lvComPorts;
	CButton cbEnumPreinstalled;
	CComboBox cbDiscoveringMode;
	CComboBox cbMitmProtection;
	CComboBox cbIoCap;
	CComboBox cbBleProtection;

	CwclBluetoothManager wclBluetoothManager;
	CwclPowerEventsMonitor FPowerMonitor;

	CString BoolToStr(bool b) const;
	CString IntToHex(int i) const;
	CString IntToHex(unsigned long i) const;
	CString IntToHex(__int64 i) const;
	CString IntToStr(int i) const;
	__int64 StrToInt64(const CString& s) const;
	int StrToInt(const CString& s) const;

	void TraceEvent(const CwclBluetoothRadio* const Radio, const CString& Event,
		const CString& Parameter, const CString& Value);
	void ClearRadios();
	void ClearDevices();
	void ClearServices();
	void RefreshRadio(const int Item);
	void ShowError(const int Error) const;
	void RefreshDevice(const int Item);
	void AddDevice(CwclBluetoothRadio* const Radio, const __int64 Address);
	void RefreshDevices();
	void ClearComPorts();
	void RefreshVComs();

	void wclBluetoothManagerAfterOpen(void* Sender);
	void wclBluetoothManagerBeforeClose(void* Sender);
	void wclBluetoothManagerClosed(void* Sender);
	void wclBluetoothManagerAuthenticationCompleted(void* Sender, CwclBluetoothRadio* const Radio,
		const __int64 Address, const int Error);
	void wclBluetoothManagerDeviceFound(void* Sender, CwclBluetoothRadio* const Radio,
		const __int64 Address);
	void wclBluetoothManagerDiscoveringCompleted(void* Sender, CwclBluetoothRadio* const Radio,
		const int Error);
	void wclBluetoothManagerDiscoveringStarted(void* Sender, CwclBluetoothRadio* const Radio);
	void wclBluetoothManagerNumericComparison(void* Sender, CwclBluetoothRadio* const Radio,
		const __int64 Address, const unsigned long Number, bool& Confirm);
	void wclBluetoothManagerPasskeyNotification(void* Sender, CwclBluetoothRadio* const Radio,
		const __int64 Address, const unsigned long Passkey);
	void wclBluetoothManagerPasskeyRequest(void* Sender, CwclBluetoothRadio* const Radio,
		const __int64 Address, unsigned long& Passkey);
	void CBluetoothManagerDlg::wclBluetoothManagerPinRequest(void* Sender, 
		CwclBluetoothRadio* const Radio, const __int64 Address, tstring& Pin);
	void wclBluetoothManagerStatusChanged(void* Sender, CwclBluetoothRadio* const Radio);
	void wclBluetoothManagerConfirm(void* Sender, CwclBluetoothRadio* const Radio,
		const __int64 Address, bool& Confirm);
	void wclBluetoothManagerIoCapabilityRequest(void* Sender, CwclBluetoothRadio* const Radio,
		const __int64 Address, wclBluetoothMitmProtection& Mitm, wclBluetoothIoCapability& IoCapability,
		bool& OobPresent);
	void wclBluetoothManagerOobDataRequest(void* Sender, CwclBluetoothRadio* const Radio,
		const __int64 Address, wclBluetoothOobData& OobData);
	void wclBluetoothManagerProtectionRequest(void* Sender, CwclBluetoothRadio* Radio,
		const __int64 Address, wclBluetoothLeProtectionLevel& Protection);

	void PowerStateChanged(void* Sender, const wclPowerState State);

public:
	afx_msg void OnBnClickedButtonClear();
	afx_msg void OnDestroy();
	afx_msg void OnBnClickedButtonRefresh();
	afx_msg void OnBnClickedButtonOpen();
	afx_msg void OnBnClickedButtonClose();
	afx_msg void OnBnClickedButtonSetConnectable();
	afx_msg void OnBnClickedButtonSetDiscoverable();
	afx_msg void OnBnClickedButtonSetName();
	afx_msg void OnBnClickedButtonEnumPaired();
	afx_msg void OnBnClickedButtonRefreshDevice();
	afx_msg void OnBnClickedButtonEnumServices();
	afx_msg void OnBnClickedButtonDiscover();
	afx_msg void OnBnClickedButtonTerminate();
	afx_msg void OnBnClickedButtonUnpair();
	afx_msg void OnBnClickedButtonPair();
	afx_msg void OnBnClickedButtonRssi();
	afx_msg void OnBnClickedButtonTurnOn();
	afx_msg void OnBnClickedButtonTurnOff();
	afx_msg void OnBnClickedButtonEnumComs();
	afx_msg void OnBnClickedButtonCreatePort();
	afx_msg void OnBnClickedButtonDestroyCom();
	afx_msg void OnBnClickedButtonInstallDevice();
	afx_msg void OnBnClickedButtonUninstallDevice();
	afx_msg void OnBnClickedButtonIsInRange();
private:
	CComboBox cbPairingMethod;
public:
	afx_msg void OnBnClickedButtonDisconnect();
	afx_msg void OnBnClickedButtonEnumConnected();
	afx_msg void OnBnClickedButtonEnumInstalledServices();
private:
	CButton cbHandlePairing;
};
