// GattClientDlg.h : header file
//

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

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

using namespace wclCommon;
using namespace wclBluetooth;


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

// Dialog Data
	enum { IDD = IDD_GATTCLIENT_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:
	CComboBox cbOperationFlag;
	CComboBox cbProtection;
	CComboBox cbParams;
	CComboBox cbWriteKind;
	CComboBox cbSubscribeKind;
	CEdit edCharValue;
	CListCtrl lvDevices;
	CListCtrl lvServices;
	CListCtrl lvCharacteristics;
	CListCtrl lvDescriptors;
	CListCtrl lvDescriptorValue;
	CListCtrl lvEvents;
	CButton cbConnectOnRead;
	CButton cbFastSubscribe;
	CButton btCCCDSubscribe;
	CButton btCCCDUnsubscribe;
	CButton cbForceIndications;

	CwclBluetoothManager wclBluetoothManager;
	CwclGattClient wclGattClient;

	wclGattCharacteristics FCharacteristics;
    wclGattDescriptors FDescriptors;
    wclGattServices FServices;

	CwclBluetoothRadio* GetRadio();
	void TraceEvent(const __int64 Address, const CString& Event, 
		const CString& Param, const CString& Value);
	void Cleanup();
	void ListProp(const CString& Name, const CString& Value);
	wclGattOperationFlag OpFlag() const;
	wclGattProtectionLevel Protection() const;

	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 wclBluetoothManagerPinRequest(void* Sender, CwclBluetoothRadio* const Radio,
		const __int64 Address, tstring& Pin);
	void wclBluetoothManagerAuthenticationCompleted(void* Sender, CwclBluetoothRadio* const Radio,
		const __int64 Address, const int Error);
	void wclBluetoothManagerDeviceFound(void* Sender, CwclBluetoothRadio* const Radio,
		const __int64 Address);
	void wclBluetoothManagerConfirm(void* Sender, CwclBluetoothRadio* const Radio, const __int64 Address,
		bool& Confirm);
	void wclBluetoothManagerProtectionLevelRequest(void* Sender, CwclBluetoothRadio* const Radio,
		const __int64 Address, wclBluetoothLeProtectionLevel& Protection);
	void wclBluetoothManagerDiscoveringCompleted(void* Sender, CwclBluetoothRadio* const Radio,
		const int Error);
	void wclBluetoothManagerDiscoveringStarted(void* Sender, CwclBluetoothRadio* const Radio);
	void wclBluetoothManagerIoCapabilityRequest(void* Sender, CwclBluetoothRadio* const Radio,
		const __int64 Address, wclBluetoothMitmProtection& Mitm, wclBluetoothIoCapability& IoCapability,
		bool& OobPresent);

	void wclGattClientCharacteristicChanged(void* Sender, const unsigned short Handle,
		const unsigned char* const Value, const unsigned long Length);
	void wclGattClientConnect(void* Sender, const int Error);
	void wclGattClientDisconnect(void* Sender, const int Reason);
	void wclGattClientConnectionParamsChanged(void* Sender);
	void wclGattClientMaxPduSizeChanged(void* Sender);
	void wclGattClientConnectionPhyChanged(void* Sender);
	
	void GetMaxPduSize();
	void GetConnectionParams();
	void GetConnectionPhy();

public:
	afx_msg void OnDestroy();
	afx_msg void OnBnClickedButtonDiscover();
	afx_msg void OnBnClickedButtonClear();
	afx_msg void OnBnClickedButtonConnect();
	afx_msg void OnBnClickedButtonDisconnect();
	afx_msg void OnBnClickedButtonGetServices();
	afx_msg void OnBnClickedButtonGetIncludedServices();
	afx_msg void OnBnClickedButtonGetCharacteristics();
	afx_msg void OnBnClickedButtonGetCharValue();
	afx_msg void OnBnClickedButtonGetDescriptors();
	afx_msg void OnBnClickedButtonGetDescValue();
	afx_msg void OnBnClickedButtonSetCharValue();
	afx_msg void OnBnClickedButtonSubscribe();
	afx_msg void OnBnClickedButtonUnsubscribe();
	afx_msg void OnBnClickedButtonWriteCccdSubscribe();
	afx_msg void OnBnClickedButtonWriteCccdUnsubscribe();
	afx_msg void OnBnClickedButtonTerminate();
	afx_msg void OnBnClickedButtonPair();
	afx_msg void OnBnClickedCheckFastSubscribe();
	afx_msg void OnBnClickedButtonGetParams();
	afx_msg void OnBnClickedButtonSetParams();
	afx_msg void OnBnClickedButtonGetMaxPduSize();
	afx_msg void OnBnClickedButtonPhy();
	afx_msg void OnStnClickedStaticIoCap();

private:
	CComboBox cbMitm;
	CComboBox cbIoCap;
public:
	afx_msg void OnBnClickedButtonUnpair();
	afx_msg void OnBnClickedButtonEnumPaired();
};
