inputFile.cpp
1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <stdio.h>
#include <list>
#include <stdlib.h>
#include "inputFile.h"
#include "ouvinteInput.h"
InputFile::InputFile(char* path) {
this->path = path;
this->ouvintes = new list<OuvinteInput*>();
finished = false;
}
InputFile::~InputFile(){
if (ouvintes) {
ouvintes->clear();
delete ouvintes;
}
}
void InputFile::initialize(){
printf("InputFile::initialize()\n");
ifstream filein(path, ifstream::binary);
if (filein.is_open()) {
char buffer [MAX_SIZE_PACKET];
while (!filein.eof()) {
filein.read(buffer, MAX_SIZE_PACKET);
unsigned char* packet = (unsigned char*) buffer;
notificaOuvintes(packet);
}
filein.close();
finished = true;
} else {
finished = true;
printf("\n# Erro! verifique se existe algum problema com o arquivo: %s\n\n", path);
}
}
bool InputFile::isFinished(){
return this->finished;
}
void InputFile::registraOuvinte(OuvinteInput* ouvinte){
this->ouvintes->push_back(ouvinte);
}
void InputFile::removeOuvinte(OuvinteInput* ouvinte) {
this->ouvintes->remove(ouvinte);
}
void InputFile::notificaOuvintes(unsigned char* pacote){
//printf("InputFile::notificaOuvintes");
for(list<OuvinteInput*>::iterator it = this->ouvintes->begin(); it != this->ouvintes->end(); it++){
(*it)->chegouInput(pacote);
}
}
/*void InputFile::notificaQuantidadeGlosas(int quantidade){
//printf("InputFile::notificaOuvintes");
for(list<OuvinteInput*>::iterator it = this->ouvintes->begin(); it != this->ouvintes->end(); it++){
(*it)->finalizouInput();
}
}*/