//---------------------------------------------------------------------------
/*
Remote Train Control Program for Windows

© Copyright 2019 by Mark DiVecchio

    This file is part of Remote Train Control.

    Remote Train Control is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Remote Train Control is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Remote Train Control.  If not, see <http://www.gnu.org/licenses/>.

*/
// Home Page : http://www.silogic.com/trains/RTC_Running.html
//---------------------------------------------------------------------------
#ifndef PBFileThreadH
#define PBFileThreadH
//---------------------------------------------------------------------------
#include <Classes.hpp>

#include <time.h>

//---------------------------------------------------------------------------
#define CALLEDBYSETUP (-1)	// used by PBFileThread to indicate the thread was started by Setup
							// button numbers 1 to 100 are used to indicate that thread was started by Hot_Com

//---------------------------------------------------------------------------
class TPlaybackFileThread : public TThread
{
private:    
	TForm * CallingScreen; 	// this pointer must be local to each Thread
	String FileName;
	TStringList * PBBuffer;
	time_t CurrentTime_t, StartTime_t, EndTime_t, ThisTime_t;
	int index, RemoteNo, iButtonNo, iParameter;
	bool bPBThreadRunning;
	TMessagePopup * MessagePopup;   // TPlaybackFileThread
	bool RepeatPlayback;
    DWORD ThreadID;

   	__fastcall TPlaybackFileThread(bool CreateSuspended);

    void __fastcall ShowTime();

protected:
	void __fastcall Execute();
    void __fastcall PB();
    void __fastcall CleanUp();
    void __fastcall Initialize();
    void __fastcall RunOnTerminate(TObject * Sender);

public:
    __fastcall TPlaybackFileThread(bool CreateSuspended, TForm * Caller, HWND Parent, int Remote, String FileName,
    		int Button, int Parameter);
    __fastcall ~TPlaybackFileThread();
    HWND ParentHandle;	// accessed by Parent

    bool Finished;
};
//---------------------------------------------------------------------------
#endif
