1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872
|
/* -*- Mode: C ; c-basic-offset: 2 -*- */
/*
* LADI Session Handler (ladish)
*
* Copyright (C) 2009, 2010, 2011 Nedko Arnaudov <nedko@arnaudov.name>
*
**************************************************************************
* This file contains implementation of graph canvas object
**************************************************************************
*
* LADI Session Handler is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* LADI Session Handler is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
* or write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <locale.h>
#include "graph_canvas.h"
#include "../dbus_constants.h"
#include "../common/catdup.h"
#include "internal.h"
struct graph_canvas
{
graph_proxy_handle graph;
canvas_handle canvas;
void (* fill_menu)(GtkMenu * menu);
struct list_head clients;
};
struct client
{
struct list_head siblings;
uint64_t id;
canvas_module_handle canvas_module;
struct list_head ports;
struct graph_canvas * owner_ptr;
unsigned int inport_count;
unsigned int outport_count;
};
struct port
{
struct list_head siblings;
uint64_t id;
bool is_input;
canvas_port_handle canvas_port;
struct graph_canvas * graph_canvas;
};
static
struct client *
find_client(
struct graph_canvas * graph_canvas_ptr,
uint64_t id)
{
struct list_head * node_ptr;
struct client * client_ptr;
list_for_each(node_ptr, &graph_canvas_ptr->clients)
{
client_ptr = list_entry(node_ptr, struct client, siblings);
if (client_ptr->id == id)
{
return client_ptr;
}
}
return NULL;
}
static
struct port *
find_port(
struct client * client_ptr,
uint64_t id)
{
struct list_head * node_ptr;
struct port * port_ptr;
list_for_each(node_ptr, &client_ptr->ports)
{
port_ptr = list_entry(node_ptr, struct port, siblings);
if (port_ptr->id == id)
{
return port_ptr;
}
}
return NULL;
}
#define port1_ptr ((struct port *)port1_context)
#define port2_ptr ((struct port *)port2_context)
static
void
connect_request(
void * port1_context,
void * port2_context)
{
log_info("connect request(%"PRIu64", %"PRIu64")", port1_ptr->id, port2_ptr->id);
ASSERT(port1_ptr->graph_canvas == port2_ptr->graph_canvas);
graph_proxy_connect_ports(port1_ptr->graph_canvas->graph, port1_ptr->id, port2_ptr->id);
}
void
disconnect_request(
void * port1_context,
void * port2_context)
{
log_info("disconnect request(%"PRIu64", %"PRIu64")", port1_ptr->id, port2_ptr->id);
ASSERT(port1_ptr->graph_canvas == port2_ptr->graph_canvas);
graph_proxy_disconnect_ports(port1_ptr->graph_canvas->graph, port1_ptr->id, port2_ptr->id);
}
#undef port1_ptr
#undef port2_ptr
#define client_ptr ((struct client *)module_context)
void
module_location_changed(
void * module_context,
double x,
double y)
{
char x_str[100];
char y_str[100];
char * locale;
log_info("module_location_changed(id = %3llu, x = %6.1f, y = %6.1f)", (unsigned long long)client_ptr->id, x, y);
locale = strdup(setlocale(LC_NUMERIC, NULL));
if (locale == NULL)
{
log_error("strdup() failed for locale string");
return;
}
setlocale(LC_NUMERIC, "POSIX");
sprintf(x_str, "%f", x);
sprintf(y_str, "%f", y);
setlocale(LC_NUMERIC, locale);
free(locale);
graph_proxy_dict_entry_set(
client_ptr->owner_ptr->graph,
GRAPH_DICT_OBJECT_TYPE_CLIENT,
client_ptr->id,
URI_CANVAS_X,
x_str);
graph_proxy_dict_entry_set(
client_ptr->owner_ptr->graph,
GRAPH_DICT_OBJECT_TYPE_CLIENT,
client_ptr->id,
URI_CANVAS_Y,
y_str);
}
static void on_popup_menu_action_client_rename(GtkWidget * menuitem, gpointer module_context)
{
log_info("on_popup_menu_action_client_rename %"PRIu64, client_ptr->id);
char * new_name;
if (name_dialog(_("Rename client"), _("Client name"), canvas_get_module_name(client_ptr->canvas_module), &new_name))
{
if (!graph_proxy_rename_client(client_ptr->owner_ptr->graph, client_ptr->id, new_name))
{
error_message_box("Rename failed");
}
free(new_name);
}
}
static void on_popup_menu_action_split(GtkWidget * menuitem, gpointer module_context)
{
//log_info("on_popup_menu_action_split");
graph_proxy_split(client_ptr->owner_ptr->graph, client_ptr->id);
}
static void on_popup_menu_action_remove(GtkWidget * menuitem, gpointer module_context)
{
//log_info("on_popup_menu_action_split");
if (!graph_proxy_remove_client(client_ptr->owner_ptr->graph, client_ptr->id))
{
error_message_box("Client remove failed");
}
}
static void fill_module_menu(GtkMenu * menu, void * module_context)
{
GtkWidget * menuitem;
log_info("fill_module_menu %"PRIu64, client_ptr->id);
menuitem = gtk_menu_item_new_with_label(_("Client rename"));
g_signal_connect(menuitem, "activate", (GCallback)on_popup_menu_action_client_rename, client_ptr);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
if (client_ptr->inport_count == 0 &&
client_ptr->outport_count == 0)
{
menuitem = gtk_menu_item_new_with_label(_("Remove"));
g_signal_connect(menuitem, "activate", (GCallback)on_popup_menu_action_remove, client_ptr);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
}
if (client_ptr->inport_count != 0 &&
client_ptr->outport_count != 0)
{
menuitem = gtk_menu_item_new_with_label(_("Split"));
g_signal_connect(menuitem, "activate", (GCallback)on_popup_menu_action_split, client_ptr);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
}
}
#undef client_ptr
#define port_ptr ((struct port *)port_context)
static void on_popup_menu_action_port_rename(GtkWidget * menuitem, gpointer port_context)
{
log_info("on_popup_menu_action_port_rename %"PRIu64, port_ptr->id);
char * new_name;
if (name_dialog(_("Rename port"), _("Port name"), canvas_get_port_name(port_ptr->canvas_port), &new_name))
{
if (!graph_proxy_rename_port(port_ptr->graph_canvas->graph, port_ptr->id, new_name))
{
error_message_box("Rename failed");
}
free(new_name);
}
}
static void on_popup_menu_action_port_move(GtkWidget * menuitem, gpointer port_context)
{
struct client * client_ptr;
log_info("on_popup_menu_action_port_move %"PRIu64, port_ptr->id);
if (!canvas_get_one_selected_module(port_ptr->graph_canvas->canvas, (void **)&client_ptr))
{
return;
}
if (!graph_proxy_move_port(port_ptr->graph_canvas->graph, port_ptr->id, client_ptr->id))
{
error_message_box("Port move failed");
}
}
static void fill_port_menu(GtkMenu * menu, void * port_context)
{
GtkWidget * menuitem;
log_info("fill_port_menu %"PRIu64, port_ptr->id);
menuitem = gtk_menu_item_new_with_label(_("Rename"));
g_signal_connect(menuitem, "activate", (GCallback)on_popup_menu_action_port_rename, port_ptr);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
if (canvas_get_selected_modules_count(port_ptr->graph_canvas->canvas) == 1)
{
menuitem = gtk_menu_item_new_with_label(_("Move port"));
g_signal_connect(menuitem, "activate", (GCallback)on_popup_menu_action_port_move, port_ptr);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
}
}
#undef port_ptr
#define canvas_ptr ((struct graph_canvas *)canvas_context)
static void on_popup_menu_action_join_clients(GtkWidget * menuitem, gpointer canvas_context)
{
struct client * client1_ptr;
struct client * client2_ptr;
if (!canvas_get_two_selected_modules(canvas_ptr->canvas, (void **)&client1_ptr, (void **)&client2_ptr))
{
return;
}
if (!graph_proxy_join(canvas_ptr->graph, client1_ptr->id, client2_ptr->id))
{
error_message_box("Join failed");
}
}
static void on_popup_menu_action_new_client(GtkWidget * menuitem, gpointer canvas_context)
{
char * new_name;
uint64_t client_id;
if (name_dialog(_("New client"), _("Client name"), "", &new_name))
{
if (!graph_proxy_new_client(canvas_ptr->graph, new_name, &client_id))
{
error_message_box("New client creation failed");
}
free(new_name);
}
}
static void fill_canvas_menu(GtkMenu * menu, void * canvas_context)
{
GtkWidget * menuitem;
log_info("fill_canvas_menu");
menuitem = gtk_menu_item_new_with_label(_("New client"));
g_signal_connect(menuitem, "activate", (GCallback)on_popup_menu_action_new_client, canvas_ptr);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
if (canvas_get_selected_modules_count(canvas_ptr->canvas) == 2)
{
menuitem = gtk_menu_item_new_with_label(_("Join clients"));
g_signal_connect(menuitem, "activate", (GCallback)on_popup_menu_action_join_clients, canvas_ptr);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
}
canvas_ptr->fill_menu(menu);
}
#undef canvas_ptr
bool
graph_canvas_create(
int width,
int height,
void (* fill_canvas_menu_callback)(GtkMenu * menu),
graph_canvas_handle * graph_canvas_handle_ptr)
{
struct graph_canvas * graph_canvas_ptr;
graph_canvas_ptr = malloc(sizeof(struct graph_canvas));
if (graph_canvas_ptr == NULL)
{
return false;
}
graph_canvas_ptr->fill_menu = fill_canvas_menu_callback;
if (!canvas_create(
width,
height,
graph_canvas_ptr,
connect_request,
disconnect_request,
module_location_changed,
fill_canvas_menu,
fill_module_menu,
fill_port_menu,
&graph_canvas_ptr->canvas))
{
free(graph_canvas_ptr);
return false;
}
graph_canvas_ptr->graph = NULL;
INIT_LIST_HEAD(&graph_canvas_ptr->clients);
*graph_canvas_handle_ptr = (graph_canvas_handle)graph_canvas_ptr;
return true;
}
#define graph_canvas_ptr ((struct graph_canvas *)graph_canvas)
static
void
clear(
void * graph_canvas)
{
log_info("canvas::clear()");
canvas_clear(graph_canvas_ptr->canvas);
}
static
void
client_appeared(
void * graph_canvas,
uint64_t id,
const char * name)
{
struct client * client_ptr;
char * x_str;
char * y_str;
double x;
double y;
char * locale;
double width;
double height;
log_info("canvas::client_appeared(%"PRIu64", \"%s\")", id, name);
canvas_get_size(graph_canvas_ptr->canvas, &width, &height);
//log_debug("width %f, height %f", width, height);
client_ptr = malloc(sizeof(struct client));
if (client_ptr == NULL)
{
log_error("allocation of memory for struct client failed");
return;
}
client_ptr->id = id;
client_ptr->inport_count = 0;
client_ptr->outport_count = 0;
INIT_LIST_HEAD(&client_ptr->ports);
client_ptr->owner_ptr = graph_canvas_ptr;
x = 0;
y = 0;
if (!graph_proxy_dict_entry_get(
client_ptr->owner_ptr->graph,
GRAPH_DICT_OBJECT_TYPE_CLIENT,
id,
URI_CANVAS_X,
&x_str))
{
x_str = NULL;
x = width / 2 - 200 + rand() % 300;
}
if (!graph_proxy_dict_entry_get(
client_ptr->owner_ptr->graph,
GRAPH_DICT_OBJECT_TYPE_CLIENT,
id,
URI_CANVAS_Y,
&y_str))
{
y_str = NULL;
y = height / 2 - 200 + rand() % 300;
}
if (x_str != NULL || y_str != NULL)
{
locale = strdup(setlocale(LC_NUMERIC, NULL));
if (locale == NULL)
{
log_error("strdup() failed for locale string");
}
else
{
setlocale(LC_NUMERIC, "POSIX");
if (x_str != NULL)
{
//log_info("converting %s", x_str);
sscanf(x_str, "%lf", &x);
}
if (y_str != NULL)
{
//log_info("converting %s", y_str);
sscanf(y_str, "%lf", &y);
}
setlocale(LC_NUMERIC, locale);
free(locale);
}
if (x_str != NULL)
{
free(x_str);
}
if (y_str != NULL)
{
free(y_str);
}
}
if (!canvas_create_module(graph_canvas_ptr->canvas, name, x, y, true, true, client_ptr, &client_ptr->canvas_module))
{
log_error("canvas_create_module(\"%s\") failed", name);
free(client_ptr);
return;
}
if (x_str == NULL || y_str == NULL)
{ /* we have generated random value, store it */
module_location_changed(client_ptr, x, y);
}
list_add_tail(&client_ptr->siblings, &graph_canvas_ptr->clients);
}
static
void
client_disappeared(
void * graph_canvas,
uint64_t id)
{
struct client * client_ptr;
log_info("canvas::client_disappeared(%"PRIu64")", id);
client_ptr = find_client(graph_canvas_ptr, id);
if (client_ptr == NULL)
{
log_error("cannot find disappearing client %"PRIu64"", id);
return;
}
list_del(&client_ptr->siblings);
canvas_destroy_module(graph_canvas_ptr->canvas, client_ptr->canvas_module);
free(client_ptr);
}
static void client_renamed(void * graph_canvas, uint64_t id, const char * old_name, const char * new_name)
{
struct client * client_ptr;
log_info("canvas::client_renamed(%"PRIu64", '%s', '%s')", id, old_name, new_name);
client_ptr = find_client(graph_canvas_ptr, id);
if (client_ptr == NULL)
{
log_error("cannot find renamed client %"PRIu64, id);
return;
}
canvas_set_module_name(client_ptr->canvas_module, new_name);
}
static
void
port_appeared(
void * graph_canvas,
uint64_t client_id,
uint64_t port_id,
const char * port_name,
bool is_input,
bool is_terminal,
bool is_midi)
{
int color;
struct client * client_ptr;
struct port * port_ptr;
char * value;
char * name_override;
log_info("canvas::port_appeared(%"PRIu64", %"PRIu64", \"%s\")", client_id, port_id, port_name);
client_ptr = find_client(graph_canvas_ptr, client_id);
if (client_ptr == NULL)
{
log_error("cannot find client %"PRIu64" of appearing port %"PRIu64" \"%s\"", client_id, port_id, port_name);
return;
}
port_ptr = malloc(sizeof(struct port));
if (port_ptr == NULL)
{
log_error("allocation of memory for struct port failed");
return;
}
port_ptr->id = port_id;
port_ptr->is_input = is_input;
port_ptr->graph_canvas = graph_canvas_ptr;
// Darkest tango palette colour, with S -= 6, V -= 6, w/ transparency
if (is_midi)
{
color = 0x960909C0;
}
else
{
color = 0x244678C0;
}
if (!graph_proxy_dict_entry_get(
client_ptr->owner_ptr->graph,
GRAPH_DICT_OBJECT_TYPE_PORT,
port_id,
URI_A2J_PORT,
&value))
{
name_override = NULL;
}
else
{
if (strcmp(value, "yes") == 0)
{
name_override = catdup(port_name, " (a2j)");
if (name_override != NULL)
{
port_name = name_override;
}
}
else
{
name_override = NULL;
}
free(value);
}
if (!canvas_create_port(graph_canvas_ptr->canvas, client_ptr->canvas_module, port_name, is_input, color, port_ptr, &port_ptr->canvas_port))
{
log_error("canvas_create_port(\"%s\") failed", port_name);
free(port_ptr);
free(name_override);
return;
}
list_add_tail(&port_ptr->siblings, &client_ptr->ports);
free(name_override);
if (is_input)
{
client_ptr->inport_count++;
}
else
{
client_ptr->outport_count++;
}
}
static
void
port_disappeared(
void * graph_canvas,
uint64_t client_id,
uint64_t port_id)
{
struct client * client_ptr;
struct port * port_ptr;
log_info("canvas::port_disappeared(%"PRIu64", %"PRIu64")", client_id, port_id);
client_ptr = find_client(graph_canvas_ptr, client_id);
if (client_ptr == NULL)
{
log_error("cannot find client %"PRIu64" of disappearing port %"PRIu64"", client_id, port_id);
return;
}
port_ptr = find_port(client_ptr, port_id);
if (client_ptr == NULL)
{
log_error("cannot find disappearing port %"PRIu64" of client %"PRIu64"", port_id, client_id);
return;
}
list_del(&port_ptr->siblings);
canvas_destroy_port(graph_canvas_ptr->canvas, port_ptr->canvas_port);
if (port_ptr->is_input)
{
client_ptr->inport_count--;
}
else
{
client_ptr->outport_count--;
}
free(port_ptr);
}
static
void
port_renamed(
void * graph_canvas,
uint64_t client_id,
uint64_t port_id,
const char * old_port_name,
const char * new_port_name)
{
struct client * client_ptr;
struct port * port_ptr;
log_info("canvas::port_renamed(%"PRIu64", %"PRIu64", '%s', '%s')", client_id, port_id, old_port_name, new_port_name);
client_ptr = find_client(graph_canvas_ptr, client_id);
if (client_ptr == NULL)
{
log_error("cannot find client %"PRIu64" of renamed port %"PRIu64"", client_id, port_id);
return;
}
port_ptr = find_port(client_ptr, port_id);
if (client_ptr == NULL)
{
log_error("cannot find renamed port %"PRIu64" of client %"PRIu64"", port_id, client_id);
return;
}
canvas_set_port_name(port_ptr->canvas_port, new_port_name);
}
static
void
ports_connected(
void * graph_canvas,
uint64_t client1_id,
uint64_t port1_id,
uint64_t client2_id,
uint64_t port2_id)
{
struct client * client1_ptr;
struct port * port1_ptr;
struct client * client2_ptr;
struct port * port2_ptr;
log_info("canvas::ports_connected(%"PRIu64", %"PRIu64", %"PRIu64", %"PRIu64")", client1_id, port1_id, client2_id, port2_id);
client1_ptr = find_client(graph_canvas_ptr, client1_id);
if (client1_ptr == NULL)
{
log_error("cannot find client %"PRIu64" of connected port %"PRIu64"", client1_id, port1_id);
return;
}
port1_ptr = find_port(client1_ptr, port1_id);
if (client1_ptr == NULL)
{
log_error("cannot find connected port %"PRIu64" of client %"PRIu64"", port1_id, client1_id);
return;
}
client2_ptr = find_client(graph_canvas_ptr, client2_id);
if (client2_ptr == NULL)
{
log_error("cannot find client %"PRIu64" of connected port %"PRIu64"", client2_id, port2_id);
return;
}
port2_ptr = find_port(client2_ptr, port2_id);
if (client2_ptr == NULL)
{
log_error("cannot find connected port %"PRIu64" of client %"PRIu64"", port2_id, client2_id);
return;
}
canvas_add_connection(
graph_canvas_ptr->canvas,
port1_ptr->canvas_port,
port2_ptr->canvas_port,
canvas_get_port_color(port1_ptr->canvas_port) + 0x22222200);
}
static
void
ports_disconnected(
void * graph_canvas,
uint64_t client1_id,
uint64_t port1_id,
uint64_t client2_id,
uint64_t port2_id)
{
struct client * client1_ptr;
struct port * port1_ptr;
struct client * client2_ptr;
struct port * port2_ptr;
log_info("canvas::ports_disconnected(%"PRIu64", %"PRIu64", %"PRIu64", %"PRIu64")", client1_id, port1_id, client2_id, port2_id);
client1_ptr = find_client(graph_canvas_ptr, client1_id);
if (client1_ptr == NULL)
{
log_error("cannot find client %"PRIu64" of disconnected port %"PRIu64"", client1_id, port1_id);
return;
}
port1_ptr = find_port(client1_ptr, port1_id);
if (client1_ptr == NULL)
{
log_error("cannot find disconnected port %"PRIu64" of client %"PRIu64"", port1_id, client1_id);
return;
}
client2_ptr = find_client(graph_canvas_ptr, client2_id);
if (client2_ptr == NULL)
{
log_error("cannot find client %"PRIu64" of disconnected port %"PRIu64"", client2_id, port2_id);
return;
}
port2_ptr = find_port(client2_ptr, port2_id);
if (client2_ptr == NULL)
{
log_error("cannot find disconnected port %"PRIu64" of client %"PRIu64"", port2_id, client2_id);
return;
}
canvas_remove_connection(
graph_canvas_ptr->canvas,
port1_ptr->canvas_port,
port2_ptr->canvas_port);
}
void
graph_canvas_destroy(
graph_canvas_handle graph_canvas)
{
if (graph_canvas_ptr->graph != NULL)
{
graph_canvas_detach(graph_canvas);
}
free(graph_canvas_ptr);
}
bool
graph_canvas_attach(
graph_canvas_handle graph_canvas,
graph_proxy_handle graph)
{
ASSERT(graph_canvas_ptr->graph == NULL);
if (!graph_proxy_attach(
graph,
graph_canvas,
clear,
client_appeared,
client_renamed,
client_disappeared,
port_appeared,
port_renamed,
port_disappeared,
ports_connected,
ports_disconnected))
{
return false;
}
graph_canvas_ptr->graph = graph;
return true;
}
void
graph_canvas_detach(
graph_canvas_handle graph_canvas)
{
ASSERT(graph_canvas_ptr->graph != NULL);
graph_proxy_detach(graph_canvas_ptr->graph, graph_canvas);
graph_canvas_ptr->graph = NULL;
}
canvas_handle
graph_canvas_get_canvas(
graph_canvas_handle graph_canvas)
{
return graph_canvas_ptr->canvas;
}
|