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

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

#define SHORT_DATA_LEN     5
#define LONG_DATA_LEN      1024

//---------------------------------------------------------------------------
class TfmMain : public TForm
{
__published:	// IDE-managed Components
        TwclGattServer *wclGattServer;
        TwclBluetoothManager *wclBluetoothManager;
        TButton *btStart;
        TButton *btStop;
        TListBox *lbLog;
        void __fastcall wclBluetoothManagerAfterOpen(TObject *Sender);
        void __fastcall wclBluetoothManagerBeforeClose(TObject *Sender);
        void __fastcall wclGattServerStarted(TObject *Sender);
        void __fastcall wclGattServerStopped(TObject *Sender);
        void __fastcall btStartClick(TObject *Sender);
        void __fastcall btStopClick(TObject *Sender);
        void __fastcall FormDestroy(TObject *Sender);
        void __fastcall wclGattServerSubscribed(TObject *Sender,
          const TwclGattServerClient *Client,
          const TwclGattLocalCharacteristic *Characteristic);
        void __fastcall wclGattServerUnsubscribed(TObject *Sender,
          const TwclGattServerClient *Client,
          const TwclGattLocalCharacteristic *Characteristic);
        void __fastcall wclGattServerClientConnected(TObject *Sender,
          const TwclGattServerClient *Client);
        void __fastcall wclGattServerClientDisconnected(TObject *Sender,
          const TwclGattServerClient *Client);
        void __fastcall wclGattServerNotificationSizeChanged(
          TObject *Sender, const TwclGattServerClient *Client);
        void __fastcall wclGattServerMaxPduSizeChanged(TObject *Sender,
          const TwclGattServerClient *Client);
        void __fastcall wclGattServerRead(TObject *Sender,
          const TwclGattServerClient *Client,
          const TwclGattLocalCharacteristic *Characteristic,
          const TwclGattLocalCharacteristicReadRequest *Request);
        void __fastcall wclGattServerWrite(TObject *Sender,
          const TwclGattServerClient *Client,
          const TwclGattLocalCharacteristic *Characteristic,
          const TwclGattLocalCharacteristicWriteRequest *Request);
        void __fastcall FormCreate(TObject *Sender);
        void __fastcall wclGattServerConnectionParamsChanged(
          TObject *Sender, const TwclGattServerClient *Client);
        void __fastcall wclGattServerConnectionPhyChanged(TObject *Sender,
          const TwclGattServerClient *Client);
private:	// User declarations
        DWORD FCounter;
        bool FStarted;

        BYTE FLongData[LONG_DATA_LEN];
        BYTE FShortData[SHORT_DATA_LEN];
        
        bool InitBluetooth(TwclBluetoothRadio*& Radio);
        void UninitBluetooth();
        bool InitServer(TwclBluetoothRadio* Radio);
        void UninitServer();
        bool AddCharacteristics(TwclGattLocalService* Service);
        bool AddServices();
        void Start();
        void Stop();

        void GetConParams(const TwclGattServerClient* Client);
        void GetConPhy(const TwclGattServerClient* Client);

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