Commit 1e589cff5f3efd5a75c6e0a9500c0d0ea0cb633c

Authored by Wesnydy Ribeiro
1 parent 67e44a37
Exists in master and in 1 other branch devel

Implementação da classe de log e melhorias

Makefile
... ... @@ -28,6 +28,7 @@ INCLUDES= \
28 28  
29 29 utilObjs= \
30 30 argParser.o \
  31 + logging.o \
31 32 logger.o
32 33  
33 34 tradutorObjs = \
... ...
extrator/src/extratorFactory.cpp
1 1 #include "extratorFactory.h"
2 2  
3   -ExtratorFactory::ExtratorFactory(){
4   - //TODO
5   -}
6   -
7   -ExtratorFactory::~ExtratorFactory(){
8   - //TODO
9   -}
10   -
11 3 Extrator* ExtratorFactory::getExtrator(Extrator::ExtratorType extrator_type) {
12 4 extrator = extrator_type;
13 5 switch(extrator){
... ...
extrator/src/extratorSRT.cpp
... ... @@ -5,7 +5,7 @@ ExtratorSRT::ExtratorSRT(){
5 5 finish = false;
6 6 seek_pos = 0;
7 7 hasNextSub = true;
8   - DPRINTF("Done!\n");
  8 + printl(util::_DEBUG, "Done!\n");
9 9 }
10 10  
11 11 ExtratorSRT::~ExtratorSRT(){
... ... @@ -13,7 +13,7 @@ ExtratorSRT::~ExtratorSRT(){
13 13 delete listeners;
14 14 //if (bff_reader) delete bff_reader;
15 15 if (file_io) delete file_io;
16   - DDDPRINTF("ExtratorSTR finalized!\n");
  16 + printl(util::_DEBUG, "ExtratorSTR finalized!\n");
17 17 }
18 18  
19 19 void ExtratorSRT::initialize(){
... ... @@ -24,7 +24,7 @@ void ExtratorSRT::initialize(){
24 24 file_io = new lavidlib::FileIO(file->getPath(), FileIO::MODE_READ);
25 25 }catch(Exception ex){
26 26 finish = true;
27   - Util::Logger::Instance()->writeLog((char*) "[ERRO: extratorSRT.cpp] Arquivo de legenda não encontrado.");
  27 + Logging::instance()->writeLog("extratorSRT.cpp <Error>: Arquivo de legenda não encontrado.");
28 28 throw ExtratorException("Falha ao abrir o arquivo de legenda! Verifique se o mesmo existe.\n");
29 29 }
30 30  
... ... @@ -43,7 +43,7 @@ void ExtratorSRT::notifyListeners(unsigned char* subtitle, int64_t pts) {
43 43 }
44 44  
45 45 void ExtratorSRT::notifyEndExtraction(int size) {
46   - DPRINTF("Extrator SRT concluiu a extração: %d legendas.\n", size);
  46 + printl(util::_DEBUG, "Extrator SRT concluiu a extração: %d legendas.\n", size);
47 47 for(list<ListenerSRT*>::iterator it = listeners->begin(); it != listeners->end(); it++){
48 48 (*it)->notifyEnd(size);
49 49 }
... ... @@ -72,11 +72,9 @@ bool ExtratorSRT::hasNextSubtitle() {
72 72 }
73 73  
74 74 void ExtratorSRT::Run(){
75   - DPRINTF("[AGUARDE] Extraindo Legendas...\n");
76   -
  75 + printl(util::_INFO, "Extraindo Legendas...\n");
77 76 int sub_index = 0;
78 77 string sub_text = "";
79   -
80 78 while(hasNextSubtitle()){
81 79 try{
82 80 subtitle = next();
... ... @@ -94,14 +92,17 @@ void ExtratorSRT::Run(){
94 92  
95 93 Subtitle* ExtratorSRT::next() {
96 94  
97   - if (seek_pos >= file_io->getSize())
98   - throw ExtratorException("[ERRO: extratorSRT.cpp] Esse arquivo já foi lido.");
  95 + if (seek_pos >= file_io->getSize()){
  96 + Logging::instance()->writeLog("extratorSRT.cpp <Error>: Arquivo de legenda já foi lido.");
  97 + throw ExtratorException("Esse arquivo já foi lido.");
  98 + }
99 99  
100 100 file_io->seek(seek_pos);
101 101 try{
102 102 bff_reader = new BufferedReader(file_io);
103 103 }catch(Exception &ex){
104   - throw ExtratorException("[ERRO: extratorSRT.cpp] O BufferedReader não foi inicializado.");
  104 + Logging::instance()->writeLog("extratorSRT.cpp <Error>: BufferedReader não inicializado.");
  105 + throw ExtratorException("O BufferedReader não foi inicializado.");
105 106 }
106 107  
107 108 Subtitle* sub = new Subtitle();
... ...
extrator/src/extratorTXT.cpp
... ... @@ -14,7 +14,7 @@
14 14 ExtratorTXT::ExtratorTXT(){
15 15 listeners = new list<ListenerTXT*>();
16 16 finish = false;
17   - DPRINTF("Done!\n");
  17 + printl(util::_DEBUG, "Done!\n");
18 18 }
19 19  
20 20 ExtratorTXT::~ExtratorTXT(){
... ... @@ -23,7 +23,7 @@ ExtratorTXT::~ExtratorTXT(){
23 23 delete file;
24 24 delete file_io;
25 25 delete bff_reader;
26   - DDDPRINTF("ExtratorTXT finalized!\n");
  26 + printl(util::_DEBUG, "ExtratorTXT finalized!\n");
27 27 }
28 28  
29 29 void ExtratorTXT::initialize(){
... ... @@ -33,7 +33,7 @@ void ExtratorTXT::initialize(){
33 33 bff_reader = new BufferedReader(file_io);
34 34 }catch(Exception &ex){
35 35 finish = true;
36   - Util::Logger::Instance()->writeLog((char*) "[ERRO: extratorTXT.cpp] Arquivo de texto não encontrado.");
  36 + Logging::instance()->writeLog("extratorTXT.cpp <Error>: Arquivo de texto não encontrado.");
37 37 throw ExtratorException("Falha ao abrir o arquivo de texto! Verifique se o mesmo existe.");
38 38 }
39 39 this->Start();
... ... @@ -50,7 +50,7 @@ void ExtratorTXT::notifyListeners(unsigned char* line) {
50 50 }
51 51  
52 52 void ExtratorTXT::notifyEndExtraction(int size) {
53   - DPRINTF("ExtratorTXT concluiu a extração: %d linhas.\n", size);
  53 + printl(util::_DEBUG, "ExtratorTXT concluiu a extração: %d linhas.\n", size);
54 54 for(list<ListenerTXT*>::iterator it = listeners->begin(); it != listeners->end(); it++){
55 55 (*it)->notifyEnd(size);
56 56 }
... ... @@ -75,9 +75,7 @@ bool ExtratorTXT::isFinished(){
75 75 }
76 76  
77 77 void ExtratorTXT::Run(){
78   -
79   - DPRINTF("[AGUARDE] Extraindo Texto...\n")
80   -
  78 + printl(util::_INFO, "Extraindo Texto...\n");
81 79 int line_index = 0;
82 80 bool hasNext = true;
83 81 string line;
... ... @@ -95,7 +93,7 @@ void ExtratorTXT::Run(){
95 93 notifyListeners((unsigned char*)"ARQUIVO_INVALIDO");
96 94 hasNext = false;
97 95 }catch (...){
98   - Util::Logger::Instance()->writeLog((char*) "[ERRO: extratorTXT.cpp] Erro durante a leitura do arquivo de texto.");
  96 + Logging::instance()->writeLog("extratorTXT.cpp <Error>: Erro durante a leitura do arquivo de texto.");
99 97 throw ExtratorException("Falha desconhecida na leitura do arquivo. Tente novamente.");
100 98 }
101 99 }
... ...
extrator/src/include/extrator.h
1 1 #ifndef EXTRATOR_H
2 2 #define EXTRATOR_H
3 3  
  4 +#include "logging.h"
4 5 #include <lavidlib/io/File.h>
5 6 #include <lavidlib/io/FileIO.h>
6 7 #include <lavidlib/io/BufferedReader.h>
7 8 #include <lavidlib/io/IOException.h>
8 9 #include <lavidlib/io/EOFException.h>
9 10  
  11 +using namespace util;
10 12 using namespace lavidlib;
11 13  
12 14 class Extrator {
... ...
extrator/src/include/extratorFactory.h
... ... @@ -8,8 +8,8 @@
8 8 class ExtratorFactory{
9 9  
10 10 public:
11   - ExtratorFactory();
12   - ~ExtratorFactory();
  11 + ExtratorFactory(){};
  12 + ~ExtratorFactory(){};
13 13  
14 14 Extrator* getExtrator(Extrator::ExtratorType extrator_type);
15 15  
... ...
extrator/src/include/extratorSRT.h
... ... @@ -13,8 +13,6 @@
13 13 #include <fstream>
14 14 #include <stdio.h>
15 15 #include "jthread.h"
16   -#include "dprintf.h"
17   -#include "logger.h"
18 16 #include "extrator.h"
19 17 #include "subtitle.h"
20 18 #include "listenerSRT.h"
... ...
extrator/src/include/extratorTXT.h
... ... @@ -14,8 +14,6 @@
14 14  
15 15 #include <list>
16 16 #include "jthread.h"
17   -#include "dprintf.h"
18   -#include "logger.h"
19 17 #include "extrator.h"
20 18 #include "listenerTXT.h"
21 19 #include "extratorException.h"
... ...
input/src/include/inputFile.h
... ... @@ -13,14 +13,14 @@
13 13 #include <stdlib.h>
14 14 #include <fstream>
15 15 #include <string.h>
16   -#include "logger.h"
  16 +#include "logging.h"
17 17 #include "listenerInput.h"
18 18 #include "inputException.h"
19   -#include "dprintf.h"
20 19  
21 20 #define MAX_SIZE_PACKET 188
22 21  
23 22 using namespace std;
  23 +using namespace util;
24 24  
25 25 class InputFile {
26 26  
... ...
input/src/inputFile.cpp
... ... @@ -5,13 +5,13 @@ InputFile::InputFile(char* path) {
5 5 this->path = path;
6 6 this->listeners = new list<ListenerInput*>();
7 7 finish = false;
8   - DPRINTF("Done!\n");
  8 + printl(util::_DEBUG, "Done!\n");
9 9 }
10 10  
11 11 InputFile::~InputFile(){
12 12 listeners->clear();
13 13 delete listeners;
14   - DDDPRINTF("Input finalized!\n");
  14 + printl(util::_DEBUG, "Input finalized!\n");
15 15 }
16 16  
17 17 void InputFile::initialize(){
... ... @@ -20,7 +20,7 @@ void InputFile::initialize(){
20 20 if (strstr(path, ".ts") != NULL) {
21 21 if (filein.is_open()) {
22 22 char buffer [MAX_SIZE_PACKET];
23   - DPRINTF("[AGUARDE] Lendo arquivo...\n")
  23 + printl(util::_INFO, "Lendo arquivo...\n");
24 24 while (!filein.eof()) {
25 25 filein.read(buffer, MAX_SIZE_PACKET);
26 26 unsigned char* packet = (unsigned char*) buffer;
... ... @@ -31,7 +31,7 @@ void InputFile::initialize(){
31 31 //finished = true;
32 32 } else {
33 33 finish = true;
34   - Util::Logger::Instance()->writeLog((char*) "[ERRO: inputFile.cpp] Arquivo de vídeo não encontrado.");
  34 + Logging::instance()->writeLog("inputFile.cpp <Error>: Arquivo de vídeo não encontrado.");
35 35 throw InputException("Falha ao abrir o arquivo de vídeo! Verifique se o mesmo existe.");
36 36 }
37 37 }
... ...
main.cpp
... ... @@ -11,21 +11,25 @@
11 11 *
12 12 * Edit on 03 de Fevereiro de 2014
13 13 */
  14 +#include <stdlib.h>
  15 +#include <string.h>
  16 +#include <sys/time.h>
  17 +#include "logging.h"
  18 +#include "argParser.h"
  19 +#include "serviceTester.h"
  20 +#include "serviceException.h"
14 21 #include "serviceWindowGenerationFromSRT.h"
15 22 #include "serviceWindowGenerationFromRec.h"
16 23 #include "serviceWindowGenerationFromText.h"
17   -#include "serviceException.h"
18 24 #include <lavidlib/base/RuntimeException.h>
19   -#include "argParser.h"
20   -#include <sys/time.h>
21   -#include <stdlib.h>
22 25  
23 26 #define MAX_SIZE_PATH 256
  27 +#define PATH_VBOX_UPLOADS "vlibras_user/.vlibras-config/uploads"
24 28 #define PATH_DEVEL_CONTENTS "vlibras_user/vlibras-contents/videos"
25 29 #define PATH_DEVEL_UPLOADS "vlibras_user/vlibras-contents/uploads"
26   -#define PATH_VBOX_UPLOADS "vlibras_user/.vlibras-config/uploads"
27 30  
28 31 using namespace std;
  32 +using namespace util;
29 33  
30 34 void serviceSRT(int service, string path_video, string path_srt, int language, int position, int size, int background, string id, int mode);
31 35 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
37 41 void hasFailed();
38 42 void hasInvalid();
39 43 void fail(string msg);
  44 +//void runTests();
40 45 void setPathContents(int mode, string id);
41 46  
42 47 bool isFailed;
... ... @@ -71,13 +76,14 @@ int main(int argc, char* argv[]) {
71 76 exit(1);
72 77 }
73 78  
74   - printf("\n################## LAViD : VLibras ##################\n\n");
  79 + //printf("\n################## LAViD : VLibras ##################\n\n");
75 80  
76 81 service = parser->getService();
  82 + util::Logging::instance()->setLevel(parser->getLog());
77 83  
78 84 switch(service){
79 85 case 1:
80   - DDPRINTF("Service Type: Video with Subtitles\n");
  86 + printl(util::_INFO, "Service Type: Video with Subtitles\n");
81 87 input = parser->getInput();
82 88 input_srt = parser->getInputSRT();
83 89 language = parser->getLanguage();
... ... @@ -90,7 +96,7 @@ int main(int argc, char* argv[]) {
90 96 break;
91 97  
92 98 case 2:
93   - DDPRINTF("Service Type: Video Recognize\n");
  99 + printl(util::_INFO, "Service Type: Video Recognize\n");
94 100 input = parser->getInput();
95 101 position = parser->getPosition();
96 102 size = parser->getSize();
... ... @@ -101,7 +107,7 @@ int main(int argc, char* argv[]) {
101 107 break;
102 108  
103 109 case 3:
104   - DDPRINTF("Service Type: Text\n");
  110 + printl(util::_INFO, "Service Type: Text\n");
105 111 input = parser->getInput();
106 112 language = parser->getLanguage();
107 113 background = parser->getBackground();
... ... @@ -111,7 +117,7 @@ int main(int argc, char* argv[]) {
111 117 break;
112 118  
113 119 case 4:
114   - DDPRINTF("Service Type: Subtitles only\n");
  120 + printl(util::_INFO, "Service Type: Subtitles only\n");
115 121 input = parser->getInput();
116 122 language = parser->getLanguage();
117 123 background = parser->getBackground();
... ... @@ -121,7 +127,7 @@ int main(int argc, char* argv[]) {
121 127 break;
122 128  
123 129 case 5: //reconhecimento de audio
124   - DDPRINTF("Service Type: Audio Recognize\n");
  130 + printl(util::_INFO, "Service Type: Audio Recognize\n");
125 131 input = parser->getInput();
126 132 background = parser->getBackground();
127 133 id = parser->getId();
... ... @@ -130,7 +136,7 @@ int main(int argc, char* argv[]) {
130 136 break;
131 137  
132 138 case 6: //Reconhecimento de video sem mixagem
133   - DDPRINTF("Service Type: Video Recognize (Mixer Disabled)\n");
  139 + printl(util::_INFO, "Service Type: Video Recognize (Mixer Disabled)\n");
134 140 input = parser->getInput();
135 141 background = parser->getBackground();
136 142 id = parser->getId();
... ... @@ -138,8 +144,12 @@ int main(int argc, char* argv[]) {
138 144 serviceREC(service, input, 0, 0, background, id, mode);//como service != 2 então não há mixagem
139 145 break;
140 146  
  147 + case 7:
  148 + cout << "Serviço sendo implementado!" << endl;
  149 + break;
  150 +
141 151 default:
142   - printf("\nOpção de serviço não reconhecida!\n");
  152 + printf("Opção de serviço não reconhecida!\n");
143 153 hasInvalid();
144 154 }
145 155  
... ... @@ -150,8 +160,8 @@ int main(int argc, char* argv[]) {
150 160  
151 161 gettimeofday(&tv2, NULL);
152 162 t2 = (double)(tv2.tv_sec) + (double)(tv2.tv_usec)/ 1000000.00;
153   - DDPRINTF("Time: %lf\n", (t2-t1));
154   - DDPRINTF("VLibras finalized!\n\n");
  163 + printl(util::_DEBUG, "Time: %lf\n", (t2-t1));
  164 + printl(util::_INFO, "VLibras finalized!\n\n");
155 165 exit(0);
156 166 }
157 167  
... ... @@ -272,9 +282,8 @@ void serviceOnlySRT(int service, string path_srt, int language, int background,
272 282 }
273 283  
274 284 void fail(string msg){
275   - printf("\n");
276   - DDDDPRINTF("Ops... Tivemos um problema! :(\n");
277   - DDDDPRINTF("Possível causa do erro: %s\n\n", msg.c_str());
  285 + printl(util::_ERROR, "\nOps... Tivemos um problema! :(\n");
  286 + printl(util::_ERROR, "Possível causa do erro: %s\n\n", msg.c_str());
278 287 }
279 288  
280 289 void hasFailed(){
... ... @@ -296,4 +305,4 @@ void setPathContents(int mode, string id){
296 305 exit(127);
297 306 }
298 307 system(command.c_str());
299 308 -}
  309 +}
300 310 \ No newline at end of file
... ...
mixer/src/Mixer.cpp
... ... @@ -9,16 +9,16 @@
9 9 /* Construtores e destrutores...*/
10 10 Mixer::Mixer() {
11 11 this->setNumThreads("1");
12   - DPRINTF("Done!\n");
  12 + printl(util::_DEBUG, "Done!\n");
13 13 }
14 14 Mixer::Mixer(string mainVideo, string secondaryVideo) {
15 15 this->setMainVideo(mainVideo);
16 16 this->setSecondaryVideo(secondaryVideo);
17 17 this->setNumThreads("1");
18   - DPRINTF("Done!\n");
  18 + printl(util::_DEBUG, "Done!\n");
19 19 }
20 20 Mixer::~Mixer() {
21   - DDDPRINTF("Mixer finalized!\n");
  21 + printl(util::_DEBUG, "Mixer finalized!\n");
22 22 }
23 23 /* FIM de Construtores e destrutores...*/
24 24  
... ... @@ -27,7 +27,7 @@ Mixer::~Mixer() {
27 27 void Mixer::initialize(string mainVideo, string slVideo, int positionSecondaryVideo, int sizeSecondaryVideo,
28 28 int transparency, char* _id, char* path_uploads, char* path_contents){
29 29  
30   - DPRINTF("[AGUARDE] Mixando...\n")
  30 + printl(util::_INFO, "Mixando...\n");
31 31 uploads = path_uploads;
32 32 contents = path_contents;
33 33 stringstream ss;
... ...
mixer/src/include/Mixer.h
... ... @@ -16,7 +16,7 @@
16 16 #include <sstream>
17 17 #include <string>
18 18 #include <fstream>
19   -#include "dprintf.h"
  19 +#include "logging.h"
20 20  
21 21 //SL Video Position
22 22 #define TOP_LEFT 1
... ... @@ -35,6 +35,7 @@
35 35 #define MAX_SIZE_PATH 256
36 36  
37 37 using namespace std;
  38 +using namespace util;
38 39  
39 40 class Mixer {
40 41 public:
... ...
recognize/src/include/recognize.h
... ... @@ -16,8 +16,7 @@
16 16 #include <iterator>
17 17 #include <sys/stat.h>
18 18 #include <lavidlib/io/FileIO.h>
19   -#include "dprintf.h"
20   -#include "logger.h"
  19 +#include "logging.h"
21 20 #include "recognizeListener.h"
22 21 #include "recognizeException.h"
23 22  
... ... @@ -51,6 +50,7 @@
51 50  
52 51 using namespace jthread;
53 52 using namespace std;
  53 +using namespace util;
54 54  
55 55 class Recognize: public Thread {
56 56  
... ...
recognize/src/recognize.cpp
... ... @@ -11,7 +11,7 @@ Recognize::Recognize(char* _pathVideo, char* _id) {
11 11 ss << _id;
12 12 ss >> id;
13 13 confidenceRate=CONFIDENCE_RATE;
14   - DPRINTF("Done!\n");
  14 + printl(util::_DEBUG, "Done!\n");
15 15 }
16 16  
17 17 Recognize::Recognize(char* _pathVideo, char* _id, char* rate) {
... ... @@ -27,7 +27,7 @@ Recognize::Recognize(char* _pathVideo, char* _id, char* rate) {
27 27 istringstream(rate) >> confidenceRate;
28 28 if (confidenceRate == 0)
29 29 confidenceRate=CONFIDENCE_RATE;
30   - DPRINTF("Done!\n");
  30 + printl(util::_DEBUG, "Done!\n");
31 31 }
32 32  
33 33 Recognize::Recognize(char* _pathVideo, int _inputType, char* _id) {
... ... @@ -38,26 +38,26 @@ Recognize::Recognize(char* _pathVideo, int _inputType, char* _id) {
38 38 frequency = FREQUENCY_PATTERN;
39 39 sizeBlocs = BLOCS_PATTERN;
40 40 id = _id;
41   - DPRINTF("Done!\n");
  41 + printl(util::_DEBUG, "Done!\n");
42 42 }
43 43  
44 44 Recognize::~Recognize() {
45 45 listeners->clear();
46 46 delete listeners;
47   - DDDPRINTF("Recognize finalized!\n");
  47 + printl(util::_DEBUG, "Recognize finalized!\n");
48 48 }
49 49  
50 50  
51 51 void Recognize::initialize() {
52 52  
53   - DPRINTF("Recognizing...\n");
  53 + printl(util::_INFO, "Reconhecendo áudio...\n");
54 54 /**printf("*** Initialized Recognition ***\n\nVideo: %s\nType [1-File; 2-Mic]: %d\nFrequency: %d\n\n",
55 55 this->pathVideo, this->inputType, this->frequency);**/
56 56  
57 57 ifstream file(pathVideo, ifstream::binary);
58 58 if(!file.is_open()){
59 59 finish = true;
60   - Util::Logger::Instance()->writeLog((char*) "[ERRO: recognize.cpp] Arquivo não encontrado.");
  60 + Logging::instance()->writeLog("recognize.cpp <Error> Arquivo não encontrado.");
61 61 throw RecognizeException("Falha ao abrir o arquivo! Verifique se o mesmo existe.");
62 62 }
63 63 this->Start();
... ... @@ -378,7 +378,7 @@ void Recognize::notifyListeners(char* text, int64_t pts) {
378 378 }
379 379  
380 380 void Recognize::notifyEndExtraction(int sentences_size) {
381   - DPRINTF("Recognizer concluiu o reconhecimento: %d sentenças.\n", sentences_size);
  381 + printl(util::_DEBUG, "Recognizer concluiu o reconhecimento: %d sentenças.\n", sentences_size);
382 382 for(list<RecognizeListener*>::iterator it = listeners->begin(); it != listeners->end(); it++){
383 383 (*it)->notifyEnd(sentences_size);
384 384 }
... ...
renderer/src/include/renderer.h
... ... @@ -2,7 +2,7 @@
2 2 #define RENDERER_H
3 3  
4 4 #include "jthread.h"
5   -#include "dprintf.h"
  5 +#include "logging.h"
6 6 #include "string.h"
7 7 #include <string>
8 8 #include <list>
... ... @@ -26,6 +26,7 @@
26 26 using namespace lavidlib;
27 27 using namespace jthread;
28 28 using namespace std;
  29 +using namespace util;
29 30  
30 31 class Renderer : public Thread {
31 32 public:
... ...
renderer/src/renderer.cpp
... ... @@ -3,20 +3,20 @@
3 3 Renderer::Renderer(char* videoPath, char* user_id) {
4 4 this->folder_id = user_id;
5 5 this->path_video = videoPath;
6   - serverInitialize();
7 6 running = true;
8 7 count_task = 0;
9 8 glosa_processed = 0;
10 9 core_socket = new StreamSocket();
11 10 listeners = new list<ListenerRenderer*>();
12   - DPRINTF("Done!\n");
  11 + serverInitialize();
  12 + printl(util::_DEBUG, "Done!\n");
13 13 }
14 14  
15 15 Renderer::~Renderer() {
16 16 listeners->clear();
17 17 delete listeners;
18 18 if(core_socket) delete core_socket;
19   - DDDPRINTF("Renderer finalized!\n");
  19 + printl(util::_DEBUG, "Renderer finalized!\n");
20 20 }
21 21  
22 22 void Renderer::serverInitialize(){
... ... @@ -33,7 +33,7 @@ void Renderer::serverInitialize(){
33 33  
34 34 command.append(" && ").append(render);
35 35 system(command.c_str());
36   - sleep(3);
  36 + sleep(5);
37 37 }
38 38  
39 39 void Renderer::receiveGlosa(std::string glosa, int64_t pts) {
... ... @@ -51,6 +51,9 @@ void Renderer::receiveGlosa(std::string glosa, int64_t pts) {
51 51  
52 52 void Renderer::sendGlosa() {
53 53 try{
  54 + // while(!core_socket->isConnected())
  55 + // sleep(1);
  56 +
54 57 int glosa_size = strlen(glosa_copy.c_str())+1;
55 58 char* glosa_buffer = new char[glosa_size];
56 59 strcpy(glosa_buffer, glosa_copy.c_str());
... ... @@ -75,7 +78,10 @@ void Renderer::sendGlosa() {
75 78 void Renderer::connectToUnity() {
76 79 try{
77 80 static InetAddress* addr = InetAddress::createByName(HOST);
78   - core_socket->connect(addr, PORTNO);
  81 + while(!core_socket->isConnected()){
  82 + core_socket->connect(addr, PORTNO);
  83 + sleep(1);
  84 + }
79 85 }catch(lavidlib::UnknownHostException &ex){
80 86 throw RuntimeException(ex.getMessage().c_str());
81 87 }catch(lavidlib::SocketException &ex){
... ... @@ -84,7 +90,7 @@ void Renderer::connectToUnity() {
84 90 }
85 91  
86 92 void Renderer::waitScreenShots() {
87   - DPRINTF("[AGUARDE] Gerando vídeo...\n");
  93 + printl(util::_INFO, "Gerando vídeo...\n");
88 94 char* endgeneration = new char[strlen(END_FLAG)+1];
89 95 int connected;
90 96 try{
... ... @@ -135,7 +141,8 @@ void Renderer::Run() {
135 141 render();
136 142 cleanFiles();
137 143 }catch(lavidlib::RuntimeException &ex){
138   - DDDDPRINTF("Erro: %s\n", ex.getMessage().c_str());
  144 + printl(util::_ERROR, "%s\n", ex.getMessage().c_str());
  145 + Logging::instance()->writeLog("renderer.cpp <Error>: Falha na comunicação com o Unity player");
139 146 throw RuntimeException(ex.getMessage().c_str());
140 147 }
141 148 }
... ...
servico/src/include/serviceTester.h 0 → 100644
... ... @@ -0,0 +1,64 @@
  1 +#ifndef SERVICETESTER_H
  2 +#define SERVICETESTER_H
  3 +
  4 +#include <iostream>
  5 +#include <json/json.h>
  6 +#include <lavidlib/io/File.h>
  7 +#include <lavidlib/io/FileIO.h>
  8 +#include "serviceException.h"
  9 +#include "serviceWindowGenerationFromRec.h"
  10 +#include "serviceWindowGenerationFromSRT.h"
  11 +#include "serviceWindowGenerationFromText.h"
  12 +
  13 +// path dos arquivos de teste
  14 +#define PATH_VID "/home/user/.vlibras-config/test/uploads/test_video.mp4"
  15 +#define PATH_SRT "/home/user/.vlibras-config/test/uploads/test_srt.srt"
  16 +#define PATH_TXT "/home/user/.vlibras-config/test/uploads/test_text.txt"
  17 +#define OUTPUT_FILE "/home/user/.vlibras-config/test/videos/Test.mp4"
  18 +#define TESTER_ID "Test"
  19 +#define MODE_TEST 3
  20 +
  21 +using namespace std;
  22 +
  23 +class ServiceTester: public Thread {
  24 +
  25 +public:
  26 + ServiceTester();
  27 + ~ServiceTester();
  28 +
  29 + bool isFinished();
  30 +
  31 + int checkServiceSRT();
  32 + int checkServiceText();
  33 + int checkServiceRec();
  34 +private:
  35 +
  36 + int language;
  37 + int position;
  38 + int resolution;
  39 + int background;
  40 +
  41 + bool fail;
  42 + bool finish;
  43 + string msgErr;
  44 +
  45 + File* fIn;
  46 + File* fOut;
  47 + FileIO* fIO_in;
  48 + FileIO* fIO_out;
  49 +
  50 + ServiceWindowGenerationFromRec* service_rec;
  51 + ServiceWindowGenerationFromSRT* service_srt;
  52 + ServiceWindowGenerationFromText* service_text;
  53 +
  54 + void serviceSRT(int service, string path_video, string path_srt, int language, int position, int size, int background, string id, int mode);
  55 + void serviceREC(int service, string path_video, int position, int size, int background, string id, int mode);
  56 + void serviceText(string path_text, int language, int background, string id, int mode);
  57 +
  58 + void Run();
  59 + bool checkFiles(string fileIn, string fileOut);
  60 + void hasFailed(string msgerr);
  61 + void deleteFiles();
  62 +};
  63 +
  64 +#endif /* SERVICETESTER_H */
0 65 \ No newline at end of file
... ...
servico/src/include/serviceWindowGeneration.h
... ... @@ -8,7 +8,7 @@
8 8 #include <sstream>
9 9 #include <locale>
10 10 #include "jthread.h"
11   -#include "dprintf.h"
  11 +#include "logging.h"
12 12 #include "Mixer.h"
13 13 #include "renderer.h"
14 14 #include "listenerRenderer.h"
... ... @@ -20,16 +20,21 @@
20 20  
21 21 #define DEVELOPER 1
22 22 #define PRODUCTION 2
  23 +#define TESTER 3
23 24 #define PATH_DEVEL_CONTENTS "vlibras_user/vlibras-contents/videos"
24 25 #define PATH_DEVEL_UPLOADS "vlibras_user/vlibras-contents/uploads"
  26 +#define PATH_TESTER_CONTENTS "vlibras_user/vlibras-config/test/videos"
  27 +#define PATH_TESTER_UPLOADS "vlibras_user/vlibras-config/test/uploads"
25 28 #define PATH_VBOX_UPLOADS "vlibras_user/.vlibras-config/uploads"
26 29 #define PATH_CONF_FILE "vlibras_user/.vlibras-config/params.json"
  30 +#define PATH_TESTER_FILE "/home/user/.vlibras-config/test/tester.json"
27 31 #define MAX_SIZE_PATH 256
28 32  
29 33 using namespace Tradutor;
30 34 using namespace jthread;
31 35 using namespace std;
32 36 using namespace lavidlib;
  37 +using namespace util;
33 38  
34 39 class ServiceWindowGeneration {
35 40  
... ...
servico/src/serviceTester.cpp 0 → 100644
... ... @@ -0,0 +1,141 @@
  1 +#include "serviceTester.h"
  2 +
  3 +ServiceTester::serviceTester(int _language, int _position, int _size, int _background) {
  4 + language = _language;
  5 + position = _position;
  6 + size = _size;
  7 + background = _background;
  8 + msgErr = "";
  9 + finish = false;
  10 + fail = false;
  11 + printl(util::_DEBUG, "Done!\n");
  12 +}
  13 +
  14 +ServiceTester::~serviceTester() {
  15 + printl(util::_DEBUG, "ServiceTester Finalized!\n");
  16 +}
  17 +
  18 +void ServiceTester::checkServiceSRT() {
  19 + service_srt = new ServiceWindowGenerationFromSRT(PATH_VID, PATH_SRT, language, position, size, background, TESTER_ID, MODE_TEST, 1);
  20 +
  21 + try{
  22 + service_srt->initialize();
  23 + }catch(ServiceException &ex){
  24 + msgErr += "Extração de legenda\n";
  25 + fail = true
  26 + return;
  27 + }
  28 +
  29 + while(!service_srt->isFinished())
  30 + sleep(5);
  31 + delete service_srt;
  32 +
  33 + bool sucess;
  34 + sucess = checkFiles(PATH_VID, FILE_OUT_SRT);
  35 + if(!sucess){
  36 + msgErr += "Extração de legenda\n";
  37 + }
  38 + deleteFiles();
  39 +}
  40 +
  41 +void ServiceTester::checkServiceRec() {
  42 + service_rec = new ServiceWindowGenerationFromRec(PATH_VID, position, size, background, TESTER_ID, MODE_TEST, 2);
  43 +
  44 + try{
  45 + service_rec->initialize();
  46 + }catch(ServiceException &ex){
  47 + msgErr += "Reconhecimento\n";
  48 + fail = true;
  49 + return;
  50 + }
  51 +
  52 + while(!service_rec->isFinished())
  53 + sleep(5);
  54 + delete service_rec;
  55 +
  56 + bool sucess;
  57 + sucess = checkFiles(PATH_VID, FILE_OUT_REC);
  58 + if(!sucess){
  59 + msgErr += "Reconhecimento\n";
  60 + }
  61 + deleteFiles();
  62 +}
  63 +void ServiceTester::checkServiceText() {
  64 + service_text = new ServiceWindowGenerationFromText(PATH_TXT, language, background, TESTER_ID, MODE_TEST);
  65 +
  66 + try{
  67 + service_text->initialize();
  68 + }catch(ServiceException &ex){
  69 + msgErr += "Extração de texto\n"
  70 + fail = true;
  71 + return;
  72 + }
  73 +
  74 + while (!service_text->isFinished())
  75 + usleep(100000); //100ms
  76 + delete service_text;
  77 +
  78 + bool sucess;
  79 + sucess = checkFiles(PATH_TXT, FILE_OUT_TXT);
  80 + if(!sucess){
  81 + msgErr += "Extração de texto\n"
  82 + }
  83 + deleteFiles();
  84 +}
  85 +
  86 +bool ServiceTester::checkFiles(string fileIn, string fileOut) {
  87 + int64_t inSize;
  88 + int64_t outSize;
  89 + fIn = new lavidlib::File(fileIn);
  90 + fOut = new lavidlib::File(fileOut);
  91 +
  92 + try{
  93 + fIO_in = new lavidlib::FileIO(fIn->getPath(), FileIO::MODE_READ);
  94 + fIO_out = new lavidlib::FileIO(fOut->getPath(), FileIO::MODE_READ);
  95 + }catch(Exception &ex){
  96 + delete fIn;
  97 + delete fOut;
  98 + fail = true;
  99 + return false;
  100 + }
  101 +
  102 + inSize = fIO_in->getSize();
  103 + outSize = fIO_out->getSize();
  104 +
  105 + delete fIn;
  106 + delete fOut;
  107 + delete fIO_in;
  108 + delete fIO_out;
  109 +
  110 + if(outSize != 0 && outSize != inSize)
  111 + return true;
  112 +
  113 + fail = true;
  114 + return false;
  115 +}
  116 +
  117 +bool ServiceTester::isFinished(){
  118 + return this->finish;
  119 +}
  120 +
  121 +void hasFailed() {
  122 + return fail;
  123 +}
  124 +
  125 +void ServiceTester::deleteFiles() {
  126 + string command = "rm -f ";
  127 + command += OUTPUT_FILE;
  128 + system(command);
  129 +}
  130 +
  131 +void ServiceTester::Run() {
  132 + printl(util::_INFO, "Verificando módulos, aguarde...\n");
  133 + checkServiceSRT();
  134 + checkServiceRec();
  135 + checkServiceText();
  136 +
  137 + if(hasFailed())
  138 + throw ServiceException(msgErr);
  139 +
  140 + finish = true;
  141 +}
0 142 \ No newline at end of file
... ...
servico/src/serviceWindowGenerationFromRec.cpp
... ... @@ -17,7 +17,7 @@ ServiceWindowGenerationFromRec::ServiceWindowGenerationFromRec(
17 17 tradutor = new TradutorPortGlosa();
18 18 running = true;
19 19 finish = false;
20   - DPRINTF("Done!\n");
  20 + printl(util::_DEBUG, "Done!\n");
21 21 }
22 22  
23 23 ServiceWindowGenerationFromRec::ServiceWindowGenerationFromRec(
... ... @@ -42,7 +42,7 @@ ServiceWindowGenerationFromRec::ServiceWindowGenerationFromRec(
42 42 }
43 43 running = true;
44 44 finish = false;
45   - DPRINTF("Done!\n");
  45 + printl(util::_DEBUG, "Done!\n");
46 46 }
47 47  
48 48 ServiceWindowGenerationFromRec::~ServiceWindowGenerationFromRec(){
... ... @@ -51,32 +51,47 @@ ServiceWindowGenerationFromRec::~ServiceWindowGenerationFromRec(){
51 51 if (renderer) delete renderer;
52 52 if (rec) delete rec;
53 53 if (mixer) delete mixer;
54   - DDDPRINTF("Service Rec finished!\n");
  54 + printl(util::_DEBUG, "Service Rec finished!\n");
55 55 }
56 56  
57 57 void ServiceWindowGenerationFromRec::setPathContents(){
58   - if(this->exec_mode == DEVELOPER){
59   - this->path_contents = PATH_DEVEL_CONTENTS;
60   - this->path_uploads = PATH_DEVEL_UPLOADS;
61   - rec->setPathAudioContents(path_uploads);
62   -
63   - }else if(this->exec_mode == PRODUCTION){
64   - ifstream conf_file(PATH_CONF_FILE, ifstream::binary);
65   - parsingSuccessful = reader.parse(conf_file, root);
66   - if(!parsingSuccessful){
67   - conf_file.close();
68   - throw ServiceException("Fail to parsing param.json");
69   - }
70   - string attr = "vlibras_user/";
71   - attr += root.get("storage", PATH_VBOX_UPLOADS).asString();
72   - this->path_contents = new char[MAX_SIZE_PATH];
73   - strcpy(this->path_contents, attr.c_str());
74   - this->path_uploads = PATH_VBOX_UPLOADS;
75   - rec->setPathAudioContents(path_uploads);
76   - conf_file.close();
77   - }else{
78   - throw ServiceException("Invalid execution mode!");
79   - }
  58 + switch(exec_mode) {
  59 + case DEVELOPER:
  60 + {
  61 + this->path_contents = (char*) PATH_DEVEL_CONTENTS;
  62 + this->path_uploads = (char*) PATH_DEVEL_UPLOADS;
  63 + rec->setPathAudioContents(path_uploads);
  64 + }break;
  65 +
  66 + case PRODUCTION:
  67 + {
  68 + ifstream conf_file(PATH_CONF_FILE, ifstream::binary);
  69 + parsingSuccessful = reader.parse(conf_file, root);
  70 +
  71 + if(parsingSuccessful) {
  72 + string attr = "vlibras_user/";
  73 + attr += root.get("storage", PATH_VBOX_UPLOADS).asString();
  74 + this->path_contents = new char[MAX_SIZE_PATH];
  75 + strcpy(this->path_contents, attr.c_str());
  76 + this->path_uploads = (char*) PATH_VBOX_UPLOADS;
  77 + rec->setPathAudioContents(path_uploads);
  78 + }else{
  79 + conf_file.close();
  80 + Logging::instance()->writeLog("Erro com a leitura do arquivo params.json");
  81 + throw RuntimeException("Fail to parsing params.json");
  82 + }
  83 + conf_file.close();
  84 + }break;
  85 +
  86 + case TESTER:
  87 + {
  88 + this->path_contents = (char*) PATH_TESTER_CONTENTS;
  89 + this->path_uploads = (char*) PATH_TESTER_UPLOADS;
  90 + }break;
  91 +
  92 + default:
  93 + throw ServiceException("Invalid execution mode!");
  94 + }
80 95 }
81 96  
82 97 void ServiceWindowGenerationFromRec::setPathLibras() {
... ... @@ -140,7 +155,7 @@ void ServiceWindowGenerationFromRec::notifyEndOfRenderization() {
140 155 }
141 156  
142 157 void ServiceWindowGenerationFromRec::notifyEnd(int sentences_size){
143   - DPRINTF("Service REC recebeu: %d sentenças.\n", sentences_size);
  158 + printl(util::_DEBUG, "Service REC recebeu: %d sentenças.\n", sentences_size);
144 159 setSizeOfSubtitles(sentences_size);
145 160 }
146 161  
... ... @@ -153,7 +168,7 @@ bool ServiceWindowGenerationFromRec::isFinished(){
153 168 }
154 169  
155 170 void ServiceWindowGenerationFromRec::initialize(){
156   - DPRINTF("Service REC Initialize.\n");
  171 + printl(util::_DEBUG, "Service REC Initialize.\n");
157 172 setPathLibras();
158 173 rec->addListener(this);
159 174 tradutor->addListener(this);
... ...
servico/src/serviceWindowGenerationFromSRT.cpp
... ... @@ -23,7 +23,7 @@ ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT(char* pathVideo,
23 23 }
24 24 running = true;
25 25 finish = false;
26   - DPRINTF("Done!\n");
  26 + printl(util::_DEBUG, "Done!\n");
27 27 }
28 28  
29 29 ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT(char* pathSRT, int sublanguage, int transp, char* id, int mode, int serviceType) {
... ... @@ -44,7 +44,7 @@ ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT(char* pathSRT, in
44 44 }
45 45 running = true;
46 46 finish = false;
47   - DPRINTF("Done!\n");
  47 + printl(util::_DEBUG, "Done!\n");
48 48 }
49 49  
50 50 ServiceWindowGenerationFromSRT::~ServiceWindowGenerationFromSRT() {
... ... @@ -54,30 +54,44 @@ ServiceWindowGenerationFromSRT::~ServiceWindowGenerationFromSRT() {
54 54 if (renderer) delete renderer;
55 55 if (extratorSRT)delete extratorSRT;
56 56 if (extrator_factory) delete extrator_factory;
57   - DDDPRINTF("Service SRT finalized!\n");
  57 + printl(util::_DEBUG, "Service SRT finalized!\n");
58 58 }
59 59  
60 60 void ServiceWindowGenerationFromSRT::setPathContents() {
61   - if(this->exec_mode == DEVELOPER){
62   - this->path_contents = PATH_DEVEL_CONTENTS;
63   - this->path_uploads = PATH_DEVEL_UPLOADS;
64   -
65   - }else if(this->exec_mode = PRODUCTION){
66   - ifstream conf_file(PATH_CONF_FILE, ifstream::binary);
67   - parsingSuccessful = reader.parse(conf_file, root);
68   - if(!parsingSuccessful){
  61 + switch(exec_mode) {
  62 + case DEVELOPER:
  63 + {
  64 + this->path_contents = (char*) PATH_DEVEL_CONTENTS;
  65 + this->path_uploads = (char*) PATH_DEVEL_UPLOADS;
  66 + }break;
  67 +
  68 + case PRODUCTION:
  69 + {
  70 + ifstream conf_file(PATH_CONF_FILE, ifstream::binary);
  71 + parsingSuccessful = reader.parse(conf_file, root);
  72 +
  73 + if(parsingSuccessful) {
  74 + string attr = "vlibras_user/";
  75 + attr += root.get("storage", PATH_VBOX_UPLOADS).asString();
  76 + this->path_contents = new char[MAX_SIZE_PATH];
  77 + strcpy(this->path_contents, attr.c_str());
  78 + this->path_uploads = (char*) PATH_VBOX_UPLOADS;
  79 + }else{
  80 + conf_file.close();
  81 + Logging::instance()->writeLog("Erro com a leitura do arquivo params.json");
  82 + throw new RuntimeException("Fail to parsing params.json");
  83 + }
69 84 conf_file.close();
70   - throw ServiceException("Fail to parsing param.json");
71   - }
72   - string attr = "vlibras_user/";
73   - attr += root.get("storage", PATH_VBOX_UPLOADS).asString();
74   - this->path_contents = new char[MAX_SIZE_PATH];
75   -
76   - strcpy(this->path_contents, attr.c_str());
77   - this->path_uploads = PATH_VBOX_UPLOADS;
78   - conf_file.close();
79   - }else{
80   - throw ServiceException("Invalid execution mode!");
  85 + }break;
  86 +
  87 + case TESTER:
  88 + {
  89 + this->path_contents = (char*) PATH_TESTER_CONTENTS;
  90 + this->path_uploads = (char*) PATH_TESTER_UPLOADS;
  91 + }break;
  92 +
  93 + default:
  94 + throw ServiceException("Invalid execution mode!");
81 95 }
82 96 }
83 97  
... ... @@ -154,7 +168,7 @@ void ServiceWindowGenerationFromSRT::notifyEndOfRenderization() {
154 168 }
155 169  
156 170 void ServiceWindowGenerationFromSRT::notifyEnd(int sub_size) {
157   - DPRINTF("Service SRT recebeu: %d legendas.\n", sub_size);
  171 + printl(util::_DEBUG, "Service SRT recebeu: %d legendas.\n", sub_size);
158 172 setSizeOfSubtitles(sub_size);
159 173 }
160 174  
... ... @@ -167,7 +181,7 @@ bool ServiceWindowGenerationFromSRT::isFinished() {
167 181 }
168 182  
169 183 void ServiceWindowGenerationFromSRT::initialize() {
170   - DPRINTF("Service SRT Initialize.\n");
  184 + printl(util::_DEBUG, "Service SRT Initialize.\n");
171 185 setPathLibras();
172 186 extratorSRT = (ExtratorSRT*) extrator_factory->getExtrator(Extrator::SRT);
173 187 extratorSRT->addListener(this);
... ...
servico/src/serviceWindowGenerationFromText.cpp
... ... @@ -18,7 +18,7 @@ ServiceWindowGenerationFromText::ServiceWindowGenerationFromText(char* pathFile,
18 18 }
19 19 running = true;
20 20 finish = false;
21   - DPRINTF("Done!\n");
  21 + printl(util::_DEBUG, "Done!\n");
22 22 }
23 23  
24 24 ServiceWindowGenerationFromText::~ServiceWindowGenerationFromText() {
... ... @@ -26,26 +26,41 @@ ServiceWindowGenerationFromText::~ServiceWindowGenerationFromText() {
26 26 if (renderer) delete renderer;
27 27 if (extratorTXT)delete extratorTXT;
28 28 if (extrator_factory) delete extrator_factory;
29   - DDDPRINTF("Service Text finalized!\n");
  29 + printl(util::_DEBUG, "Service Text finalized!\n");
30 30 }
31 31  
32 32 void ServiceWindowGenerationFromText::setPathContents() {
33   - if(this->exec_mode == DEVELOPER){
34   - this->path_contents = PATH_DEVEL_CONTENTS;
35   - //this->path_uploads = PATH_DEVEL_UPLOADS;
36   - }else if(this->exec_mode == PRODUCTION){
37   - ifstream conf_file(PATH_CONF_FILE, ifstream::binary);
38   - parsingSuccessful = reader.parse(conf_file, root);
39   - if(!parsingSuccessful){
40   - throw new RuntimeException("Fail to parsing param.json");
41   - }
42   - string attr = "vlibras_user/";
43   - attr += root.get("storage", PATH_VBOX_UPLOADS).asString();
44   - this->path_contents = new char[MAX_SIZE_PATH];
45   - strcpy(this->path_contents, attr.c_str());
46   - //this->path_uploads = PATH_VBOX_UPLOADS;
47   - }else{
48   - throw ServiceException("Invalid execution mode!");
  33 + switch(exec_mode) {
  34 + case DEVELOPER:
  35 + {
  36 + this->path_contents = (char*) PATH_DEVEL_CONTENTS;
  37 + }break;
  38 +
  39 + case PRODUCTION:
  40 + {
  41 + ifstream conf_file(PATH_CONF_FILE, ifstream::binary);
  42 + parsingSuccessful = reader.parse(conf_file, root);
  43 +
  44 + if(parsingSuccessful) {
  45 + string attr = "vlibras_user/";
  46 + attr += root.get("storage", PATH_VBOX_UPLOADS).asString();
  47 + this->path_contents = new char[MAX_SIZE_PATH];
  48 + strcpy(this->path_contents, attr.c_str());
  49 + }else{
  50 + conf_file.close();
  51 + Logging::instance()->writeLog("Erro com a leitura do arquivo params.json");
  52 + throw new RuntimeException("Fail to parsing params.json");
  53 + }
  54 + conf_file.close();
  55 + }break;
  56 +
  57 + case TESTER:
  58 + {
  59 + this->path_contents = (char*) PATH_TESTER_CONTENTS;
  60 + }break;
  61 +
  62 + default:
  63 + throw ServiceException("Invalid execution mode!");
49 64 }
50 65 }
51 66  
... ... @@ -102,7 +117,7 @@ void ServiceWindowGenerationFromText::notifyEndOfRenderization() {
102 117 }
103 118  
104 119 void ServiceWindowGenerationFromText::notifyEnd(int line_size) {
105   - DPRINTF("Service Text recebeu: %d linhas.\n", line_size);
  120 + printl(util::_DEBUG, "Service Text recebeu: %d linhas.\n", line_size);
106 121 setSizeOfSubtitles(line_size);
107 122 }
108 123  
... ... @@ -115,7 +130,7 @@ bool ServiceWindowGenerationFromText::isFinished() {
115 130 }
116 131  
117 132 void ServiceWindowGenerationFromText::initialize() {
118   - DPRINTF("Service Text Initialize.\n");
  133 + printl(util::_DEBUG, "Service Text Initialize.\n");
119 134 setPathLibras();
120 135 extratorTXT = (ExtratorTXT*) extrator_factory->getExtrator(Extrator::TXT);
121 136 extratorTXT->addListener(this);
... ...
tradutor/src/include/tradutorPortGlosa.h
... ... @@ -18,12 +18,13 @@
18 18 #include "listenerTradutor.h"
19 19 #include "pyTradutor.h"
20 20 #include "listenerInput.h"
21   -#include "dprintf.h"
  21 +#include "logging.h"
22 22  
23 23 #ifndef _GERADOR_GLOSA_H_
24 24 #define _GERADOR_GLOSA_H_
25 25  
26 26 using namespace std;
  27 +using namespace util;
27 28  
28 29 namespace Tradutor {
29 30  
... ...
tradutor/src/tradutorPortGlosa.cpp
... ... @@ -21,7 +21,7 @@ namespace Tradutor {
21 21 // Inicia o mutex
22 22 mutex = (pthread_mutex_t *) malloc( sizeof(pthread_mutex_t) );
23 23 pthread_mutex_init(mutex, NULL);
24   - DPRINTF("Done!\n")
  24 + printl(util::_DEBUG, "Done!\n");
25 25 }
26 26  
27 27  
... ... @@ -31,11 +31,10 @@ namespace Tradutor {
31 31 if (mutex) {
32 32 int ret = pthread_mutex_destroy(mutex);
33 33 if (ret)
34   - DDDPRINTF("Erro, destruindo mutex.\n");
  34 + printl(util::_ERROR, "Erro, destruindo mutex.\n");
35 35 free(mutex);
36 36 }
37   - DDDPRINTF("Translator finalized!\n")
38   -
  37 + printl(util::_DEBUG, "Translator finalized!\n");
39 38 }
40 39  
41 40 void TradutorPortGlosa::addListener(ListenerTradutor* listener) {
... ...
util/src/argParser.cpp
... ... @@ -10,27 +10,29 @@ void ArgParser::readArgs(char** argv, int argc)
10 10 int long_index = 0;
11 11  
12 12 static struct option long_options[] = {
13   - {"audio", required_argument, NULL, 'A'},
14   - {"subtitle", required_argument, NULL, 'S'},
15   - {"text", required_argument, NULL, 'T'},
16   - {"video", required_argument, NULL, 'V'},
17   - {"language", required_argument, NULL, 'l'},
18   - {"background", required_argument, NULL, 'b'},
19   - {"resolution", required_argument, NULL, 'r'},
20   - {"position", required_argument, NULL, 'p'},
21   - {"mode", required_argument, NULL, 'm'},
22   - {"id", required_argument, NULL, 'i'},
23   - {"no-mixer", no_argument, NULL, 'x'},
24   - {"help", no_argument, NULL, 'h'},
25   - {0, 0, 0, 0 }
  13 + {"audio", required_argument, NULL, 'A'},
  14 + {"subtitle", required_argument, NULL, 'S'},
  15 + {"text", required_argument, NULL, 'T'},
  16 + {"video", required_argument, NULL, 'V'},
  17 + {"language", required_argument, NULL, 'l'},
  18 + {"background", required_argument, NULL, 'b'},
  19 + {"resolution", required_argument, NULL, 'r'},
  20 + {"position", required_argument, NULL, 'p'},
  21 + {"mode", required_argument, NULL, 'm'},
  22 + {"id", required_argument, NULL, 'i'},
  23 + {"no-mixer", no_argument, NULL, 'x'},
  24 + {"check-modules", no_argument, NULL, 'C'},
  25 + {"loglevel", required_argument, NULL, 'v'},
  26 + {"help", no_argument, NULL, 'h'},
  27 + {0, 0, 0, 0 }
26 28 };
27 29  
28   - while ((opt = getopt_long_only(argc, argv, "A:S:T:V:l:b:r:p:m:", long_options, &long_index))!= -1)
  30 + while ((opt = getopt_long_only(argc, argv, "A:S:T:V:b:l:m:p:r:v:", long_options, &long_index))!= -1)
29 31 {
30 32 switch (opt)
31 33 {
32 34 case 'A':
33   - if(argc <= 5)
  35 + if(argc <= 9)
34 36 returnErr("Insuficient arguments. Try again");
35 37  
36 38 globalArgs.service = _REC_AUDIO;
... ... @@ -38,7 +40,7 @@ void ArgParser::readArgs(char** argv, int argc)
38 40 break;
39 41  
40 42 case 'S':
41   - if(argc <= 6 || (globalArgs.service == _REC_VIDEO && argc <= 9))
  43 + if(argc <= 11 || (globalArgs.service == _REC_VIDEO && argc <= 17))
42 44 returnErr("Insuficient arguments. Try again");
43 45  
44 46 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)
51 53 break;
52 54  
53 55 case 'T':
54   - if(argc <= 5)
  56 + if(argc <= 9)
55 57 returnErr("Insuficient arguments. Try again");
56 58  
57 59 globalArgs.service = _TEXT;
... ... @@ -59,7 +61,7 @@ void ArgParser::readArgs(char** argv, int argc)
59 61 break;
60 62  
61 63 case 'V':
62   - if(argc <= 7 || ((globalArgs.service == _ONLY_SRT && argc <= 9)))
  64 + if(argc <= 13 || ((globalArgs.service == _ONLY_SRT && argc <= 17)))
63 65 returnErr("Insuficient arguments. Try again");
64 66  
65 67 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)
73 75 break;
74 76  
75 77 case 'l':
76   - if (strcmp(optarg,"portugues") == 0)
77   - globalArgs.language = _PORTUGUESE;
78   - else if (strcmp(optarg,"libras") == 0)
79   - globalArgs.language = _GLOSA;
80   - else
81   - returnErr("--language");
  78 + globalArgs.language = languageFromString(optarg);
82 79 break;
83 80  
84 81 case 'b':
85   - if (strcmp(optarg,"opaque") == 0)
86   - globalArgs.back = _OPAQUE;
87   - else if (strcmp(optarg,"transp") == 0)
88   - globalArgs.back = _TRANSPARENT;
89   - else
90   - returnErr("--background");
  82 + globalArgs.back = backgroundFromString(optarg);
91 83 break;
92 84  
93 85 case 'r':
94   - if (strcmp(optarg,"small") == 0)
95   - globalArgs.size = _SMALL;
96   - else if (strcmp(optarg,"medium") == 0)
97   - globalArgs.size = _MEDIUM;
98   - else if (strcmp(optarg,"large") == 0)
99   - globalArgs.size = _LARGE;
100   - else
101   - returnErr("--resolution");
  86 + globalArgs.size = resolutionFromString(optarg);
102 87 break;
103 88  
104 89 case 'p':
105   - if (strcmp(optarg,"top_left") == 0)
106   - globalArgs.position = _TOP_LEFT;
107   - else if (strcmp(optarg,"top_right") == 0)
108   - globalArgs.position = _TOP_RIGHT;
109   - else if (strcmp(optarg,"bottom_right") == 0)
110   - globalArgs.position = _BOTTOM_RIGHT;
111   - else if (strcmp(optarg,"bottom_left") == 0)
112   - globalArgs.position = _BOTTOM_LEFT;
113   - else
114   - returnErr("--position");
  90 + globalArgs.position = positionFromString(optarg);
115 91 break;
116 92  
117 93 case 'm':
118   - if(strcmp(optarg,"prod") == 0)
119   - globalArgs.mode = _PROD;
120   - else if (strcmp(optarg,"devel") == 0)
121   - globalArgs.mode = _DEVEL;
122   - else
123   - returnErr("--mode");
  94 + globalArgs.mode = executionModeFromString(optarg);
124 95 break;
125 96  
126 97 case 'i':
... ... @@ -134,6 +105,14 @@ void ArgParser::readArgs(char** argv, int argc)
134 105 globalArgs.mixer = _NO_MIXER;
135 106 break;
136 107  
  108 + case 'C':
  109 + globalArgs.service = _TESTER;
  110 + break;
  111 +
  112 + case 'v':
  113 + globalArgs.l_level = logFromString(optarg);
  114 + break;
  115 +
137 116 case 'h':
138 117 help();
139 118 break;
... ... @@ -155,9 +134,9 @@ void ArgParser::readArgs(char** argv, int argc)
155 134 /* Mostra os argumentos restantes depois das opções de linha de comando */
156 135 if (optind < argc)
157 136 {
158   - printf("non-option ARGV-elements: ");
  137 + printf("non-option ARGV-elements:\n");
159 138 while (optind < argc)
160   - printf("%s ", argv[optind++]);
  139 + printf("%s\n", argv[optind++]);
161 140 }
162 141 }
163 142  
... ... @@ -184,12 +163,84 @@ void ArgParser::help()
184 163 throw lavidlib::RuntimeException(); //para nao iniciar o vlibras
185 164 }
186 165  
187   -void ArgParser::returnErr(string option)
  166 +void ArgParser::returnErr(const string& option)
188 167 {
189 168 cout << "Option '" << option << "' contains an invalid argument." << endl;
190 169 throw lavidlib::RuntimeException();
191 170 }
192 171  
  172 +util::logLevel ArgParser::logFromString(const string& level)
  173 +{
  174 + if(level == "quiet")
  175 + return util::_QUIET;
  176 + if(level == "debug")
  177 + return util::_DEBUG;
  178 + if(level == "info")
  179 + return util::_INFO;
  180 + if(level == "warning")
  181 + return util::_WARNING;
  182 + if(level == "error")
  183 + return util::_ERROR;
  184 +
  185 + return util::_INFO;//default
  186 +}
  187 +
  188 +ArgParser::Languages ArgParser::languageFromString(const string& language)
  189 +{
  190 + if(language == "portugues")
  191 + return _PORTUGUESE;
  192 + if(language == "libras")
  193 + return _GLOSA;
  194 +
  195 + returnErr("--language");
  196 +}
  197 +
  198 +ArgParser::Positions ArgParser::positionFromString(const string& position)
  199 +{
  200 + if(position == "top_left")
  201 + return _TOP_LEFT;
  202 + if(position == "top_right")
  203 + return _TOP_RIGHT;
  204 + if(position == "bottom_right")
  205 + return _BOTTOM_RIGHT;
  206 + if(position == "bottom_left")
  207 + return _BOTTOM_LEFT;
  208 +
  209 + returnErr("--position");
  210 +}
  211 +
  212 +ArgParser::Resolution ArgParser::resolutionFromString(const string& resolution)
  213 +{
  214 + if(resolution == "small")
  215 + return _SMALL;
  216 + if(resolution == "medium")
  217 + return _MEDIUM;
  218 + if(resolution == "large")
  219 + return _LARGE;
  220 +
  221 + returnErr("--resolution");
  222 +}
  223 +
  224 +ArgParser::Background ArgParser::backgroundFromString(const string& back)
  225 +{
  226 + if(back == "opaque")
  227 + return _OPAQUE;
  228 + if(back == "transp")
  229 + return _TRANSPARENT;
  230 +
  231 + returnErr("--background");
  232 +}
  233 +
  234 +ArgParser::Mode ArgParser::executionModeFromString(const string& mode)
  235 +{
  236 + if(mode == "prod")
  237 + return _PROD;
  238 + if(mode == "devel")
  239 + return _DEVEL;
  240 +
  241 + returnErr("--mode");
  242 +}
  243 +
193 244 int ArgParser::getService()
194 245 {
195 246 return globalArgs.service;
... ... @@ -238,4 +289,9 @@ string ArgParser::getInputSRT()
238 289 string ArgParser::getId()
239 290 {
240 291 return globalArgs.id;
  292 +}
  293 +
  294 +util::logLevel ArgParser::getLog()
  295 +{
  296 + return globalArgs.l_level;
241 297 }
242 298 \ No newline at end of file
... ...
util/src/include/argParser.h
... ... @@ -7,6 +7,7 @@
7 7 #include <stdlib.h>
8 8 #include <unistd.h>
9 9 #include <getopt.h>
  10 +#include "logging.h"
10 11 #include <lavidlib/base/RuntimeException.h>
11 12  
12 13 #define MAX_SIZE_PATH 256
... ... @@ -30,12 +31,13 @@ public:
30 31 string getInput();
31 32 string getInputSRT();
32 33 string getId();
  34 + util::logLevel getLog();
33 35  
34 36 private:
35   - enum Services { _VIDEO_WITH_SRT = 1, _REC_VIDEO, _TEXT, _ONLY_SRT, _REC_AUDIO, _WITHOUT_MIXER };
  37 + enum Services { _VIDEO_WITH_SRT = 1, _REC_VIDEO, _TEXT, _ONLY_SRT, _REC_AUDIO, _WITHOUT_MIXER, _TESTER };
36 38 enum Languages { _PORTUGUESE = 1, _GLOSA };
37 39 enum Positions { _TOP_LEFT = 1, _TOP_RIGHT, _BOTTOM_RIGHT, _BOTTOM_LEFT };
38   - enum Sizes { _SMALL = 1, _MEDIUM, _LARGE };
  40 + enum Resolution { _SMALL = 1, _MEDIUM, _LARGE };
39 41 enum Background { _OPAQUE, _TRANSPARENT };
40 42 enum Options { _NO_MIXER = 1 };
41 43 enum Mode { _DEVEL = 1 , _PROD };
... ... @@ -44,17 +46,24 @@ private:
44 46 Services service;
45 47 Languages language;
46 48 Positions position;
47   - Sizes size;
  49 + Resolution size;
48 50 Background back;
49 51 Options mixer;
50 52 Mode mode;
51 53 string input;
52 54 string input_srt;
53 55 string id;
  56 + util::logLevel l_level;
54 57 }globalArgs;
55 58  
56 59 void help();
57   - void returnErr(string option);
  60 + void returnErr(const string& option);
  61 + Languages languageFromString(const string& language);
  62 + Positions positionFromString(const string& position);
  63 + Resolution resolutionFromString(const string& resolution);
  64 + Background backgroundFromString(const string& backg);
  65 + Mode executionModeFromString(const string& mode);
  66 + util::logLevel logFromString(const string& level);
58 67 };
59 68  
60 69 #endif /* ARG_PARSER_H */
61 70 \ No newline at end of file
... ...
util/src/include/dprintf.h
... ... @@ -1,79 +0,0 @@
1   -#ifndef __DPRINTF_H__
2   -#define __DPRINTF_H__
3   -
4   -/* A macro DEBUG_LEVEL determina o nivel de debugging
5   - * A seguinte regra eh utilizada:
6   - *
7   - * DEBUG_LEVEL >= 3: Apenas DDDPRINTF serah compilada.
8   - * DEBUG_LEVEL >= 2: DDDPRINTF E DDPRINTF serao compiladas.
9   - * DEBUG_LEVEL >= 1: DDDPRINTF, DDPRINTF e DPRINTF serao compiladas.
10   - * DEBUG_LEVEL == 0: Nada sera compilado. */
11   -
12   -#include <stdio.h>
13   -
14   -/* tamanho maximo (em bytes) do arquivo de log (1M) */
15   -//#define TAMANHO_MAXIMO_LOG 1048576
16   -#define TAMANHO_MAXIMO_LOG 5242880
17   -
18   - #define _DPRINTF_ERROR "\033[30m"
19   - #define _DPRINTF_WARN "\033[33m"
20   - #define _DPRINTF_INFO "\033[32m"
21   - #define _DPRINTF_FAIL "\033[31m"
22   - #define _DPRINTF_END "\033[0m"
23   -
24   -#define _DPRINTF_NOP(format, ...) do { } while (0)
25   -
26   -#ifdef DEBUG_LEVEL
27   -
28   - #if DEBUG_LEVEL & 4
29   - #define DDDPRINTF(format, ...) { \
30   - fprintf(stderr, \
31   - _DPRINTF_ERROR"%s::%s [%d] -> "_DPRINTF_END format, \
32   - __FILE__, __FUNCTION__, __LINE__, ## __VA_ARGS__); \
33   - }
34   -
35   - #else /* !DEBUG_LEVEL > 2 */
36   - #define DDDPRINTF _DPRINTF_NOP
37   - #endif /* DEBUG_LEVEL > 2 */
38   -
39   - #if DEBUG_LEVEL & 2
40   - #define DDPRINTF(format, ...) { \
41   - fprintf(stderr, \
42   - _DPRINTF_WARN"%s::%s [%d] -> "_DPRINTF_END format, \
43   - __FILE__, __FUNCTION__, __LINE__, ## __VA_ARGS__); \
44   - }
45   -
46   -#else /* !DEBUG_LEVEL > 1 */
47   - #define DDPRINTF _DPRINTF_NOP
48   - #endif /* DEBUG_LEVEL > 1 */
49   -
50   - #if DEBUG_LEVEL & 1
51   - #define DPRINTF(format, ...) { \
52   - fprintf(stderr, \
53   - _DPRINTF_INFO"%s::%s [%d] -> "_DPRINTF_END format, \
54   - __FILE__, __FUNCTION__, __LINE__, ## __VA_ARGS__); \
55   - }
56   -
57   - #else /* !DEBUG_LEVEL > 0 */
58   - #define DPRINTF _DPRINTF_NOP
59   - #endif /* DEBUG_LEVEL > 0 */
60   -
61   - #if DEBUG_LEVEL & 1
62   - #define DDDDPRINTF(format, ...) { \
63   - fprintf(stderr, \
64   - _DPRINTF_FAIL"%s::%s [%d] -> "_DPRINTF_END format, \
65   - __FILE__, __FUNCTION__, __LINE__, ## __VA_ARGS__); \
66   - }
67   -
68   - #else /* !DEBUG_LEVEL > 0 */
69   - #define DDDDPRINTF _DPRINTF_NOP
70   - #endif /* DEBUG_LEVEL > 0 */
71   -
72   -#else /* DEBUG_LEVEL */
73   - #define DPRINTF _DPRINTF_NOP
74   - #define DDPRINTF _DPRINTF_NOP
75   - #define DDDPRINTF _DPRINTF_NOP
76   -#endif /* ! DEBUG_LEVEL */
77   -
78   -#endif /* __DPRINTF_H__ */
79   -
util/src/include/logger.h
... ... @@ -1,52 +0,0 @@
1   -/***************************************************************************
2   - * Universidade Federal da Paraíba *
3   - * Copyright (C) 2014 by Laboratório de Aplicações de Vídeo Digital *
4   - * *
5   - * Centro de Informática - UFPB - Campus I *
6   - * João Pessoa - PB - Brasil *
7   - * *
8   - * Author: Erickson Silva (erickson.silva@lavid.ufpb.br) *
9   - * *
10   - **************************************************************************/
11   -
12   -#include <iostream>
13   -#include <fstream>
14   -#include <time.h>
15   -#include <stdio.h>
16   -#include <stdlib.h>
17   -#include <stddef.h>
18   -#include <iostream>
19   -#include <ctime>
20   -//#include <lavidlib/utils/Logger.h>
21   -
22   -
23   -#ifndef _LOGGER_H_
24   -#define _LOGGER_H_
25   -
26   -using namespace std;
27   -
28   -namespace Util {
29   -
30   - class Logger {
31   - public:
32   - static Logger* Instance();
33   - void openLogFile();
34   - void writeLog(char* log);
35   - void closeLogFile();
36   - char* getTime();
37   -
38   - private:
39   - Logger() ; // Private so that it can not be called
40   - Logger(Logger const&){}; // copy constructor is private
41   - Logger& operator=(Logger const&){}; // assignment operator is private
42   - static Logger* m_pInstance;
43   - ofstream file;
44   -
45   -
46   - };
47   -
48   -
49   -}
50   -
51   -
52   -#endif
util/src/include/logging.h 0 → 100644
... ... @@ -0,0 +1,61 @@
  1 +#ifndef LOGGING_H
  2 +#define LOGGING_H
  3 +
  4 +#include <stdio.h>
  5 +#include <stdlib.h>
  6 +#include <stdarg.h>
  7 +#include <time.h>
  8 +
  9 +#define _ERROR_ "\033[31m"
  10 +#define _DEBUG_ "\033[30m"
  11 +#define _WARN_ "\033[33m"
  12 +#define _INFO_ "\033[32m"
  13 +#define _END_ "\033[0m"
  14 +#define LOG_FILE "vlibras_user/vlibras-core/log/log"
  15 +
  16 +namespace util {
  17 +
  18 + enum logLevel { _QUIET , _ERROR, _WARNING, _INFO, _DEBUG};
  19 +
  20 + class Logging {
  21 + public:
  22 + static Logging* instance();
  23 + logLevel getLevel();
  24 + void setLevel(logLevel level);
  25 + void writeLog(const char* logMsg);
  26 +
  27 + private:
  28 + Logging(){};
  29 + Logging(Logging const&){};
  30 + Logging& operator=(Logging const&){};
  31 +
  32 + static Logging* l_instance;
  33 + static logLevel l_level;
  34 + FILE* l_file;
  35 +
  36 + char* getTime();
  37 + };
  38 +
  39 + #define printl(level, format, ... ) { \
  40 + logLevel llevel; \
  41 + llevel = Logging::instance()->getLevel(); \
  42 + if(level <= llevel){ \
  43 + switch(level){ \
  44 + case _DEBUG: \
  45 + fprintf(stdout, _DEBUG_"%s::%s<%d>: "_END_ format, __FILE__, __FUNCTION__, __LINE__, ## __VA_ARGS__); \
  46 + break; \
  47 + case _INFO: \
  48 + fprintf(stdout, _INFO_"%s::%s<%d>: "_END_ format, __FILE__, __FUNCTION__, __LINE__, ## __VA_ARGS__); \
  49 + break; \
  50 + case _WARNING: \
  51 + fprintf(stdout, _WARN_"%s::%s<%d>: "_END_ format, __FILE__, __FUNCTION__, __LINE__, ## __VA_ARGS__); \
  52 + break; \
  53 + case _ERROR: \
  54 + fprintf(stderr, _ERROR_"%s::%s<%d>: "_END_ format, __FILE__, __FUNCTION__, __LINE__, ## __VA_ARGS__); \
  55 + break; \
  56 + } \
  57 + } \
  58 + }//fim da função printl
  59 +}
  60 +
  61 +#endif /* LOGGING_H */
0 62 \ No newline at end of file
... ...
util/src/logger.cpp
... ... @@ -1,51 +0,0 @@
1   -/***************************************************************************
2   - * Universidade Federal da Paraíba *
3   - * Copyright (C) 2014 by Laboratório de Aplicações de Vídeo Digital *
4   - * *
5   - * Centro de Informática - UFPB - Campus I *
6   - * João Pessoa - PB - Brasil *
7   - * *
8   - * Author: Erickson Silva (erickson.silva@lavid.ufpb.br) *
9   - * *
10   - **************************************************************************/
11   -
12   -#include "logger.h"
13   -
14   -namespace Util {
15   -
16   - Logger* Logger::m_pInstance = NULL;
17   -
18   - Logger::Logger(){
19   - }
20   -
21   - Logger* Logger::Instance(){
22   - if (!m_pInstance) // Only allow one instance of class to be generated.
23   - m_pInstance = new Logger;
24   -
25   - return m_pInstance;
26   - }
27   -
28   -
29   - void Logger::openLogFile(){
30   - file.open("vlibras_user/vlibras-core/log/log", ios_base::app);
31   - }
32   -
33   -
34   - void Logger::closeLogFile(){
35   - file.close();
36   - }
37   -
38   - char* Logger::getTime(){
39   - time_t curtime;
40   - time(&curtime);
41   - return ctime(&curtime);
42   - }
43   -
44   - void Logger::writeLog(char* exception){
45   - this->openLogFile();
46   - file << getTime();
47   - file << exception << "\n\n\r";
48   - this->closeLogFile();
49   - }
50   -
51   -}
util/src/logging.cpp 0 → 100644
... ... @@ -0,0 +1,38 @@
  1 +#include "logging.h"
  2 +
  3 +namespace util {
  4 +
  5 + Logging* Logging::l_instance = NULL;
  6 + logLevel Logging::l_level = _INFO;
  7 +
  8 + Logging* Logging::instance() {
  9 + if(!l_instance)
  10 + l_instance = new Logging();
  11 + return l_instance;
  12 + }
  13 +
  14 + logLevel Logging::getLevel() {
  15 + return this->l_level;
  16 + }
  17 +
  18 + void Logging::setLevel(logLevel level) {
  19 + if(level != NULL)
  20 + this->l_level = level;
  21 + }
  22 +
  23 + char* Logging::getTime() {
  24 + time_t curtime;
  25 + time(&curtime);
  26 + return ctime(&curtime);
  27 + }
  28 +
  29 + void Logging::writeLog(const char* logMsg) {
  30 + l_file = fopen(LOG_FILE, "a");
  31 +
  32 + if(l_file == NULL)
  33 + return;
  34 +
  35 + fprintf(l_file, "%s'%s'\n\n\r", getTime() ,logMsg);
  36 + fclose(l_file);
  37 + }
  38 +}
0 39 \ No newline at end of file
... ...