23 #include "fuse_transfer_widget.h"
24 #include "colormap_viewer_widget.h"
26 #include <fvutils/net/fuse_client.h>
27 #include <fvutils/net/fuse_message.h>
28 #include <fvutils/net/fuse_lut_content.h>
29 #include <fvutils/net/fuse_lutlist_content.h>
31 #include <fvmodels/color/lookuptable.h>
33 #include <netinet/in.h>
36 using namespace fawkes;
37 using namespace firevision;
51 m_local_lut_list = Gtk::ListStore::create(m_lut_record);
52 m_remote_lut_list = Gtk::ListStore::create(m_lut_record);
54 m_signal_update_local_lut_list.connect( sigc::mem_fun( *
this, &FuseTransferWidget::update_local_lut_list) );
55 m_signal_update_remote_lut_list.connect( sigc::mem_fun( *
this, &FuseTransferWidget::update_remote_lut_list) );
56 m_signal_get_lut_list.connect( sigc::mem_fun( *
this, &FuseTransferWidget::get_lut_list) );
57 m_signal_delete_client.connect( sigc::mem_fun( *
this, &FuseTransferWidget::delete_clients) );
58 m_signal_update_remote_lut.connect( sigc::mem_fun( *
this, &FuseTransferWidget::update_remote_lut) );
60 m_new_clients.clear();
61 m_delete_clients.clear();
63 m_cur_client.active =
false;
69 m_trv_local_lut_list = 0;
70 m_trv_remote_lut_list = 0;
76 delete m_local_colormap_viewer;
77 delete m_remote_colormap_viewer;
81 while (m_new_clients.size() != 0)
83 c = m_new_clients.front().client;
90 m_new_clients.unlock();
92 if (m_cur_client.active)
94 m_cur_client.active =
false;
95 m_delete_clients.push_locked(m_cur_client.client);
108 const char* host_name,
113 data.service_name = std::string(name);
114 data.host_name = std::string(host_name);
118 m_new_clients.push_locked(data);
119 m_signal_get_lut_list();
129 Gtk::TreeModel::Children children = m_remote_lut_list->children();
130 Gtk::TreeModel::Children::iterator iter = children.begin();
131 while( iter != children.end() )
133 Gtk::TreeModel::Row row = *iter;
134 if (row[m_lut_record.service_name] == Glib::ustring(name))
136 iter = m_local_lut_list->erase(iter);
137 m_local_lut_list->row_deleted( m_local_lut_list->get_path(iter) );
153 m_current_colormap = colormap;
156 Gtk::TreeModel::Children children = m_local_lut_list->children();
157 Gtk::TreeModel::Children::iterator iter = children.begin();
158 while ( iter != children.end() )
160 Gtk::TreeModel::Row row = *iter;
161 if (row[m_lut_record.filename] ==
"Current")
163 iter = m_local_lut_list->erase(iter);
164 m_local_lut_list->row_deleted( m_local_lut_list->get_path(iter) );
172 Gtk::TreeModel::Row row = *m_local_lut_list->prepend();
173 row[m_lut_record.filename] =
"Current";
174 row[m_lut_record.width] = colormap->
width();
175 row[m_lut_record.height] = colormap->
height();
176 row[m_lut_record.depth] = colormap->
depth();
180 FuseTransferWidget::update_local_lut_list()
182 if (m_trv_local_lut_list)
183 { m_trv_local_lut_list->queue_draw(); }
187 FuseTransferWidget::update_remote_lut_list()
189 if (m_trv_remote_lut_list)
190 { m_trv_remote_lut_list->queue_draw(); }
200 m_btn_upload->signal_clicked().connect( sigc::mem_fun( *
this, &FuseTransferWidget::upload_lut) );
209 m_btn_download = btn;
219 m_local_colormap_viewer->set_colormap_img(m_img_local);
228 m_local_colormap_viewer->set_layer_selector(scl);
238 m_remote_colormap_viewer->set_colormap_img(m_img_remote);
247 m_remote_colormap_viewer->set_layer_selector(scl);
256 m_trv_local_lut_list = trv;
257 m_trv_local_lut_list->set_model(m_local_lut_list);
258 m_trv_local_lut_list->append_column(
"Filename", m_lut_record.filename);
259 m_trv_local_lut_list->append_column(
"Width", m_lut_record.width);
260 m_trv_local_lut_list->append_column(
"Height", m_lut_record.height);
261 m_trv_local_lut_list->append_column(
"Depth", m_lut_record.depth);
264 m_trv_local_lut_list->signal_cursor_changed().connect( sigc::mem_fun( *
this, &FuseTransferWidget::local_lut_selected) );
273 m_trv_remote_lut_list = trv;
274 m_trv_remote_lut_list->set_model(m_remote_lut_list);
275 m_trv_remote_lut_list->append_column(
"Host", m_lut_record.host_name);
277 m_trv_remote_lut_list->append_column(
"ID", m_lut_record.lut_id);
278 m_trv_remote_lut_list->append_column(
"Width", m_lut_record.width);
279 m_trv_remote_lut_list->append_column(
"Height", m_lut_record.height);
280 m_trv_remote_lut_list->append_column(
"Depth", m_lut_record.depth);
281 m_trv_remote_lut_list->append_column(
"BPC", m_lut_record.bytes_per_cell);
283 m_trv_remote_lut_list->signal_cursor_changed().connect( sigc::mem_fun( *
this, &FuseTransferWidget::remote_lut_selected) );
287 FuseTransferWidget::get_lut_list()
289 if (m_cur_client.active)
293 m_new_clients.lock();
294 if (m_new_clients.size() == 0)
296 m_new_clients.unlock();
300 m_cur_client = m_new_clients.front();
301 m_cur_client.active =
true;
303 m_new_clients.unlock();
307 m_cur_client.client =
new FuseClient( m_cur_client.host_name.c_str(),
308 m_cur_client.port, this );
309 m_cur_client.client->
connect();
310 m_cur_client.client->start();
311 m_cur_client.client->enqueue(FUSE_MT_GET_LUT_LIST);
316 m_cur_client.client->cancel();
317 m_cur_client.client->join();
318 delete m_cur_client.client;
319 m_cur_client.active =
false;
324 FuseTransferWidget::delete_clients()
328 m_delete_clients.lock();
329 while (m_delete_clients.size() != 0)
331 c = m_delete_clients.front();
332 m_delete_clients.pop();
339 m_delete_clients.unlock();
343 FuseTransferWidget::update_local_lut()
348 m_local_colormap_viewer->draw();
352 FuseTransferWidget::update_remote_lut()
357 m_remote_colormap_viewer->draw();
361 FuseTransferWidget::upload_lut()
363 if ( !m_local_colormap )
367 Glib::RefPtr<Gtk::TreeSelection> selection = m_trv_remote_lut_list->get_selection();
369 if ( 1 != selection->count_selected_rows() )
371 printf(
"No remote lut selected\n");
375 Gtk::TreeModel::iterator i = selection->get_selected();
376 Glib::ustring hostname = (*i)[m_lut_record.host_name];
377 unsigned int port = (*i)[m_lut_record.port];
378 Glib::ustring lut_id = (*i)[m_lut_record.lut_id];
380 printf(
"sending lut to %s:%d id %s\n", hostname.c_str(), port, lut_id.c_str());
383 m_local_colormap->get_buffer(),
384 m_local_colormap->width(),
385 m_local_colormap->height(),
386 m_local_colormap->depth(),
401 m_delete_clients.push_locked(client);
413 FuseTransferWidget::local_lut_selected()
415 Glib::RefPtr<Gtk::TreeSelection> selection = m_trv_local_lut_list->get_selection();
416 if (selection->count_selected_rows() != 1)
419 Gtk::TreeModel::iterator it = selection->get_selected();
420 Glib::ustring filename = (*it)[m_lut_record.filename];
422 if (filename ==
"Current")
424 m_local_colormap = m_current_colormap;
431 m_local_colormap_viewer->set_colormap(m_local_colormap);
436 FuseTransferWidget::remote_lut_selected()
438 Glib::RefPtr<Gtk::TreeSelection> selection = m_trv_remote_lut_list->get_selection();
439 if (selection->count_selected_rows() != 1)
442 Gtk::TreeModel::iterator it = selection->get_selected();
443 Glib::ustring host_name = (*it)[m_lut_record.host_name];
444 unsigned int port = (*it)[m_lut_record.port];
445 Glib::ustring lut_id = (*it)[m_lut_record.lut_id];
455 strncpy(lut_desc->
lut_id, lut_id.c_str(), LUT_ID_MAX_LENGTH);
458 m_delete_clients.push_locked(c);
471 uint32_t remote_version)
throw()
473 printf(
"Invalid versions: local: %u remote: %u\n", local_version, remote_version);
484 if (m_cur_client.active)
486 m_delete_clients.push_locked(m_cur_client.client);
487 m_cur_client.active =
false;
490 m_signal_delete_client();
498 case FUSE_MT_LUT_LIST:
508 char lut_id[LUT_ID_MAX_LENGTH + 1];
509 lut_id[LUT_ID_MAX_LENGTH] =
'\0';
510 strncpy(lut_id, lut_info->
lut_id, LUT_ID_MAX_LENGTH);
512 Gtk::TreeModel::Children children = m_remote_lut_list->children();
513 Gtk::TreeModel::Children::iterator iter = children.begin();
514 while ( iter != children.end() )
516 Gtk::TreeModel::Row row = *iter;
517 if ( row[m_lut_record.lut_id] == Glib::ustring(lut_id) )
518 { iter = m_remote_lut_list->erase(iter); }
523 Gtk::TreeModel::Row row = *m_remote_lut_list->append();
524 row[m_lut_record.service_name] = Glib::ustring(m_cur_client.service_name);
525 row[m_lut_record.host_name] = Glib::ustring(m_cur_client.host_name);
526 row[m_lut_record.port] = m_cur_client.port;
527 row[m_lut_record.lut_id] = Glib::ustring(lut_id);
528 row[m_lut_record.width] = ntohl(lut_info->
width);
529 row[m_lut_record.height] = ntohl(lut_info->
height);
530 row[m_lut_record.depth] = ntohl(lut_info->
depth);
531 row[m_lut_record.bytes_per_cell] = ntohl(lut_info->
bytes_per_cell);
541 m_delete_clients.push_locked(m_cur_client.client);
542 m_cur_client.active =
false;
544 m_signal_update_remote_lut_list();
545 m_signal_get_lut_list();
546 m_signal_delete_client();
555 if (m_remote_colormap)
556 {
delete m_remote_colormap; }
558 if ( lut_content->
width() != 256 ||
559 lut_content->
height() != 256 )
561 m_signal_delete_client();
566 m_remote_colormap->
set( lut_content->
buffer() );
574 m_remote_colormap_viewer->set_colormap(m_remote_colormap);
575 m_signal_update_remote_lut();
576 m_signal_delete_client();
580 case FUSE_MT_SET_LUT_FAILED:
581 printf(
"LUT upload failed\n");
583 case FUSE_MT_SET_LUT_SUCCEEDED:
584 printf(
"LUT upload succeeded\n");
585 m_signal_delete_client();
589 printf(
"Unhandled message type\n");