Commit c9375703af04c228529097bb448beab24967a0d5
1 parent
2687f5ec
Exists in
master
and in
1 other branch
Adicionado o componente Renderer
Showing
10 changed files
with
291 additions
and
176 deletions
Show diff stats
| @@ -0,0 +1,14 @@ | @@ -0,0 +1,14 @@ | ||
| 1 | +#ifndef LISTENER_RENDERER_H | ||
| 2 | +#define LISTENER_RENDERER_H | ||
| 3 | + | ||
| 4 | +#include <string> | ||
| 5 | +#include <stdint.h> | ||
| 6 | + | ||
| 7 | +using namespace std; | ||
| 8 | + | ||
| 9 | +class ListenerRenderer { | ||
| 10 | +public: | ||
| 11 | + virtual void notifyEndOfRenderization() = 0; | ||
| 12 | +}; | ||
| 13 | + | ||
| 14 | +#endif /* LISTENER_RENDERER_H */ | ||
| 0 | \ No newline at end of file | 15 | \ No newline at end of file |
| @@ -0,0 +1,57 @@ | @@ -0,0 +1,57 @@ | ||
| 1 | +#ifndef RENDERER_H | ||
| 2 | +#define RENDERER_H | ||
| 3 | + | ||
| 4 | +#include "jthread.h" | ||
| 5 | +#include "dprintf.h" | ||
| 6 | +#include "stdint.h" | ||
| 7 | +#include "string.h" | ||
| 8 | +#include <string> | ||
| 9 | +#include <list> | ||
| 10 | +#include <sstream> | ||
| 11 | +#include <iostream> | ||
| 12 | +#include "listenerRenderer.h" | ||
| 13 | +#include <lavidlib/net/StreamSocket.h> | ||
| 14 | +#include <lavidlib/net/InetAddress.h> | ||
| 15 | +#include <lavidlib/base/RuntimeException.h> | ||
| 16 | +#include <lavidlib/net/UnknownHostException.h> | ||
| 17 | +#include <lavidlib/net/SocketException.h> | ||
| 18 | + | ||
| 19 | +#define END_FLAG "FINALIZE" | ||
| 20 | +// #define HOST "150.165.205.127" | ||
| 21 | +// #define PORTNO 5555 | ||
| 22 | +#define HOST "127.0.0.1" | ||
| 23 | +#define PORTNO 12345 | ||
| 24 | + | ||
| 25 | +using namespace lavidlib; | ||
| 26 | +using namespace jthread; | ||
| 27 | +using namespace std; | ||
| 28 | + | ||
| 29 | +class Renderer : public Thread { | ||
| 30 | +public: | ||
| 31 | + Renderer(); | ||
| 32 | + ~Renderer(); | ||
| 33 | + | ||
| 34 | + bool isSending(); | ||
| 35 | + void receiveGlosa(std::string glosa, int64_t pts); | ||
| 36 | + void addListener(ListenerRenderer* listener); | ||
| 37 | + | ||
| 38 | + void finalize(); | ||
| 39 | + void Run(); | ||
| 40 | + | ||
| 41 | +private: | ||
| 42 | + StreamSocket* core_socket; | ||
| 43 | + list<ListenerRenderer*> * listeners; | ||
| 44 | + | ||
| 45 | + bool running; | ||
| 46 | + int count_task; | ||
| 47 | + int glosa_processed; | ||
| 48 | + | ||
| 49 | + string glosa_copy; | ||
| 50 | + | ||
| 51 | + void notifyListeners(); | ||
| 52 | + void sendGlosa(); | ||
| 53 | + void connectToUnity(); | ||
| 54 | + void waitScreenShots(); | ||
| 55 | +}; | ||
| 56 | + | ||
| 57 | +#endif /* RENDERER_H */ |
| @@ -0,0 +1,116 @@ | @@ -0,0 +1,116 @@ | ||
| 1 | +#include "renderer.h" | ||
| 2 | + | ||
| 3 | +Renderer::Renderer() { | ||
| 4 | + core_socket = new StreamSocket(); | ||
| 5 | + listeners = new list<ListenerRenderer*>(); | ||
| 6 | + running = true; | ||
| 7 | + count_task = 0; | ||
| 8 | + glosa_processed = 0; | ||
| 9 | + DPRINTF("Done!\n"); | ||
| 10 | +} | ||
| 11 | + | ||
| 12 | +Renderer::~Renderer() { | ||
| 13 | + listeners->clear(); | ||
| 14 | + delete listeners; | ||
| 15 | + if(core_socket) delete core_socket; | ||
| 16 | + DDDPRINTF("Renderer finalized!\n"); | ||
| 17 | +} | ||
| 18 | + | ||
| 19 | +void Renderer::addListener(ListenerRenderer* listener) { | ||
| 20 | + listeners->push_back(listener); | ||
| 21 | +} | ||
| 22 | + | ||
| 23 | +void Renderer::notifyListeners() { | ||
| 24 | + for (list<ListenerRenderer*>::iterator i = listeners->begin(); i != listeners->end(); i++) { | ||
| 25 | + (*i)->notifyEndOfRenderization(); | ||
| 26 | + } | ||
| 27 | +} | ||
| 28 | + | ||
| 29 | +void Renderer::receiveGlosa(std::string glosa, int64_t pts) { | ||
| 30 | + glosa_copy = glosa; | ||
| 31 | + stringstream ss; | ||
| 32 | + ss << pts; | ||
| 33 | + glosa_copy += "#"; // '#' para identificar que vem um pts | ||
| 34 | + glosa_copy += ss.str(); | ||
| 35 | + count_task++; | ||
| 36 | +} | ||
| 37 | + | ||
| 38 | +void Renderer::sendGlosa() { | ||
| 39 | + try{ | ||
| 40 | + int glosa_size = strlen(glosa_copy.c_str())+1; | ||
| 41 | + char* glosa_buffer = new char[glosa_size]; | ||
| 42 | + strcpy(glosa_buffer, glosa_copy.c_str()); | ||
| 43 | + core_socket->write(glosa_buffer, glosa_size); | ||
| 44 | + | ||
| 45 | + char* ok_core = new char[3]; | ||
| 46 | + do { | ||
| 47 | + core_socket->read(ok_core, 3); //aguarda o unity confirmar o recebimento da glosa | ||
| 48 | + }while(strcmp(ok_core, "OK") != 0); | ||
| 49 | + glosa_processed++; | ||
| 50 | + | ||
| 51 | + delete [] ok_core; | ||
| 52 | + delete [] glosa_buffer; | ||
| 53 | + | ||
| 54 | + }catch(lavidlib::RuntimeException &ex){ | ||
| 55 | + throw lavidlib::RuntimeException(ex.getMessage().c_str()); | ||
| 56 | + }catch(lavidlib::IOException &ex){ | ||
| 57 | + throw lavidlib::RuntimeException(ex.getMessage().c_str()); | ||
| 58 | + } | ||
| 59 | +} | ||
| 60 | + | ||
| 61 | +void Renderer::connectToUnity() { | ||
| 62 | + try{ | ||
| 63 | + static InetAddress* addr = InetAddress::createByName(HOST); | ||
| 64 | + core_socket->connect(addr, PORTNO); | ||
| 65 | + }catch(lavidlib::UnknownHostException &ex){ | ||
| 66 | + throw RuntimeException(ex.getMessage().c_str()); | ||
| 67 | + }catch(lavidlib::SocketException &ex){ | ||
| 68 | + throw RuntimeException(ex.getMessage().c_str()); | ||
| 69 | + } | ||
| 70 | +} | ||
| 71 | + | ||
| 72 | +void Renderer::waitScreenShots() { | ||
| 73 | + char* endgeneration = new char[strlen(END_FLAG)+1]; | ||
| 74 | + int connected; | ||
| 75 | + try{ | ||
| 76 | + do{ | ||
| 77 | + | ||
| 78 | + connected = core_socket->read(endgeneration, sizeof(endgeneration)); | ||
| 79 | + }while(strcmp(endgeneration, END_FLAG) != 0 && connected != 0); | ||
| 80 | + core_socket->close(); | ||
| 81 | + notifyListeners(); | ||
| 82 | + }catch(IOException &ex){ | ||
| 83 | + throw RuntimeException(ex.getMessage().c_str()); | ||
| 84 | + } | ||
| 85 | +} | ||
| 86 | + | ||
| 87 | +void Renderer::finalize() { | ||
| 88 | + while(glosa_processed < count_task) | ||
| 89 | + usleep(10000); | ||
| 90 | + receiveGlosa(END_FLAG, (int64_t) -1); | ||
| 91 | + this->running = false; | ||
| 92 | +} | ||
| 93 | + | ||
| 94 | +bool Renderer::isSending() { | ||
| 95 | + if(glosa_processed < count_task) | ||
| 96 | + return true; | ||
| 97 | + else | ||
| 98 | + return false; | ||
| 99 | +} | ||
| 100 | + | ||
| 101 | +void Renderer::Run() { | ||
| 102 | + try{ | ||
| 103 | + while(running){ | ||
| 104 | + while(count_task <= glosa_processed){ | ||
| 105 | + usleep(10000); | ||
| 106 | + } | ||
| 107 | + if(!core_socket->isConnected()) | ||
| 108 | + connectToUnity(); | ||
| 109 | + sendGlosa(); | ||
| 110 | + } | ||
| 111 | + waitScreenShots(); | ||
| 112 | + }catch(lavidlib::RuntimeException &ex){ | ||
| 113 | + DDDDPRINTF("Erro: %s\n", ex.getMessage().c_str()); | ||
| 114 | + throw RuntimeException(ex.getMessage().c_str()); | ||
| 115 | + } | ||
| 116 | +} | ||
| 0 | \ No newline at end of file | 117 | \ No newline at end of file |
servico/src/include/serviceWindowGeneration.h
| @@ -5,18 +5,17 @@ | @@ -5,18 +5,17 @@ | ||
| 5 | #include <iostream> | 5 | #include <iostream> |
| 6 | #include <stdint.h> | 6 | #include <stdint.h> |
| 7 | #include <string> | 7 | #include <string> |
| 8 | +#include <sstream> | ||
| 8 | #include <locale> | 9 | #include <locale> |
| 9 | #include "jthread.h" | 10 | #include "jthread.h" |
| 10 | #include "dprintf.h" | 11 | #include "dprintf.h" |
| 11 | #include "Mixer.h" | 12 | #include "Mixer.h" |
| 13 | +#include "renderer.h" | ||
| 14 | +#include "listenerRenderer.h" | ||
| 12 | #include "listenerTradutor.h" | 15 | #include "listenerTradutor.h" |
| 13 | #include "tradutorPortGlosa.h" | 16 | #include "tradutorPortGlosa.h" |
| 14 | #include "serviceException.h" | 17 | #include "serviceException.h" |
| 15 | #include <json/json.h> | 18 | #include <json/json.h> |
| 16 | -#include <lavidlib/net/StreamSocket.h> | ||
| 17 | -#include <lavidlib/net/InetAddress.h> | ||
| 18 | -#include <lavidlib/net/UnknownHostException.h> | ||
| 19 | -#include <lavidlib/net/SocketException.h> | ||
| 20 | #include <lavidlib/base/RuntimeException.h> | 19 | #include <lavidlib/base/RuntimeException.h> |
| 21 | 20 | ||
| 22 | #define DEVELOPER "devel" | 21 | #define DEVELOPER "devel" |
| @@ -24,11 +23,8 @@ | @@ -24,11 +23,8 @@ | ||
| 24 | #define PATH_DEVEL_CONTENTS "vlibras_user/vlibras-contents/videos/" | 23 | #define PATH_DEVEL_CONTENTS "vlibras_user/vlibras-contents/videos/" |
| 25 | #define PATH_DEVEL_UPLOADS "vlibras_user/vlibras-contents/uploads/" | 24 | #define PATH_DEVEL_UPLOADS "vlibras_user/vlibras-contents/uploads/" |
| 26 | #define PATH_VBOX_UPLOADS "vlibras_user/.vlibras-conf/uploads/" | 25 | #define PATH_VBOX_UPLOADS "vlibras_user/.vlibras-conf/uploads/" |
| 27 | -#define PATH_CONF_FILE "vlibras_user/.vlibras-conf/param.json" | 26 | +#define PATH_CONF_FILE "vlibras_user/.vlibras-conf/params.json" |
| 28 | #define MAX_SIZE_PATH 256 | 27 | #define MAX_SIZE_PATH 256 |
| 29 | -#define END_NOTIFICATION "FINALIZE" | ||
| 30 | -#define HOST "127.0.0.1" | ||
| 31 | -#define PORTNO 12345 | ||
| 32 | 28 | ||
| 33 | using namespace Json; | 29 | using namespace Json; |
| 34 | using namespace Tradutor; | 30 | using namespace Tradutor; |
| @@ -40,8 +36,8 @@ class ServiceWindowGeneration { | @@ -40,8 +36,8 @@ class ServiceWindowGeneration { | ||
| 40 | 36 | ||
| 41 | protected: | 37 | protected: |
| 42 | TradutorPortGlosa* tradutor; | 38 | TradutorPortGlosa* tradutor; |
| 39 | + Renderer* renderer; | ||
| 43 | Mixer* mixer; | 40 | Mixer* mixer; |
| 44 | - StreamSocket* core_socket; | ||
| 45 | 41 | ||
| 46 | Value root; | 42 | Value root; |
| 47 | Reader reader; | 43 | Reader reader; |
| @@ -68,10 +64,6 @@ protected: | @@ -68,10 +64,6 @@ protected: | ||
| 68 | 64 | ||
| 69 | virtual void setSizeOfSubtitles(int sub_size) = 0; | 65 | virtual void setSizeOfSubtitles(int sub_size) = 0; |
| 70 | virtual void setPathContents() = 0; | 66 | virtual void setPathContents() = 0; |
| 71 | - | ||
| 72 | - virtual void connectToUnity() = 0; | ||
| 73 | - virtual void sendGlosa(string glosa) = 0; | ||
| 74 | - virtual void waitVideoGeneration() = 0; | ||
| 75 | 67 | ||
| 76 | public: | 68 | public: |
| 77 | virtual void initialize() = 0; | 69 | virtual void initialize() = 0; |
servico/src/include/serviceWindowGenerationFromRec.h
| @@ -8,7 +8,7 @@ | @@ -8,7 +8,7 @@ | ||
| 8 | #define SERVICE_TYPE_REC 2 | 8 | #define SERVICE_TYPE_REC 2 |
| 9 | #define SERVICE_TYPE_REC_ONLY_AUDIO 5 | 9 | #define SERVICE_TYPE_REC_ONLY_AUDIO 5 |
| 10 | 10 | ||
| 11 | -class ServiceWindowGenerationFromRec : public ServiceWindowGeneration, public RecognizeListener, public ListenerTradutor, public Thread { | 11 | +class ServiceWindowGenerationFromRec : public ServiceWindowGeneration, public RecognizeListener, public ListenerTradutor, public ListenerRenderer, public Thread { |
| 12 | 12 | ||
| 13 | private: | 13 | private: |
| 14 | Recognize* rec; | 14 | Recognize* rec; |
| @@ -16,11 +16,6 @@ private: | @@ -16,11 +16,6 @@ private: | ||
| 16 | void addPTS(int64_t pts); | 16 | void addPTS(int64_t pts); |
| 17 | void setSizeOfSubtitles(int sub_size); | 17 | void setSizeOfSubtitles(int sub_size); |
| 18 | void setPathContents(); | 18 | void setPathContents(); |
| 19 | - | ||
| 20 | - void connectToUnity(); | ||
| 21 | - void sendGlosa(string glosa); | ||
| 22 | - void waitVideoGeneration(); | ||
| 23 | - | ||
| 24 | bool isRunning(); | 19 | bool isRunning(); |
| 25 | public: | 20 | public: |
| 26 | ServiceWindowGenerationFromRec(char* pathVideo, int sublanguage, int position, int size, | 21 | ServiceWindowGenerationFromRec(char* pathVideo, int sublanguage, int position, int size, |
| @@ -30,6 +25,7 @@ public: | @@ -30,6 +25,7 @@ public: | ||
| 30 | ~ServiceWindowGenerationFromRec(); | 25 | ~ServiceWindowGenerationFromRec(); |
| 31 | 26 | ||
| 32 | void notifyTextRecognized(unsigned char* text, int64_t pts); | 27 | void notifyTextRecognized(unsigned char* text, int64_t pts); |
| 28 | + void notifyEndOfRenderization(); | ||
| 33 | void notifyTranslation(vector<string>* glosas); | 29 | void notifyTranslation(vector<string>* glosas); |
| 34 | void notifyTranslator(unsigned char* text); | 30 | void notifyTranslator(unsigned char* text); |
| 35 | void notifyEnd(int sentences_size); | 31 | void notifyEnd(int sentences_size); |
servico/src/include/serviceWindowGenerationFromSRT.h
| @@ -8,7 +8,7 @@ | @@ -8,7 +8,7 @@ | ||
| 8 | #define SERVICE_TYPE_SRT 1 | 8 | #define SERVICE_TYPE_SRT 1 |
| 9 | #define SERVICE_TYPE_SRT_ONLY 4 | 9 | #define SERVICE_TYPE_SRT_ONLY 4 |
| 10 | 10 | ||
| 11 | -class ServiceWindowGenerationFromSRT : public ServiceWindowGeneration, public ListenerSRT, public ListenerTradutor, public Thread { | 11 | +class ServiceWindowGenerationFromSRT : public ServiceWindowGeneration, public ListenerSRT, public ListenerTradutor, public ListenerRenderer, public Thread { |
| 12 | 12 | ||
| 13 | private: | 13 | private: |
| 14 | ExtratorFactory* extrator_factory; | 14 | ExtratorFactory* extrator_factory; |
| @@ -19,11 +19,6 @@ private: | @@ -19,11 +19,6 @@ private: | ||
| 19 | void addPTS(int64_t pts); | 19 | void addPTS(int64_t pts); |
| 20 | void setSizeOfSubtitles(int sub_size); | 20 | void setSizeOfSubtitles(int sub_size); |
| 21 | void setPathContents(); | 21 | void setPathContents(); |
| 22 | - | ||
| 23 | - void connectToUnity(); | ||
| 24 | - void sendGlosa(string glosa); | ||
| 25 | - void waitVideoGeneration(); | ||
| 26 | - | ||
| 27 | bool isRunning(); | 22 | bool isRunning(); |
| 28 | public: | 23 | public: |
| 29 | //construtor de serviço de video e legenda | 24 | //construtor de serviço de video e legenda |
| @@ -34,6 +29,7 @@ public: | @@ -34,6 +29,7 @@ public: | ||
| 34 | ~ServiceWindowGenerationFromSRT(); | 29 | ~ServiceWindowGenerationFromSRT(); |
| 35 | 30 | ||
| 36 | void notifySubtitle(unsigned char* subtitle, int64_t pts); | 31 | void notifySubtitle(unsigned char* subtitle, int64_t pts); |
| 32 | + void notifyEndOfRenderization(); | ||
| 37 | void notifyTranslation(vector<string>* glosas); | 33 | void notifyTranslation(vector<string>* glosas); |
| 38 | void notifyTranslator(unsigned char* text); | 34 | void notifyTranslator(unsigned char* text); |
| 39 | void notifyEnd(int sub_size); | 35 | void notifyEnd(int sub_size); |
servico/src/include/serviceWindowGenerationFromText.h
| @@ -7,7 +7,7 @@ | @@ -7,7 +7,7 @@ | ||
| 7 | 7 | ||
| 8 | #define MAX_TEXT_SIZE 2048 //FIXME: está restrito a 2K bytes de texto | 8 | #define MAX_TEXT_SIZE 2048 //FIXME: está restrito a 2K bytes de texto |
| 9 | 9 | ||
| 10 | -class ServiceWindowGenerationFromText : public ServiceWindowGeneration, public ListenerTXT, public ListenerTradutor, public Thread { | 10 | +class ServiceWindowGenerationFromText : public ServiceWindowGeneration, public ListenerTXT, public ListenerTradutor, public ListenerRenderer, public Thread { |
| 11 | 11 | ||
| 12 | private: | 12 | private: |
| 13 | ExtratorFactory* extrator_factory; | 13 | ExtratorFactory* extrator_factory; |
| @@ -15,17 +15,13 @@ private: | @@ -15,17 +15,13 @@ private: | ||
| 15 | 15 | ||
| 16 | void setSizeOfSubtitles(int sub_size); | 16 | void setSizeOfSubtitles(int sub_size); |
| 17 | void setPathContents(); | 17 | void setPathContents(); |
| 18 | - | ||
| 19 | - void connectToUnity(); | ||
| 20 | - void sendGlosa(string glosa); | ||
| 21 | - void waitVideoGeneration(); | ||
| 22 | - | ||
| 23 | bool isRunning(); | 18 | bool isRunning(); |
| 24 | public: | 19 | public: |
| 25 | ServiceWindowGenerationFromText(char* pathFile, int transparency, char* id, char* client); | 20 | ServiceWindowGenerationFromText(char* pathFile, int transparency, char* id, char* client); |
| 26 | ~ServiceWindowGenerationFromText(); | 21 | ~ServiceWindowGenerationFromText(); |
| 27 | 22 | ||
| 28 | void notifyLine(unsigned char* line); | 23 | void notifyLine(unsigned char* line); |
| 24 | + void notifyEndOfRenderization(); | ||
| 29 | void notifyTranslation(vector<string>* glosas); | 25 | void notifyTranslation(vector<string>* glosas); |
| 30 | void notifyTranslator(unsigned char* text); | 26 | void notifyTranslator(unsigned char* text); |
| 31 | void notifyEnd(int line_size); | 27 | void notifyEnd(int line_size); |
servico/src/serviceWindowGenerationFromRec.cpp
| @@ -15,6 +15,7 @@ ServiceWindowGenerationFromRec::ServiceWindowGenerationFromRec( | @@ -15,6 +15,7 @@ ServiceWindowGenerationFromRec::ServiceWindowGenerationFromRec( | ||
| 15 | vetor_pts = new vector<int64_t >(); | 15 | vetor_pts = new vector<int64_t >(); |
| 16 | rec = new Recognize(pathVideo, id, rate); | 16 | rec = new Recognize(pathVideo, id, rate); |
| 17 | tradutor = new TradutorPortGlosa(); | 17 | tradutor = new TradutorPortGlosa(); |
| 18 | + renderer = new Renderer(); | ||
| 18 | running = true; | 19 | running = true; |
| 19 | finish = false; | 20 | finish = false; |
| 20 | DPRINTF("Done!\n"); | 21 | DPRINTF("Done!\n"); |
| @@ -36,6 +37,7 @@ ServiceWindowGenerationFromRec::ServiceWindowGenerationFromRec( | @@ -36,6 +37,7 @@ ServiceWindowGenerationFromRec::ServiceWindowGenerationFromRec( | ||
| 36 | vetor_pts = new vector<int64_t >(); | 37 | vetor_pts = new vector<int64_t >(); |
| 37 | rec = new Recognize(path_input, id); | 38 | rec = new Recognize(path_input, id); |
| 38 | tradutor = new TradutorPortGlosa(); | 39 | tradutor = new TradutorPortGlosa(); |
| 40 | + renderer = new Renderer(); | ||
| 39 | try{ | 41 | try{ |
| 40 | setPathContents(); | 42 | setPathContents(); |
| 41 | }catch(RuntimeException ex){ | 43 | }catch(RuntimeException ex){ |
| @@ -49,6 +51,7 @@ ServiceWindowGenerationFromRec::ServiceWindowGenerationFromRec( | @@ -49,6 +51,7 @@ ServiceWindowGenerationFromRec::ServiceWindowGenerationFromRec( | ||
| 49 | ServiceWindowGenerationFromRec::~ServiceWindowGenerationFromRec(){ | 51 | ServiceWindowGenerationFromRec::~ServiceWindowGenerationFromRec(){ |
| 50 | free(vetor_pts); | 52 | free(vetor_pts); |
| 51 | if (tradutor) delete tradutor; | 53 | if (tradutor) delete tradutor; |
| 54 | + if (renderer) delete renderer; | ||
| 52 | if (rec) delete rec; | 55 | if (rec) delete rec; |
| 53 | if (mixer) delete mixer; | 56 | if (mixer) delete mixer; |
| 54 | DDDPRINTF("Service Rec finished!\n"); | 57 | DDDPRINTF("Service Rec finished!\n"); |
| @@ -80,8 +83,11 @@ void ServiceWindowGenerationFromRec::setPathContents(){ | @@ -80,8 +83,11 @@ void ServiceWindowGenerationFromRec::setPathContents(){ | ||
| 80 | void ServiceWindowGenerationFromRec::setSizeOfSubtitles(int sub_size){ | 83 | void ServiceWindowGenerationFromRec::setSizeOfSubtitles(int sub_size){ |
| 81 | numero_legendas = sub_size; | 84 | numero_legendas = sub_size; |
| 82 | if (legendas_enviadas >= numero_legendas){ | 85 | if (legendas_enviadas >= numero_legendas){ |
| 83 | - sendGlosa(END_NOTIFICATION); | ||
| 84 | - waitVideoGeneration(); | 86 | + try{ |
| 87 | + renderer->finalize(); | ||
| 88 | + }catch(lavidlib::RuntimeException &ex){ | ||
| 89 | + throw ServiceException(ex.getMessage().c_str()); | ||
| 90 | + } | ||
| 85 | } | 91 | } |
| 86 | } | 92 | } |
| 87 | 93 | ||
| @@ -100,23 +106,36 @@ void ServiceWindowGenerationFromRec::notifyTextRecognized(unsigned char* text, i | @@ -100,23 +106,36 @@ void ServiceWindowGenerationFromRec::notifyTextRecognized(unsigned char* text, i | ||
| 100 | } | 106 | } |
| 101 | 107 | ||
| 102 | void ServiceWindowGenerationFromRec::notifyTranslation(vector<string> * glosas) { | 108 | void ServiceWindowGenerationFromRec::notifyTranslation(vector<string> * glosas) { |
| 109 | + string glosa = ""; | ||
| 103 | for (int i = 0; i < glosas->size(); i++) { | 110 | for (int i = 0; i < glosas->size(); i++) { |
| 104 | locale loc; | 111 | locale loc; |
| 105 | string glosa_lower = ""; | 112 | string glosa_lower = ""; |
| 106 | for (int k = 0; k < glosas->at(i).length(); k++){ | 113 | for (int k = 0; k < glosas->at(i).length(); k++){ |
| 107 | glosa_lower += std::tolower(glosas->at(i).at(k), loc); | 114 | glosa_lower += std::tolower(glosas->at(i).at(k), loc); |
| 108 | } | 115 | } |
| 109 | - //int64_t pts_notificado = vetor_pts->front(); | ||
| 110 | - sendGlosa(glosa_lower); | 116 | + glosa += glosa_lower; |
| 117 | + glosa += " "; | ||
| 118 | + | ||
| 119 | + } | ||
| 120 | + int64_t pts_notificado = vetor_pts->front(); | ||
| 121 | + while(renderer->isSending()) | ||
| 122 | + usleep(10000); | ||
| 123 | + try{ | ||
| 124 | + renderer->receiveGlosa(glosa, pts_notificado); | ||
| 125 | + legendas_enviadas++; | ||
| 126 | + }catch(lavidlib::RuntimeException &ex){ | ||
| 127 | + throw ServiceException(ex.getMessage().c_str()); | ||
| 111 | } | 128 | } |
| 112 | - | ||
| 113 | vetor_pts->erase(vetor_pts->begin()); | 129 | vetor_pts->erase(vetor_pts->begin()); |
| 114 | legendas_enviadas++; | 130 | legendas_enviadas++; |
| 115 | } | 131 | } |
| 116 | 132 | ||
| 133 | +void ServiceWindowGenerationFromRec::notifyEndOfRenderization() { | ||
| 134 | + running = false; | ||
| 135 | +} | ||
| 136 | + | ||
| 117 | void ServiceWindowGenerationFromRec::notifyEnd(int sentences_size){ | 137 | void ServiceWindowGenerationFromRec::notifyEnd(int sentences_size){ |
| 118 | DPRINTF("Service REC recebeu: %d sentenças.\n", sentences_size); | 138 | DPRINTF("Service REC recebeu: %d sentenças.\n", sentences_size); |
| 119 | - cout << "chamou: " << sentences_size << endl; | ||
| 120 | setSizeOfSubtitles(sentences_size); | 139 | setSizeOfSubtitles(sentences_size); |
| 121 | } | 140 | } |
| 122 | 141 | ||
| @@ -133,54 +152,19 @@ void ServiceWindowGenerationFromRec::initialize(){ | @@ -133,54 +152,19 @@ void ServiceWindowGenerationFromRec::initialize(){ | ||
| 133 | 152 | ||
| 134 | rec->addListener(this); | 153 | rec->addListener(this); |
| 135 | tradutor->addListener(this); | 154 | tradutor->addListener(this); |
| 136 | - connectToUnity(); | ||
| 137 | - | 155 | + renderer->addListener(this); |
| 156 | + | ||
| 138 | try{ | 157 | try{ |
| 158 | + renderer->Start(); | ||
| 139 | rec->initialize(); | 159 | rec->initialize(); |
| 140 | } catch(RecognizeException ex){ | 160 | } catch(RecognizeException ex){ |
| 141 | throw ServiceException(ex.getMessage()); | 161 | throw ServiceException(ex.getMessage()); |
| 142 | - } | 162 | + } catch(RuntimeException &ex){ |
| 163 | + throw ServiceException(ex.getMessage().c_str()); | ||
| 164 | + } | ||
| 143 | this->Start(); | 165 | this->Start(); |
| 144 | } | 166 | } |
| 145 | 167 | ||
| 146 | -void ServiceWindowGenerationFromRec::sendGlosa(string glosa) { | ||
| 147 | - char* glosa_buffer = new char[strlen(glosa.c_str())+1]; | ||
| 148 | - strcpy(glosa_buffer, glosa.c_str()); | ||
| 149 | - int tamanho = strlen(glosa_buffer)+1; | ||
| 150 | - //cout << "Enviando glosa: " << glosa_buffer << endl; | ||
| 151 | - core_socket->write(glosa_buffer, tamanho); | ||
| 152 | - delete [] glosa_buffer; | ||
| 153 | - | ||
| 154 | - char* ok_core = new char[4]; | ||
| 155 | - core_socket->read(ok_core, 4); //aguarda o unity confirmar o recebimento da glosa | ||
| 156 | - delete [] ok_core; | ||
| 157 | -} | ||
| 158 | - | ||
| 159 | -void ServiceWindowGenerationFromRec::connectToUnity() { | ||
| 160 | - core_socket = new StreamSocket(); | ||
| 161 | - try{ | ||
| 162 | - static InetAddress* addr = InetAddress::createByName(HOST); | ||
| 163 | - core_socket->connect(addr, PORTNO); | ||
| 164 | - }catch(UnknownHostException ex){ | ||
| 165 | - throw ServiceException(ex.getMessage()); | ||
| 166 | - }catch(SocketException ex){ | ||
| 167 | - throw ServiceException(ex.getMessage()); | ||
| 168 | - } | ||
| 169 | -} | ||
| 170 | - | ||
| 171 | -void ServiceWindowGenerationFromRec::waitVideoGeneration() { | ||
| 172 | - char* endgeneration = new char[strlen(END_NOTIFICATION) + 1]; | ||
| 173 | - try{ | ||
| 174 | - do{ | ||
| 175 | - core_socket->read(endgeneration, sizeof(endgeneration)); | ||
| 176 | - }while(strcmp(endgeneration, END_NOTIFICATION) != 0); | ||
| 177 | - core_socket->close(); | ||
| 178 | - this->running = false; | ||
| 179 | - }catch(IOException ex){ | ||
| 180 | - throw ServiceException(ex.getMessage()); | ||
| 181 | - } | ||
| 182 | -} | ||
| 183 | - | ||
| 184 | void ServiceWindowGenerationFromRec::Run(){ | 168 | void ServiceWindowGenerationFromRec::Run(){ |
| 185 | while(isRunning()){ | 169 | while(isRunning()){ |
| 186 | usleep(200000); | 170 | usleep(200000); |
servico/src/serviceWindowGenerationFromSRT.cpp
| @@ -16,6 +16,7 @@ ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT(char* pathVideo, | @@ -16,6 +16,7 @@ ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT(char* pathVideo, | ||
| 16 | legendas_enviadas = 0; | 16 | legendas_enviadas = 0; |
| 17 | vetor_pts = new vector<int64_t >(); | 17 | vetor_pts = new vector<int64_t >(); |
| 18 | tradutor = new TradutorPortGlosa(); | 18 | tradutor = new TradutorPortGlosa(); |
| 19 | + renderer = new Renderer(); | ||
| 19 | extrator_factory = new ExtratorFactory(); | 20 | extrator_factory = new ExtratorFactory(); |
| 20 | try{ | 21 | try{ |
| 21 | setPathContents(); | 22 | setPathContents(); |
| @@ -38,6 +39,7 @@ ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT(char* pathSRT, in | @@ -38,6 +39,7 @@ ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT(char* pathSRT, in | ||
| 38 | legendas_enviadas = 0; | 39 | legendas_enviadas = 0; |
| 39 | vetor_pts = new vector<int64_t >(); | 40 | vetor_pts = new vector<int64_t >(); |
| 40 | tradutor = new TradutorPortGlosa(); | 41 | tradutor = new TradutorPortGlosa(); |
| 42 | + renderer = new Renderer(); | ||
| 41 | extrator_factory = new ExtratorFactory(); | 43 | extrator_factory = new ExtratorFactory(); |
| 42 | try{ | 44 | try{ |
| 43 | setPathContents(); | 45 | setPathContents(); |
| @@ -53,6 +55,7 @@ ServiceWindowGenerationFromSRT::~ServiceWindowGenerationFromSRT() { | @@ -53,6 +55,7 @@ ServiceWindowGenerationFromSRT::~ServiceWindowGenerationFromSRT() { | ||
| 53 | free(vetor_pts); | 55 | free(vetor_pts); |
| 54 | if (mixer) delete mixer; | 56 | if (mixer) delete mixer; |
| 55 | if (tradutor) delete tradutor; | 57 | if (tradutor) delete tradutor; |
| 58 | + if (renderer) delete renderer; | ||
| 56 | if (extratorSRT)delete extratorSRT; | 59 | if (extratorSRT)delete extratorSRT; |
| 57 | if (extrator_factory) delete extrator_factory; | 60 | if (extrator_factory) delete extrator_factory; |
| 58 | DDDPRINTF("Service SRT finalized!\n"); | 61 | DDDPRINTF("Service SRT finalized!\n"); |
| @@ -80,8 +83,11 @@ void ServiceWindowGenerationFromSRT::setPathContents() { | @@ -80,8 +83,11 @@ void ServiceWindowGenerationFromSRT::setPathContents() { | ||
| 80 | void ServiceWindowGenerationFromSRT::setSizeOfSubtitles(int sub_size) { | 83 | void ServiceWindowGenerationFromSRT::setSizeOfSubtitles(int sub_size) { |
| 81 | numero_legendas = sub_size; | 84 | numero_legendas = sub_size; |
| 82 | if (legendas_enviadas >= numero_legendas){ | 85 | if (legendas_enviadas >= numero_legendas){ |
| 83 | - sendGlosa(END_NOTIFICATION); | ||
| 84 | - waitVideoGeneration(); | 86 | + try{ |
| 87 | + renderer->finalize(); | ||
| 88 | + }catch(lavidlib::RuntimeException &ex){ | ||
| 89 | + throw ServiceException(ex.getMessage().c_str()); | ||
| 90 | + } | ||
| 85 | } | 91 | } |
| 86 | } | 92 | } |
| 87 | 93 | ||
| @@ -103,20 +109,34 @@ void ServiceWindowGenerationFromSRT::notifySubtitle(unsigned char *subtitle, int | @@ -103,20 +109,34 @@ void ServiceWindowGenerationFromSRT::notifySubtitle(unsigned char *subtitle, int | ||
| 103 | } | 109 | } |
| 104 | 110 | ||
| 105 | void ServiceWindowGenerationFromSRT::notifyTranslation(vector<string> * glosas) { | 111 | void ServiceWindowGenerationFromSRT::notifyTranslation(vector<string> * glosas) { |
| 112 | + string glosa = ""; | ||
| 106 | for (int i = 0; i < glosas->size(); i++) { | 113 | for (int i = 0; i < glosas->size(); i++) { |
| 107 | locale loc; | 114 | locale loc; |
| 108 | string glosa_lower = ""; | 115 | string glosa_lower = ""; |
| 109 | for (int k = 0; k < glosas->at(i).length(); k++){ | 116 | for (int k = 0; k < glosas->at(i).length(); k++){ |
| 110 | glosa_lower += std::tolower(glosas->at(i).at(k), loc); | 117 | glosa_lower += std::tolower(glosas->at(i).at(k), loc); |
| 111 | } | 118 | } |
| 112 | - sendGlosa(glosa_lower); | ||
| 113 | - //int64_t pts_notificado = vetor_pts->front(); | 119 | + glosa += glosa_lower; |
| 120 | + glosa += " "; | ||
| 121 | + | ||
| 114 | } | 122 | } |
| 115 | - | 123 | + int64_t pts_notificado = vetor_pts->front(); |
| 124 | + while(renderer->isSending()) | ||
| 125 | + usleep(10000); | ||
| 126 | + try{ | ||
| 127 | + renderer->receiveGlosa(glosa, pts_notificado); | ||
| 128 | + legendas_enviadas++; | ||
| 129 | + }catch(lavidlib::RuntimeException &ex){ | ||
| 130 | + throw ServiceException(ex.getMessage().c_str()); | ||
| 131 | + } | ||
| 116 | vetor_pts->erase(vetor_pts->begin()); | 132 | vetor_pts->erase(vetor_pts->begin()); |
| 117 | legendas_enviadas++; | 133 | legendas_enviadas++; |
| 118 | } | 134 | } |
| 119 | 135 | ||
| 136 | +void ServiceWindowGenerationFromSRT::notifyEndOfRenderization() { | ||
| 137 | + this->running = false; | ||
| 138 | +} | ||
| 139 | + | ||
| 120 | void ServiceWindowGenerationFromSRT::notifyEnd(int sub_size) { | 140 | void ServiceWindowGenerationFromSRT::notifyEnd(int sub_size) { |
| 121 | DPRINTF("Service SRT recebeu: %d legendas.\n", sub_size); | 141 | DPRINTF("Service SRT recebeu: %d legendas.\n", sub_size); |
| 122 | setSizeOfSubtitles(sub_size); | 142 | setSizeOfSubtitles(sub_size); |
| @@ -137,59 +157,19 @@ void ServiceWindowGenerationFromSRT::initialize() { | @@ -137,59 +157,19 @@ void ServiceWindowGenerationFromSRT::initialize() { | ||
| 137 | extratorSRT->setFilePath(path_srt); | 157 | extratorSRT->setFilePath(path_srt); |
| 138 | 158 | ||
| 139 | tradutor->addListener(this); | 159 | tradutor->addListener(this); |
| 140 | - | ||
| 141 | - // if (service_type != SERVICE_TYPE_SRT) { | ||
| 142 | - // uint64_t pcr_base = (uint64_t) 1000; //FIXME: macro | ||
| 143 | - // } | ||
| 144 | - | ||
| 145 | - connectToUnity(); | ||
| 146 | - | ||
| 147 | - try{ | 160 | + renderer->addListener(this); |
| 161 | + | ||
| 162 | + try{ | ||
| 163 | + renderer->Start(); | ||
| 148 | extratorSRT->initialize(); | 164 | extratorSRT->initialize(); |
| 149 | }catch(ExtratorException ex){ | 165 | }catch(ExtratorException ex){ |
| 150 | throw ServiceException(ex.getMessage()); | 166 | throw ServiceException(ex.getMessage()); |
| 167 | + }catch(RuntimeException &ex){ | ||
| 168 | + throw ServiceException(ex.getMessage().c_str()); | ||
| 151 | } | 169 | } |
| 152 | this->Start(); | 170 | this->Start(); |
| 153 | } | 171 | } |
| 154 | 172 | ||
| 155 | -void ServiceWindowGenerationFromSRT::sendGlosa(string glosa) { | ||
| 156 | - char* glosa_buffer = new char[strlen(glosa.c_str())+1]; | ||
| 157 | - strcpy(glosa_buffer, glosa.c_str()); | ||
| 158 | - int tamanho = strlen(glosa_buffer)+1; | ||
| 159 | - //cout << "Enviando glosa: " << glosa_buffer << endl; | ||
| 160 | - core_socket->write(glosa_buffer, tamanho); | ||
| 161 | - delete [] glosa_buffer; | ||
| 162 | - | ||
| 163 | - char* ok_core = new char[3]; | ||
| 164 | - core_socket->read(ok_core, 3); //aguarda o unity confirmar o recebimento da glosa | ||
| 165 | - delete [] ok_core; | ||
| 166 | -} | ||
| 167 | - | ||
| 168 | -void ServiceWindowGenerationFromSRT::connectToUnity() { | ||
| 169 | - core_socket = new StreamSocket(); | ||
| 170 | - try{ | ||
| 171 | - static InetAddress* addr = InetAddress::createByName(HOST); | ||
| 172 | - core_socket->connect(addr, PORTNO); | ||
| 173 | - }catch(UnknownHostException ex){ | ||
| 174 | - throw ServiceException(ex.getMessage()); | ||
| 175 | - }catch(SocketException ex){ | ||
| 176 | - throw ServiceException(ex.getMessage()); | ||
| 177 | - } | ||
| 178 | -} | ||
| 179 | - | ||
| 180 | -void ServiceWindowGenerationFromSRT::waitVideoGeneration() { | ||
| 181 | - char* endgeneration = new char[strlen(END_NOTIFICATION) + 1]; | ||
| 182 | - try{ | ||
| 183 | - do{ | ||
| 184 | - core_socket->read(endgeneration, sizeof(endgeneration)); | ||
| 185 | - }while(strcmp(endgeneration, END_NOTIFICATION) != 0); | ||
| 186 | - core_socket->close(); | ||
| 187 | - this->running = false; | ||
| 188 | - }catch(IOException ex){ | ||
| 189 | - throw ServiceException(ex.getMessage()); | ||
| 190 | - } | ||
| 191 | -} | ||
| 192 | - | ||
| 193 | void ServiceWindowGenerationFromSRT::Run() { | 173 | void ServiceWindowGenerationFromSRT::Run() { |
| 194 | while(isRunning()){ | 174 | while(isRunning()){ |
| 195 | usleep(200000); | 175 | usleep(200000); |
servico/src/serviceWindowGenerationFromText.cpp
| @@ -11,6 +11,7 @@ ServiceWindowGenerationFromText::ServiceWindowGenerationFromText(char* pathFile, | @@ -11,6 +11,7 @@ ServiceWindowGenerationFromText::ServiceWindowGenerationFromText(char* pathFile, | ||
| 11 | legendas_enviadas = 0; | 11 | legendas_enviadas = 0; |
| 12 | vetor_pts = new vector<int64_t >(); | 12 | vetor_pts = new vector<int64_t >(); |
| 13 | tradutor = new TradutorPortGlosa(); | 13 | tradutor = new TradutorPortGlosa(); |
| 14 | + renderer = new Renderer(); | ||
| 14 | extrator_factory = new ExtratorFactory(); | 15 | extrator_factory = new ExtratorFactory(); |
| 15 | try{ | 16 | try{ |
| 16 | setPathContents(); | 17 | setPathContents(); |
| @@ -25,6 +26,7 @@ ServiceWindowGenerationFromText::ServiceWindowGenerationFromText(char* pathFile, | @@ -25,6 +26,7 @@ ServiceWindowGenerationFromText::ServiceWindowGenerationFromText(char* pathFile, | ||
| 25 | ServiceWindowGenerationFromText::~ServiceWindowGenerationFromText() { | 26 | ServiceWindowGenerationFromText::~ServiceWindowGenerationFromText() { |
| 26 | free(vetor_pts); | 27 | free(vetor_pts); |
| 27 | if (tradutor) delete tradutor; | 28 | if (tradutor) delete tradutor; |
| 29 | + if (renderer) delete renderer; | ||
| 28 | if (extratorTXT)delete extratorTXT; | 30 | if (extratorTXT)delete extratorTXT; |
| 29 | if (extrator_factory) delete extrator_factory; | 31 | if (extrator_factory) delete extrator_factory; |
| 30 | DDDPRINTF("Service Text finalized!\n"); | 32 | DDDPRINTF("Service Text finalized!\n"); |
| @@ -48,10 +50,13 @@ void ServiceWindowGenerationFromText::setPathContents() { | @@ -48,10 +50,13 @@ void ServiceWindowGenerationFromText::setPathContents() { | ||
| 48 | } | 50 | } |
| 49 | 51 | ||
| 50 | void ServiceWindowGenerationFromText::setSizeOfSubtitles(int sub_size) { | 52 | void ServiceWindowGenerationFromText::setSizeOfSubtitles(int sub_size) { |
| 51 | - numero_legendas = sub_size; | 53 | + numero_legendas = sub_size; |
| 52 | if (legendas_enviadas >= numero_legendas){ | 54 | if (legendas_enviadas >= numero_legendas){ |
| 53 | - sendGlosa(END_NOTIFICATION); | ||
| 54 | - waitVideoGeneration(); | 55 | + try{ |
| 56 | + renderer->finalize(); | ||
| 57 | + }catch(lavidlib::RuntimeException &ex){ | ||
| 58 | + throw ServiceException(ex.getMessage().c_str()); | ||
| 59 | + } | ||
| 55 | } | 60 | } |
| 56 | } | 61 | } |
| 57 | 62 | ||
| @@ -64,15 +69,30 @@ void ServiceWindowGenerationFromText::notifyLine(unsigned char* line) { | @@ -64,15 +69,30 @@ void ServiceWindowGenerationFromText::notifyLine(unsigned char* line) { | ||
| 64 | } | 69 | } |
| 65 | 70 | ||
| 66 | void ServiceWindowGenerationFromText::notifyTranslation(vector<string> * glosas) { | 71 | void ServiceWindowGenerationFromText::notifyTranslation(vector<string> * glosas) { |
| 72 | + string glosa = ""; | ||
| 67 | for (int i = 0; i < glosas->size(); i++) { | 73 | for (int i = 0; i < glosas->size(); i++) { |
| 68 | locale loc; | 74 | locale loc; |
| 69 | string glosa_lower = ""; | 75 | string glosa_lower = ""; |
| 70 | for (int k = 0; k < glosas->at(i).length(); k++){ | 76 | for (int k = 0; k < glosas->at(i).length(); k++){ |
| 71 | glosa_lower += std::tolower(glosas->at(i).at(k), loc); | 77 | glosa_lower += std::tolower(glosas->at(i).at(k), loc); |
| 72 | } | 78 | } |
| 73 | - sendGlosa(glosa_lower); | 79 | + glosa += glosa_lower; |
| 80 | + glosa += " "; | ||
| 81 | + } | ||
| 82 | + while(renderer->isSending()){ | ||
| 83 | + usleep(10000); | ||
| 84 | + } // aguarda o renderizador processar a glosa anterior | ||
| 85 | + | ||
| 86 | + try{ | ||
| 87 | + renderer->receiveGlosa(glosa, (int64_t) -1); | ||
| 88 | + legendas_enviadas++; | ||
| 89 | + }catch(lavidlib::RuntimeException &ex){ | ||
| 90 | + throw ServiceException(ex.getMessage().c_str()); | ||
| 74 | } | 91 | } |
| 75 | - legendas_enviadas++; | 92 | +} |
| 93 | + | ||
| 94 | +void ServiceWindowGenerationFromText::notifyEndOfRenderization() { | ||
| 95 | + this->running = false; | ||
| 76 | } | 96 | } |
| 77 | 97 | ||
| 78 | void ServiceWindowGenerationFromText::notifyEnd(int line_size) { | 98 | void ServiceWindowGenerationFromText::notifyEnd(int line_size) { |
| @@ -95,55 +115,19 @@ void ServiceWindowGenerationFromText::initialize() { | @@ -95,55 +115,19 @@ void ServiceWindowGenerationFromText::initialize() { | ||
| 95 | extratorTXT->setFilePath(path_input); | 115 | extratorTXT->setFilePath(path_input); |
| 96 | 116 | ||
| 97 | tradutor->addListener(this); | 117 | tradutor->addListener(this); |
| 98 | - | ||
| 99 | - connectToUnity(); | ||
| 100 | - | 118 | + renderer->addListener(this); |
| 119 | + | ||
| 101 | try{ | 120 | try{ |
| 121 | + renderer->Start(); | ||
| 102 | extratorTXT->initialize(); | 122 | extratorTXT->initialize(); |
| 103 | }catch(ExtratorException ex){ | 123 | }catch(ExtratorException ex){ |
| 104 | - throw ServiceException(ex.getMessage()); | 124 | + throw ServiceException(ex.getMessage().c_str()); |
| 125 | + }catch(RuntimeException &ex){ | ||
| 126 | + throw ServiceException(ex.getMessage().c_str()); | ||
| 105 | } | 127 | } |
| 106 | this->Start(); | 128 | this->Start(); |
| 107 | } | 129 | } |
| 108 | 130 | ||
| 109 | -void ServiceWindowGenerationFromText::sendGlosa(string glosa) { | ||
| 110 | - char* glosa_buffer = new char[strlen(glosa.c_str())+1]; | ||
| 111 | - strcpy(glosa_buffer, glosa.c_str()); | ||
| 112 | - int tamanho = strlen(glosa_buffer)+1; | ||
| 113 | - //cout << "Enviando glosa: " << glosa_buffer << endl; | ||
| 114 | - core_socket->write(glosa_buffer, tamanho); | ||
| 115 | - delete [] glosa_buffer; | ||
| 116 | - | ||
| 117 | - char* ok_core = new char[3]; | ||
| 118 | - core_socket->read(ok_core, 3); //aguarda o unity confirmar o recebimento da glosa | ||
| 119 | - delete [] ok_core; | ||
| 120 | -} | ||
| 121 | - | ||
| 122 | -void ServiceWindowGenerationFromText::connectToUnity() { | ||
| 123 | - core_socket = new StreamSocket(); | ||
| 124 | - try{ | ||
| 125 | - static InetAddress* addr = InetAddress::createByName(HOST); | ||
| 126 | - core_socket->connect(addr, PORTNO); | ||
| 127 | - }catch(UnknownHostException ex){ | ||
| 128 | - throw ServiceException(ex.getMessage()); | ||
| 129 | - }catch(SocketException ex){ | ||
| 130 | - throw ServiceException(ex.getMessage()); | ||
| 131 | - } | ||
| 132 | -} | ||
| 133 | - | ||
| 134 | -void ServiceWindowGenerationFromText::waitVideoGeneration() { | ||
| 135 | - char* endgeneration = new char[strlen(END_NOTIFICATION) + 1]; | ||
| 136 | - try{ | ||
| 137 | - do{ | ||
| 138 | - core_socket->read(endgeneration, sizeof(endgeneration)); | ||
| 139 | - }while(strcmp(endgeneration, END_NOTIFICATION) != 0); | ||
| 140 | - core_socket->close(); | ||
| 141 | - this->running = false; | ||
| 142 | - }catch(IOException ex){ | ||
| 143 | - throw ServiceException(ex.getMessage()); | ||
| 144 | - } | ||
| 145 | -} | ||
| 146 | - | ||
| 147 | void ServiceWindowGenerationFromText::Run(){ | 131 | void ServiceWindowGenerationFromText::Run(){ |
| 148 | while(isRunning()){ | 132 | while(isRunning()){ |
| 149 | usleep(200000); | 133 | usleep(200000); |