mainwindow.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. MainWindow::MainWindow(QWidget *parent) :
  4. QMainWindow(parent),
  5. ui(new Ui::MainWindow)
  6. {
  7. ui->setupUi(this);
  8. ui->listWidget->setAutoScroll(true);
  9. iSANServer = new SANServer();
  10. iSANSorter = new SANSorting(iSANServer);
  11. connect(iSANServer, SIGNAL(EmitClientAccepted(bool)), this, SLOT(ClientAccepted(bool)));
  12. connect(iSANServer, SIGNAL(EmitServerConnected(bool)), this, SLOT(NotifyServerConnected(bool)));
  13. connect(iSANServer, SIGNAL(EmitDataReceived(QString)), this, SLOT(DisplayRecdData(QString)));
  14. //connect(iSANServer, SIGNAL(EmitSortData()), iSANSorter, SLOT(SortAndSend()));
  15. connect(iSANSorter, SIGNAL(EmitServerToClient(bool)), this, SLOT(ServerToClient(bool)));
  16. connect(iSANSorter, SIGNAL(EmitDisplaySortedData(char*)), this, SLOT(DisplaySortedData(char*)));
  17. }
  18. MainWindow::~MainWindow()
  19. {
  20. delete ui;
  21. }
  22. void MainWindow::on_pushButton_pressed()
  23. {
  24. if(iSANServer->isRunning() == true)
  25. iSANServer->quit();
  26. if(iSANSorter->isRunning() == true)
  27. iSANSorter->quit();
  28. delete iSANServer;
  29. delete iSANSorter;
  30. exit(0);
  31. }
  32. void MainWindow::on_pushButton_2_pressed()
  33. {
  34. QString port = ui->lineEdit->text();
  35. int port_1 = port.toInt();
  36. port_1 = 9993;
  37. QString num = ui->lineEdit_2->text();
  38. int num_1 = num.toInt();
  39. iSANServer->SetServerPort(port_1);
  40. iSANServer->SetMaxClients(num_1);
  41. iSANServer->start();
  42. }
  43. void MainWindow::NotifyServerConnected(bool aStatus)
  44. {
  45. QMessageBox temp;
  46. QString str("Awaiting Client connections!");
  47. if(aStatus == true)
  48. temp.setText("Server Started Successfully!");
  49. else
  50. temp.setText("Server Start Uncessful");
  51. temp.setStandardButtons(QMessageBox::Ok);
  52. int ret = temp.exec();
  53. switch(ret)
  54. {
  55. case QMessageBox::Ok:
  56. ui->page->hide();
  57. ui->page_4->show();
  58. ui->listWidget_2->addItem(str);
  59. ui->listWidget_2->scrollToBottom();
  60. break;
  61. default:
  62. break;
  63. }
  64. if(aStatus == false)
  65. {
  66. if(iSANServer->isRunning() == true)
  67. iSANServer->quit();
  68. if(iSANSorter->isRunning() == true)
  69. iSANSorter->quit();
  70. delete iSANServer;
  71. delete iSANSorter;
  72. exit(0);
  73. }
  74. }
  75. void MainWindow::ClientAccepted(bool aStatus)
  76. {
  77. QMessageBox temp;
  78. QString str;
  79. if(aStatus == true)
  80. str = "Client Connected!";
  81. else
  82. str = "Client Not connected";
  83. temp.setText(str);
  84. temp.setStandardButtons(QMessageBox::Ok);
  85. int ret = temp.exec();
  86. switch(ret)
  87. {
  88. case QMessageBox::Ok:
  89. ui->listWidget->addItem(str);
  90. ui->listWidget->scrollToBottom();
  91. ui->page_4->hide();
  92. ui->page_3->show();
  93. break;
  94. default:
  95. break;
  96. }
  97. }
  98. void MainWindow::DisplayRecdData(QString aBuf)
  99. {
  100. ui->listWidget->addItem(aBuf);
  101. ui->listWidget->scrollToBottom();
  102. }
  103. void MainWindow::on_pushButton_3_pressed()
  104. {
  105. QString num = QString::number(iSANServer->GetDroppedCount());
  106. num.append(" packets dropped! ");
  107. QString num_1 = QString::number((iSANServer->GetCount()));
  108. num_1.append(" packets received! ");
  109. QString num_2 = QString::number(iSANSorter->GetCount());
  110. num_2.append(" packets sorted! ");
  111. QString final = num + num_1 + num_2;
  112. QMessageBox temp;
  113. temp.setText(final);
  114. temp.setStandardButtons(QMessageBox::Ok);
  115. int ret = temp.exec();
  116. switch(ret)
  117. {
  118. case QMessageBox::Ok:
  119. if(iSANServer->isRunning() == true)
  120. iSANServer->quit();
  121. if(iSANSorter->isRunning() == true)
  122. iSANSorter->quit();
  123. delete iSANServer;
  124. delete iSANSorter;
  125. exit(0);
  126. break;
  127. default:
  128. break;
  129. }
  130. }
  131. void MainWindow::on_pushButton_5_pressed()
  132. {
  133. if(iSANServer->isRunning() == true)
  134. iSANServer->quit();
  135. if(iSANSorter->isRunning() == true)
  136. iSANSorter->quit();
  137. delete iSANServer;
  138. delete iSANSorter;
  139. exit(0);
  140. }
  141. void MainWindow::on_pushButton_4_pressed()
  142. {
  143. QString addr = ui->lineEdit_3->text();
  144. QString port = ui->lineEdit_4->text();
  145. int port_1 = port.toInt();
  146. std::string addr_1 = addr.toStdString();
  147. //addr_1 = "192.168.110.201";
  148. addr_1 = "127.0.0.1";
  149. iSANSorter->SetPort(port_1);
  150. iSANSorter->SetIp(addr_1);
  151. iSANSorter->ConnectSortingThread();
  152. }
  153. void MainWindow::ServerToClient(bool aStatus)
  154. {
  155. QMessageBox temp;
  156. if(aStatus == true)
  157. {
  158. temp.setText("Server Connected to Client");
  159. iSANSorter->start();
  160. }
  161. else
  162. temp.setText("Server Not connected to Client");
  163. temp.setStandardButtons(QMessageBox::Ok);
  164. int ret = temp.exec();
  165. switch(ret)
  166. {
  167. case QMessageBox::Ok:
  168. ui->page_3->hide();
  169. ui->page_2->show();
  170. break;
  171. default:
  172. break;
  173. }
  174. }
  175. void MainWindow::DisplaySortedData(char *aBuf)
  176. {
  177. QString temp(aBuf);
  178. ui->listWidget_3->addItem(temp);
  179. ui->listWidget_3->scrollToBottom();
  180. }