//---------------------------------------------------------------------------

#ifndef mainH
#define mainH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include "wclBluetooth.hpp"
#include <ComCtrls.hpp>

//---------------------------------------------------------------------------
class TfmMain : public TForm
{
__published:	// IDE-managed Components
        TButton *btStart;
        TButton *btStop;
        TButton *btClear;
        TwclBluetoothManager *wclBluetoothManager;
        TwclGattServer *wclGattServer;
        TListView *lvDevices;
        TLabel *laData;
        TEdit *edData;
        TButton *btNotify;
        TButton *btNotifyAll;
        TLabel *laRepeats;
        TEdit *edRepeats;
        TButton *btDisconnect;
        TButton *btSetParameters;
        TListBox *lbLog;
        TComboBox *cbParams;
        void __fastcall btClearClick(TObject *Sender);
        void __fastcall FormCreate(TObject *Sender);
        void __fastcall wclBluetoothManagerAfterOpen(TObject *Sender);
        void __fastcall wclBluetoothManagerBeforeClose(TObject *Sender);
        void __fastcall wclBluetoothManagerClosed(TObject *Sender);
        void __fastcall wclGattServerStarted(TObject *Sender);
        void __fastcall wclGattServerStopped(TObject *Sender);
        void __fastcall FormDestroy(TObject *Sender);
        void __fastcall btStartClick(TObject *Sender);
        void __fastcall btStopClick(TObject *Sender);
        void __fastcall wclGattServerClientConnected(TObject *Sender,
          const TwclGattServerClient *Client);
        void __fastcall wclGattServerMaxPduSizeChanged(TObject *Sender,
          const TwclGattServerClient *Client);
        void __fastcall wclGattServerConnectionParamsChanged(
          TObject *Sender, const TwclGattServerClient *Client);
        void __fastcall wclGattServerConnectionPhyChanged(TObject *Sender,
          const TwclGattServerClient *Client);
        void __fastcall wclGattServerNotificationSizeChanged(
          TObject *Sender, const TwclGattServerClient *Client);
        void __fastcall wclGattServerClientDisconnected(TObject *Sender,
          const TwclGattServerClient *Client);
        void __fastcall lvDevicesSelectItem(TObject *Sender,
          TListItem *Item, bool Selected);
        void __fastcall btDisconnectClick(TObject *Sender);
        void __fastcall wclGattServerWrite(TObject *Sender,
          const TwclGattServerClient *Client,
          const TwclGattLocalCharacteristic *Characteristic,
          const TwclGattLocalCharacteristicWriteRequest *Request);
        void __fastcall edDataKeyPress(TObject *Sender, char &Key);
        void __fastcall wclGattServerSubscribed(TObject *Sender,
          const TwclGattServerClient *Client,
          const TwclGattLocalCharacteristic *Characteristic);
        void __fastcall wclGattServerUnsubscribed(TObject *Sender,
          const TwclGattServerClient *Client,
          const TwclGattLocalCharacteristic *Characteristic);
        void __fastcall wclGattServerRead(TObject *Sender,
          const TwclGattServerClient *Client,
          const TwclGattLocalCharacteristic *Characteristic,
          const TwclGattLocalCharacteristicReadRequest *Request);
        void __fastcall btNotifyAllClick(TObject *Sender);
        void __fastcall btNotifyClick(TObject *Sender);
        void __fastcall edRepeatsKeyPress(TObject *Sender, char &Key);
        void __fastcall btSetParametersClick(TObject *Sender);
private:	// User declarations
        void __fastcall Trace(const String& Msg);
        void __fastcall Trace(const Byte Spaces, const String& Msg);
        void __fastcall Trace(const String& Msg, const int Error);
        void __fastcall Trace(const Byte Spaces, const String& Msg,
                const int Error);

        bool __fastcall InitializeBluetooth(TwclBluetoothRadio*& Radio);
        void __fastcall UninitializeBluetooth();

        bool __fastcall InitializeServer(TwclBluetoothRadio* const Radio);
        void __fastcall UninitializeServer();

        bool __fastcall AddCharacteristics(TwclGattLocalService* const Service);
        TwclGattLocalService* __fastcall AddService();

        void __fastcall Start();
        void __fastcall Stop();

        TListItem* __fastcall FindItem(
                TwclGattServerClient* const Client);

        void __fastcall UpdateMaxPduSize(
                TwclGattServerClient* const Client);
        void __fastcall UpdateConnectionParams(
                TwclGattServerClient* const Client);
        void __fastcall UpdatePhy(TwclGattServerClient* const Client);
        void __fastcall UpdateNotificationSize(
                TwclGattServerClient* const Client);

        void __fastcall UpdateNotifyAllStatus();

        void __fastcall Notify(const __int64 Address);

public:		// User declarations
        __fastcall TfmMain(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TfmMain *fmMain;
//---------------------------------------------------------------------------
#endif
