23 #include "fuse_transfer_widget.h"
25 #include "colormap_viewer_widget.h"
27 #include <fvmodels/color/lookuptable.h>
28 #include <fvutils/net/fuse_client.h>
29 #include <fvutils/net/fuse_lut_content.h>
30 #include <fvutils/net/fuse_lutlist_content.h>
31 #include <fvutils/net/fuse_message.h>
32 #include <netinet/in.h>
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(
55 sigc::mem_fun(*
this, &FuseTransferWidget::update_local_lut_list));
56 m_signal_update_remote_lut_list.connect(
57 sigc::mem_fun(*
this, &FuseTransferWidget::update_remote_lut_list));
58 m_signal_get_lut_list.connect(sigc::mem_fun(*
this, &FuseTransferWidget::get_lut_list));
59 m_signal_delete_client.connect(sigc::mem_fun(*
this, &FuseTransferWidget::delete_clients));
60 m_signal_update_remote_lut.connect(sigc::mem_fun(*
this, &FuseTransferWidget::update_remote_lut));
62 m_new_clients.clear();
63 m_delete_clients.clear();
65 m_cur_client.active =
false;
71 m_trv_local_lut_list = 0;
72 m_trv_remote_lut_list = 0;
78 delete m_local_colormap_viewer;
79 delete m_remote_colormap_viewer;
82 while (m_new_clients.size() != 0) {
90 m_new_clients.unlock();
92 if (m_cur_client.active) {
93 m_cur_client.active =
false;
94 m_delete_clients.push_locked(m_cur_client.client);
110 data.service_name = std::string(name);
111 data.host_name = std::string(host_name);
115 m_new_clients.push_locked(data);
116 m_signal_get_lut_list();
126 Gtk::TreeModel::Children children = m_remote_lut_list->children();
127 Gtk::TreeModel::Children::iterator iter = children.begin();
128 while (iter != children.end()) {
129 Gtk::TreeModel::Row row = *iter;
130 if (row[m_lut_record.service_name] == Glib::ustring(name)) {
131 iter = m_local_lut_list->erase(iter);
132 m_local_lut_list->row_deleted(m_local_lut_list->get_path(iter));
146 m_current_colormap = colormap;
149 Gtk::TreeModel::Children children = m_local_lut_list->children();
150 Gtk::TreeModel::Children::iterator iter = children.begin();
151 while (iter != children.end()) {
152 Gtk::TreeModel::Row row = *iter;
153 if (row[m_lut_record.filename] ==
"Current") {
154 iter = m_local_lut_list->erase(iter);
155 m_local_lut_list->row_deleted(m_local_lut_list->get_path(iter));
161 Gtk::TreeModel::Row row = *m_local_lut_list->prepend();
162 row[m_lut_record.filename] =
"Current";
163 row[m_lut_record.width] = colormap->
width();
164 row[m_lut_record.height] = colormap->
height();
165 row[m_lut_record.depth] = colormap->
depth();
169 FuseTransferWidget::update_local_lut_list()
171 if (m_trv_local_lut_list) {
172 m_trv_local_lut_list->queue_draw();
177 FuseTransferWidget::update_remote_lut_list()
179 if (m_trv_remote_lut_list) {
180 m_trv_remote_lut_list->queue_draw();
191 m_btn_upload->signal_clicked().connect(sigc::mem_fun(*
this, &FuseTransferWidget::upload_lut));
200 m_btn_download = btn;
210 m_local_colormap_viewer->set_colormap_img(m_img_local);
219 m_local_colormap_viewer->set_layer_selector(scl);
229 m_remote_colormap_viewer->set_colormap_img(m_img_remote);
238 m_remote_colormap_viewer->set_layer_selector(scl);
247 m_trv_local_lut_list = trv;
248 m_trv_local_lut_list->set_model(m_local_lut_list);
249 m_trv_local_lut_list->append_column(
"Filename", m_lut_record.filename);
250 m_trv_local_lut_list->append_column(
"Width", m_lut_record.width);
251 m_trv_local_lut_list->append_column(
"Height", m_lut_record.height);
252 m_trv_local_lut_list->append_column(
"Depth", m_lut_record.depth);
255 m_trv_local_lut_list->signal_cursor_changed().connect(
256 sigc::mem_fun(*
this, &FuseTransferWidget::local_lut_selected));
265 m_trv_remote_lut_list = trv;
266 m_trv_remote_lut_list->set_model(m_remote_lut_list);
267 m_trv_remote_lut_list->append_column(
"Host", m_lut_record.host_name);
269 m_trv_remote_lut_list->append_column(
"ID", m_lut_record.lut_id);
270 m_trv_remote_lut_list->append_column(
"Width", m_lut_record.width);
271 m_trv_remote_lut_list->append_column(
"Height", m_lut_record.height);
272 m_trv_remote_lut_list->append_column(
"Depth", m_lut_record.depth);
273 m_trv_remote_lut_list->append_column(
"BPC", m_lut_record.bytes_per_cell);
275 m_trv_remote_lut_list->signal_cursor_changed().connect(
276 sigc::mem_fun(*
this, &FuseTransferWidget::remote_lut_selected));
280 FuseTransferWidget::get_lut_list()
282 if (m_cur_client.active)
288 m_new_clients.lock();
289 if (m_new_clients.size() == 0) {
290 m_new_clients.unlock();
294 m_cur_client = m_new_clients.front();
295 m_cur_client.active =
true;
297 m_new_clients.unlock();
300 m_cur_client.client =
new FuseClient(m_cur_client.host_name.c_str(), m_cur_client.port,
this);
301 m_cur_client.client->connect();
302 m_cur_client.client->start();
303 m_cur_client.client->enqueue(FUSE_MT_GET_LUT_LIST);
306 m_cur_client.client->cancel();
307 m_cur_client.client->join();
308 delete m_cur_client.client;
309 m_cur_client.active =
false;
314 FuseTransferWidget::delete_clients()
316 m_delete_clients.lock();
317 while (m_delete_clients.size() != 0) {
319 m_delete_clients.pop();
326 m_delete_clients.unlock();
330 FuseTransferWidget::update_local_lut()
336 m_local_colormap_viewer->draw();
340 FuseTransferWidget::update_remote_lut()
346 m_remote_colormap_viewer->draw();
350 FuseTransferWidget::upload_lut()
352 if (!m_local_colormap) {
357 Glib::RefPtr<Gtk::TreeSelection> selection = m_trv_remote_lut_list->get_selection();
359 if (1 != selection->count_selected_rows()) {
360 printf(
"No remote lut selected\n");
364 Gtk::TreeModel::iterator i = selection->get_selected();
365 Glib::ustring hostname = (*i)[m_lut_record.host_name];
366 unsigned int port = (*i)[m_lut_record.port];
367 Glib::ustring lut_id = (*i)[m_lut_record.lut_id];
369 printf(
"sending lut to %s:%u id %s\n", hostname.c_str(), port, lut_id.c_str());
372 m_local_colormap->get_buffer(),
373 m_local_colormap->width(),
374 m_local_colormap->height(),
375 m_local_colormap->depth(),
389 m_delete_clients.push_locked(client);
399 FuseTransferWidget::local_lut_selected()
401 Glib::RefPtr<Gtk::TreeSelection> selection = m_trv_local_lut_list->get_selection();
402 if (selection->count_selected_rows() != 1) {
406 Gtk::TreeModel::iterator it = selection->get_selected();
407 Glib::ustring filename = (*it)[m_lut_record.filename];
409 if (filename ==
"Current") {
410 m_local_colormap = m_current_colormap;
415 m_local_colormap_viewer->set_colormap(m_local_colormap);
420 FuseTransferWidget::remote_lut_selected()
422 Glib::RefPtr<Gtk::TreeSelection> selection = m_trv_remote_lut_list->get_selection();
423 if (selection->count_selected_rows() != 1) {
427 Gtk::TreeModel::iterator it = selection->get_selected();
428 Glib::ustring host_name = (*it)[m_lut_record.host_name];
429 unsigned int port = (*it)[m_lut_record.port];
430 Glib::ustring lut_id = (*it)[m_lut_record.lut_id];
440 strncpy(lut_desc->
lut_id, lut_id.c_str(), LUT_ID_MAX_LENGTH - 1);
443 m_delete_clients.push_locked(c);
454 uint32_t remote_version)
throw()
456 printf(
"Invalid versions: local: %u remote: %u\n", local_version, remote_version);
467 if (m_cur_client.active) {
468 m_delete_clients.push_locked(m_cur_client.client);
469 m_cur_client.active =
false;
472 m_signal_delete_client();
479 case FUSE_MT_LUT_LIST:
486 char lut_id[LUT_ID_MAX_LENGTH + 1];
487 lut_id[LUT_ID_MAX_LENGTH] =
'\0';
488 strncpy(lut_id, lut_info->
lut_id, LUT_ID_MAX_LENGTH);
490 Gtk::TreeModel::Children children = m_remote_lut_list->children();
491 Gtk::TreeModel::Children::iterator iter = children.begin();
492 while (iter != children.end()) {
493 Gtk::TreeModel::Row row = *iter;
494 if (row[m_lut_record.lut_id] == Glib::ustring(lut_id)) {
495 iter = m_remote_lut_list->erase(iter);
501 Gtk::TreeModel::Row row = *m_remote_lut_list->append();
502 row[m_lut_record.service_name] = Glib::ustring(m_cur_client.service_name);
503 row[m_lut_record.host_name] = Glib::ustring(m_cur_client.host_name);
504 row[m_lut_record.port] = m_cur_client.port;
505 row[m_lut_record.lut_id] = Glib::ustring(lut_id);
506 row[m_lut_record.width] = ntohl(lut_info->
width);
507 row[m_lut_record.height] = ntohl(lut_info->
height);
508 row[m_lut_record.depth] = ntohl(lut_info->
depth);
509 row[m_lut_record.bytes_per_cell] = ntohl(lut_info->
bytes_per_cell);
517 m_delete_clients.push_locked(m_cur_client.client);
518 m_cur_client.active =
false;
520 m_signal_update_remote_lut_list();
521 m_signal_get_lut_list();
522 m_signal_delete_client();
530 if (m_remote_colormap) {
531 delete m_remote_colormap;
534 if (lut_content->
width() != 256 || lut_content->
height() != 256) {
535 m_signal_delete_client();
540 m_remote_colormap->set(lut_content->
buffer());
546 m_remote_colormap_viewer->set_colormap(m_remote_colormap);
547 m_signal_update_remote_lut();
548 m_signal_delete_client();
552 case FUSE_MT_SET_LUT_FAILED: printf(
"LUT upload failed\n");
554 case FUSE_MT_SET_LUT_SUCCEEDED:
555 printf(
"LUT upload succeeded\n");
556 m_signal_delete_client();
559 default: printf(
"Unhandled message type\n");
Base class for exceptions in Fawkes.
void print_trace()
Prints trace to stderr.
void start(bool wait=true)
Call this method to start the thread.
void join()
Join the thread.
void cancel()
Cancel a thread.
void enqueue(FuseNetworkMessage *m)
Enqueue message.
void disconnect()
Disconnect.
FUSE lookup table content.
unsigned char * buffer() const
Get buffer.
unsigned int height() const
Height of LUT.
unsigned int depth() const
Depth of LUT.
unsigned int width() const
Width of LUT.
FUSE lookup table list content.
bool has_next()
Check if another LUT info is available.
FUSE_lutinfo_t * next()
Get next LUT info.
virtual unsigned int height() const
Get height of colormap.
virtual unsigned int depth() const
Get depth of colormap.
virtual unsigned int width() const
Get width of colormap.
Fawkes library namespace.
char lut_id[LUT_ID_MAX_LENGTH]
LUT ID.
uint32_t height
height of LUT
uint32_t bytes_per_cell
bytes per cell
uint32_t width
width of LUT
uint32_t depth
depth of LUT
char lut_id[LUT_ID_MAX_LENGTH]
LUT ID.