From 40535e79fc2e27ca8b920429951a8860d4cfb754 Mon Sep 17 00:00:00 2001 From: Wesnydy Ribeiro Date: Thu, 11 Jun 2015 13:13:38 -0300 Subject: [PATCH] Adicionado a API jsoncpp --- Makefile | 5 +++-- mixer/src/include/Mixer.h | 6 +----- servico/src/include/serviceWindowGeneration.h | 9 ++++++--- servico/src/serviceWindowGenerationFromRec.cpp | 19 ++++++++++--------- servico/src/serviceWindowGenerationFromSRT.cpp | 29 +++++++++++++++-------------- servico/src/serviceWindowGenerationFromText.cpp | 19 ++++++++++--------- util/src/include/logger.h | 3 --- util/src/include/property.h | 65 ----------------------------------------------------------------- util/src/logger.cpp | 9 --------- util/src/property.cpp | 236 -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 10 files changed, 45 insertions(+), 355 deletions(-) delete mode 100644 util/src/include/property.h delete mode 100644 util/src/property.cpp diff --git a/Makefile b/Makefile index 11d3f77..65230b6 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,8 @@ FLAGS=-g LIBS= \ `pkg-config --cflags jlibcpp` \ `pkg-config --libs jlibcpp` \ + `pkg-config --cflags jsoncpp` \ + `pkg-config --libs jsoncpp` \ -lpython2.7 -llavid_base -llavid_io INCLUDES= \ @@ -24,8 +26,7 @@ INCLUDES= \ #-I libs/jthread/include -I libs/jcommon/include -I libs/jsocket/include -Wall utilObjs= \ - logger.o \ - property.o + logger.o tradutorObjs = \ pyTradutor.o \ diff --git a/mixer/src/include/Mixer.h b/mixer/src/include/Mixer.h index 2a495bb..626912f 100644 --- a/mixer/src/include/Mixer.h +++ b/mixer/src/include/Mixer.h @@ -17,7 +17,6 @@ #include #include #include "dprintf.h" -#include "property.h" //SL Video Position #define TOP_LEFT 1 @@ -80,10 +79,7 @@ private: char* uploads; int positionSecondaryVideo; double widthSecondaryVideo, heightSecondaryVideo; - int transparency; - - PropertyHandler* reader; - + int transparency; }; #endif /* MIXER_H */ diff --git a/servico/src/include/serviceWindowGeneration.h b/servico/src/include/serviceWindowGeneration.h index 0a97533..53b4d63 100644 --- a/servico/src/include/serviceWindowGeneration.h +++ b/servico/src/include/serviceWindowGeneration.h @@ -7,13 +7,13 @@ #include #include "jthread.h" #include "dprintf.h" -#include "property.h" #include "Mixer.h" #include "synchronizer.h" #include "listenerSynchronizer.h" #include "listenerTradutor.h" #include "tradutorPortGlosa.h" #include "serviceException.h" +#include #include #define DEVELOPER "devel" @@ -25,9 +25,10 @@ #define PATH_DEVEL "vlibras_user/vlibras-contents/videos/" #define PATH_DEVEL_UPLOADS "vlibras_user/vlibras-contents/uploads/" #define PATH_VBOX_UPLOADS "vlibras_user/.vlibras-conf/uploads/" -#define PATH_CONF_FILE "vlibras_user/.vlibras-conf/configuration/params-vbox.conf" +#define PATH_CONF_FILE "vlibras_user/.vlibras-conf/param.json" #define MAX_SIZE_PATH 256 +using namespace Json; using namespace Tradutor; using namespace jthread; using namespace std; @@ -37,13 +38,15 @@ class ServiceWindowGeneration { protected: TradutorPortGlosa* tradutor; Synchronizer* sincronizador; - PropertyHandler* ppty_h; Mixer* mixer; + Value root; + Reader reader; vector* vetor_pts; bool finish; bool running; + bool parsingSuccessful; char* path_input; char* path_libras; diff --git a/servico/src/serviceWindowGenerationFromRec.cpp b/servico/src/serviceWindowGenerationFromRec.cpp index 887eff8..3d538aa 100644 --- a/servico/src/serviceWindowGenerationFromRec.cpp +++ b/servico/src/serviceWindowGenerationFromRec.cpp @@ -44,7 +44,6 @@ ServiceWindowGenerationFromRec::ServiceWindowGenerationFromRec( ServiceWindowGenerationFromRec::~ServiceWindowGenerationFromRec(){ free(vetor_pts); - delete(ppty_h); if (tradutor) delete tradutor; if (rec) delete rec; if (sincronizador) delete sincronizador; @@ -58,16 +57,18 @@ void ServiceWindowGenerationFromRec::setPathContents(){ this->path_uploads = PATH_DEVEL_UPLOADS; rec->setPathAudioContents(path_uploads); }else if(strcmp(client_type, PRODUCTION) == 0){ - try{ - ppty_h = new PropertyHandler(PATH_CONF_FILE, PropertyHandler::READ); - this->path_contents = (char*) ppty_h->get_attibute_value("STORAGE"); - }catch(RuntimeException &ex){ - printf("%s\n", ex.getMessage().c_str()); - } - this->path_uploads = PATH_VBOX_UPLOADS; + ifstream conf_file(PATH_CONF_FILE, ifstream::binary); + parsingSuccessful = reader.parse(conf_file, root); + if(!parsingSuccessful){ + throw ServiceException("Fail to parsing param.json"); + } + string 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); }else{ - throw new ServiceException("Invalid client!"); + throw ServiceException("Invalid client!"); } } diff --git a/servico/src/serviceWindowGenerationFromSRT.cpp b/servico/src/serviceWindowGenerationFromSRT.cpp index dc8b8ce..7160f5a 100644 --- a/servico/src/serviceWindowGenerationFromSRT.cpp +++ b/servico/src/serviceWindowGenerationFromSRT.cpp @@ -43,7 +43,6 @@ ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT(char* pathSRT, in ServiceWindowGenerationFromSRT::~ServiceWindowGenerationFromSRT() { free(vetor_pts); - delete(ppty_h); if (mixer) delete mixer; if (tradutor) delete tradutor; if (sincronizador) delete sincronizador; @@ -54,19 +53,21 @@ ServiceWindowGenerationFromSRT::~ServiceWindowGenerationFromSRT() { void ServiceWindowGenerationFromSRT::setPathContents() { if(strcmp(client_type,DEVELOPER) == 0){ - this->path_contents = PATH_DEVEL; - this->path_uploads = PATH_DEVEL_UPLOADS; - }else if(strcmp(client_type, PRODUCTION) == 0){ - try{ - ppty_h = new PropertyHandler(PATH_CONF_FILE, PropertyHandler::READ); - this->path_contents = (char*) ppty_h->get_attibute_value("STORAGE"); - }catch(RuntimeException &ex){ - printf("%s\n", ex.getMessage().c_str()); - } - this->path_uploads = PATH_VBOX_UPLOADS; - }else{ - throw new ServiceException("Invalid client!"); - } + this->path_contents = PATH_DEVEL; + this->path_uploads = PATH_DEVEL_UPLOADS; + }else if(strcmp(client_type, PRODUCTION) == 0){ + ifstream conf_file(PATH_CONF_FILE, ifstream::binary); + parsingSuccessful = reader.parse(conf_file, root); + if(!parsingSuccessful){ + throw ServiceException("Fail to parsing param.json"); + } + string 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 client!"); + } } void ServiceWindowGenerationFromSRT::setPathLibras() { diff --git a/servico/src/serviceWindowGenerationFromText.cpp b/servico/src/serviceWindowGenerationFromText.cpp index 91a78c3..4b77d85 100644 --- a/servico/src/serviceWindowGenerationFromText.cpp +++ b/servico/src/serviceWindowGenerationFromText.cpp @@ -20,7 +20,6 @@ ServiceWindowGenerationFromText::ServiceWindowGenerationFromText(char* pathFile, ServiceWindowGenerationFromText::~ServiceWindowGenerationFromText() { free(vetor_pts); - delete(ppty_h); if (tradutor) delete tradutor; if (sincronizador) delete sincronizador; if (extratorTXT)delete extratorTXT; @@ -29,19 +28,21 @@ ServiceWindowGenerationFromText::~ServiceWindowGenerationFromText() { } void ServiceWindowGenerationFromText::setPathContents() { - if(strcmp(client_type,DEVELOPER) == 0){ + if(strcmp(client_type,DEVELOPER) == 0){ this->path_contents = PATH_DEVEL; - this->path_uploads = PATH_DEVEL_UPLOADS; + this->path_uploads = PATH_DEVEL_UPLOADS; }else if(strcmp(client_type, PRODUCTION) == 0){ - try{ - ppty_h = new PropertyHandler(PATH_CONF_FILE, PropertyHandler::READ); - this->path_contents = (char*) ppty_h->get_attibute_value("STORAGE"); - }catch(RuntimeException &ex){ - printf("%s\n", ex.getMessage().c_str()); + ifstream conf_file(PATH_CONF_FILE, ifstream::binary); + parsingSuccessful = reader.parse(conf_file, root); + if(!parsingSuccessful){ + throw ServiceException("Fail to parsing param.json"); } + string 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 new ServiceException("Invalid client!"); + throw ServiceException("Invalid client!"); } } diff --git a/util/src/include/logger.h b/util/src/include/logger.h index ed7d3f3..ed54bf5 100644 --- a/util/src/include/logger.h +++ b/util/src/include/logger.h @@ -17,7 +17,6 @@ #include #include #include -#include "property.h" //#include @@ -32,9 +31,7 @@ namespace Util { public: static Logger* Instance(); void openLogFile(); - void openInfoLogFile(char* filepath); void writeLog(char* log); - void writeInfoLog(char* filepath ,char* infoLog); void closeLogFile(); char* getTime(); diff --git a/util/src/include/property.h b/util/src/include/property.h deleted file mode 100644 index f518d40..0000000 --- a/util/src/include/property.h +++ /dev/null @@ -1,65 +0,0 @@ -/*************************************************************************** - * Universidade Federal da Paraíba * - * Copyright (C) 2013 by Laboratório de Aplicações de Vídeo Digital * - * * - * Centro de Informática - UFPB - Campus I * - * João Pessoa - PB - Brasil * - * * - * Author: Leonardo de Araújo Domingues (leonardo.araujo@lavid.ufpb.br) * - * Date: Mon Jun 1 19:29:50 BRT 2015 * - * * - **************************************************************************/ - - #ifndef PROPERTYHANDLER_H - #define PROPERTYHANDLER_H - - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - - using namespace lavidlib; - - class PropertyHandler { - public: - enum HandlerMode { - READ, - WRITE - }; - PropertyHandler(char* _filename, PropertyHandler::HandlerMode _handler_mode); - virtual ~PropertyHandler(); - - int attr_exists(char* _attr); - const char* get_attibute_value(char* _attr); - void set_attribute_value(char* _attr_p, char* _value_p); - void update_properties(); - int remove_attribute(char* _attr_p); - - private: - - std::string filename; - File* file_p; - FileIO* file_io_p; - BufferedReader* buff_reader_p; - HandlerMode handler_mode; - - std::map * map_ppty_p; - - int check_file_extension(char* _filename); - void format_line_str(std::string* _line_str); - int load_properties(); - void init_write_mode(); - std::string get_key(std::string _ppty_line); - std::string get_value(std::string _ppty_line); - int write_properties_on_file(std::string _key, std::string _value, FILE* _file_output); - }; - - - #endif /* PROPERTYHANDLER_H */ \ No newline at end of file diff --git a/util/src/logger.cpp b/util/src/logger.cpp index 2d2b218..4527923 100644 --- a/util/src/logger.cpp +++ b/util/src/logger.cpp @@ -30,9 +30,6 @@ namespace Util { file.open("vlibras_user/vlibras-core/log/log", ios_base::app); } - void Logger::openInfoLogFile(char* filepath){ - file.open(filepath , ios_base::trunc); - } void Logger::closeLogFile(){ file.close(); @@ -51,10 +48,4 @@ namespace Util { this->closeLogFile(); } - void Logger::writeInfoLog(char* filepath ,char* infoLog){ - this->openInfoLogFile(filepath); - file << "READY="; - file << infoLog << "\n\r"; - this->closeLogFile(); - } } diff --git a/util/src/property.cpp b/util/src/property.cpp deleted file mode 100644 index 612cc1e..0000000 --- a/util/src/property.cpp +++ /dev/null @@ -1,236 +0,0 @@ -/*************************************************************************** - * Universidade Federal da Paraíba * - * Copyright (C) 2013 by Laboratório de Aplicações de Vídeo Digital * - * * - * Centro de Informática - UFPB - Campus I * - * João Pessoa - PB - Brasil * - * * - * Author: Leonardo de Araújo Domingues (leonardo.araujo@lavid.ufpb.br) * - * Date: Mon Jun 1 19:29:50 BRT 2015 * - * * - **************************************************************************/ - -#include "property.h" - - -PropertyHandler::PropertyHandler(char* _filename, PropertyHandler::HandlerMode _handler_mode) -{ - if ( check_file_extension(_filename) == -1 ) - throw new RuntimeException("Format file not is supported"); - - filename = (std::string) _filename; - handler_mode = _handler_mode; - - switch (handler_mode) - { - case READ: - if ( load_properties() <= 0 ) - throw new RuntimeException("Cannot to load properties of the file"); - break; - case WRITE: - init_write_mode(); - break; - default: - printf("Handler mode not supported"); - exit(1); - } - -} - - -PropertyHandler::~PropertyHandler() -{ - if (handler_mode == WRITE) - update_properties(); - - if (buff_reader_p) delete buff_reader_p; - if (file_io_p) delete file_io_p; - if (file_p) delete file_p; - if (map_ppty_p) delete map_ppty_p; - -} - - -int PropertyHandler::load_properties() -{ - std::string buff_str; - int buff_index = 0; - - file_p = new File(filename); - try { - file_io_p = new FileIO(file_p->getPath(), FileIO::MODE_READ); - } - catch(IOException &ex) { - printf("[ERROR] %s\n", ex.getMessage().c_str()); - exit(1); - } - - buff_reader_p = new BufferedReader(file_io_p); - map_ppty_p = new std::map(); - - try { - buff_str = buff_reader_p->readLine(); - - while (buff_str.size() > 0) - { - buff_index++; - format_line_str(&buff_str); - - map_ppty_p->insert(map_ppty_p->begin(), - (std::pair(get_key(buff_str), get_value(buff_str)))); - - /* get next line (key, value) */ - buff_str = buff_reader_p->readLine(); - } - - } catch (EOFException &ex) { - printf("[ERROR] %s\n", ex.getMessage().c_str()); - } - - return buff_index; - -} - - -void PropertyHandler::init_write_mode() -{ - /* init map structure to manipulate the properties in WRITE mode */ - map_ppty_p = new std::map(); -} - - -int PropertyHandler::attr_exists(char* _attr) -{ - std::map::iterator it; - if ( (it = map_ppty_p->find((const char*) _attr)) != map_ppty_p->end() ) - return 1; - return 0; -} - -const char* PropertyHandler::get_attibute_value(char* _attr) -{ - if (attr_exists(_attr)) - { - return (map_ppty_p->find((const char*) _attr)->second).c_str(); - } - return _attr; -} - - -void PropertyHandler::set_attribute_value(char* _attr_p, char* _value_p) -{ - if (handler_mode == PropertyHandler::READ) - throw new RuntimeException("Cannot set properties in the READ mode"); - - if (attr_exists(_attr_p)) - throw new RuntimeException("This attribute already exists"); - - map_ppty_p->insert(map_ppty_p->begin(), - (std::pair((std::string) _attr_p, (std::string) _value_p))); -} - - -void PropertyHandler::update_properties() -{ - FILE* file_output_p; - file_output_p = fopen (filename.c_str(), "w"); - if (file_output_p == NULL) - throw new IOException("Cannot open file to write properties"); - fseek(file_output_p, 0, SEEK_SET); - - std::string str_properties; - - std::map::iterator it; - for (it = map_ppty_p->begin(); it != map_ppty_p->end(); it++) - if ( write_properties_on_file(it->first, it->second, file_output_p) == 0 ) - throw new IOException("Error to write properties in the file"); - - fclose (file_output_p); -} - - -int PropertyHandler::write_properties_on_file(std::string _key, std::string _value, FILE* _file_output) -{ - std::string str_properties = _key; - str_properties.append("="); - str_properties.append(_value); - - int count_bytes = 0; - - count_bytes += fputs((char*) str_properties.c_str(), _file_output); - count_bytes += fputs("\n", _file_output); - - return count_bytes; -} - -//TODO -int PropertyHandler::remove_attribute(char* _attr_p) -{ - - if (attr_exists(_attr_p)) { - - if ( map_ppty_p->erase((const char*) _attr_p) != 1 ) - throw new RuntimeException("Cannot remove attribute of the map structure"); - - /* if delete the attribute corretly, update the map of the properties */ - update_properties(); - return 1; - } - return 0; -} - - -#define CONF_FILE_EXTENSION ".conf" -/** - Verify if the file extension is valid. -*/ -int PropertyHandler::check_file_extension(char* _filename) -{ - return ((std::string) _filename).find(CONF_FILE_EXTENSION); -} - -#undef CONF_FILE_EXTENSION /* .conf */ - - -#define CHAR_TO_REMOVE " \t" -/** - Remove all whitespaces in the text line. -*/ -void PropertyHandler::format_line_str(std::string* _line_str) -{ - int index = -1; - std::string chars_rm_str = (std::string) CHAR_TO_REMOVE; - for (int i = 0; i < chars_rm_str.size(); i++) - { - while ( (index = (int) _line_str->find(chars_rm_str[i]) ) != std::string::npos) - { - _line_str->replace(index, 1, ""); // remove whitespaces (" ") replacing your position by "" - } - } -} -#undef CHAR_TO_REMOVE - -#define TOKEN_ATTR "=" -std::string PropertyHandler::get_key(std::string _ppty_line) -{ - int target_pos = -1; - target_pos = _ppty_line.find(TOKEN_ATTR); - - if (target_pos < 1) /* minimum lenght of a key (k=value) */ - throw new RuntimeException("Bad format sentence"); - - return (std::string) _ppty_line.substr(0, target_pos); -} - - -std::string PropertyHandler::get_value(std::string _ppty_line) -{ - int target_pos = -1; - target_pos = _ppty_line.find(TOKEN_ATTR); - - if (target_pos < 1) /* minimum lenght of a key (k=value) */ - throw new RuntimeException("Bad format sentence"); - - return (std::string) _ppty_line.substr(target_pos+1, _ppty_line.size()); -} -#undef TOKEN_ATTR \ No newline at end of file -- libgit2 0.21.2