** This is part of the CTSim program
** Copyright (C) 1983-2001 Kevin Rosenberg
**
-** $Id: backgroundsupr.h,v 1.5 2001/02/26 17:36:56 kevin Exp $
+** $Id: backgroundsupr.h,v 1.11 2001/03/09 21:31:51 kevin Exp $
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License (version 2) as
};
-// Pure virtual class for BackgroundSupervisor that can communication
-// with BackgroundManager via messages
+// Pure virtual class for BackgroundSupervisor that can communication with BackgroundManager via messages
class BackgroundWorkerThread;
+class BackgroundProcessingDocument;
class BackgroundSupervisor : public wxEvtHandler {
private:
DECLARE_DYNAMIC_CLASS(BackgroundSupervisor)
-
+
SupervisorThread* m_pMyThread;
wxFrame* m_pParentFrame;
- wxDocument* m_pDocument;
+ BackgroundProcessingDocument* m_pDocument;
const std::string m_strProcessTitle;
- wxProgressDialog* m_pDialogProgress;
-
+
+ const unsigned int m_iTotalUnits;
+ int m_iNumThreads;
+ volatile bool m_bDone;
volatile bool m_bFail;
std::string m_strFailMessage;
- int m_iNumThreads;
+ volatile bool m_bCancelled;
volatile int m_iRunning;
- unsigned int m_iUnitsDone;
- const unsigned int m_iTotalUnits;
- bool m_bCancelled;
- bool m_bDone;
+ volatile unsigned int m_iUnitsDone;
Timer* m_pTimer;
- bool m_bBackgroundTaskAdded;
- bool m_bWorkersDeleted;
+ volatile bool m_bWorkersDeleted;
+ volatile bool m_bBackgroundManagerAdded;
typedef std::vector<BackgroundWorkerThread*> ThreadContainer;
ThreadContainer m_vecpThreads;
wxCriticalSection m_critsectThreads;
-
public:
enum {
MSG_BACKGROUND_SUPERVISOR_ADD = 7500, // sends to BackgroundManager and Document
MSG_WORKER_THREAD_FAIL = 7507, // sent by workers when they fail
};
- BackgroundSupervisor (SupervisorThread* pMyThread, wxFrame* pParentFrame, wxDocument* pDocument, const char* const pszProcessTitle,
+ BackgroundSupervisor (SupervisorThread* pMyThread, wxFrame* pParentFrame, BackgroundProcessingDocument* pDocument, const char* const pszProcessTitle,
int iTotalUnits);
BackgroundSupervisor ()
- : m_iTotalUnits(0), wxEvtHandler()
+ : wxEvtHandler(), m_iTotalUnits(0)
{}
virtual ~BackgroundSupervisor();
bool start();
virtual void onDone() {};
- virtual void OnWorkerFail(wxCommandEvent& event);
- virtual void OnWorkerUnitTick(wxCommandEvent& event);
- virtual void OnWorkerDone(wxCommandEvent& event);
- virtual void OnCancel(wxCommandEvent& event);
- virtual void OnAckDocumentRemove(wxCommandEvent& event);
+ virtual void onCancel();
+
+ virtual void onWorkerFail(int iThread, std::string strFailMessage);
+ virtual void onWorkerUnitTick();
+ virtual void onWorkerDone(int iThread);
void deleteWorkers();
+ void ackRemoveBackgroundManager();
+ bool workersDone() const { return m_iRunning == 0; }
bool workersDeleted() const { return m_bWorkersDeleted; }
bool isDone() const {return m_bDone;}
void setDone() { m_bDone = true; }
bool fail() const {return m_bFail;}
const std::string& getFailMessage() const { return m_strFailMessage; }
+ bool cancelled() const {return m_bCancelled;}
int getNumWorkers() const { return m_iNumThreads; }
double getTimerEnd() { return m_pTimer->timerEnd(); }
- static void cancelSupervisor (BackgroundSupervisor* pSupervisor);
-
DECLARE_EVENT_TABLE()
};
class BackgroundWorkerThread : public wxThread {
protected:
BackgroundSupervisor* m_pSupervisor;
+ const int m_iThread;
const int m_iStartUnit;
const int m_iNumUnits;
- const int m_iThread;
public:
BackgroundWorkerThread (BackgroundSupervisor* pSupervisor, int iThread, int iStartUnit, int iNumUnits)
- : m_pSupervisor(pSupervisor), m_iThread(iThread), m_iStartUnit(iStartUnit), m_iNumUnits(iNumUnits),
- wxThread (wxTHREAD_DETACHED)
+ : wxThread (wxTHREAD_DETACHED), m_pSupervisor(pSupervisor), m_iThread(iThread), m_iStartUnit(iStartUnit), m_iNumUnits(iNumUnits)
{}
};