Commit e009fab11c973a4c5e32cf73a9e94a9e1815ecb6
1 parent
bac43399
Exists in
devel
fix socket connection issues
Showing
3 changed files
with
34 additions
and
36 deletions
Show diff stats
extrator/src/extratorTXT.cpp
... | ... | @@ -10,6 +10,7 @@ |
10 | 10 | **************************************************************************/ |
11 | 11 | |
12 | 12 | #include "extratorTXT.h" |
13 | +#include <iostream> | |
13 | 14 | |
14 | 15 | ExtratorTXT::ExtratorTXT(){ |
15 | 16 | listeners = new list<ListenerTXT*>(); |
... | ... | @@ -61,15 +62,14 @@ void ExtratorTXT::setFilePath(char* path){ |
61 | 62 | } |
62 | 63 | |
63 | 64 | void ExtratorTXT::initialize(){ |
64 | - file = new lavidlib::File(filePath); | |
65 | - try{ | |
66 | - file_io = new lavidlib::FileIO(file->getPath(), FileIO::MODE_READ); | |
67 | - bff_reader = new BufferedReader(file_io); | |
68 | - }catch(Exception &ex){ | |
65 | + ifs_.open(this->filePath, std::ifstream::in); | |
66 | + | |
67 | + if(!(ifs_.is_open() && ifs_.good())) { | |
69 | 68 | finish = true; |
70 | 69 | Logging::instance()->writeLog("extratorTXT.cpp <Error>: Arquivo de texto não encontrado."); |
71 | 70 | throw ExtratorException("Falha ao abrir o arquivo de texto! Verifique se o mesmo existe."); |
72 | 71 | } |
72 | + | |
73 | 73 | this->Start(); |
74 | 74 | } |
75 | 75 | |
... | ... | @@ -79,26 +79,19 @@ bool ExtratorTXT::isFinished(){ |
79 | 79 | |
80 | 80 | void ExtratorTXT::Run(){ |
81 | 81 | PRINTL(util::_INFO, "Extraindo Texto...\n"); |
82 | - int line_index = 0; | |
83 | - bool hasNext = true; | |
84 | - string line; | |
85 | - | |
86 | - while (hasNext) { | |
87 | - try{ | |
88 | - line = bff_reader->readLine(); | |
89 | - if (line.length() > 0){ | |
90 | - notifyListeners((unsigned char*) line.c_str()); | |
82 | + | |
83 | + int line_index = 0; | |
84 | + string current_line; | |
85 | + | |
86 | + while (ifs_.good()) { | |
87 | + getline(ifs_, current_line, '\n'); | |
88 | + | |
89 | + if (current_line.length() != 0) { | |
90 | + notifyListeners((unsigned char*) current_line.c_str()); | |
91 | 91 | line_index++; |
92 | 92 | } |
93 | - }catch (EOFException &ex){ | |
94 | - if(line_index == 0) | |
95 | - notifyListeners((unsigned char*)"ARQUIVO_INVALIDO"); | |
96 | - hasNext = false; | |
97 | - }catch (...){ | |
98 | - Logging::instance()->writeLog("extratorTXT.cpp <Error>: Erro durante a leitura do arquivo de texto."); | |
99 | - throw ExtratorException("Falha desconhecida na leitura do arquivo. Tente novamente."); | |
100 | - } | |
101 | 93 | } |
94 | + | |
102 | 95 | finish = true; |
103 | 96 | notifyEndExtraction(line_index); |
104 | 97 | } | ... | ... |
extrator/src/include/extratorTXT.h
... | ... | @@ -14,6 +14,8 @@ |
14 | 14 | #include "listenerTXT.h" |
15 | 15 | #include "extratorException.h" |
16 | 16 | |
17 | +#include <fstream> | |
18 | + | |
17 | 19 | using namespace jthread; |
18 | 20 | using namespace std; |
19 | 21 | |
... | ... | @@ -73,8 +75,10 @@ public: |
73 | 75 | void Run(); |
74 | 76 | |
75 | 77 | private: |
76 | - list<ListenerTXT*> *listeners; | |
77 | - void encodingfiletoUTF8(); | |
78 | + void encodingfiletoUTF8(); | |
79 | + | |
80 | + list<ListenerTXT*> *listeners; | |
81 | + ifstream ifs_; | |
78 | 82 | }; |
79 | 83 | |
80 | 84 | #endif /* EXTRATORTXT_H */ | ... | ... |
renderer/src/renderer.cpp
1 | 1 | #include "renderer.h" |
2 | +#include <iostream> | |
2 | 3 | |
3 | 4 | Renderer::Renderer(char* path_Contents, char* id) { |
4 | 5 | this->pathOutVideo = path_Contents; |
... | ... | @@ -94,33 +95,32 @@ void Renderer::exportGlosa() { |
94 | 95 | if(glosaQueue.empty()) |
95 | 96 | throw lavidlib::RuntimeException("Fila de glosas vazia!"); |
96 | 97 | |
97 | - int glosaSize; | |
98 | 98 | char* glosaBff; |
99 | 99 | |
100 | 100 | string glosaCpy = glosaQueue.front(); //Pega quem estiver na frente da fila |
101 | - glosaSize = strlen(glosaCpy.c_str())+1; | |
102 | - glosaBff = new char[glosaSize]; | |
101 | + int size = glosaCpy.length() + 1; | |
102 | + glosaBff = new char[size]; | |
103 | 103 | strcpy(glosaBff, glosaCpy.c_str()); |
104 | - | |
105 | 104 | try { |
106 | - cSocket->write(glosaBff, glosaSize); //Envia a glosa formatada p/ o player | |
105 | + cSocket->write(glosaBff, size); //Envia a glosa formatada p/ o player | |
106 | + usleep(1500); | |
107 | 107 | }catch(lavidlib::IOException &ex){ |
108 | - throw lavidlib::RuntimeException(ex.getMessage().c_str()); | |
108 | + throw lavidlib::RuntimeException("Erro ao enviar glosa"); | |
109 | 109 | } |
110 | 110 | |
111 | - char* received = new char[3]; //Mensagem de confirmação de recebimento da glosa: "OK[3]; //Mensagem de confirmação de recebimento da glosa: "OK\0"" | |
111 | + static char received[3]; //Mensagem de confirmação de recebimento da glosa: "OK[3]; //Mensagem de confirmação de recebimento da glosa: "OK\0"" | |
112 | 112 | do { |
113 | 113 | try { |
114 | - cSocket->read(received, 3); //Aguarda a confirmação | |
115 | - }catch(lavidlib::IOException &ex){ | |
116 | - throw lavidlib::RuntimeException(ex.getMessage().c_str()); | |
114 | + cSocket->receive(received, 3); //Aguarda a confirmação | |
115 | + }catch(lavidlib::Exception &ex){ | |
116 | + throw lavidlib::RuntimeException("Não foram recebidas respostas do player"); | |
117 | 117 | } |
118 | 118 | }while(strcmp(received, OK_FLAG) != 0); //Verifica se é a confirmação correta |
119 | 119 | |
120 | 120 | glosaQueue.pop(); //Se o envio foi bem sucedido, remove a glosa da fila |
121 | 121 | |
122 | 122 | delete [] glosaBff; |
123 | - delete [] received; | |
123 | + // delete [] received; | |
124 | 124 | } |
125 | 125 | |
126 | 126 | void Renderer::waitScreenShots() { |
... | ... | @@ -154,10 +154,11 @@ void Renderer::initialize() { |
154 | 154 | executeServerScript(); |
155 | 155 | try{ |
156 | 156 | connectToUnityPlayer(); |
157 | + this->Start(); | |
157 | 158 | }catch(lavidlib::RuntimeException &ex){ |
158 | 159 | throw lavidlib::RuntimeException(ex.getMessage().c_str()); |
159 | 160 | } |
160 | - this->Start(); | |
161 | + | |
161 | 162 | } |
162 | 163 | |
163 | 164 | void Renderer::Run() { | ... | ... |