diff --git a/renderer/src/include/listenerRenderer.h b/renderer/src/include/listenerRenderer.h new file mode 100644 index 0000000..b725618 --- /dev/null +++ b/renderer/src/include/listenerRenderer.h @@ -0,0 +1,14 @@ +#ifndef LISTENER_RENDERER_H +#define LISTENER_RENDERER_H + +#include +#include + +using namespace std; + +class ListenerRenderer { +public: + virtual void notifyEndOfRenderization() = 0; +}; + +#endif /* LISTENER_RENDERER_H */ \ No newline at end of file diff --git a/renderer/src/include/renderer.h b/renderer/src/include/renderer.h new file mode 100644 index 0000000..e897f92 --- /dev/null +++ b/renderer/src/include/renderer.h @@ -0,0 +1,57 @@ +#ifndef RENDERER_H +#define RENDERER_H + +#include "jthread.h" +#include "dprintf.h" +#include "stdint.h" +#include "string.h" +#include +#include +#include +#include +#include "listenerRenderer.h" +#include +#include +#include +#include +#include + +#define END_FLAG "FINALIZE" +// #define HOST "150.165.205.127" +// #define PORTNO 5555 +#define HOST "127.0.0.1" +#define PORTNO 12345 + +using namespace lavidlib; +using namespace jthread; +using namespace std; + +class Renderer : public Thread { +public: + Renderer(); + ~Renderer(); + + bool isSending(); + void receiveGlosa(std::string glosa, int64_t pts); + void addListener(ListenerRenderer* listener); + + void finalize(); + void Run(); + +private: + StreamSocket* core_socket; + list * listeners; + + bool running; + int count_task; + int glosa_processed; + + string glosa_copy; + + void notifyListeners(); + void sendGlosa(); + void connectToUnity(); + void waitScreenShots(); +}; + +#endif /* RENDERER_H */ diff --git a/renderer/src/renderer.cpp b/renderer/src/renderer.cpp new file mode 100644 index 0000000..570c016 --- /dev/null +++ b/renderer/src/renderer.cpp @@ -0,0 +1,116 @@ +#include "renderer.h" + +Renderer::Renderer() { + core_socket = new StreamSocket(); + listeners = new list(); + running = true; + count_task = 0; + glosa_processed = 0; + DPRINTF("Done!\n"); +} + +Renderer::~Renderer() { + listeners->clear(); + delete listeners; + if(core_socket) delete core_socket; + DDDPRINTF("Renderer finalized!\n"); +} + +void Renderer::addListener(ListenerRenderer* listener) { + listeners->push_back(listener); +} + +void Renderer::notifyListeners() { + for (list::iterator i = listeners->begin(); i != listeners->end(); i++) { + (*i)->notifyEndOfRenderization(); + } +} + +void Renderer::receiveGlosa(std::string glosa, int64_t pts) { + glosa_copy = glosa; + stringstream ss; + ss << pts; + glosa_copy += "#"; // '#' para identificar que vem um pts + glosa_copy += ss.str(); + count_task++; +} + +void Renderer::sendGlosa() { + try{ + int glosa_size = strlen(glosa_copy.c_str())+1; + char* glosa_buffer = new char[glosa_size]; + strcpy(glosa_buffer, glosa_copy.c_str()); + core_socket->write(glosa_buffer, glosa_size); + + char* ok_core = new char[3]; + do { + core_socket->read(ok_core, 3); //aguarda o unity confirmar o recebimento da glosa + }while(strcmp(ok_core, "OK") != 0); + glosa_processed++; + + delete [] ok_core; + delete [] glosa_buffer; + + }catch(lavidlib::RuntimeException &ex){ + throw lavidlib::RuntimeException(ex.getMessage().c_str()); + }catch(lavidlib::IOException &ex){ + throw lavidlib::RuntimeException(ex.getMessage().c_str()); + } +} + +void Renderer::connectToUnity() { + try{ + static InetAddress* addr = InetAddress::createByName(HOST); + core_socket->connect(addr, PORTNO); + }catch(lavidlib::UnknownHostException &ex){ + throw RuntimeException(ex.getMessage().c_str()); + }catch(lavidlib::SocketException &ex){ + throw RuntimeException(ex.getMessage().c_str()); + } +} + +void Renderer::waitScreenShots() { + char* endgeneration = new char[strlen(END_FLAG)+1]; + int connected; + try{ + do{ + + connected = core_socket->read(endgeneration, sizeof(endgeneration)); + }while(strcmp(endgeneration, END_FLAG) != 0 && connected != 0); + core_socket->close(); + notifyListeners(); + }catch(IOException &ex){ + throw RuntimeException(ex.getMessage().c_str()); + } +} + +void Renderer::finalize() { + while(glosa_processed < count_task) + usleep(10000); + receiveGlosa(END_FLAG, (int64_t) -1); + this->running = false; +} + +bool Renderer::isSending() { + if(glosa_processed < count_task) + return true; + else + return false; +} + +void Renderer::Run() { + try{ + while(running){ + while(count_task <= glosa_processed){ + usleep(10000); + } + if(!core_socket->isConnected()) + connectToUnity(); + sendGlosa(); + } + waitScreenShots(); + }catch(lavidlib::RuntimeException &ex){ + DDDDPRINTF("Erro: %s\n", ex.getMessage().c_str()); + throw RuntimeException(ex.getMessage().c_str()); + } +} \ No newline at end of file diff --git a/servico/src/include/serviceWindowGeneration.h b/servico/src/include/serviceWindowGeneration.h index a85b8cc..647d52e 100644 --- a/servico/src/include/serviceWindowGeneration.h +++ b/servico/src/include/serviceWindowGeneration.h @@ -5,18 +5,17 @@ #include #include #include +#include #include #include "jthread.h" #include "dprintf.h" #include "Mixer.h" +#include "renderer.h" +#include "listenerRenderer.h" #include "listenerTradutor.h" #include "tradutorPortGlosa.h" #include "serviceException.h" #include -#include -#include -#include -#include #include #define DEVELOPER "devel" @@ -24,11 +23,8 @@ #define PATH_DEVEL_CONTENTS "vlibras_user/vlibras-contents/videos/" #define PATH_DEVEL_UPLOADS "vlibras_user/vlibras-contents/uploads/" #define PATH_VBOX_UPLOADS "vlibras_user/.vlibras-conf/uploads/" -#define PATH_CONF_FILE "vlibras_user/.vlibras-conf/param.json" +#define PATH_CONF_FILE "vlibras_user/.vlibras-conf/params.json" #define MAX_SIZE_PATH 256 -#define END_NOTIFICATION "FINALIZE" -#define HOST "127.0.0.1" -#define PORTNO 12345 using namespace Json; using namespace Tradutor; @@ -40,8 +36,8 @@ class ServiceWindowGeneration { protected: TradutorPortGlosa* tradutor; + Renderer* renderer; Mixer* mixer; - StreamSocket* core_socket; Value root; Reader reader; @@ -68,10 +64,6 @@ protected: virtual void setSizeOfSubtitles(int sub_size) = 0; virtual void setPathContents() = 0; - - virtual void connectToUnity() = 0; - virtual void sendGlosa(string glosa) = 0; - virtual void waitVideoGeneration() = 0; public: virtual void initialize() = 0; diff --git a/servico/src/include/serviceWindowGenerationFromRec.h b/servico/src/include/serviceWindowGenerationFromRec.h index 5bab290..5843ee8 100644 --- a/servico/src/include/serviceWindowGenerationFromRec.h +++ b/servico/src/include/serviceWindowGenerationFromRec.h @@ -8,7 +8,7 @@ #define SERVICE_TYPE_REC 2 #define SERVICE_TYPE_REC_ONLY_AUDIO 5 -class ServiceWindowGenerationFromRec : public ServiceWindowGeneration, public RecognizeListener, public ListenerTradutor, public Thread { +class ServiceWindowGenerationFromRec : public ServiceWindowGeneration, public RecognizeListener, public ListenerTradutor, public ListenerRenderer, public Thread { private: Recognize* rec; @@ -16,11 +16,6 @@ private: void addPTS(int64_t pts); void setSizeOfSubtitles(int sub_size); void setPathContents(); - - void connectToUnity(); - void sendGlosa(string glosa); - void waitVideoGeneration(); - bool isRunning(); public: ServiceWindowGenerationFromRec(char* pathVideo, int sublanguage, int position, int size, @@ -30,6 +25,7 @@ public: ~ServiceWindowGenerationFromRec(); void notifyTextRecognized(unsigned char* text, int64_t pts); + void notifyEndOfRenderization(); void notifyTranslation(vector* glosas); void notifyTranslator(unsigned char* text); void notifyEnd(int sentences_size); diff --git a/servico/src/include/serviceWindowGenerationFromSRT.h b/servico/src/include/serviceWindowGenerationFromSRT.h index 57c206e..10e68c6 100644 --- a/servico/src/include/serviceWindowGenerationFromSRT.h +++ b/servico/src/include/serviceWindowGenerationFromSRT.h @@ -8,7 +8,7 @@ #define SERVICE_TYPE_SRT 1 #define SERVICE_TYPE_SRT_ONLY 4 -class ServiceWindowGenerationFromSRT : public ServiceWindowGeneration, public ListenerSRT, public ListenerTradutor, public Thread { +class ServiceWindowGenerationFromSRT : public ServiceWindowGeneration, public ListenerSRT, public ListenerTradutor, public ListenerRenderer, public Thread { private: ExtratorFactory* extrator_factory; @@ -19,11 +19,6 @@ private: void addPTS(int64_t pts); void setSizeOfSubtitles(int sub_size); void setPathContents(); - - void connectToUnity(); - void sendGlosa(string glosa); - void waitVideoGeneration(); - bool isRunning(); public: //construtor de serviço de video e legenda @@ -34,6 +29,7 @@ public: ~ServiceWindowGenerationFromSRT(); void notifySubtitle(unsigned char* subtitle, int64_t pts); + void notifyEndOfRenderization(); void notifyTranslation(vector* glosas); void notifyTranslator(unsigned char* text); void notifyEnd(int sub_size); diff --git a/servico/src/include/serviceWindowGenerationFromText.h b/servico/src/include/serviceWindowGenerationFromText.h index 9131a9c..1c13d35 100644 --- a/servico/src/include/serviceWindowGenerationFromText.h +++ b/servico/src/include/serviceWindowGenerationFromText.h @@ -7,7 +7,7 @@ #define MAX_TEXT_SIZE 2048 //FIXME: está restrito a 2K bytes de texto -class ServiceWindowGenerationFromText : public ServiceWindowGeneration, public ListenerTXT, public ListenerTradutor, public Thread { +class ServiceWindowGenerationFromText : public ServiceWindowGeneration, public ListenerTXT, public ListenerTradutor, public ListenerRenderer, public Thread { private: ExtratorFactory* extrator_factory; @@ -15,17 +15,13 @@ private: void setSizeOfSubtitles(int sub_size); void setPathContents(); - - void connectToUnity(); - void sendGlosa(string glosa); - void waitVideoGeneration(); - bool isRunning(); public: ServiceWindowGenerationFromText(char* pathFile, int transparency, char* id, char* client); ~ServiceWindowGenerationFromText(); void notifyLine(unsigned char* line); + void notifyEndOfRenderization(); void notifyTranslation(vector* glosas); void notifyTranslator(unsigned char* text); void notifyEnd(int line_size); diff --git a/servico/src/serviceWindowGenerationFromRec.cpp b/servico/src/serviceWindowGenerationFromRec.cpp index 9a20188..eab0ad3 100644 --- a/servico/src/serviceWindowGenerationFromRec.cpp +++ b/servico/src/serviceWindowGenerationFromRec.cpp @@ -15,6 +15,7 @@ ServiceWindowGenerationFromRec::ServiceWindowGenerationFromRec( vetor_pts = new vector(); rec = new Recognize(pathVideo, id, rate); tradutor = new TradutorPortGlosa(); + renderer = new Renderer(); running = true; finish = false; DPRINTF("Done!\n"); @@ -36,6 +37,7 @@ ServiceWindowGenerationFromRec::ServiceWindowGenerationFromRec( vetor_pts = new vector(); rec = new Recognize(path_input, id); tradutor = new TradutorPortGlosa(); + renderer = new Renderer(); try{ setPathContents(); }catch(RuntimeException ex){ @@ -49,6 +51,7 @@ ServiceWindowGenerationFromRec::ServiceWindowGenerationFromRec( ServiceWindowGenerationFromRec::~ServiceWindowGenerationFromRec(){ free(vetor_pts); if (tradutor) delete tradutor; + if (renderer) delete renderer; if (rec) delete rec; if (mixer) delete mixer; DDDPRINTF("Service Rec finished!\n"); @@ -80,8 +83,11 @@ void ServiceWindowGenerationFromRec::setPathContents(){ void ServiceWindowGenerationFromRec::setSizeOfSubtitles(int sub_size){ numero_legendas = sub_size; if (legendas_enviadas >= numero_legendas){ - sendGlosa(END_NOTIFICATION); - waitVideoGeneration(); + try{ + renderer->finalize(); + }catch(lavidlib::RuntimeException &ex){ + throw ServiceException(ex.getMessage().c_str()); + } } } @@ -100,23 +106,36 @@ void ServiceWindowGenerationFromRec::notifyTextRecognized(unsigned char* text, i } void ServiceWindowGenerationFromRec::notifyTranslation(vector * glosas) { + string glosa = ""; for (int i = 0; i < glosas->size(); i++) { locale loc; string glosa_lower = ""; for (int k = 0; k < glosas->at(i).length(); k++){ glosa_lower += std::tolower(glosas->at(i).at(k), loc); } - //int64_t pts_notificado = vetor_pts->front(); - sendGlosa(glosa_lower); + glosa += glosa_lower; + glosa += " "; + + } + int64_t pts_notificado = vetor_pts->front(); + while(renderer->isSending()) + usleep(10000); + try{ + renderer->receiveGlosa(glosa, pts_notificado); + legendas_enviadas++; + }catch(lavidlib::RuntimeException &ex){ + throw ServiceException(ex.getMessage().c_str()); } - vetor_pts->erase(vetor_pts->begin()); legendas_enviadas++; } +void ServiceWindowGenerationFromRec::notifyEndOfRenderization() { + running = false; +} + void ServiceWindowGenerationFromRec::notifyEnd(int sentences_size){ DPRINTF("Service REC recebeu: %d sentenças.\n", sentences_size); - cout << "chamou: " << sentences_size << endl; setSizeOfSubtitles(sentences_size); } @@ -133,54 +152,19 @@ void ServiceWindowGenerationFromRec::initialize(){ rec->addListener(this); tradutor->addListener(this); - connectToUnity(); - + renderer->addListener(this); + try{ + renderer->Start(); rec->initialize(); } catch(RecognizeException ex){ throw ServiceException(ex.getMessage()); - } + } catch(RuntimeException &ex){ + throw ServiceException(ex.getMessage().c_str()); + } this->Start(); } -void ServiceWindowGenerationFromRec::sendGlosa(string glosa) { - char* glosa_buffer = new char[strlen(glosa.c_str())+1]; - strcpy(glosa_buffer, glosa.c_str()); - int tamanho = strlen(glosa_buffer)+1; - //cout << "Enviando glosa: " << glosa_buffer << endl; - core_socket->write(glosa_buffer, tamanho); - delete [] glosa_buffer; - - char* ok_core = new char[4]; - core_socket->read(ok_core, 4); //aguarda o unity confirmar o recebimento da glosa - delete [] ok_core; -} - -void ServiceWindowGenerationFromRec::connectToUnity() { - core_socket = new StreamSocket(); - try{ - static InetAddress* addr = InetAddress::createByName(HOST); - core_socket->connect(addr, PORTNO); - }catch(UnknownHostException ex){ - throw ServiceException(ex.getMessage()); - }catch(SocketException ex){ - throw ServiceException(ex.getMessage()); - } -} - -void ServiceWindowGenerationFromRec::waitVideoGeneration() { - char* endgeneration = new char[strlen(END_NOTIFICATION) + 1]; - try{ - do{ - core_socket->read(endgeneration, sizeof(endgeneration)); - }while(strcmp(endgeneration, END_NOTIFICATION) != 0); - core_socket->close(); - this->running = false; - }catch(IOException ex){ - throw ServiceException(ex.getMessage()); - } -} - void ServiceWindowGenerationFromRec::Run(){ while(isRunning()){ usleep(200000); diff --git a/servico/src/serviceWindowGenerationFromSRT.cpp b/servico/src/serviceWindowGenerationFromSRT.cpp index 9bfa90c..197e892 100644 --- a/servico/src/serviceWindowGenerationFromSRT.cpp +++ b/servico/src/serviceWindowGenerationFromSRT.cpp @@ -16,6 +16,7 @@ ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT(char* pathVideo, legendas_enviadas = 0; vetor_pts = new vector(); tradutor = new TradutorPortGlosa(); + renderer = new Renderer(); extrator_factory = new ExtratorFactory(); try{ setPathContents(); @@ -38,6 +39,7 @@ ServiceWindowGenerationFromSRT::ServiceWindowGenerationFromSRT(char* pathSRT, in legendas_enviadas = 0; vetor_pts = new vector(); tradutor = new TradutorPortGlosa(); + renderer = new Renderer(); extrator_factory = new ExtratorFactory(); try{ setPathContents(); @@ -53,6 +55,7 @@ ServiceWindowGenerationFromSRT::~ServiceWindowGenerationFromSRT() { free(vetor_pts); if (mixer) delete mixer; if (tradutor) delete tradutor; + if (renderer) delete renderer; if (extratorSRT)delete extratorSRT; if (extrator_factory) delete extrator_factory; DDDPRINTF("Service SRT finalized!\n"); @@ -80,8 +83,11 @@ void ServiceWindowGenerationFromSRT::setPathContents() { void ServiceWindowGenerationFromSRT::setSizeOfSubtitles(int sub_size) { numero_legendas = sub_size; if (legendas_enviadas >= numero_legendas){ - sendGlosa(END_NOTIFICATION); - waitVideoGeneration(); + try{ + renderer->finalize(); + }catch(lavidlib::RuntimeException &ex){ + throw ServiceException(ex.getMessage().c_str()); + } } } @@ -103,20 +109,34 @@ void ServiceWindowGenerationFromSRT::notifySubtitle(unsigned char *subtitle, int } void ServiceWindowGenerationFromSRT::notifyTranslation(vector * glosas) { + string glosa = ""; for (int i = 0; i < glosas->size(); i++) { locale loc; string glosa_lower = ""; for (int k = 0; k < glosas->at(i).length(); k++){ glosa_lower += std::tolower(glosas->at(i).at(k), loc); } - sendGlosa(glosa_lower); - //int64_t pts_notificado = vetor_pts->front(); + glosa += glosa_lower; + glosa += " "; + } - + int64_t pts_notificado = vetor_pts->front(); + while(renderer->isSending()) + usleep(10000); + try{ + renderer->receiveGlosa(glosa, pts_notificado); + legendas_enviadas++; + }catch(lavidlib::RuntimeException &ex){ + throw ServiceException(ex.getMessage().c_str()); + } vetor_pts->erase(vetor_pts->begin()); legendas_enviadas++; } +void ServiceWindowGenerationFromSRT::notifyEndOfRenderization() { + this->running = false; +} + void ServiceWindowGenerationFromSRT::notifyEnd(int sub_size) { DPRINTF("Service SRT recebeu: %d legendas.\n", sub_size); setSizeOfSubtitles(sub_size); @@ -137,59 +157,19 @@ void ServiceWindowGenerationFromSRT::initialize() { extratorSRT->setFilePath(path_srt); tradutor->addListener(this); - - // if (service_type != SERVICE_TYPE_SRT) { - // uint64_t pcr_base = (uint64_t) 1000; //FIXME: macro - // } - - connectToUnity(); - - try{ + renderer->addListener(this); + + try{ + renderer->Start(); extratorSRT->initialize(); }catch(ExtratorException ex){ throw ServiceException(ex.getMessage()); + }catch(RuntimeException &ex){ + throw ServiceException(ex.getMessage().c_str()); } this->Start(); } -void ServiceWindowGenerationFromSRT::sendGlosa(string glosa) { - char* glosa_buffer = new char[strlen(glosa.c_str())+1]; - strcpy(glosa_buffer, glosa.c_str()); - int tamanho = strlen(glosa_buffer)+1; - //cout << "Enviando glosa: " << glosa_buffer << endl; - core_socket->write(glosa_buffer, tamanho); - delete [] glosa_buffer; - - char* ok_core = new char[3]; - core_socket->read(ok_core, 3); //aguarda o unity confirmar o recebimento da glosa - delete [] ok_core; -} - -void ServiceWindowGenerationFromSRT::connectToUnity() { - core_socket = new StreamSocket(); - try{ - static InetAddress* addr = InetAddress::createByName(HOST); - core_socket->connect(addr, PORTNO); - }catch(UnknownHostException ex){ - throw ServiceException(ex.getMessage()); - }catch(SocketException ex){ - throw ServiceException(ex.getMessage()); - } -} - -void ServiceWindowGenerationFromSRT::waitVideoGeneration() { - char* endgeneration = new char[strlen(END_NOTIFICATION) + 1]; - try{ - do{ - core_socket->read(endgeneration, sizeof(endgeneration)); - }while(strcmp(endgeneration, END_NOTIFICATION) != 0); - core_socket->close(); - this->running = false; - }catch(IOException ex){ - throw ServiceException(ex.getMessage()); - } -} - void ServiceWindowGenerationFromSRT::Run() { while(isRunning()){ usleep(200000); diff --git a/servico/src/serviceWindowGenerationFromText.cpp b/servico/src/serviceWindowGenerationFromText.cpp index da023c1..1be8b9e 100644 --- a/servico/src/serviceWindowGenerationFromText.cpp +++ b/servico/src/serviceWindowGenerationFromText.cpp @@ -11,6 +11,7 @@ ServiceWindowGenerationFromText::ServiceWindowGenerationFromText(char* pathFile, legendas_enviadas = 0; vetor_pts = new vector(); tradutor = new TradutorPortGlosa(); + renderer = new Renderer(); extrator_factory = new ExtratorFactory(); try{ setPathContents(); @@ -25,6 +26,7 @@ ServiceWindowGenerationFromText::ServiceWindowGenerationFromText(char* pathFile, ServiceWindowGenerationFromText::~ServiceWindowGenerationFromText() { free(vetor_pts); if (tradutor) delete tradutor; + if (renderer) delete renderer; if (extratorTXT)delete extratorTXT; if (extrator_factory) delete extrator_factory; DDDPRINTF("Service Text finalized!\n"); @@ -48,10 +50,13 @@ void ServiceWindowGenerationFromText::setPathContents() { } void ServiceWindowGenerationFromText::setSizeOfSubtitles(int sub_size) { - numero_legendas = sub_size; + numero_legendas = sub_size; if (legendas_enviadas >= numero_legendas){ - sendGlosa(END_NOTIFICATION); - waitVideoGeneration(); + try{ + renderer->finalize(); + }catch(lavidlib::RuntimeException &ex){ + throw ServiceException(ex.getMessage().c_str()); + } } } @@ -64,15 +69,30 @@ void ServiceWindowGenerationFromText::notifyLine(unsigned char* line) { } void ServiceWindowGenerationFromText::notifyTranslation(vector * glosas) { + string glosa = ""; for (int i = 0; i < glosas->size(); i++) { locale loc; string glosa_lower = ""; for (int k = 0; k < glosas->at(i).length(); k++){ glosa_lower += std::tolower(glosas->at(i).at(k), loc); } - sendGlosa(glosa_lower); + glosa += glosa_lower; + glosa += " "; + } + while(renderer->isSending()){ + usleep(10000); + } // aguarda o renderizador processar a glosa anterior + + try{ + renderer->receiveGlosa(glosa, (int64_t) -1); + legendas_enviadas++; + }catch(lavidlib::RuntimeException &ex){ + throw ServiceException(ex.getMessage().c_str()); } - legendas_enviadas++; +} + +void ServiceWindowGenerationFromText::notifyEndOfRenderization() { + this->running = false; } void ServiceWindowGenerationFromText::notifyEnd(int line_size) { @@ -95,55 +115,19 @@ void ServiceWindowGenerationFromText::initialize() { extratorTXT->setFilePath(path_input); tradutor->addListener(this); - - connectToUnity(); - + renderer->addListener(this); + try{ + renderer->Start(); extratorTXT->initialize(); }catch(ExtratorException ex){ - throw ServiceException(ex.getMessage()); + throw ServiceException(ex.getMessage().c_str()); + }catch(RuntimeException &ex){ + throw ServiceException(ex.getMessage().c_str()); } this->Start(); } -void ServiceWindowGenerationFromText::sendGlosa(string glosa) { - char* glosa_buffer = new char[strlen(glosa.c_str())+1]; - strcpy(glosa_buffer, glosa.c_str()); - int tamanho = strlen(glosa_buffer)+1; - //cout << "Enviando glosa: " << glosa_buffer << endl; - core_socket->write(glosa_buffer, tamanho); - delete [] glosa_buffer; - - char* ok_core = new char[3]; - core_socket->read(ok_core, 3); //aguarda o unity confirmar o recebimento da glosa - delete [] ok_core; -} - -void ServiceWindowGenerationFromText::connectToUnity() { - core_socket = new StreamSocket(); - try{ - static InetAddress* addr = InetAddress::createByName(HOST); - core_socket->connect(addr, PORTNO); - }catch(UnknownHostException ex){ - throw ServiceException(ex.getMessage()); - }catch(SocketException ex){ - throw ServiceException(ex.getMessage()); - } -} - -void ServiceWindowGenerationFromText::waitVideoGeneration() { - char* endgeneration = new char[strlen(END_NOTIFICATION) + 1]; - try{ - do{ - core_socket->read(endgeneration, sizeof(endgeneration)); - }while(strcmp(endgeneration, END_NOTIFICATION) != 0); - core_socket->close(); - this->running = false; - }catch(IOException ex){ - throw ServiceException(ex.getMessage()); - } -} - void ServiceWindowGenerationFromText::Run(){ while(isRunning()){ usleep(200000); -- libgit2 0.21.2