Commit d3a60ed1 authored by artificiel's avatar artificiel
Browse files

ClientConnector: demenagement du handle TCP dans la thread

parent d08c4eaf
......@@ -2,6 +2,7 @@
#include "ClientsManager.hpp"
#include "ofThread.h"
#include "ofxGui.h"
#include "ofxTimeMeasurements.h"
namespace ofxCloudLib
{
......@@ -22,7 +23,6 @@ ClientConnector::ClientConnector(int start_port, int tcp_port, int osc_port,
tcp_port_ = tcp_port;
osc_port_ = osc_port;
last_mesh_.setMode(OF_PRIMITIVE_POINTS);
sticky_mesh_.setMode(OF_PRIMITIVE_POINTS);
......@@ -46,12 +46,20 @@ void ClientConnector::threadedFunction()
xyz_receiver_.receive(fresh_mesh);
if (fresh_mesh.getNumVertices()) {
fresh_mesh.removeVertex(0);
TS_START("Client::send channel thread");
aggregated_.send(std::move(fresh_mesh));
TS_STOP("Client::send channel thread");
}
// std::cout << "NEW CLOUD IN THREAD " << client_name_ << "#" << cloud_counter_ << std::endl;
} else {
std::this_thread::sleep_for(std::chrono::milliseconds(10));
handle_connection();
// TS_START("Client::sleep()");
// std::this_thread::sleep_for(std::chrono::milliseconds(10));
// TS_STOP("Client::sleep()");
}
}
}
......@@ -67,9 +75,7 @@ bool ClientConnector::is_xyz_new()
void ClientConnector::setup()
{
AbstractClient::setup();
// de l'extérieur!
gui_.add(parameters_);
gui_.add(cropper_parameters_);
......@@ -79,7 +85,7 @@ void ClientConnector::receive_mesh()
{
while (aggregated_.tryReceive(last_mesh_)) {
// std::cout << "...NEW FRAME IN THREAD A " << client_name_ << std::endl;
// std::cout << "...NEW FRAME IN THREAD A " << client_name_ << std::endl;
is_new_ = true;
}
......@@ -141,9 +147,22 @@ void ClientConnector::draw()
void ClientConnector::update()
{
// handle_connection();
}
void ClientConnector::handle_connection()
{
// if (dead_client_) return;
TS_START("ClientConnector::handle_connection()");
bool res = false;
res = isConnected();
if (res) {
if (isConnected()) {
if (sync_active_) osc_sync_.update();
......@@ -166,6 +185,7 @@ void ClientConnector::update()
// std::cout << " tokens:" << t << std::endl;
}
lock();
if (message.size() == 0) {
std::cout << "TCP erreur: message vide" << std::endl;
} else if (message[0] == "zero") {
......@@ -223,9 +243,12 @@ void ClientConnector::update()
std::cout << "got TCP unknown msg from " << client_name_ << ":" << str
<< std::endl;
}
unlock();
// std::cout << "DONE PROCESSING TCP STREAM FROM " << client_name_ << std::endl;
}
} else {
delta_time_ = ofGetElapsedTimeMillis() - connect_time_;
if (delta_time_ > reconnect_time_) {
......@@ -256,5 +279,6 @@ void ClientConnector::update()
connect_time_ = ofGetElapsedTimeMillis();
}
}
TS_STOP("ClientConnector::handle_connection()");
}
}
\ No newline at end of file
......@@ -47,6 +47,7 @@ class ClientConnector : public ofxTCPClient,
private:
void threadedFunction();
void handle_connection();
ofThreadChannel<ofMesh> aggregated_;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment