serviceWindowGenerationFromText.cpp 1.46 KB
#include "serviceWindowGenerationFromText.h"

ServiceWindowGenerationFromText::ServiceWindowGenerationFromText (
		char* path_file, char* username, int transp, int serviceType, char* client_type) {

    extrator_factory = new ExtratorFactory();
	setPathInput(path_file);
	setClientType(client_type);
	setUserId(username);
    setTransparency(transp);
    setServiceType(serviceType);
	finish = false;
    DPRINTF("Done!\n");
}

ServiceWindowGenerationFromText::~ServiceWindowGenerationFromText() {
	delete extratorTXT;
	DDDPRINTF("Service Text finished!\n");
}

void ServiceWindowGenerationFromText::notifyLine(unsigned char* line) {
    tradutor->traduz(line);
}

void ServiceWindowGenerationFromText::notifyEnd(int line_size) {
    DDPRINTF("Service TXT recebeu: %d linhas.\n", line_size);
    setSizeOfSubtitles(line_size);
}

bool ServiceWindowGenerationFromText::isFinished() {
    return finish;
}

void ServiceWindowGenerationFromText::initialize() {
	DDPRINTF("Service Text Initialize.\n");

    extratorTXT = (ExtratorTXT*) extrator_factory->getExtrator(TXT);	    
    extratorTXT->addListener(this);
    extratorTXT->setFilePath(getPathInput());
    
    ServiceWindowGeneration::initialize();

    try{
  	    extratorTXT->initialize();            
    }catch(ExtratorException ex){
        throw ServiceException(ex.getMessage());
    }
    this->Start();
}

void ServiceWindowGenerationFromText::Run() {	
	while (isRunning()) {	  
	    usleep(200000); //200ms
	}	
	finish = true;
}