diff --git a/Makefile b/Makefile index 66fbd8f..76f7044 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,7 @@ INCLUDES= \ utilObjs= \ argParser.o \ + logging.o \ logger.o tradutorObjs = \ diff --git a/extrator/src/extratorFactory.cpp b/extrator/src/extratorFactory.cpp index b78f068..298ba4b 100644 --- a/extrator/src/extratorFactory.cpp +++ b/extrator/src/extratorFactory.cpp @@ -1,13 +1,5 @@ #include "extratorFactory.h" -ExtratorFactory::ExtratorFactory(){ - //TODO -} - -ExtratorFactory::~ExtratorFactory(){ - //TODO -} - Extrator* ExtratorFactory::getExtrator(Extrator::ExtratorType extrator_type) { extrator = extrator_type; switch(extrator){ diff --git a/extrator/src/extratorSRT.cpp b/extrator/src/extratorSRT.cpp index 0a9a2e2..34529cf 100644 --- a/extrator/src/extratorSRT.cpp +++ b/extrator/src/extratorSRT.cpp @@ -5,7 +5,7 @@ ExtratorSRT::ExtratorSRT(){ finish = false; seek_pos = 0; hasNextSub = true; - DPRINTF("Done!\n"); + printl(util::_DEBUG, "Done!\n"); } ExtratorSRT::~ExtratorSRT(){ @@ -13,7 +13,7 @@ ExtratorSRT::~ExtratorSRT(){ delete listeners; //if (bff_reader) delete bff_reader; if (file_io) delete file_io; - DDDPRINTF("ExtratorSTR finalized!\n"); + printl(util::_DEBUG, "ExtratorSTR finalized!\n"); } void ExtratorSRT::initialize(){ @@ -24,7 +24,7 @@ void ExtratorSRT::initialize(){ file_io = new lavidlib::FileIO(file->getPath(), FileIO::MODE_READ); }catch(Exception ex){ finish = true; - Util::Logger::Instance()->writeLog((char*) "[ERRO: extratorSRT.cpp] Arquivo de legenda não encontrado."); + Logging::instance()->writeLog("extratorSRT.cpp : Arquivo de legenda não encontrado."); throw ExtratorException("Falha ao abrir o arquivo de legenda! Verifique se o mesmo existe.\n"); } @@ -43,7 +43,7 @@ void ExtratorSRT::notifyListeners(unsigned char* subtitle, int64_t pts) { } void ExtratorSRT::notifyEndExtraction(int size) { - DPRINTF("Extrator SRT concluiu a extração: %d legendas.\n", size); + printl(util::_DEBUG, "Extrator SRT concluiu a extração: %d legendas.\n", size); for(list::iterator it = listeners->begin(); it != listeners->end(); it++){ (*it)->notifyEnd(size); } @@ -72,11 +72,9 @@ bool ExtratorSRT::hasNextSubtitle() { } void ExtratorSRT::Run(){ - DPRINTF("[AGUARDE] Extraindo Legendas...\n"); - + printl(util::_INFO, "Extraindo Legendas...\n"); int sub_index = 0; string sub_text = ""; - while(hasNextSubtitle()){ try{ subtitle = next(); @@ -94,14 +92,17 @@ void ExtratorSRT::Run(){ Subtitle* ExtratorSRT::next() { - if (seek_pos >= file_io->getSize()) - throw ExtratorException("[ERRO: extratorSRT.cpp] Esse arquivo já foi lido."); + if (seek_pos >= file_io->getSize()){ + Logging::instance()->writeLog("extratorSRT.cpp : Arquivo de legenda já foi lido."); + throw ExtratorException("Esse arquivo já foi lido."); + } file_io->seek(seek_pos); try{ bff_reader = new BufferedReader(file_io); }catch(Exception &ex){ - throw ExtratorException("[ERRO: extratorSRT.cpp] O BufferedReader não foi inicializado."); + Logging::instance()->writeLog("extratorSRT.cpp : BufferedReader não inicializado."); + throw ExtratorException("O BufferedReader não foi inicializado."); } Subtitle* sub = new Subtitle(); diff --git a/extrator/src/extratorTXT.cpp b/extrator/src/extratorTXT.cpp index e36d87d..abaff5c 100644 --- a/extrator/src/extratorTXT.cpp +++ b/extrator/src/extratorTXT.cpp @@ -14,7 +14,7 @@ ExtratorTXT::ExtratorTXT(){ listeners = new list(); finish = false; - DPRINTF("Done!\n"); + printl(util::_DEBUG, "Done!\n"); } ExtratorTXT::~ExtratorTXT(){ @@ -23,7 +23,7 @@ ExtratorTXT::~ExtratorTXT(){ delete file; delete file_io; delete bff_reader; - DDDPRINTF("ExtratorTXT finalized!\n"); + printl(util::_DEBUG, "ExtratorTXT finalized!\n"); } void ExtratorTXT::initialize(){ @@ -33,7 +33,7 @@ void ExtratorTXT::initialize(){ bff_reader = new BufferedReader(file_io); }catch(Exception &ex){ finish = true; - Util::Logger::Instance()->writeLog((char*) "[ERRO: extratorTXT.cpp] Arquivo de texto não encontrado."); + Logging::instance()->writeLog("extratorTXT.cpp : Arquivo de texto não encontrado."); throw ExtratorException("Falha ao abrir o arquivo de texto! Verifique se o mesmo existe."); } this->Start(); @@ -50,7 +50,7 @@ void ExtratorTXT::notifyListeners(unsigned char* line) { } void ExtratorTXT::notifyEndExtraction(int size) { - DPRINTF("ExtratorTXT concluiu a extração: %d linhas.\n", size); + printl(util::_DEBUG, "ExtratorTXT concluiu a extração: %d linhas.\n", size); for(list::iterator it = listeners->begin(); it != listeners->end(); it++){ (*it)->notifyEnd(size); } @@ -75,9 +75,7 @@ bool ExtratorTXT::isFinished(){ } void ExtratorTXT::Run(){ - - DPRINTF("[AGUARDE] Extraindo Texto...\n") - + printl(util::_INFO, "Extraindo Texto...\n"); int line_index = 0; bool hasNext = true; string line; @@ -95,7 +93,7 @@ void ExtratorTXT::Run(){ notifyListeners((unsigned char*)"ARQUIVO_INVALIDO"); hasNext = false; }catch (...){ - Util::Logger::Instance()->writeLog((char*) "[ERRO: extratorTXT.cpp] Erro durante a leitura do arquivo de texto."); + Logging::instance()->writeLog("extratorTXT.cpp : Erro durante a leitura do arquivo de texto."); throw ExtratorException("Falha desconhecida na leitura do arquivo. Tente novamente."); } } diff --git a/extrator/src/include/extrator.h b/extrator/src/include/extrator.h index b9502f6..710058e 100644 --- a/extrator/src/include/extrator.h +++ b/extrator/src/include/extrator.h @@ -1,12 +1,14 @@ #ifndef EXTRATOR_H #define EXTRATOR_H +#include "logging.h" #include #include #include #include #include +using namespace util; using namespace lavidlib; class Extrator { diff --git a/extrator/src/include/extratorFactory.h b/extrator/src/include/extratorFactory.h index a3faa79..5cfc715 100644 --- a/extrator/src/include/extratorFactory.h +++ b/extrator/src/include/extratorFactory.h @@ -8,8 +8,8 @@ class ExtratorFactory{ public: - ExtratorFactory(); - ~ExtratorFactory(); + ExtratorFactory(){}; + ~ExtratorFactory(){}; Extrator* getExtrator(Extrator::ExtratorType extrator_type); diff --git a/extrator/src/include/extratorSRT.h b/extrator/src/include/extratorSRT.h index 6f8a52f..d16388a 100644 --- a/extrator/src/include/extratorSRT.h +++ b/extrator/src/include/extratorSRT.h @@ -13,8 +13,6 @@ #include #include #include "jthread.h" -#include "dprintf.h" -#include "logger.h" #include "extrator.h" #include "subtitle.h" #include "listenerSRT.h" diff --git a/extrator/src/include/extratorTXT.h b/extrator/src/include/extratorTXT.h index 51bf9e7..fd8a4b1 100644 --- a/extrator/src/include/extratorTXT.h +++ b/extrator/src/include/extratorTXT.h @@ -14,8 +14,6 @@ #include #include "jthread.h" -#include "dprintf.h" -#include "logger.h" #include "extrator.h" #include "listenerTXT.h" #include "extratorException.h" diff --git a/input/src/include/inputFile.h b/input/src/include/inputFile.h index 32353b4..f33b098 100644 --- a/input/src/include/inputFile.h +++ b/input/src/include/inputFile.h @@ -13,14 +13,14 @@ #include #include #include -#include "logger.h" +#include "logging.h" #include "listenerInput.h" #include "inputException.h" -#include "dprintf.h" #define MAX_SIZE_PACKET 188 using namespace std; +using namespace util; class InputFile { diff --git a/input/src/inputFile.cpp b/input/src/inputFile.cpp index 46896f2..43be481 100644 --- a/input/src/inputFile.cpp +++ b/input/src/inputFile.cpp @@ -5,13 +5,13 @@ InputFile::InputFile(char* path) { this->path = path; this->listeners = new list(); finish = false; - DPRINTF("Done!\n"); + printl(util::_DEBUG, "Done!\n"); } InputFile::~InputFile(){ listeners->clear(); delete listeners; - DDDPRINTF("Input finalized!\n"); + printl(util::_DEBUG, "Input finalized!\n"); } void InputFile::initialize(){ @@ -20,7 +20,7 @@ void InputFile::initialize(){ if (strstr(path, ".ts") != NULL) { if (filein.is_open()) { char buffer [MAX_SIZE_PACKET]; - DPRINTF("[AGUARDE] Lendo arquivo...\n") + printl(util::_INFO, "Lendo arquivo...\n"); while (!filein.eof()) { filein.read(buffer, MAX_SIZE_PACKET); unsigned char* packet = (unsigned char*) buffer; @@ -31,7 +31,7 @@ void InputFile::initialize(){ //finished = true; } else { finish = true; - Util::Logger::Instance()->writeLog((char*) "[ERRO: inputFile.cpp] Arquivo de vídeo não encontrado."); + Logging::instance()->writeLog("inputFile.cpp : Arquivo de vídeo não encontrado."); throw InputException("Falha ao abrir o arquivo de vídeo! Verifique se o mesmo existe."); } } diff --git a/main.cpp b/main.cpp index 52236bd..d59a135 100644 --- a/main.cpp +++ b/main.cpp @@ -11,21 +11,25 @@ * * Edit on 03 de Fevereiro de 2014 */ +#include +#include +#include +#include "logging.h" +#include "argParser.h" +#include "serviceTester.h" +#include "serviceException.h" #include "serviceWindowGenerationFromSRT.h" #include "serviceWindowGenerationFromRec.h" #include "serviceWindowGenerationFromText.h" -#include "serviceException.h" #include -#include "argParser.h" -#include -#include #define MAX_SIZE_PATH 256 +#define PATH_VBOX_UPLOADS "vlibras_user/.vlibras-config/uploads" #define PATH_DEVEL_CONTENTS "vlibras_user/vlibras-contents/videos" #define PATH_DEVEL_UPLOADS "vlibras_user/vlibras-contents/uploads" -#define PATH_VBOX_UPLOADS "vlibras_user/.vlibras-config/uploads" using namespace std; +using namespace util; void serviceSRT(int service, string path_video, string path_srt, int language, int position, int size, int background, string id, int mode); void serviceREC(int service, string path_video, int position, int size, int background, string id, int mode); @@ -37,6 +41,7 @@ void serviceRECWithoutMixing(int service, string path_video, int background, str void hasFailed(); void hasInvalid(); void fail(string msg); +//void runTests(); void setPathContents(int mode, string id); bool isFailed; @@ -71,13 +76,14 @@ int main(int argc, char* argv[]) { exit(1); } - printf("\n################## LAViD : VLibras ##################\n\n"); + //printf("\n################## LAViD : VLibras ##################\n\n"); service = parser->getService(); + util::Logging::instance()->setLevel(parser->getLog()); switch(service){ case 1: - DDPRINTF("Service Type: Video with Subtitles\n"); + printl(util::_INFO, "Service Type: Video with Subtitles\n"); input = parser->getInput(); input_srt = parser->getInputSRT(); language = parser->getLanguage(); @@ -90,7 +96,7 @@ int main(int argc, char* argv[]) { break; case 2: - DDPRINTF("Service Type: Video Recognize\n"); + printl(util::_INFO, "Service Type: Video Recognize\n"); input = parser->getInput(); position = parser->getPosition(); size = parser->getSize(); @@ -101,7 +107,7 @@ int main(int argc, char* argv[]) { break; case 3: - DDPRINTF("Service Type: Text\n"); + printl(util::_INFO, "Service Type: Text\n"); input = parser->getInput(); language = parser->getLanguage(); background = parser->getBackground(); @@ -111,7 +117,7 @@ int main(int argc, char* argv[]) { break; case 4: - DDPRINTF("Service Type: Subtitles only\n"); + printl(util::_INFO, "Service Type: Subtitles only\n"); input = parser->getInput(); language = parser->getLanguage(); background = parser->getBackground(); @@ -121,7 +127,7 @@ int main(int argc, char* argv[]) { break; case 5: //reconhecimento de audio - DDPRINTF("Service Type: Audio Recognize\n"); + printl(util::_INFO, "Service Type: Audio Recognize\n"); input = parser->getInput(); background = parser->getBackground(); id = parser->getId(); @@ -130,7 +136,7 @@ int main(int argc, char* argv[]) { break; case 6: //Reconhecimento de video sem mixagem - DDPRINTF("Service Type: Video Recognize (Mixer Disabled)\n"); + printl(util::_INFO, "Service Type: Video Recognize (Mixer Disabled)\n"); input = parser->getInput(); background = parser->getBackground(); id = parser->getId(); @@ -138,8 +144,12 @@ int main(int argc, char* argv[]) { serviceREC(service, input, 0, 0, background, id, mode);//como service != 2 então não há mixagem break; + case 7: + cout << "Serviço sendo implementado!" << endl; + break; + default: - printf("\nOpção de serviço não reconhecida!\n"); + printf("Opção de serviço não reconhecida!\n"); hasInvalid(); } @@ -150,8 +160,8 @@ int main(int argc, char* argv[]) { gettimeofday(&tv2, NULL); t2 = (double)(tv2.tv_sec) + (double)(tv2.tv_usec)/ 1000000.00; - DDPRINTF("Time: %lf\n", (t2-t1)); - DDPRINTF("VLibras finalized!\n\n"); + printl(util::_DEBUG, "Time: %lf\n", (t2-t1)); + printl(util::_INFO, "VLibras finalized!\n\n"); exit(0); } @@ -272,9 +282,8 @@ void serviceOnlySRT(int service, string path_srt, int language, int background, } void fail(string msg){ - printf("\n"); - DDDDPRINTF("Ops... Tivemos um problema! :(\n"); - DDDDPRINTF("Possível causa do erro: %s\n\n", msg.c_str()); + printl(util::_ERROR, "\nOps... Tivemos um problema! :(\n"); + printl(util::_ERROR, "Possível causa do erro: %s\n\n", msg.c_str()); } void hasFailed(){ @@ -296,4 +305,4 @@ void setPathContents(int mode, string id){ exit(127); } system(command.c_str()); -} +} \ No newline at end of file diff --git a/mixer/src/Mixer.cpp b/mixer/src/Mixer.cpp index 7929929..ec81027 100644 --- a/mixer/src/Mixer.cpp +++ b/mixer/src/Mixer.cpp @@ -9,16 +9,16 @@ /* Construtores e destrutores...*/ Mixer::Mixer() { this->setNumThreads("1"); - DPRINTF("Done!\n"); + printl(util::_DEBUG, "Done!\n"); } Mixer::Mixer(string mainVideo, string secondaryVideo) { this->setMainVideo(mainVideo); this->setSecondaryVideo(secondaryVideo); this->setNumThreads("1"); - DPRINTF("Done!\n"); + printl(util::_DEBUG, "Done!\n"); } Mixer::~Mixer() { - DDDPRINTF("Mixer finalized!\n"); + printl(util::_DEBUG, "Mixer finalized!\n"); } /* FIM de Construtores e destrutores...*/ @@ -27,7 +27,7 @@ Mixer::~Mixer() { void Mixer::initialize(string mainVideo, string slVideo, int positionSecondaryVideo, int sizeSecondaryVideo, int transparency, char* _id, char* path_uploads, char* path_contents){ - DPRINTF("[AGUARDE] Mixando...\n") + printl(util::_INFO, "Mixando...\n"); uploads = path_uploads; contents = path_contents; stringstream ss; diff --git a/mixer/src/include/Mixer.h b/mixer/src/include/Mixer.h index 8a458fa..73e0c02 100644 --- a/mixer/src/include/Mixer.h +++ b/mixer/src/include/Mixer.h @@ -16,7 +16,7 @@ #include #include #include -#include "dprintf.h" +#include "logging.h" //SL Video Position #define TOP_LEFT 1 @@ -35,6 +35,7 @@ #define MAX_SIZE_PATH 256 using namespace std; +using namespace util; class Mixer { public: diff --git a/recognize/src/include/recognize.h b/recognize/src/include/recognize.h index 8641183..2befb30 100644 --- a/recognize/src/include/recognize.h +++ b/recognize/src/include/recognize.h @@ -16,8 +16,7 @@ #include #include #include -#include "dprintf.h" -#include "logger.h" +#include "logging.h" #include "recognizeListener.h" #include "recognizeException.h" @@ -51,6 +50,7 @@ using namespace jthread; using namespace std; +using namespace util; class Recognize: public Thread { diff --git a/recognize/src/recognize.cpp b/recognize/src/recognize.cpp index 2e6e8c3..b28223d 100644 --- a/recognize/src/recognize.cpp +++ b/recognize/src/recognize.cpp @@ -11,7 +11,7 @@ Recognize::Recognize(char* _pathVideo, char* _id) { ss << _id; ss >> id; confidenceRate=CONFIDENCE_RATE; - DPRINTF("Done!\n"); + printl(util::_DEBUG, "Done!\n"); } Recognize::Recognize(char* _pathVideo, char* _id, char* rate) { @@ -27,7 +27,7 @@ Recognize::Recognize(char* _pathVideo, char* _id, char* rate) { istringstream(rate) >> confidenceRate; if (confidenceRate == 0) confidenceRate=CONFIDENCE_RATE; - DPRINTF("Done!\n"); + printl(util::_DEBUG, "Done!\n"); } Recognize::Recognize(char* _pathVideo, int _inputType, char* _id) { @@ -38,26 +38,26 @@ Recognize::Recognize(char* _pathVideo, int _inputType, char* _id) { frequency = FREQUENCY_PATTERN; sizeBlocs = BLOCS_PATTERN; id = _id; - DPRINTF("Done!\n"); + printl(util::_DEBUG, "Done!\n"); } Recognize::~Recognize() { listeners->clear(); delete listeners; - DDDPRINTF("Recognize finalized!\n"); + printl(util::_DEBUG, "Recognize finalized!\n"); } void Recognize::initialize() { - DPRINTF("Recognizing...\n"); + printl(util::_INFO, "Reconhecendo áudio...\n"); /**printf("*** Initialized Recognition ***\n\nVideo: %s\nType [1-File; 2-Mic]: %d\nFrequency: %d\n\n", this->pathVideo, this->inputType, this->frequency);**/ ifstream file(pathVideo, ifstream::binary); if(!file.is_open()){ finish = true; - Util::Logger::Instance()->writeLog((char*) "[ERRO: recognize.cpp] Arquivo não encontrado."); + Logging::instance()->writeLog("recognize.cpp Arquivo não encontrado."); throw RecognizeException("Falha ao abrir o arquivo! Verifique se o mesmo existe."); } this->Start(); @@ -378,7 +378,7 @@ void Recognize::notifyListeners(char* text, int64_t pts) { } void Recognize::notifyEndExtraction(int sentences_size) { - DPRINTF("Recognizer concluiu o reconhecimento: %d sentenças.\n", sentences_size); + printl(util::_DEBUG, "Recognizer concluiu o reconhecimento: %d sentenças.\n", sentences_size); for(list::iterator it = listeners->begin(); it != listeners->end(); it++){ (*it)->notifyEnd(sentences_size); } diff --git a/renderer/src/include/renderer.h b/renderer/src/include/renderer.h index 9a8ed6e..080641f 100644 --- a/renderer/src/include/renderer.h +++ b/renderer/src/include/renderer.h @@ -2,7 +2,7 @@ #define RENDERER_H #include "jthread.h" -#include "dprintf.h" +#include "logging.h" #include "string.h" #include #include @@ -26,6 +26,7 @@ using namespace lavidlib; using namespace jthread; using namespace std; +using namespace util; class Renderer : public Thread { public: diff --git a/renderer/src/renderer.cpp b/renderer/src/renderer.cpp index 5674aee..78bb754 100644 --- a/renderer/src/renderer.cpp +++ b/renderer/src/renderer.cpp @@ -3,20 +3,20 @@ Renderer::Renderer(char* videoPath, char* user_id) { this->folder_id = user_id; this->path_video = videoPath; - serverInitialize(); running = true; count_task = 0; glosa_processed = 0; core_socket = new StreamSocket(); listeners = new list(); - DPRINTF("Done!\n"); + serverInitialize(); + printl(util::_DEBUG, "Done!\n"); } Renderer::~Renderer() { listeners->clear(); delete listeners; if(core_socket) delete core_socket; - DDDPRINTF("Renderer finalized!\n"); + printl(util::_DEBUG, "Renderer finalized!\n"); } void Renderer::serverInitialize(){ @@ -33,7 +33,7 @@ void Renderer::serverInitialize(){ command.append(" && ").append(render); system(command.c_str()); - sleep(3); + sleep(5); } void Renderer::receiveGlosa(std::string glosa, int64_t pts) { @@ -51,6 +51,9 @@ void Renderer::receiveGlosa(std::string glosa, int64_t pts) { void Renderer::sendGlosa() { try{ + // while(!core_socket->isConnected()) + // sleep(1); + int glosa_size = strlen(glosa_copy.c_str())+1; char* glosa_buffer = new char[glosa_size]; strcpy(glosa_buffer, glosa_copy.c_str()); @@ -75,7 +78,10 @@ void Renderer::sendGlosa() { void Renderer::connectToUnity() { try{ static InetAddress* addr = InetAddress::createByName(HOST); - core_socket->connect(addr, PORTNO); + while(!core_socket->isConnected()){ + core_socket->connect(addr, PORTNO); + sleep(1); + } }catch(lavidlib::UnknownHostException &ex){ throw RuntimeException(ex.getMessage().c_str()); }catch(lavidlib::SocketException &ex){ @@ -84,7 +90,7 @@ void Renderer::connectToUnity() { } void Renderer::waitScreenShots() { - DPRINTF("[AGUARDE] Gerando vídeo...\n"); + printl(util::_INFO, "Gerando vídeo...\n"); char* endgeneration = new char[strlen(END_FLAG)+1]; int connected; try{ @@ -135,7 +141,8 @@ void Renderer::Run() { render(); cleanFiles(); }catch(lavidlib::RuntimeException &ex){ - DDDDPRINTF("Erro: %s\n", ex.getMessage().c_str()); + printl(util::_ERROR, "%s\n", ex.getMessage().c_str()); + Logging::instance()->writeLog("renderer.cpp : Falha na comunicação com o Unity player"); throw RuntimeException(ex.getMessage().c_str()); } } diff --git a/servico/src/include/serviceTester.h b/servico/src/include/serviceTester.h new file mode 100644 index 0000000..838ba7c --- /dev/null +++ b/servico/src/include/serviceTester.h @@ -0,0 +1,64 @@ +#ifndef SERVICETESTER_H +#define SERVICETESTER_H + +#include +#include +#include +#include +#include "serviceException.h" +#include "serviceWindowGenerationFromRec.h" +#include "serviceWindowGenerationFromSRT.h" +#include "serviceWindowGenerationFromText.h" + +// path dos arquivos de teste +#define PATH_VID "/home/user/.vlibras-config/test/uploads/test_video.mp4" +#define PATH_SRT "/home/user/.vlibras-config/test/uploads/test_srt.srt" +#define PATH_TXT "/home/user/.vlibras-config/test/uploads/test_text.txt" +#define OUTPUT_FILE "/home/user/.vlibras-config/test/videos/Test.mp4" +#define TESTER_ID "Test" +#define MODE_TEST 3 + +using namespace std; + +class ServiceTester: public Thread { + +public: + ServiceTester(); + ~ServiceTester(); + + bool isFinished(); + + int checkServiceSRT(); + int checkServiceText(); + int checkServiceRec(); +private: + + int language; + int position; + int resolution; + int background; + + bool fail; + bool finish; + string msgErr; + + File* fIn; + File* fOut; + FileIO* fIO_in; + FileIO* fIO_out; + + ServiceWindowGenerationFromRec* service_rec; + ServiceWindowGenerationFromSRT* service_srt; + ServiceWindowGenerationFromText* service_text; + + void serviceSRT(int service, string path_video, string path_srt, int language, int position, int size, int background, string id, int mode); + void serviceREC(int service, string path_video, int position, int size, int background, string id, int mode); + void serviceText(string path_text, int language, int background, string id, int mode); + + void Run(); + bool checkFiles(string fileIn, string fileOut); + void hasFailed(string msgerr); + void deleteFiles(); +}; + +#endif /* SERVICETESTER_H */ \ No newline at end of file diff --git a/servico/src/include/serviceWindowGeneration.h b/servico/src/include/serviceWindowGeneration.h index 192e050..247250c 100644 --- a/servico/src/include/serviceWindowGeneration.h +++ b/servico/src/include/serviceWindowGeneration.h @@ -8,7 +8,7 @@ #include #include #include "jthread.h" -#include "dprintf.h" +#include "logging.h" #include "Mixer.h" #include "renderer.h" #include "listenerRenderer.h" @@ -20,16 +20,21 @@ #define DEVELOPER 1 #define PRODUCTION 2 +#define TESTER 3 #define PATH_DEVEL_CONTENTS "vlibras_user/vlibras-contents/videos" #define PATH_DEVEL_UPLOADS "vlibras_user/vlibras-contents/uploads" +#define PATH_TESTER_CONTENTS "vlibras_user/vlibras-config/test/videos" +#define PATH_TESTER_UPLOADS "vlibras_user/vlibras-config/test/uploads" #define PATH_VBOX_UPLOADS "vlibras_user/.vlibras-config/uploads" #define PATH_CONF_FILE "vlibras_user/.vlibras-config/params.json" +#define PATH_TESTER_FILE "/home/user/.vlibras-config/test/tester.json" #define MAX_SIZE_PATH 256 using namespace Tradutor; using namespace jthread; using namespace std; using namespace lavidlib; +using namespace util; class ServiceWindowGeneration { diff --git a/servico/src/serviceTester.cpp b/servico/src/serviceTester.cpp new file mode 100644 index 0000000..f07bb18 --- /dev/null +++ b/servico/src/serviceTester.cpp @@ -0,0 +1,141 @@ +#include "serviceTester.h" + +ServiceTester::serviceTester(int _language, int _position, int _size, int _background) { + language = _language; + position = _position; + size = _size; + background = _background; + msgErr = ""; + finish = false; + fail = false; + printl(util::_DEBUG, "Done!\n"); +} + +ServiceTester::~serviceTester() { + printl(util::_DEBUG, "ServiceTester Finalized!\n"); +} + +void ServiceTester::checkServiceSRT() { + service_srt = new ServiceWindowGenerationFromSRT(PATH_VID, PATH_SRT, language, position, size, background, TESTER_ID, MODE_TEST, 1); + + try{ + service_srt->initialize(); + }catch(ServiceException &ex){ + msgErr += "Extração de legenda\n"; + fail = true + return; + } + + while(!service_srt->isFinished()) + sleep(5); + delete service_srt; + + bool sucess; + sucess = checkFiles(PATH_VID, FILE_OUT_SRT); + if(!sucess){ + msgErr += "Extração de legenda\n"; + } + deleteFiles(); +} + +void ServiceTester::checkServiceRec() { + service_rec = new ServiceWindowGenerationFromRec(PATH_VID, position, size, background, TESTER_ID, MODE_TEST, 2); + + try{ + service_rec->initialize(); + }catch(ServiceException &ex){ + msgErr += "Reconhecimento\n"; + fail = true; + return; + } + + while(!service_rec->isFinished()) + sleep(5); + delete service_rec; + + bool sucess; + sucess = checkFiles(PATH_VID, FILE_OUT_REC); + if(!sucess){ + msgErr += "Reconhecimento\n"; + } + deleteFiles(); +} +void ServiceTester::checkServiceText() { + service_text = new ServiceWindowGenerationFromText(PATH_TXT, language, background, TESTER_ID, MODE_TEST); + + try{ + service_text->initialize(); + }catch(ServiceException &ex){ + msgErr += "Extração de texto\n" + fail = true; + return; + } + + while (!service_text->isFinished()) + usleep(100000); //100ms + delete service_text; + + bool sucess; + sucess = checkFiles(PATH_TXT, FILE_OUT_TXT); + if(!sucess){ + msgErr += "Extração de texto\n" + } + deleteFiles(); +} + +bool ServiceTester::checkFiles(string fileIn, string fileOut) { + int64_t inSize; + int64_t outSize; + fIn = new lavidlib::File(fileIn); + fOut = new lavidlib::File(fileOut); + + try{ + fIO_in = new lavidlib::FileIO(fIn->getPath(), FileIO::MODE_READ); + fIO_out = new lavidlib::FileIO(fOut->getPath(), FileIO::MODE_READ); + }catch(Exception &ex){ + delete fIn; + delete fOut; + fail = true; + return false; + } + + inSize = fIO_in->getSize(); + outSize = fIO_out->getSize(); + + delete fIn; + delete fOut; + delete fIO_in; + delete fIO_out; + + if(outSize != 0 && outSize != inSize) + return true; + + fail = true; + return false; +} + +bool ServiceTester::isFinished(){ + return this->finish; +} + +void hasFailed() { + return fail; +} + +void ServiceTester::deleteFiles() { + string command = "rm -f "; + command += OUTPUT_FILE; + system(command); +} + +void ServiceTester::Run() { + printl(util::_INFO, "Verificando módulos, aguarde...\n"); + checkServiceSRT(); + checkServiceRec(); + checkServiceText(); + + if(hasFailed()) + throw ServiceException(msgErr); + + finish = true; +} \ No newline at end of file diff --git a/servico/src/serviceWindowGenerationFromRec.cpp b/servico/src/serviceWindowGenerationFromRec.cpp index 8d8d7fd..be56fbe 100644 --- a/servico/src/serviceWindowGenerationFromRec.cpp +++ b/servico/src/serviceWindowGenerationFromRec.cpp @@ -17,7 +17,7 @@ ServiceWindowGenerationFromRec::ServiceWindowGenerationFromRec( tradutor = new TradutorPortGlosa(); running = true; finish = false; - DPRINTF("Done!\n"); + printl(util::_DEBUG, "Done!\n"); } ServiceWindowGenerationFromRec::ServiceWindowGenerationFromRec( @@ -42,7 +42,7 @@ ServiceWindowGenerationFromRec::ServiceWindowGenerationFromRec( } running = true; finish = false; - DPRINTF("Done!\n"); + printl(util::_DEBUG, "Done!\n"); } ServiceWindowGenerationFromRec::~ServiceWindowGenerationFromRec(){ @@ -51,32 +51,47 @@ ServiceWindowGenerationFromRec::~ServiceWindowGenerationFromRec(){ if (renderer) delete renderer; if (rec) delete rec; if (mixer) delete mixer; - DDDPRINTF("Service Rec finished!\n"); + printl(util::_DEBUG, "Service Rec finished!\n"); } void ServiceWindowGenerationFromRec::setPathContents(){ - if(this->exec_mode == DEVELOPER){ - this->path_contents = PATH_DEVEL_CONTENTS; - this->path_uploads = PATH_DEVEL_UPLOADS; - rec->setPathAudioContents(path_uploads); - - }else if(this->exec_mode == PRODUCTION){ - ifstream conf_file(PATH_CONF_FILE, ifstream::binary); - parsingSuccessful = reader.parse(conf_file, root); - if(!parsingSuccessful){ - conf_file.close(); - throw ServiceException("Fail to parsing param.json"); - } - string attr = "vlibras_user/"; - attr += root.get("storage", PATH_VBOX_UPLOADS).asString(); - this->path_contents = new char[MAX_SIZE_PATH]; - strcpy(this->path_contents, attr.c_str()); - this->path_uploads = PATH_VBOX_UPLOADS; - rec->setPathAudioContents(path_uploads); - conf_file.close(); - }else{ - throw ServiceException("Invalid execution mode!"); - } + switch(exec_mode) { + case DEVELOPER: + { + this->path_contents = (char*) PATH_DEVEL_CONTENTS; + this->path_uploads = (char*) PATH_DEVEL_UPLOADS; + rec->setPathAudioContents(path_uploads); + }break; + + case PRODUCTION: + { + ifstream conf_file(PATH_CONF_FILE, ifstream::binary); + parsingSuccessful = reader.parse(conf_file, root); + + if(parsingSuccessful) { + string attr = "vlibras_user/"; + attr += root.get("storage", PATH_VBOX_UPLOADS).asString(); + this->path_contents = new char[MAX_SIZE_PATH]; + strcpy(this->path_contents, attr.c_str()); + this->path_uploads = (char*) PATH_VBOX_UPLOADS; + rec->setPathAudioContents(path_uploads); + }else{ + conf_file.close(); + Logging::instance()->writeLog("Erro com a leitura do arquivo params.json"); + throw RuntimeException("Fail to parsing params.json"); + } + conf_file.close(); + }break; + + case TESTER: + { + this->path_contents = (char*) PATH_TESTER_CONTENTS; + this->path_uploads = (char*) PATH_TESTER_UPLOADS; + }break; + + default: + throw ServiceException("Invalid execution mode!"); + } } void ServiceWindowGenerationFromRec::setPathLibras() { @@ -140,7 +155,7 @@ void ServiceWindowGenerationFromRec::notifyEndOfRenderization() { } void ServiceWindowGenerationFromRec::notifyEnd(int sentences_size){ - DPRINTF("Service REC recebeu: %d sentenças.\n", sentences_size); + printl(util::_DEBUG, "Service REC recebeu: %d sentenças.\n", sentences_size); setSizeOfSubtitles(sentences_size); } @@ -153,7 +168,7 @@ bool ServiceWindowGenerationFromRec::isFinished(){ } void ServiceWindowGenerationFromRec::initialize(){ - DPRINTF("Service REC Initialize.\n"); + printl(util::_DEBUG, "Service REC Initialize.\n"); setPathLibras(); rec->addListener(this); tradutor->addListener(this); diff --git a/servico/src/serviceWindowGenerationFromSRT.cpp b/servico/src/serviceWindowGenerationFromSRT.cpp index 57258c2..7d15e65 100644 --- a/servico/src/serviceWindowGenerationFromSRT.cpp +++ b/servico/src/serviceWindowGenerationFromSRT.cpp @@ -23,7 +23,7 @@ ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT(char* pathVideo, } running = true; finish = false; - DPRINTF("Done!\n"); + printl(util::_DEBUG, "Done!\n"); } ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT(char* pathSRT, int sublanguage, int transp, char* id, int mode, int serviceType) { @@ -44,7 +44,7 @@ ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT(char* pathSRT, in } running = true; finish = false; - DPRINTF("Done!\n"); + printl(util::_DEBUG, "Done!\n"); } ServiceWindowGenerationFromSRT::~ServiceWindowGenerationFromSRT() { @@ -54,30 +54,44 @@ ServiceWindowGenerationFromSRT::~ServiceWindowGenerationFromSRT() { if (renderer) delete renderer; if (extratorSRT)delete extratorSRT; if (extrator_factory) delete extrator_factory; - DDDPRINTF("Service SRT finalized!\n"); + printl(util::_DEBUG, "Service SRT finalized!\n"); } void ServiceWindowGenerationFromSRT::setPathContents() { - if(this->exec_mode == DEVELOPER){ - this->path_contents = PATH_DEVEL_CONTENTS; - this->path_uploads = PATH_DEVEL_UPLOADS; - - }else if(this->exec_mode = PRODUCTION){ - ifstream conf_file(PATH_CONF_FILE, ifstream::binary); - parsingSuccessful = reader.parse(conf_file, root); - if(!parsingSuccessful){ + switch(exec_mode) { + case DEVELOPER: + { + this->path_contents = (char*) PATH_DEVEL_CONTENTS; + this->path_uploads = (char*) PATH_DEVEL_UPLOADS; + }break; + + case PRODUCTION: + { + ifstream conf_file(PATH_CONF_FILE, ifstream::binary); + parsingSuccessful = reader.parse(conf_file, root); + + if(parsingSuccessful) { + string attr = "vlibras_user/"; + attr += root.get("storage", PATH_VBOX_UPLOADS).asString(); + this->path_contents = new char[MAX_SIZE_PATH]; + strcpy(this->path_contents, attr.c_str()); + this->path_uploads = (char*) PATH_VBOX_UPLOADS; + }else{ + conf_file.close(); + Logging::instance()->writeLog("Erro com a leitura do arquivo params.json"); + throw new RuntimeException("Fail to parsing params.json"); + } conf_file.close(); - throw ServiceException("Fail to parsing param.json"); - } - string attr = "vlibras_user/"; - attr += root.get("storage", PATH_VBOX_UPLOADS).asString(); - this->path_contents = new char[MAX_SIZE_PATH]; - - strcpy(this->path_contents, attr.c_str()); - this->path_uploads = PATH_VBOX_UPLOADS; - conf_file.close(); - }else{ - throw ServiceException("Invalid execution mode!"); + }break; + + case TESTER: + { + this->path_contents = (char*) PATH_TESTER_CONTENTS; + this->path_uploads = (char*) PATH_TESTER_UPLOADS; + }break; + + default: + throw ServiceException("Invalid execution mode!"); } } @@ -154,7 +168,7 @@ void ServiceWindowGenerationFromSRT::notifyEndOfRenderization() { } void ServiceWindowGenerationFromSRT::notifyEnd(int sub_size) { - DPRINTF("Service SRT recebeu: %d legendas.\n", sub_size); + printl(util::_DEBUG, "Service SRT recebeu: %d legendas.\n", sub_size); setSizeOfSubtitles(sub_size); } @@ -167,7 +181,7 @@ bool ServiceWindowGenerationFromSRT::isFinished() { } void ServiceWindowGenerationFromSRT::initialize() { - DPRINTF("Service SRT Initialize.\n"); + printl(util::_DEBUG, "Service SRT Initialize.\n"); setPathLibras(); extratorSRT = (ExtratorSRT*) extrator_factory->getExtrator(Extrator::SRT); extratorSRT->addListener(this); diff --git a/servico/src/serviceWindowGenerationFromText.cpp b/servico/src/serviceWindowGenerationFromText.cpp index e91f522..11b4ba0 100644 --- a/servico/src/serviceWindowGenerationFromText.cpp +++ b/servico/src/serviceWindowGenerationFromText.cpp @@ -18,7 +18,7 @@ ServiceWindowGenerationFromText::ServiceWindowGenerationFromText(char* pathFile, } running = true; finish = false; - DPRINTF("Done!\n"); + printl(util::_DEBUG, "Done!\n"); } ServiceWindowGenerationFromText::~ServiceWindowGenerationFromText() { @@ -26,26 +26,41 @@ ServiceWindowGenerationFromText::~ServiceWindowGenerationFromText() { if (renderer) delete renderer; if (extratorTXT)delete extratorTXT; if (extrator_factory) delete extrator_factory; - DDDPRINTF("Service Text finalized!\n"); + printl(util::_DEBUG, "Service Text finalized!\n"); } void ServiceWindowGenerationFromText::setPathContents() { - if(this->exec_mode == DEVELOPER){ - this->path_contents = PATH_DEVEL_CONTENTS; - //this->path_uploads = PATH_DEVEL_UPLOADS; - }else if(this->exec_mode == PRODUCTION){ - ifstream conf_file(PATH_CONF_FILE, ifstream::binary); - parsingSuccessful = reader.parse(conf_file, root); - if(!parsingSuccessful){ - throw new RuntimeException("Fail to parsing param.json"); - } - string attr = "vlibras_user/"; - attr += root.get("storage", PATH_VBOX_UPLOADS).asString(); - this->path_contents = new char[MAX_SIZE_PATH]; - strcpy(this->path_contents, attr.c_str()); - //this->path_uploads = PATH_VBOX_UPLOADS; - }else{ - throw ServiceException("Invalid execution mode!"); + switch(exec_mode) { + case DEVELOPER: + { + this->path_contents = (char*) PATH_DEVEL_CONTENTS; + }break; + + case PRODUCTION: + { + ifstream conf_file(PATH_CONF_FILE, ifstream::binary); + parsingSuccessful = reader.parse(conf_file, root); + + if(parsingSuccessful) { + string attr = "vlibras_user/"; + attr += root.get("storage", PATH_VBOX_UPLOADS).asString(); + this->path_contents = new char[MAX_SIZE_PATH]; + strcpy(this->path_contents, attr.c_str()); + }else{ + conf_file.close(); + Logging::instance()->writeLog("Erro com a leitura do arquivo params.json"); + throw new RuntimeException("Fail to parsing params.json"); + } + conf_file.close(); + }break; + + case TESTER: + { + this->path_contents = (char*) PATH_TESTER_CONTENTS; + }break; + + default: + throw ServiceException("Invalid execution mode!"); } } @@ -102,7 +117,7 @@ void ServiceWindowGenerationFromText::notifyEndOfRenderization() { } void ServiceWindowGenerationFromText::notifyEnd(int line_size) { - DPRINTF("Service Text recebeu: %d linhas.\n", line_size); + printl(util::_DEBUG, "Service Text recebeu: %d linhas.\n", line_size); setSizeOfSubtitles(line_size); } @@ -115,7 +130,7 @@ bool ServiceWindowGenerationFromText::isFinished() { } void ServiceWindowGenerationFromText::initialize() { - DPRINTF("Service Text Initialize.\n"); + printl(util::_DEBUG, "Service Text Initialize.\n"); setPathLibras(); extratorTXT = (ExtratorTXT*) extrator_factory->getExtrator(Extrator::TXT); extratorTXT->addListener(this); diff --git a/tradutor/src/include/tradutorPortGlosa.h b/tradutor/src/include/tradutorPortGlosa.h index f5ba0bc..634f2a3 100644 --- a/tradutor/src/include/tradutorPortGlosa.h +++ b/tradutor/src/include/tradutorPortGlosa.h @@ -18,12 +18,13 @@ #include "listenerTradutor.h" #include "pyTradutor.h" #include "listenerInput.h" -#include "dprintf.h" +#include "logging.h" #ifndef _GERADOR_GLOSA_H_ #define _GERADOR_GLOSA_H_ using namespace std; +using namespace util; namespace Tradutor { diff --git a/tradutor/src/tradutorPortGlosa.cpp b/tradutor/src/tradutorPortGlosa.cpp index 8f1e20f..ae8ad79 100644 --- a/tradutor/src/tradutorPortGlosa.cpp +++ b/tradutor/src/tradutorPortGlosa.cpp @@ -21,7 +21,7 @@ namespace Tradutor { // Inicia o mutex mutex = (pthread_mutex_t *) malloc( sizeof(pthread_mutex_t) ); pthread_mutex_init(mutex, NULL); - DPRINTF("Done!\n") + printl(util::_DEBUG, "Done!\n"); } @@ -31,11 +31,10 @@ namespace Tradutor { if (mutex) { int ret = pthread_mutex_destroy(mutex); if (ret) - DDDPRINTF("Erro, destruindo mutex.\n"); + printl(util::_ERROR, "Erro, destruindo mutex.\n"); free(mutex); } - DDDPRINTF("Translator finalized!\n") - + printl(util::_DEBUG, "Translator finalized!\n"); } void TradutorPortGlosa::addListener(ListenerTradutor* listener) { diff --git a/util/src/argParser.cpp b/util/src/argParser.cpp index 30f8264..fff0fb8 100644 --- a/util/src/argParser.cpp +++ b/util/src/argParser.cpp @@ -10,27 +10,29 @@ void ArgParser::readArgs(char** argv, int argc) int long_index = 0; static struct option long_options[] = { - {"audio", required_argument, NULL, 'A'}, - {"subtitle", required_argument, NULL, 'S'}, - {"text", required_argument, NULL, 'T'}, - {"video", required_argument, NULL, 'V'}, - {"language", required_argument, NULL, 'l'}, - {"background", required_argument, NULL, 'b'}, - {"resolution", required_argument, NULL, 'r'}, - {"position", required_argument, NULL, 'p'}, - {"mode", required_argument, NULL, 'm'}, - {"id", required_argument, NULL, 'i'}, - {"no-mixer", no_argument, NULL, 'x'}, - {"help", no_argument, NULL, 'h'}, - {0, 0, 0, 0 } + {"audio", required_argument, NULL, 'A'}, + {"subtitle", required_argument, NULL, 'S'}, + {"text", required_argument, NULL, 'T'}, + {"video", required_argument, NULL, 'V'}, + {"language", required_argument, NULL, 'l'}, + {"background", required_argument, NULL, 'b'}, + {"resolution", required_argument, NULL, 'r'}, + {"position", required_argument, NULL, 'p'}, + {"mode", required_argument, NULL, 'm'}, + {"id", required_argument, NULL, 'i'}, + {"no-mixer", no_argument, NULL, 'x'}, + {"check-modules", no_argument, NULL, 'C'}, + {"loglevel", required_argument, NULL, 'v'}, + {"help", no_argument, NULL, 'h'}, + {0, 0, 0, 0 } }; - while ((opt = getopt_long_only(argc, argv, "A:S:T:V:l:b:r:p:m:", long_options, &long_index))!= -1) + while ((opt = getopt_long_only(argc, argv, "A:S:T:V:b:l:m:p:r:v:", long_options, &long_index))!= -1) { switch (opt) { case 'A': - if(argc <= 5) + if(argc <= 9) returnErr("Insuficient arguments. Try again"); globalArgs.service = _REC_AUDIO; @@ -38,7 +40,7 @@ void ArgParser::readArgs(char** argv, int argc) break; case 'S': - if(argc <= 6 || (globalArgs.service == _REC_VIDEO && argc <= 9)) + if(argc <= 11 || (globalArgs.service == _REC_VIDEO && argc <= 17)) returnErr("Insuficient arguments. Try again"); if(globalArgs.service == _REC_VIDEO){ // ativa o serviço de vídeo e legendas @@ -51,7 +53,7 @@ void ArgParser::readArgs(char** argv, int argc) break; case 'T': - if(argc <= 5) + if(argc <= 9) returnErr("Insuficient arguments. Try again"); globalArgs.service = _TEXT; @@ -59,7 +61,7 @@ void ArgParser::readArgs(char** argv, int argc) break; case 'V': - if(argc <= 7 || ((globalArgs.service == _ONLY_SRT && argc <= 9))) + if(argc <= 13 || ((globalArgs.service == _ONLY_SRT && argc <= 17))) returnErr("Insuficient arguments. Try again"); if(globalArgs.service == _ONLY_SRT){ // ativa o serviço de vídeo e legendas @@ -73,54 +75,23 @@ void ArgParser::readArgs(char** argv, int argc) break; case 'l': - if (strcmp(optarg,"portugues") == 0) - globalArgs.language = _PORTUGUESE; - else if (strcmp(optarg,"libras") == 0) - globalArgs.language = _GLOSA; - else - returnErr("--language"); + globalArgs.language = languageFromString(optarg); break; case 'b': - if (strcmp(optarg,"opaque") == 0) - globalArgs.back = _OPAQUE; - else if (strcmp(optarg,"transp") == 0) - globalArgs.back = _TRANSPARENT; - else - returnErr("--background"); + globalArgs.back = backgroundFromString(optarg); break; case 'r': - if (strcmp(optarg,"small") == 0) - globalArgs.size = _SMALL; - else if (strcmp(optarg,"medium") == 0) - globalArgs.size = _MEDIUM; - else if (strcmp(optarg,"large") == 0) - globalArgs.size = _LARGE; - else - returnErr("--resolution"); + globalArgs.size = resolutionFromString(optarg); break; case 'p': - if (strcmp(optarg,"top_left") == 0) - globalArgs.position = _TOP_LEFT; - else if (strcmp(optarg,"top_right") == 0) - globalArgs.position = _TOP_RIGHT; - else if (strcmp(optarg,"bottom_right") == 0) - globalArgs.position = _BOTTOM_RIGHT; - else if (strcmp(optarg,"bottom_left") == 0) - globalArgs.position = _BOTTOM_LEFT; - else - returnErr("--position"); + globalArgs.position = positionFromString(optarg); break; case 'm': - if(strcmp(optarg,"prod") == 0) - globalArgs.mode = _PROD; - else if (strcmp(optarg,"devel") == 0) - globalArgs.mode = _DEVEL; - else - returnErr("--mode"); + globalArgs.mode = executionModeFromString(optarg); break; case 'i': @@ -134,6 +105,14 @@ void ArgParser::readArgs(char** argv, int argc) globalArgs.mixer = _NO_MIXER; break; + case 'C': + globalArgs.service = _TESTER; + break; + + case 'v': + globalArgs.l_level = logFromString(optarg); + break; + case 'h': help(); break; @@ -155,9 +134,9 @@ void ArgParser::readArgs(char** argv, int argc) /* Mostra os argumentos restantes depois das opções de linha de comando */ if (optind < argc) { - printf("non-option ARGV-elements: "); + printf("non-option ARGV-elements:\n"); while (optind < argc) - printf("%s ", argv[optind++]); + printf("%s\n", argv[optind++]); } } @@ -184,12 +163,84 @@ void ArgParser::help() throw lavidlib::RuntimeException(); //para nao iniciar o vlibras } -void ArgParser::returnErr(string option) +void ArgParser::returnErr(const string& option) { cout << "Option '" << option << "' contains an invalid argument." << endl; throw lavidlib::RuntimeException(); } +util::logLevel ArgParser::logFromString(const string& level) +{ + if(level == "quiet") + return util::_QUIET; + if(level == "debug") + return util::_DEBUG; + if(level == "info") + return util::_INFO; + if(level == "warning") + return util::_WARNING; + if(level == "error") + return util::_ERROR; + + return util::_INFO;//default +} + +ArgParser::Languages ArgParser::languageFromString(const string& language) +{ + if(language == "portugues") + return _PORTUGUESE; + if(language == "libras") + return _GLOSA; + + returnErr("--language"); +} + +ArgParser::Positions ArgParser::positionFromString(const string& position) +{ + if(position == "top_left") + return _TOP_LEFT; + if(position == "top_right") + return _TOP_RIGHT; + if(position == "bottom_right") + return _BOTTOM_RIGHT; + if(position == "bottom_left") + return _BOTTOM_LEFT; + + returnErr("--position"); +} + +ArgParser::Resolution ArgParser::resolutionFromString(const string& resolution) +{ + if(resolution == "small") + return _SMALL; + if(resolution == "medium") + return _MEDIUM; + if(resolution == "large") + return _LARGE; + + returnErr("--resolution"); +} + +ArgParser::Background ArgParser::backgroundFromString(const string& back) +{ + if(back == "opaque") + return _OPAQUE; + if(back == "transp") + return _TRANSPARENT; + + returnErr("--background"); +} + +ArgParser::Mode ArgParser::executionModeFromString(const string& mode) +{ + if(mode == "prod") + return _PROD; + if(mode == "devel") + return _DEVEL; + + returnErr("--mode"); +} + int ArgParser::getService() { return globalArgs.service; @@ -238,4 +289,9 @@ string ArgParser::getInputSRT() string ArgParser::getId() { return globalArgs.id; +} + +util::logLevel ArgParser::getLog() +{ + return globalArgs.l_level; } \ No newline at end of file diff --git a/util/src/include/argParser.h b/util/src/include/argParser.h index 550169c..ad9139f 100644 --- a/util/src/include/argParser.h +++ b/util/src/include/argParser.h @@ -7,6 +7,7 @@ #include #include #include +#include "logging.h" #include #define MAX_SIZE_PATH 256 @@ -30,12 +31,13 @@ public: string getInput(); string getInputSRT(); string getId(); + util::logLevel getLog(); private: - enum Services { _VIDEO_WITH_SRT = 1, _REC_VIDEO, _TEXT, _ONLY_SRT, _REC_AUDIO, _WITHOUT_MIXER }; + enum Services { _VIDEO_WITH_SRT = 1, _REC_VIDEO, _TEXT, _ONLY_SRT, _REC_AUDIO, _WITHOUT_MIXER, _TESTER }; enum Languages { _PORTUGUESE = 1, _GLOSA }; enum Positions { _TOP_LEFT = 1, _TOP_RIGHT, _BOTTOM_RIGHT, _BOTTOM_LEFT }; - enum Sizes { _SMALL = 1, _MEDIUM, _LARGE }; + enum Resolution { _SMALL = 1, _MEDIUM, _LARGE }; enum Background { _OPAQUE, _TRANSPARENT }; enum Options { _NO_MIXER = 1 }; enum Mode { _DEVEL = 1 , _PROD }; @@ -44,17 +46,24 @@ private: Services service; Languages language; Positions position; - Sizes size; + Resolution size; Background back; Options mixer; Mode mode; string input; string input_srt; string id; + util::logLevel l_level; }globalArgs; void help(); - void returnErr(string option); + void returnErr(const string& option); + Languages languageFromString(const string& language); + Positions positionFromString(const string& position); + Resolution resolutionFromString(const string& resolution); + Background backgroundFromString(const string& backg); + Mode executionModeFromString(const string& mode); + util::logLevel logFromString(const string& level); }; #endif /* ARG_PARSER_H */ \ No newline at end of file diff --git a/util/src/include/dprintf.h b/util/src/include/dprintf.h deleted file mode 100644 index ddd2c5d..0000000 --- a/util/src/include/dprintf.h +++ /dev/null @@ -1,79 +0,0 @@ -#ifndef __DPRINTF_H__ -#define __DPRINTF_H__ - -/* A macro DEBUG_LEVEL determina o nivel de debugging - * A seguinte regra eh utilizada: - * - * DEBUG_LEVEL >= 3: Apenas DDDPRINTF serah compilada. - * DEBUG_LEVEL >= 2: DDDPRINTF E DDPRINTF serao compiladas. - * DEBUG_LEVEL >= 1: DDDPRINTF, DDPRINTF e DPRINTF serao compiladas. - * DEBUG_LEVEL == 0: Nada sera compilado. */ - -#include - -/* tamanho maximo (em bytes) do arquivo de log (1M) */ -//#define TAMANHO_MAXIMO_LOG 1048576 -#define TAMANHO_MAXIMO_LOG 5242880 - - #define _DPRINTF_ERROR "\033[30m" - #define _DPRINTF_WARN "\033[33m" - #define _DPRINTF_INFO "\033[32m" - #define _DPRINTF_FAIL "\033[31m" - #define _DPRINTF_END "\033[0m" - -#define _DPRINTF_NOP(format, ...) do { } while (0) - -#ifdef DEBUG_LEVEL - - #if DEBUG_LEVEL & 4 - #define DDDPRINTF(format, ...) { \ - fprintf(stderr, \ - _DPRINTF_ERROR"%s::%s [%d] -> "_DPRINTF_END format, \ - __FILE__, __FUNCTION__, __LINE__, ## __VA_ARGS__); \ - } - - #else /* !DEBUG_LEVEL > 2 */ - #define DDDPRINTF _DPRINTF_NOP - #endif /* DEBUG_LEVEL > 2 */ - - #if DEBUG_LEVEL & 2 - #define DDPRINTF(format, ...) { \ - fprintf(stderr, \ - _DPRINTF_WARN"%s::%s [%d] -> "_DPRINTF_END format, \ - __FILE__, __FUNCTION__, __LINE__, ## __VA_ARGS__); \ - } - -#else /* !DEBUG_LEVEL > 1 */ - #define DDPRINTF _DPRINTF_NOP - #endif /* DEBUG_LEVEL > 1 */ - - #if DEBUG_LEVEL & 1 - #define DPRINTF(format, ...) { \ - fprintf(stderr, \ - _DPRINTF_INFO"%s::%s [%d] -> "_DPRINTF_END format, \ - __FILE__, __FUNCTION__, __LINE__, ## __VA_ARGS__); \ - } - - #else /* !DEBUG_LEVEL > 0 */ - #define DPRINTF _DPRINTF_NOP - #endif /* DEBUG_LEVEL > 0 */ - - #if DEBUG_LEVEL & 1 - #define DDDDPRINTF(format, ...) { \ - fprintf(stderr, \ - _DPRINTF_FAIL"%s::%s [%d] -> "_DPRINTF_END format, \ - __FILE__, __FUNCTION__, __LINE__, ## __VA_ARGS__); \ - } - - #else /* !DEBUG_LEVEL > 0 */ - #define DDDDPRINTF _DPRINTF_NOP - #endif /* DEBUG_LEVEL > 0 */ - -#else /* DEBUG_LEVEL */ - #define DPRINTF _DPRINTF_NOP - #define DDPRINTF _DPRINTF_NOP - #define DDDPRINTF _DPRINTF_NOP -#endif /* ! DEBUG_LEVEL */ - -#endif /* __DPRINTF_H__ */ - diff --git a/util/src/include/logger.h b/util/src/include/logger.h deleted file mode 100644 index ed54bf5..0000000 --- a/util/src/include/logger.h +++ /dev/null @@ -1,52 +0,0 @@ -/*************************************************************************** - * Universidade Federal da Paraíba * - * Copyright (C) 2014 by Laboratório de Aplicações de Vídeo Digital * - * * - * Centro de Informática - UFPB - Campus I * - * João Pessoa - PB - Brasil * - * * - * Author: Erickson Silva (erickson.silva@lavid.ufpb.br) * - * * - **************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include -//#include - - -#ifndef _LOGGER_H_ -#define _LOGGER_H_ - -using namespace std; - -namespace Util { - - class Logger { - public: - static Logger* Instance(); - void openLogFile(); - void writeLog(char* log); - void closeLogFile(); - char* getTime(); - - private: - Logger() ; // Private so that it can not be called - Logger(Logger const&){}; // copy constructor is private - Logger& operator=(Logger const&){}; // assignment operator is private - static Logger* m_pInstance; - ofstream file; - - - }; - - -} - - -#endif diff --git a/util/src/include/logging.h b/util/src/include/logging.h new file mode 100644 index 0000000..37fd564 --- /dev/null +++ b/util/src/include/logging.h @@ -0,0 +1,61 @@ +#ifndef LOGGING_H +#define LOGGING_H + +#include +#include +#include +#include + +#define _ERROR_ "\033[31m" +#define _DEBUG_ "\033[30m" +#define _WARN_ "\033[33m" +#define _INFO_ "\033[32m" +#define _END_ "\033[0m" +#define LOG_FILE "vlibras_user/vlibras-core/log/log" + +namespace util { + + enum logLevel { _QUIET , _ERROR, _WARNING, _INFO, _DEBUG}; + + class Logging { + public: + static Logging* instance(); + logLevel getLevel(); + void setLevel(logLevel level); + void writeLog(const char* logMsg); + + private: + Logging(){}; + Logging(Logging const&){}; + Logging& operator=(Logging const&){}; + + static Logging* l_instance; + static logLevel l_level; + FILE* l_file; + + char* getTime(); + }; + + #define printl(level, format, ... ) { \ + logLevel llevel; \ + llevel = Logging::instance()->getLevel(); \ + if(level <= llevel){ \ + switch(level){ \ + case _DEBUG: \ + fprintf(stdout, _DEBUG_"%s::%s<%d>: "_END_ format, __FILE__, __FUNCTION__, __LINE__, ## __VA_ARGS__); \ + break; \ + case _INFO: \ + fprintf(stdout, _INFO_"%s::%s<%d>: "_END_ format, __FILE__, __FUNCTION__, __LINE__, ## __VA_ARGS__); \ + break; \ + case _WARNING: \ + fprintf(stdout, _WARN_"%s::%s<%d>: "_END_ format, __FILE__, __FUNCTION__, __LINE__, ## __VA_ARGS__); \ + break; \ + case _ERROR: \ + fprintf(stderr, _ERROR_"%s::%s<%d>: "_END_ format, __FILE__, __FUNCTION__, __LINE__, ## __VA_ARGS__); \ + break; \ + } \ + } \ + }//fim da função printl +} + +#endif /* LOGGING_H */ \ No newline at end of file diff --git a/util/src/logger.cpp b/util/src/logger.cpp deleted file mode 100644 index 4527923..0000000 --- a/util/src/logger.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/*************************************************************************** - * Universidade Federal da Paraíba * - * Copyright (C) 2014 by Laboratório de Aplicações de Vídeo Digital * - * * - * Centro de Informática - UFPB - Campus I * - * João Pessoa - PB - Brasil * - * * - * Author: Erickson Silva (erickson.silva@lavid.ufpb.br) * - * * - **************************************************************************/ - -#include "logger.h" - -namespace Util { - - Logger* Logger::m_pInstance = NULL; - - Logger::Logger(){ - } - - Logger* Logger::Instance(){ - if (!m_pInstance) // Only allow one instance of class to be generated. - m_pInstance = new Logger; - - return m_pInstance; - } - - - void Logger::openLogFile(){ - file.open("vlibras_user/vlibras-core/log/log", ios_base::app); - } - - - void Logger::closeLogFile(){ - file.close(); - } - - char* Logger::getTime(){ - time_t curtime; - time(&curtime); - return ctime(&curtime); - } - - void Logger::writeLog(char* exception){ - this->openLogFile(); - file << getTime(); - file << exception << "\n\n\r"; - this->closeLogFile(); - } - -} diff --git a/util/src/logging.cpp b/util/src/logging.cpp new file mode 100644 index 0000000..5fcbd49 --- /dev/null +++ b/util/src/logging.cpp @@ -0,0 +1,38 @@ +#include "logging.h" + +namespace util { + + Logging* Logging::l_instance = NULL; + logLevel Logging::l_level = _INFO; + + Logging* Logging::instance() { + if(!l_instance) + l_instance = new Logging(); + return l_instance; + } + + logLevel Logging::getLevel() { + return this->l_level; + } + + void Logging::setLevel(logLevel level) { + if(level != NULL) + this->l_level = level; + } + + char* Logging::getTime() { + time_t curtime; + time(&curtime); + return ctime(&curtime); + } + + void Logging::writeLog(const char* logMsg) { + l_file = fopen(LOG_FILE, "a"); + + if(l_file == NULL) + return; + + fprintf(l_file, "%s'%s'\n\n\r", getTime() ,logMsg); + fclose(l_file); + } +} \ No newline at end of file -- libgit2 0.21.2