diff --git a/.gitignore b/.gitignore index 122c1ec..e65f3e8 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ *.so *.o *.log -plugin/ \ No newline at end of file +plugin/ +vlibras_test diff --git a/Makefile b/Makefile index a78b479..3938804 100644 --- a/Makefile +++ b/Makefile @@ -29,9 +29,7 @@ CFLAGS =\ LDFLAGS =\ `python-config --ldflags`\ -lX11\ - -lcurl\ - -llavid_base\ - -llavid_io + -lcurl HEADERS =\ py_tradutor.h\ diff --git a/Makefile.build b/Makefile.build index 0414b4a..5cc9f90 100644 --- a/Makefile.build +++ b/Makefile.build @@ -16,10 +16,10 @@ shared: clean: @echo -n Cleaning... - @rm -rf $(addprefix $(SRCDIR),$(OBJS)) $(PLUGINDIR) 2> /dev/null && \ + @rm -rf $(addprefix $(SRCDIR),$(OBJS)) $(PLUGINDIR) vlibras_test 2> /dev/null && \ echo " $(OK)" || (echo " $(FAILED)"; exit 1;) vlibras_test: @echo -n Compiling source test file... - @$(CXX) $(CFLAGS) $(SOURCES) $(TESTSDIR)/main.cpp $(LDFLAGS) -o $(TESTSDIR)/vlibras_test && \ + @$(CXX) $(CFLAGS) $(TESTSDIR)/main.cpp $(LDFLAGS) -o vlibras_test && \ echo " $(OK)" || (echo " $(FAILED)"; exit 1;) \ No newline at end of file diff --git a/include/core_plugin.h b/include/core_plugin.h index a9b5e60..11ea580 100644 --- a/include/core_plugin.h +++ b/include/core_plugin.h @@ -23,7 +23,8 @@ #include #include #include -#include +//#include +#include #include // install libjson diff --git a/include/property.h b/include/property.h index eaa385c..3806753 100644 --- a/include/property.h +++ b/include/property.h @@ -17,26 +17,22 @@ #include #include #include - #include - #include - #include - #include - #include + #include + #include - using namespace lavidlib; + #define MAX_BUFFER 1024 namespace util { class PropertyHandler { public: - PropertyHandler(std::string filename); + PropertyHandler(std::string _filename); virtual ~PropertyHandler(); std::string getAttributeValue(std::string attr); private: - BufferedReader* rbuffer; - FileIO* file_property; + std::string filename; int checkFileExtension(std::string &filename); }; diff --git a/src/core_plugin.cpp b/src/core_plugin.cpp index 820c464..1cacdc9 100644 --- a/src/core_plugin.cpp +++ b/src/core_plugin.cpp @@ -48,7 +48,8 @@ int coreFinalize() int coreUpdateInstall_player() { - system(SCRIPT_UPDATE_VLIBRAS); + int r = system(SCRIPT_UPDATE_VLIBRAS); + if (r < 0) printf("%s has returned %d value\n", SCRIPT_UPDATE_VLIBRAS, r); return system("/./opt/vlibras_desktop/script/launcher.sh &"); } @@ -163,32 +164,8 @@ int get_version_from_string(std::string json_message, std::string _key) //@Deprecated int get_version_from_json(std::string json_message, std::string _key) -{ - +{ return -1; - - /*//Code to JsonCpp - Json::Value parsed_from_str; - Json::Reader json_reader; - bool parsing_flag = json_reader.parse(json_message, parsed_from_str); - - if (!parsing_flag) - throw new RuntimeException("Cannot convert the json message to string."); - - std::string version_str = parsed_from_str[_key].asString(); - - // Check if the version of dictionary contains '_' token. - if ( version_str.find("_") != std::string::npos ) - { - char *tokens_ptr = strtok ((char*) version_str.c_str(), "_"); - if (tokens_ptr == NULL) - throw new RuntimeException("Cannot handler the version of dictionary."); - version_str = (std::string) tokens_ptr; - } - - remove_special_chars(&version_str, ".", (char*) ""); - return atoi(version_str.c_str()); - */ } @@ -206,13 +183,14 @@ std::string request_current_versions() if(curl_ptr) { std::string url_endpoint = property_handler_ptr->getAttributeValue(ENDPOINT_UPDATE_ID); + printf("url_endpoint -> %s\n", url_endpoint.c_str()); std::stringstream ss_convert; ss_convert << dict_current_version; url_endpoint.append(ss_convert.str()); if (url_endpoint.size() <= 0) - throw new RuntimeException("The URL for this Endpoint is not available on the file config."); + throw "The URL for this Endpoint is not available on the file config."; curl_easy_setopt(curl_ptr, CURLOPT_URL, (char*) url_endpoint.c_str()); curl_easy_setopt(curl_ptr, CURLOPT_WRITEFUNCTION, writeDataCallback); diff --git a/src/property.cpp b/src/property.cpp index fc1237d..2d0c142 100644 --- a/src/property.cpp +++ b/src/property.cpp @@ -16,57 +16,58 @@ namespace util { - PropertyHandler::PropertyHandler(std::string filename) { - try { - if (checkFileExtension(filename) != 1) - throw new RuntimeException("Format file not is recognized!"); - file_property = new FileIO(filename, FileIO::MODE_READ); - } catch (lavidlib::IOException &ex) { - printf("[FAILED] Cannot open file %s.\n%s\n", filename.c_str(), - ex.getMessage().c_str()); - } + PropertyHandler::PropertyHandler(std::string _filename) + { + if (checkFileExtension(_filename) != 1) + throw "Format file not is recognized"; + + filename = _filename; } - PropertyHandler::~PropertyHandler() { - if (rbuffer) - delete rbuffer; - if (file_property) - delete file_property; + PropertyHandler::~PropertyHandler() + { + //todo } - std::string PropertyHandler::getAttributeValue(std::string attr) { - - rbuffer = new BufferedReader(file_property); - std::string fline; + std::string PropertyHandler::getAttributeValue(std::string attr) + { + std::ifstream file_property(filename.c_str()); + std::string buffer_str; try { int target_pos = -1, begin = 0; std::string attr_t, value_t; - while((fline = rbuffer->readLine()).size() > 0) { - target_pos = fline.find("="); + while (std::getline(file_property, buffer_str)) + { + target_pos = buffer_str.find("="); if (target_pos < 2) - throw new RuntimeException("The assignment symbol was not found."); + throw "The assignment symbol was not found."; - attr_t = fline.substr(begin, target_pos); + attr_t = buffer_str.substr(begin, target_pos); begin = target_pos+1; - value_t = fline.substr(begin, fline.size()); - if (attr.compare(attr_t) == 0) { - file_property->seek(0); - return value_t; + value_t = buffer_str.substr(begin, buffer_str.size()); + if (attr.compare(attr_t) == 0) + { + file_property.seekg (0, file_property.beg); + return value_t; } target_pos = -1; begin = 0; } - } catch (lavidlib::EOFException &ex) { - printf("[INFO] File is completed.\n%s\n", ex.getMessage().c_str()); + } + catch (std::exception& ex) + { + printf("[Exception] File is completed\n[Error] %s\n", ex.what()); } - file_property->seek(0); - //FIXME: throw new exception - return fline; + file_property.seekg (0, file_property.beg); + + return buffer_str; + } + #define EXTENSION ".conf" int PropertyHandler::checkFileExtension(std::string &filename) { diff --git a/test/main.cpp b/test/main.cpp index 96480ad..bbdc168 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -9,70 +9,58 @@ /** * \file main.cpp - * \author Gustavo Sobral, Leonardo Araújo - * \date Janeiro 2015 + * \author Leonardo Araújo + * \date Outubro 2015 */ -#include - +#include +#include #include #include #include int main() { - - if (coreInitialize() != 1) - { - printf("Cannot initialize the CorePlugin.\n"); - exit(-1); - } - int result_check = coreUpdateCheck(); - switch (result_check) + void *vlibras_lib_handler; + const char *dlsym_error_ptr; + + vlibras_lib_handler = dlopen("plugin/libCorePlugin.so", RTLD_LAZY); + if (!vlibras_lib_handler) { - case 0: - printf("The VLibras is up-to-date!\n"); - break; - case 1: - printf("The VLibras is outdated! Upgrading...\n"); - break; - case 2: - printf("Only the dictionary is outdated! Upgrading...\n"); - break; - case -1: - printf("Error!\n"); - break; - default: - printf("Option not found! Try again.\n"); + fprintf(stderr, "%s\n", dlerror()); + exit(1); } - - // Inicializa o tradutor - //PyTradutor *tradutorTest; - //tradutorTest = new PyTradutor(); - - // Pega o conteúdo do clipboard e salva em `pasteboardContent` - //std::string pasteboardContent = Pasteboard::getGeneralContent(); - // Traduz o conteúdo do clipboard em `pasteboardContent` para a string `traducao` - //char* str = new char[10]; - //strcpy(str, "o gato comeu o rato"); - //std::string traducao = tradutorTest->convertStringToGlosa(str); - - // [LOG] Exibe o conteudo do buffer de clipboard em `pasteboardContent` e traduz para glosa salvando seu resultado em `traducao` - //std::cout << "[[ Conteudo em memoria ]]\n" << str << std::endl; - //std::cout << "[[ Tradução ]]\n" << traducao << std::endl; - //std::cout << "\n##### ##### #####" << std::endl; + typedef void (*coreplugin_t)(); + dlerror(); + + coreplugin_t core_init_f = (coreplugin_t) dlsym(vlibras_lib_handler, "coreInitialize"); + dlsym_error_ptr = dlerror(); + if (dlsym_error_ptr) + { + printf("Cannot load symbol 'coreInitialize': %s\n", dlsym_error_ptr); + dlclose(vlibras_lib_handler); + return 1; + } + + /* Test coreInitialize function */ + core_init_f(); + + coreplugin_t core_update_f = (coreplugin_t) dlsym(vlibras_lib_handler, "coreUpdateCheck"); + dlsym_error_ptr = dlerror(); + if (dlsym_error_ptr) + { + printf("Cannot load symbol 'coreUpdateCheck': %s\n", dlsym_error_ptr); + dlclose(vlibras_lib_handler); + return 1; + } - // Inicializa o plugin - //std::cout << "[[Initialize]] | " << coreInitialize() << std::endl; - // Executa o CorePlugin - //std::cout << "[[Execute]] | " << coreExecute() << std::endl; - // Finaliza o ambiente - //std::cout << "[[Finalize]] | " << coreFinalize() << std::endl; + /* Test coreUpdateCheck function */ + core_update_f(); - // Exclui o que foi utilizado - // delete tradutorTest; + /* Close load library */ + dlclose(vlibras_lib_handler); return 0; } \ No newline at end of file -- libgit2 0.21.2