- #include "ring_qthread.h" 
- #include "ui_ring_qthread.h" 
-   
-   
-   
- //Global Variables 
- struct_buff_t in_buff[BUFF_SIZE+1], out_buff[BUFF_SIZE+1]; 
- int i_return = 0; 
- long int i_tot_count = 0; 
- long int i_out_count = 0; 
- bool b_inp = false; 
- bool b_out = false; 
- //i_tot_count=i_out_count=0; 
-   
-   
- /* 
-  * Start of Predefined Functions 
-  */ 
-   
- Ring_Qthread ::Ring_Qthread(QWidget *- parent ) :
-     ui(new Ui::Ring_Qthread) 
- { 
-     ui->setupUi(this); 
-     fn_create_conn(); 
-   
- } 
-   
-   
- Ring_Qthread::~Ring_Qthread() 
- { 
-     delete ui; 
- } 
-   
- void-  Ring_Qthread ::changeEvent(QEvent *- e )
 
- { 
-     switch (e->type()) 
-     { 
-         qDebug() << "omg"; 
-         ui->retranslateUi(this); 
-         break; 
-     default: 
-         break; 
-     } 
- } 
-   
- /* 
-  * End of Pre-defined Functions 
-  */ 
-   
-   
- /* 
-  * Event filter function for get call after mouse click on all buttons. 
-  */ 
-   
-   
- { 
-   
-     if(- _event -- >type () == QEvent::MouseButtonPress)// && ((QMouseEvent*)_event)->button() == Qt::LeftButton)
 
-     { 
-         qDebug() << "This is Event filter to help u\n"; 
-         if(_obj->objectName() == "btn_quit") 
-         { 
-             qDebug() << "btn_quit"; 
-             emit slot_quite_me(); 
-         } 
-         else if (_obj->objectName() == "btn_process") 
-         { 
-             qDebug() << "btn_process"; 
-             emit slot_start_process(); 
-         } 
-         else if (_obj->objectName() == "btn_load") 
-         { 
-             qDebug() << "btn_load"; 
-             emit slot_load_buffer(); 
-         } 
-         return true; 
-   
-     } 
-     else 
-         return false; 
- } 
-   
-   
- /* 
-  * Start of create connections Functions. 
-  */ 
- void Ring_Qthread::fn_create_conn() 
- { 
-   
-       //Use the below commented code if u r gonna use slot and signals 
-   
-     connect(ui->btn_load, SIGNAL(clicked()), this, SLOT(slot_load_buffer())); 
-     connect(ui->btn_process, SIGNAL(clicked()), this, SLOT(slot_start_process())); 
-     connect(ui->btn_quit, SIGNAL(clicked()), this, SLOT(slot_quite_me())); 
-   
-   /* 
-     ui->btn_process->installEventFilter(this); 
-     ui->btn_quit->installEventFilter(this); 
-     ui->btn_load->installEventFilter(this); 
-    */ 
- } 
-   
- /* 
-  * End of Create connections Functions 
-  */ 
-   
- /* 
-  * Start of Slot Functions. 
-  */ 
-   
- void Ring_Qthread::slot_load_buffer() 
- { 
-     for (int i=0; i<BUFF_SIZE; ++i) 
-     { 
-         in_buff[i].xval = rand() % 10; 
-         in_buff[i].yval = rand() % 10; 
-   
-         in_buff[i].xtime = rand() % 500; 
-         in_buff[i].ytime = rand() % 500; 
-     } 
-     in_buff[BUFF_SIZE].xval = -1; 
-     in_buff[BUFF_SIZE].yval = -1; 
-   
-     in_buff[BUFF_SIZE].xtime = -1; 
-     in_buff[BUFF_SIZE].ytime = -1; 
-   
-             in_file  = new QFile("input_buffer.txt")- ; 
-         qDebug() << "Error in open the input Buffer file"; 
-     for (int j=0;j<=BUFF_SIZE;j++) 
-     { 
-         stream_in << in_buff[j].xval << " " << in_buff[j].yval << " " << in_buff[j].xtime << " " << in_buff[j].ytime << "\n"; 
-   
-     } 
-   
- } 
-   
- void Ring_Qthread::slot_start_process() 
- { 
-   
-     Writer writer1; 
-     Reader reader1; 
-   
-     writer1.start(); 
-     reader1.start(); 
-   
-     writer1.wait(); 
-     reader1.wait(); 
-   
-     return (void)NULL; 
-   
-   
-   
- } 
-   
- void Ring_Qthread::slot_quite_me() 
- { 
-     exit(0); 
- } 
-   
- /////////////////////////////////////////////////////////////// 
- /* 
-  * Start of Class Writer Functions. 
-  */ 
-   
- { 
-     //Code if u want. 
- } 
-   
- void Writer::run() 
- { 
-     //i_return = 3; 
-     for (int j=0; j<=BUFF_SIZE; j++) 
-     { 
-         qDebug() << in_buff[j].xval << " " << in_buff[j].yval << " " << in_buff[j].xtime << " " << in_buff[j].ytime << "\n"; 
-     } 
-   
-     forever 
-     { 
-         mut_check.lock(); 
-         if (i_return !=4) 
-         { 
-         i_return = fn_process(1, &in_buff[i_tot_count].xval, &in_buff[i_tot_count].yval, &in_buff[i_tot_count].xtime, &in_buff[i_tot_count].ytime); 
-         if (i_return == 4) 
-         { 
-             cond_check.wait(&mut_check); 
-         } 
-         else if (i_return == 2) 
-         { 
-             //qDebug() << "Writer \n"; 
-   
-             i_tot_count++; 
-             //cond_check.wait(&mut_check); 
-         } 
-         if(in_buff[i_tot_count-1].xval == -1) 
-             b_inp = true; 
-     } 
-         mut_check.unlock(); 
-   
-         if (b_inp && b_out) 
-             return (void) NULL; 
-     } 
-   
- } 
-   
- /* 
-  * End of Class Writer Functions. 
-  */ 
-   
-   
-   
- /////////////////////////////////////////////////////////////// 
- /* 
-  * Start of Reader Class Functions 
-  */ 
-   
- { 
-     //Code if u want 
- } 
-   
- void Reader::run() 
- { 
-     forever 
-     { 
-         mut_check.lock(); 
-      if(i_return !=1) 
-      { 
-         i_return = fn_process(2, &out_buff[i_out_count].xval, &out_buff[i_out_count].yval, &out_buff[i_out_count].xtime, &out_buff[i_out_count].ytime); 
-   
-         if(i_return == 3) 
-         { 
-             //qDebug() << "reader\n"; 
-   
-             i_out_count++; 
-             //cond_check.wakeOne(); 
-         } 
-         else if (i_return == 1) 
-         { 
-             qDebug() << "go man go\n"; 
-             cond_check.wakeOne(); 
-         } 
-         if (out_buff[i_out_count-1].xval == -1) 
-             b_out = true; 
-     } 
-         mut_check.unlock(); 
-   
-         if (b_inp && b_out) 
-         { 
-             qDebug() << "\nOutPut man.\n"; 
-             for (int j=0; j<=BUFF_SIZE; j++) 
-             { 
-                 qDebug() << out_buff[j].xval << " " << out_buff[j].yval << " " << out_buff[j].xtime << " " << out_buff[j].ytime << "\n"; 
-             } 
-             return (void)NULL; 
-         } 
-     } 
- } 
-   
- /* 
-  * End of Reader Class functions. 
-  */ 
-   
- /////////////////////////////////////////////////////////////// 
Bookmarks