Commit fe1c00b3 authored by Johnny Jazeix's avatar Johnny Jazeix

Début des thread. Ca écrit dans la console pour le moment car il y a des

problemes avec Qt pour afficher des QObject dans le thread.
parent de59e9c8
#include "Progress_bar_thread.hpp"
void Progress_bar_thread::init(Parser *p, Interface_console *i){
_interface_console = i;
_parser = p;
}
void Progress_bar_thread::run() {
_file_size = _parser->get_total_size_of_file();
_interface_console->get_progress_dialog()->setRange(0, _file_size);
int loaded = 0;
while(1) {
//show_widget_avancement();
std::cout << loaded << " on " << _file_size << std::endl;
loaded += _parser->get_size_loaded();
msleep(500); // We wait 500 ms
emit _interface_console->get_progress_dialog()->setValue(1400);
std::cout << _interface_console->get_progress_dialog()->minimum() << " " << _interface_console->get_progress_dialog()->maximum() << " " << _interface_console->get_progress_dialog()->labelText().toStdString() << std::endl;
}
}
#ifndef PROGRESS_BAR_THREAD_HPP
#define PROGRESS_BAR_THREAD_HPP
#include <QThread>
#include "../parser/Parser.hpp"
#include "interface_console.hpp"
#include <iostream>
class Progress_bar_thread : public QThread {
Q_OBJECT
private:
Interface_console *_interface_console;
long _file_size;
Parser *_parser;
public:
void init(Parser *p,Interface_console *i);
protected:
void run();
};
#endif // PROGRESS_BAR_THREAD_HPP
......@@ -93,6 +93,8 @@ bool Interface_console::draw_trace(const string & filename, const int format){
Trace trace;
ParserPaje parser;
parser.set_file_to_parse(filename);
QApplication::setOverrideCursor(Qt::WaitCursor);
......@@ -103,17 +105,33 @@ bool Interface_console::draw_trace(const string & filename, const int format){
case _DRAW_OPENGL:
{
DrawTrace<Render_opengl> drawing_ogl;
// Init of the thread
Progress_bar_thread thread;
thread.init(&parser, this);
_progress_dialog = new QProgressDialog(_main_window);
_progress_dialog->setLabelText("Parsing");
_progress_dialog->show();
thread.start();
try{
parser.parse(filename, trace);
}
catch (const string &error){
thread.terminate();
_progress_dialog->hide();
*Message::get_instance() << "Reason : " << error << Message::ende;
QApplication::restoreOverrideCursor();
delete _progress_dialog;
return false;
}
_progress_dialog->hide();
thread.terminate();
delete _progress_dialog;
drawing_ogl.build(_render_opengl, &trace);
_render_opengl->build();
_render_opengl->build();
_render_opengl->updateGL();
}
......@@ -134,6 +152,7 @@ bool Interface_console::draw_trace(const string & filename, const int format){
}
catch (const string &error){
*Message::get_instance() << "Reason : " << error << Message::ende;
QApplication::restoreOverrideCursor();
return false;
}
......@@ -573,3 +592,6 @@ const QString* Interface_console::get_runenv() const{
return _run_env;
}
QProgressDialog *Interface_console::get_progress_dialog(){
return _progress_dialog;
}
......@@ -20,11 +20,11 @@ class Interface_console;
#include "../parser/ParserPaje.hpp"
#include "resource.hpp"
#include "Progress_bar_thread.hpp"
//#include <pthread.h>
/*!
*\brief This class is an terminal interface, it inherited from the Interface interface.
*/
......@@ -213,8 +213,12 @@ protected:
/*!
*\brief The parser thread.
*/
// pthread_t _thread_parser;
/*!
*\brief To show the avancement of parsing.
*/
QProgressDialog *_progress_dialog;
/*!
* \brief Return the state of ViTE according to the arguments.
......@@ -342,6 +346,12 @@ protected:
void selection_information(const std::string) const{
}
/*!
*\brief Return the progress dialog used during threads.
*/
QProgressDialog *get_progress_dialog();
};
......
......@@ -446,37 +446,5 @@
</hint>
</hints>
</connection>
<connection>
<sender>option_export_ok</sender>
<signal>clicked()</signal>
<receiver>time_selector</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel" >
<x>202</x>
<y>346</y>
</hint>
<hint type="destinationlabel" >
<x>202</x>
<y>390</y>
</hint>
</hints>
</connection>
<connection>
<sender>cancel</sender>
<signal>clicked()</signal>
<receiver>time_selector</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel" >
<x>124</x>
<y>352</y>
</hint>
<hint type="destinationlabel" >
<x>112</x>
<y>391</y>
</hint>
</hints>
</connection>
</connections>
</ui>
......@@ -20,7 +20,7 @@ Line::Line(const char *filename){
Line::~Line(){
if(!_tokens.empty()){
_tokens.clear();
}
}
}
void Line::open(const char *filename){
......@@ -44,7 +44,7 @@ bool Line::starts_with(const string &s) const{
return false;
}
bool Line::item (unsigned int i, string &e) const{
bool Line::item(unsigned int i, string &e) const{
if (i >= _tokens.size())
return false;
e = _tokens[i];
......
......@@ -2,6 +2,7 @@
#define PARSER_HPP
#include <string>
#include "../trace/Trace.hpp"
#ifndef VITE_DEBUG
#include "../message/Errors.hpp"
......@@ -25,6 +26,20 @@ public:
*/
virtual void parse(std::string filename, Trace &trace) = 0;
virtual ~Parser() {};
/*!
* \fn long get_size_loaded() = 0;
* \return the size already loaded of the file by the parser
*/
virtual long get_size_loaded() = 0;
/*!
* \fn get_total_size_of_file()
* \return the size of the file parsed
*/
virtual long get_total_size_of_file() = 0;
};
#endif // PARSER_HPP
......@@ -10,11 +10,10 @@ void ParserPaje::parse(string filename, Trace &trace){
if(position_of_dot == string::npos || filename.substr(position_of_dot) != ".trace"){
Error::set_and_print(Error::_BAD_FILE_EXTENSION, Error::_WARNING);
}
ParserDefinitionDecoder *parserdefinition = new ParserDefinitionDecoder();
ParserEventDecoder *parserevent = new ParserEventDecoder();
Line line(filename);
Line line(_file_to_parse);
static const string PERCENT = "%";
string event_identity_string;
......@@ -23,13 +22,13 @@ void ParserPaje::parse(string filename, Trace &trace){
while(!line.is_eof()) {
line.newline();
if(line.starts_with(PERCENT)){
if(line.starts_with(PERCENT)) {
parserdefinition->store_definition(line);
}
else if (!line.item(0, event_identity_string)){
continue; // We have \n
}
else{
else {
// We check if we have an event identifier
if(sscanf(event_identity_string.c_str(), "%d", &event_identity) != 1){
Error::set_and_print(Error::_EXPECT_ID_DEF, line.get_line_count(), Error::_ERROR);
......@@ -55,3 +54,22 @@ void ParserPaje::parse(string filename, Trace &trace){
delete parserdefinition;
delete parserevent;
}
void ParserPaje::set_file_to_parse(const string filename){
_file_to_parse = filename;
}
long ParserPaje::get_size_loaded(){
static long temporary_solution = 0;
return (++ temporary_solution);
}
long ParserPaje::get_total_size_of_file(){
struct stat buf;
if(stat(_file_to_parse.c_str(), &buf) == -1){
perror(_file_to_parse.c_str());
}
return buf.st_size; // In bytes / octets
}
......@@ -27,6 +27,8 @@
*
*/
class ParserPaje : public Parser{
private:
std::string _file_to_parse;
public:
/*!
......@@ -36,6 +38,19 @@ public:
*/
void parse(std::string filename, Trace &trace);
void set_file_to_parse(const std::string filename);
/*!
* \fn get_size_loaded()
* \return the size already loaded of the file by the parser
*/
long get_size_loaded();
/*!
* \fn get_total_size_of_file()
* \return the size of the file parsed
*/
long get_total_size_of_file();
};
#endif // PARSERPAJE_HPP
......
......@@ -21,6 +21,7 @@ HEADERS += message/Message.hpp \
interface/interface.hpp \
interface/interface_console.hpp \
interface/interface_graphic.hpp \
interface/Progress_bar_thread.hpp \
interface/resource.hpp \
# Render headers
render/render.hpp \
......@@ -68,6 +69,7 @@ SOURCES += message/Message.cpp \
# Interface code files
interface/interface_console.cpp \
interface/interface_graphic.cpp \
interface/Progress_bar_thread.cpp \
# Render code files
render/render_opengl.cpp \
render/render_svg.cpp \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment