// Main -----------------------------------------------------------------
int main(int argc, char *argv[])
{
// creates class that contains packets and methods
CHostIFTools * hostifTools = new CHostIFTools();
// create threads to handle UDP recieves and tranmits
CHostIF hostifReceive( hostifTools );
// start independant threads
hostifReceive.start();
// create application class
CHostIF * hostif = new CHostIF( 0, hostifTools );
// display main widget
hostif->show();
// run application
app.exec();
// stop independant threads
hostifReceive.quit();
// wait for thread to finish
hostifReceive.wait();
// delay to ensure that threads are really terminated
printf("Waiting for thread to shutdown");
fflush(stdout);
for (int sleepIdx=0; sleepIdx<5; sleepIdx++)
{
printf("..");
fflush(stdout);
sleep (1);
}
printf("done!!\n");
fflush(stdout);
// need to remove the tools class
delete hostifTools;
return 0;
}
// Class definition ----------------------------------------------------------------------
class CHostIFReceive
: public QThread{
public:
// CHostIFReceive : class initialization method
CHostIFReceive( CHostIFTools * tools=0 );
// ~CHostIFReceive : class destrcutor method
~CHostIFReceive();
// run : local implementation of the QThread run method
void run();
// stop : used to set the stop variable
void quit();
protected:
// defines the tools class that is to be used
CHostIFTools * hostifTools;
// provides clean approch to terminting the thread
volatile bool stopThreads;
};
// Class code ----------------------------------------------------------------------------
CHostIFReceive::CHostIFReceive(CHostIFTools * tools)
{
// instantiate configuration tools class
hostifTools = tools;
// indicate thread is in a running state
stopThreads = false;
}
void CHostIFReceive::run()
{
// as long as thread has not been terminated
while ( ! stopThreads )
{
// update the system value
hostifTools->updateSystemInformation1();
// wait for a little while
sleep( 1 );
}
}
void CHostIFReceive::quit()
{
stopThreads = true;
}
Bookmarks