mainwindow.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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. iSANClient = new SANClient();
  9. iSANReceive = new SANReceive();
  10. connect(iSANClient, SIGNAL(EmitClientConnected(bool)), this, SLOT(ClientConnected(bool)));
  11. connect(iSANReceive, SIGNAL(EmitClientAccepted(bool)), this, SLOT(ClientAccepted(bool)));
  12. connect(iSANReceive, SIGNAL(EmitServerStart(bool)), this, SLOT(ServerStart(bool)));
  13. connect(iSANClient, SIGNAL(EmitDataSent(char*)), this, SLOT(DataSent(char*)));
  14. connect(iSANReceive, SIGNAL(EmitDisplaySortedData(QString)), this, SLOT(DisplaySortedData(QString)));
  15. }
  16. MainWindow::~MainWindow()
  17. {
  18. delete ui;
  19. }
  20. void MainWindow::on_pushButton_pressed()
  21. {
  22. bool status;
  23. QString name = ui->lineEdit->text();
  24. std::string name_1 = name.toStdString();
  25. QString ip = ui->lineEdit_2->text();
  26. std::string ip_1 = ip.toStdString();
  27. QString port = ui->lineEdit_3->text();
  28. int port_1 = port.toInt();
  29. name_1 = "big.txt";
  30. //ip_1 = "127.0.0.1";
  31. ip_1 = "192.168.110.201";
  32. port_1 = 3600;
  33. //port_1 = 9993;
  34. iSANClient->SetDestnIp(ip_1);
  35. iSANClient->SetDestnPort(port_1);
  36. status = iSANClient->OpenFile(name_1);
  37. status = iSANClient->SetupConnection() && status;
  38. status = iSANClient->ConnectToServer() && status;
  39. if(status == true)
  40. {
  41. QMessageBox temp;
  42. int ret;
  43. temp.setText("Client connected");
  44. temp.setStandardButtons(QMessageBox::Ok);
  45. ret = temp.exec();
  46. switch(ret)
  47. {
  48. case QMessageBox::Ok:
  49. break;
  50. default:
  51. break;
  52. }
  53. ui->page->hide();
  54. ui->page_2->show();
  55. }
  56. else
  57. {
  58. QMessageBox temp;
  59. int ret;
  60. temp.setText("Client not connected");
  61. temp.setStandardButtons(QMessageBox::Ok);
  62. ret = temp.exec();
  63. switch(ret)
  64. {
  65. case QMessageBox::Ok:
  66. exit(0);
  67. break;
  68. default:
  69. break;
  70. }
  71. }
  72. }
  73. void MainWindow::on_pushButton_2_pressed()
  74. {
  75. if(iSANClient->isRunning() == true)
  76. iSANClient->quit();
  77. if(iSANReceive->isRunning() == true)
  78. iSANReceive->quit();
  79. delete iSANClient;
  80. delete iSANReceive;
  81. exit(0);
  82. }
  83. void MainWindow::on_pushButton_3_pressed()
  84. {
  85. if(iSANClient->isRunning() == true)
  86. iSANClient->quit();
  87. if(iSANReceive->isRunning() == true)
  88. iSANReceive->quit();
  89. delete iSANClient;
  90. delete iSANReceive;
  91. exit(0);
  92. }
  93. void MainWindow::on_pushButton_4_pressed()
  94. {
  95. if(ui->radioButton->isChecked() == true)
  96. {
  97. iSANClient->SetDistribution(KPoisson);
  98. }
  99. else if(ui->radioButton_2->isChecked() == true)
  100. {
  101. iSANClient->SetDistribution(KBinomial);
  102. }
  103. else
  104. iSANClient->SetDistribution(KUniform);
  105. QString rate = ui->lineEdit_4->text();
  106. double rate_1 = rate.toDouble();
  107. qDebug("rate : %f", rate_1);
  108. if(rate == 0)
  109. iSANClient->SetSendRate(1);
  110. else
  111. iSANClient->SetSendRate(rate_1);
  112. if(iSANClient->GetDistribution() != KPoisson)
  113. {
  114. double delay = (DATA_LEN )/(rate_1 * 1000000);
  115. qDebug("delay %f", delay);
  116. //in secs
  117. iSANClient->iUSleep = delay * 1000000;
  118. }
  119. qDebug("sleep time %d",iSANClient->iUSleep);
  120. qDebug("distribution is %d", iSANClient->GetDistribution());
  121. ui->page_2->hide();
  122. ui->page_4->show();
  123. }
  124. void MainWindow::on_pushButton_5_pressed()
  125. {
  126. if(iSANClient->isRunning() == true)
  127. {
  128. iSANClient->terminate();
  129. iSANClient->quit();
  130. }
  131. if(iSANReceive->isRunning() == true)
  132. {
  133. iSANReceive->terminate();
  134. iSANReceive->quit();
  135. }
  136. delete iSANClient;
  137. delete iSANReceive;
  138. exit(0);
  139. }
  140. void MainWindow::on_pushButton_6_pressed()
  141. {
  142. iSANClient->start();
  143. iSANReceive->start();
  144. }
  145. void MainWindow::ClientConnected(bool aStatus)
  146. {
  147. QMessageBox temp;
  148. int ret;
  149. if(aStatus == true)
  150. temp.setText("Client Connected");
  151. else
  152. temp.setText("Client not connected");
  153. temp.setStandardButtons(QMessageBox::Ok);
  154. ret = temp.exec();
  155. switch(ret)
  156. {
  157. case QMessageBox::Ok:
  158. ui->page->hide();
  159. ui->page_2->show();
  160. break;
  161. default:
  162. break;
  163. }
  164. }
  165. void MainWindow::on_pushButton_7_pressed()
  166. {
  167. if(iSANClient->isRunning() == true)
  168. iSANClient->terminate();
  169. if(iSANReceive->isRunning() == true)
  170. iSANReceive->terminate();
  171. long long count = iSANClient->GetCount();
  172. long long count_1 = iSANReceive->GetCount();
  173. QString num;
  174. num = QString::number(count);
  175. num.append(" packets sent! ");
  176. QString num_1;
  177. num_1 = QString::number(count_1);
  178. num_1.append(" packets received!");
  179. QString final = num + num_1;
  180. QByteArray w = final.toUtf8();
  181. char *t = w.data();
  182. qDebug("Result %s", t);
  183. qDebug("Totaldelay = %f", iSANClient->GetTotDelay());
  184. qDebug("Average delay = %f", iSANClient->GetTotDelay()/(double)count);
  185. }
  186. void MainWindow::on_pushButton_9_pressed()
  187. {
  188. if(iSANClient->isRunning() == true)
  189. iSANClient->quit();
  190. if(iSANReceive->isRunning() == true)
  191. iSANReceive->quit();
  192. delete iSANClient;
  193. delete iSANReceive;
  194. exit(0);
  195. }
  196. void MainWindow::on_pushButton_8_pressed()
  197. {
  198. QString port = ui->lineEdit_6->text();
  199. int port_1 = port.toInt();
  200. iSANReceive->SetPort(port_1);
  201. iSANReceive->start();
  202. }
  203. void MainWindow::ClientAccepted(bool aStatus)
  204. {
  205. QMessageBox temp;
  206. int ret;
  207. if(aStatus == true)
  208. temp.setText("Server accepted as client");
  209. else
  210. temp.setText("Server not accepted as client");
  211. temp.setStandardButtons(QMessageBox::Ok);
  212. ret = temp.exec();
  213. switch(ret)
  214. {
  215. case QMessageBox::Ok:
  216. break;
  217. default:
  218. break;
  219. }
  220. }
  221. void MainWindow::ServerStart(bool aStatus)
  222. {
  223. QMessageBox temp;
  224. int ret;
  225. if(aStatus == true)
  226. temp.setText("Server started at client");
  227. else
  228. temp.setText("Server not started at client");
  229. temp.setStandardButtons(QMessageBox::Ok);
  230. ret = temp.exec();
  231. switch(ret)
  232. {
  233. case QMessageBox::Ok:
  234. ui->page_4->hide();
  235. ui->page_3->show();
  236. break;
  237. default:
  238. break;
  239. }
  240. }
  241. void MainWindow::DataSent(char *aBuf)
  242. {
  243. QString temp(aBuf);
  244. ui->listWidget->addItem(temp);
  245. ui->listWidget->scrollToBottom();
  246. }
  247. void MainWindow::DisplaySortedData(QString temp)
  248. {
  249. ui->listWidget_2->addItem(temp);
  250. ui->listWidget_2->scrollToBottom();
  251. }