2009-08-11 10:13:00 +03:00
|
|
|
/* -*- Mode: C ; c-basic-offset: 2 -*- */
|
|
|
|
/*
|
|
|
|
* LADI Session Handler (ladish)
|
|
|
|
*
|
2011-06-01 03:04:18 +03:00
|
|
|
* Copyright (C) 2009, 2010, 2011 Nedko Arnaudov <nedko@arnaudov.name>
|
2009-08-11 10:13:00 +03:00
|
|
|
*
|
|
|
|
**************************************************************************
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2009-09-07 20:53:56 +03:00
|
|
|
#include <locale.h>
|
2009-08-11 10:13:00 +03:00
|
|
|
|
|
|
|
#include "graph_canvas.h"
|
2009-09-07 20:53:56 +03:00
|
|
|
#include "../dbus_constants.h"
|
2010-12-29 23:44:04 +02:00
|
|
|
#include "../common/catdup.h"
|
2009-08-11 10:13:00 +03:00
|
|
|
|
|
|
|
struct graph_canvas
|
|
|
|
{
|
2009-09-03 05:55:28 +03:00
|
|
|
graph_proxy_handle graph;
|
2009-08-11 10:13:00 +03:00
|
|
|
canvas_handle canvas;
|
2009-08-12 18:04:29 +03:00
|
|
|
struct list_head clients;
|
2009-08-11 10:13:00 +03:00
|
|
|
};
|
|
|
|
|
2009-08-12 18:04:29 +03:00
|
|
|
struct client
|
|
|
|
{
|
|
|
|
struct list_head siblings;
|
|
|
|
uint64_t id;
|
|
|
|
canvas_module_handle canvas_module;
|
|
|
|
struct list_head ports;
|
2009-09-07 20:53:56 +03:00
|
|
|
struct graph_canvas * owner_ptr;
|
2011-06-01 03:04:18 +03:00
|
|
|
unsigned int inport_count;
|
|
|
|
unsigned int outport_count;
|
2009-08-12 18:04:29 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct port
|
|
|
|
{
|
|
|
|
struct list_head siblings;
|
|
|
|
uint64_t id;
|
2011-06-01 03:04:18 +03:00
|
|
|
bool is_input;
|
2009-08-12 18:04:29 +03:00
|
|
|
canvas_port_handle canvas_port;
|
2009-08-12 19:12:10 +03:00
|
|
|
struct graph_canvas * graph_canvas;
|
2009-08-12 18:04:29 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-08-12 19:12:10 +03:00
|
|
|
#define port1_ptr ((struct port *)port1_context)
|
|
|
|
#define port2_ptr ((struct port *)port2_context)
|
|
|
|
|
|
|
|
static
|
|
|
|
void
|
|
|
|
connect_request(
|
|
|
|
void * port1_context,
|
|
|
|
void * port2_context)
|
|
|
|
{
|
2009-09-20 18:23:42 +03:00
|
|
|
log_info("connect request(%"PRIu64", %"PRIu64")", port1_ptr->id, port2_ptr->id);
|
2009-08-12 19:12:10 +03:00
|
|
|
|
2009-09-20 18:48:42 +03:00
|
|
|
ASSERT(port1_ptr->graph_canvas == port2_ptr->graph_canvas);
|
2009-08-12 19:12:10 +03:00
|
|
|
|
2009-09-03 05:55:28 +03:00
|
|
|
graph_proxy_connect_ports(port1_ptr->graph_canvas->graph, port1_ptr->id, port2_ptr->id);
|
2009-08-12 19:12:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
disconnect_request(
|
|
|
|
void * port1_context,
|
|
|
|
void * port2_context)
|
|
|
|
{
|
2009-09-20 18:23:42 +03:00
|
|
|
log_info("disconnect request(%"PRIu64", %"PRIu64")", port1_ptr->id, port2_ptr->id);
|
2009-08-12 19:12:10 +03:00
|
|
|
|
2009-09-20 18:48:42 +03:00
|
|
|
ASSERT(port1_ptr->graph_canvas == port2_ptr->graph_canvas);
|
2009-08-12 19:12:10 +03:00
|
|
|
|
2009-09-03 05:55:28 +03:00
|
|
|
graph_proxy_disconnect_ports(port1_ptr->graph_canvas->graph, port1_ptr->id, port2_ptr->id);
|
2009-08-12 19:12:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#undef port1_ptr
|
|
|
|
#undef port2_ptr
|
|
|
|
|
2009-09-07 20:53:56 +03:00
|
|
|
#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;
|
|
|
|
|
2009-09-20 18:23:42 +03:00
|
|
|
log_info("module_location_changed(id = %3llu, x = %6.1f, y = %6.1f)", (unsigned long long)client_ptr->id, x, y);
|
2009-09-07 20:53:56 +03:00
|
|
|
|
|
|
|
locale = strdup(setlocale(LC_NUMERIC, NULL));
|
|
|
|
if (locale == NULL)
|
|
|
|
{
|
2009-09-20 18:23:42 +03:00
|
|
|
log_error("strdup() failed for locale string");
|
2009-09-07 20:53:56 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
setlocale(LC_NUMERIC, "POSIX");
|
|
|
|
sprintf(x_str, "%f", x);
|
|
|
|
sprintf(y_str, "%f", y);
|
|
|
|
setlocale(LC_NUMERIC, locale);
|
|
|
|
free(locale);
|
|
|
|
|
2009-09-12 09:44:52 +03:00
|
|
|
graph_proxy_dict_entry_set(
|
|
|
|
client_ptr->owner_ptr->graph,
|
2009-09-07 20:53:56 +03:00
|
|
|
GRAPH_DICT_OBJECT_TYPE_CLIENT,
|
|
|
|
client_ptr->id,
|
|
|
|
URI_CANVAS_X,
|
|
|
|
x_str);
|
|
|
|
|
2009-09-12 09:44:52 +03:00
|
|
|
graph_proxy_dict_entry_set(
|
|
|
|
client_ptr->owner_ptr->graph,
|
2009-09-07 20:53:56 +03:00
|
|
|
GRAPH_DICT_OBJECT_TYPE_CLIENT,
|
|
|
|
client_ptr->id,
|
|
|
|
URI_CANVAS_Y,
|
|
|
|
y_str);
|
|
|
|
}
|
|
|
|
|
2011-06-01 03:04:18 +03:00
|
|
|
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 fill_module_menu(GtkMenu * menu, void * module_context)
|
|
|
|
{
|
|
|
|
GtkWidget * menuitem;
|
|
|
|
|
|
|
|
log_info("fill_module_menu %"PRIu64, client_ptr->id);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-07 20:53:56 +03:00
|
|
|
#undef client_ptr
|
|
|
|
|
2011-06-01 03:04:18 +03:00
|
|
|
#define port_ptr ((struct client *)port_context)
|
|
|
|
|
|
|
|
static void fill_port_menu(GtkMenu * menu, void * port_context)
|
|
|
|
{
|
|
|
|
log_info("fill_port_menu %"PRIu64, port_ptr->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef port_ptr
|
|
|
|
|
2009-08-11 10:13:00 +03:00
|
|
|
bool
|
|
|
|
graph_canvas_create(
|
|
|
|
int width,
|
|
|
|
int height,
|
2010-09-05 18:51:17 +03:00
|
|
|
void (* fill_canvas_menu)(GtkMenu * menu),
|
2009-08-11 10:13:00 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-09-05 18:51:17 +03:00
|
|
|
if (!canvas_create(
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
connect_request,
|
|
|
|
disconnect_request,
|
|
|
|
module_location_changed,
|
|
|
|
fill_canvas_menu,
|
2011-06-01 03:04:18 +03:00
|
|
|
fill_module_menu,
|
|
|
|
fill_port_menu,
|
2010-09-05 18:51:17 +03:00
|
|
|
&graph_canvas_ptr->canvas))
|
2009-08-11 10:13:00 +03:00
|
|
|
{
|
|
|
|
free(graph_canvas_ptr);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
graph_canvas_ptr->graph = NULL;
|
2009-08-12 18:04:29 +03:00
|
|
|
INIT_LIST_HEAD(&graph_canvas_ptr->clients);
|
2009-08-11 10:13:00 +03:00
|
|
|
|
|
|
|
*graph_canvas_handle_ptr = (graph_canvas_handle)graph_canvas_ptr;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define graph_canvas_ptr ((struct graph_canvas *)graph_canvas)
|
|
|
|
|
2009-08-12 15:41:09 +03:00
|
|
|
static
|
|
|
|
void
|
|
|
|
clear(
|
|
|
|
void * graph_canvas)
|
|
|
|
{
|
2009-09-20 18:23:42 +03:00
|
|
|
log_info("canvas::clear()");
|
2009-08-12 18:04:29 +03:00
|
|
|
canvas_clear(graph_canvas_ptr->canvas);
|
2009-08-12 15:41:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
void
|
|
|
|
client_appeared(
|
|
|
|
void * graph_canvas,
|
|
|
|
uint64_t id,
|
|
|
|
const char * name)
|
|
|
|
{
|
2009-08-12 18:04:29 +03:00
|
|
|
struct client * client_ptr;
|
2009-09-07 20:53:56 +03:00
|
|
|
char * x_str;
|
|
|
|
char * y_str;
|
|
|
|
double x;
|
|
|
|
double y;
|
|
|
|
char * locale;
|
2009-10-05 00:15:53 +03:00
|
|
|
double width;
|
|
|
|
double height;
|
2009-08-12 18:04:29 +03:00
|
|
|
|
2009-09-20 18:23:42 +03:00
|
|
|
log_info("canvas::client_appeared(%"PRIu64", \"%s\")", id, name);
|
2009-08-12 18:04:29 +03:00
|
|
|
|
2009-10-05 00:15:53 +03:00
|
|
|
canvas_get_size(graph_canvas_ptr->canvas, &width, &height);
|
|
|
|
//log_debug("width %f, height %f", width, height);
|
|
|
|
|
2009-08-12 18:04:29 +03:00
|
|
|
client_ptr = malloc(sizeof(struct client));
|
|
|
|
if (client_ptr == NULL)
|
|
|
|
{
|
2009-09-20 18:23:42 +03:00
|
|
|
log_error("allocation of memory for struct client failed");
|
2009-08-12 18:04:29 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
client_ptr->id = id;
|
2011-06-01 03:04:18 +03:00
|
|
|
client_ptr->inport_count = 0;
|
|
|
|
client_ptr->outport_count = 0;
|
2009-08-12 18:04:29 +03:00
|
|
|
INIT_LIST_HEAD(&client_ptr->ports);
|
2009-09-07 20:53:56 +03:00
|
|
|
client_ptr->owner_ptr = graph_canvas_ptr;
|
|
|
|
|
|
|
|
x = 0;
|
|
|
|
y = 0;
|
|
|
|
|
2009-09-12 09:44:52 +03:00
|
|
|
if (!graph_proxy_dict_entry_get(
|
|
|
|
client_ptr->owner_ptr->graph,
|
2009-09-07 20:53:56 +03:00
|
|
|
GRAPH_DICT_OBJECT_TYPE_CLIENT,
|
|
|
|
id,
|
|
|
|
URI_CANVAS_X,
|
|
|
|
&x_str))
|
|
|
|
{
|
|
|
|
x_str = NULL;
|
2009-12-22 00:12:59 +02:00
|
|
|
x = width / 2 - 200 + rand() % 300;
|
2009-09-07 20:53:56 +03:00
|
|
|
}
|
|
|
|
|
2009-09-12 09:44:52 +03:00
|
|
|
if (!graph_proxy_dict_entry_get(
|
|
|
|
client_ptr->owner_ptr->graph,
|
2009-09-07 20:53:56 +03:00
|
|
|
GRAPH_DICT_OBJECT_TYPE_CLIENT,
|
|
|
|
id,
|
|
|
|
URI_CANVAS_Y,
|
|
|
|
&y_str))
|
|
|
|
{
|
|
|
|
y_str = NULL;
|
2009-12-22 00:12:59 +02:00
|
|
|
y = height / 2 - 200 + rand() % 300;
|
2009-09-07 20:53:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (x_str != NULL || y_str != NULL)
|
|
|
|
{
|
|
|
|
locale = strdup(setlocale(LC_NUMERIC, NULL));
|
|
|
|
if (locale == NULL)
|
|
|
|
{
|
2009-09-20 18:23:42 +03:00
|
|
|
log_error("strdup() failed for locale string");
|
2009-09-07 20:53:56 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setlocale(LC_NUMERIC, "POSIX");
|
|
|
|
if (x_str != NULL)
|
|
|
|
{
|
2009-09-20 18:23:42 +03:00
|
|
|
//log_info("converting %s", x_str);
|
2009-09-07 20:53:56 +03:00
|
|
|
sscanf(x_str, "%lf", &x);
|
|
|
|
}
|
|
|
|
if (y_str != NULL)
|
|
|
|
{
|
2009-09-20 18:23:42 +03:00
|
|
|
//log_info("converting %s", y_str);
|
2009-09-07 20:53:56 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2009-08-12 18:04:29 +03:00
|
|
|
|
2009-09-07 20:53:56 +03:00
|
|
|
if (!canvas_create_module(graph_canvas_ptr->canvas, name, x, y, true, true, client_ptr, &client_ptr->canvas_module))
|
2009-08-12 18:04:29 +03:00
|
|
|
{
|
2009-09-20 18:23:42 +03:00
|
|
|
log_error("canvas_create_module(\"%s\") failed", name);
|
2009-08-12 18:04:29 +03:00
|
|
|
free(client_ptr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-12-08 00:56:31 +02:00
|
|
|
if (x_str == NULL || y_str == NULL)
|
|
|
|
{ /* we have generated random value, store it */
|
|
|
|
module_location_changed(client_ptr, x, y);
|
|
|
|
}
|
|
|
|
|
2009-08-12 18:04:29 +03:00
|
|
|
list_add_tail(&client_ptr->siblings, &graph_canvas_ptr->clients);
|
2009-08-12 15:41:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
void
|
|
|
|
client_disappeared(
|
|
|
|
void * graph_canvas,
|
|
|
|
uint64_t id)
|
|
|
|
{
|
2009-08-12 18:04:29 +03:00
|
|
|
struct client * client_ptr;
|
|
|
|
|
2009-09-20 18:23:42 +03:00
|
|
|
log_info("canvas::client_disappeared(%"PRIu64")", id);
|
2009-08-12 18:04:29 +03:00
|
|
|
|
|
|
|
client_ptr = find_client(graph_canvas_ptr, id);
|
|
|
|
if (client_ptr == NULL)
|
|
|
|
{
|
2009-09-20 18:23:42 +03:00
|
|
|
log_error("cannot find disappearing client %"PRIu64"", id);
|
2009-08-12 18:04:29 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
list_del(&client_ptr->siblings);
|
|
|
|
canvas_destroy_module(graph_canvas_ptr->canvas, client_ptr->canvas_module);
|
|
|
|
free(client_ptr);
|
2009-08-12 15:41:09 +03:00
|
|
|
}
|
|
|
|
|
2009-12-26 22:46:20 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2009-08-12 15:41:09 +03:00
|
|
|
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)
|
|
|
|
{
|
2009-08-12 18:04:29 +03:00
|
|
|
int color;
|
|
|
|
struct client * client_ptr;
|
|
|
|
struct port * port_ptr;
|
2010-12-29 23:44:04 +02:00
|
|
|
char * value;
|
|
|
|
char * name_override;
|
2009-08-12 18:04:29 +03:00
|
|
|
|
2009-09-20 18:23:42 +03:00
|
|
|
log_info("canvas::port_appeared(%"PRIu64", %"PRIu64", \"%s\")", client_id, port_id, port_name);
|
2009-08-12 18:04:29 +03:00
|
|
|
|
|
|
|
client_ptr = find_client(graph_canvas_ptr, client_id);
|
|
|
|
if (client_ptr == NULL)
|
|
|
|
{
|
2009-09-20 18:23:42 +03:00
|
|
|
log_error("cannot find client %"PRIu64" of appearing port %"PRIu64" \"%s\"", client_id, port_id, port_name);
|
2009-08-12 18:04:29 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
port_ptr = malloc(sizeof(struct port));
|
|
|
|
if (port_ptr == NULL)
|
|
|
|
{
|
2009-09-20 18:23:42 +03:00
|
|
|
log_error("allocation of memory for struct port failed");
|
2009-08-12 18:04:29 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
port_ptr->id = port_id;
|
2011-06-01 03:04:18 +03:00
|
|
|
port_ptr->is_input = is_input;
|
2009-08-12 19:12:10 +03:00
|
|
|
port_ptr->graph_canvas = graph_canvas_ptr;
|
2009-08-12 18:04:29 +03:00
|
|
|
|
|
|
|
// Darkest tango palette colour, with S -= 6, V -= 6, w/ transparency
|
|
|
|
if (is_midi)
|
|
|
|
{
|
|
|
|
color = 0x960909C0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
color = 0x244678C0;
|
|
|
|
}
|
|
|
|
|
2010-12-29 23:44:04 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2009-08-12 19:12:10 +03:00
|
|
|
if (!canvas_create_port(graph_canvas_ptr->canvas, client_ptr->canvas_module, port_name, is_input, color, port_ptr, &port_ptr->canvas_port))
|
2009-08-12 18:04:29 +03:00
|
|
|
{
|
2009-09-20 18:23:42 +03:00
|
|
|
log_error("canvas_create_port(\"%s\") failed", port_name);
|
2010-12-29 23:44:04 +02:00
|
|
|
free(port_ptr);
|
|
|
|
free(name_override);
|
2009-08-12 18:04:29 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
list_add_tail(&port_ptr->siblings, &client_ptr->ports);
|
2010-12-29 23:44:04 +02:00
|
|
|
|
|
|
|
free(name_override);
|
2011-06-01 03:04:18 +03:00
|
|
|
|
|
|
|
if (is_input)
|
|
|
|
{
|
|
|
|
client_ptr->inport_count++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
client_ptr->outport_count++;
|
|
|
|
}
|
2009-08-12 15:41:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
void
|
|
|
|
port_disappeared(
|
|
|
|
void * graph_canvas,
|
|
|
|
uint64_t client_id,
|
|
|
|
uint64_t port_id)
|
|
|
|
{
|
2009-08-12 18:04:29 +03:00
|
|
|
struct client * client_ptr;
|
|
|
|
struct port * port_ptr;
|
|
|
|
|
2009-09-20 18:23:42 +03:00
|
|
|
log_info("canvas::port_disappeared(%"PRIu64", %"PRIu64")", client_id, port_id);
|
2009-08-12 18:04:29 +03:00
|
|
|
|
|
|
|
client_ptr = find_client(graph_canvas_ptr, client_id);
|
|
|
|
if (client_ptr == NULL)
|
|
|
|
{
|
2009-09-20 18:23:42 +03:00
|
|
|
log_error("cannot find client %"PRIu64" of disappearing port %"PRIu64"", client_id, port_id);
|
2009-08-12 18:04:29 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
port_ptr = find_port(client_ptr, port_id);
|
|
|
|
if (client_ptr == NULL)
|
|
|
|
{
|
2009-09-20 18:23:42 +03:00
|
|
|
log_error("cannot find disappearing port %"PRIu64" of client %"PRIu64"", port_id, client_id);
|
2009-08-12 18:04:29 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
list_del(&port_ptr->siblings);
|
|
|
|
canvas_destroy_port(graph_canvas_ptr->canvas, port_ptr->canvas_port);
|
2011-06-01 03:04:18 +03:00
|
|
|
|
|
|
|
if (port_ptr->is_input)
|
|
|
|
{
|
|
|
|
client_ptr->inport_count--;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
client_ptr->outport_count--;
|
|
|
|
}
|
|
|
|
|
2009-08-12 18:04:29 +03:00
|
|
|
free(port_ptr);
|
2009-08-12 15:41:09 +03:00
|
|
|
}
|
|
|
|
|
2009-12-21 20:46:14 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2009-08-12 15:41:09 +03:00
|
|
|
static
|
|
|
|
void
|
|
|
|
ports_connected(
|
|
|
|
void * graph_canvas,
|
|
|
|
uint64_t client1_id,
|
|
|
|
uint64_t port1_id,
|
|
|
|
uint64_t client2_id,
|
|
|
|
uint64_t port2_id)
|
|
|
|
{
|
2009-08-12 18:04:29 +03:00
|
|
|
struct client * client1_ptr;
|
|
|
|
struct port * port1_ptr;
|
|
|
|
struct client * client2_ptr;
|
|
|
|
struct port * port2_ptr;
|
|
|
|
|
2009-09-20 18:23:42 +03:00
|
|
|
log_info("canvas::ports_connected(%"PRIu64", %"PRIu64", %"PRIu64", %"PRIu64")", client1_id, port1_id, client2_id, port2_id);
|
2009-08-12 18:04:29 +03:00
|
|
|
|
|
|
|
client1_ptr = find_client(graph_canvas_ptr, client1_id);
|
|
|
|
if (client1_ptr == NULL)
|
|
|
|
{
|
2009-09-20 18:23:42 +03:00
|
|
|
log_error("cannot find client %"PRIu64" of connected port %"PRIu64"", client1_id, port1_id);
|
2009-08-12 18:04:29 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
port1_ptr = find_port(client1_ptr, port1_id);
|
|
|
|
if (client1_ptr == NULL)
|
|
|
|
{
|
2009-09-20 18:23:42 +03:00
|
|
|
log_error("cannot find connected port %"PRIu64" of client %"PRIu64"", port1_id, client1_id);
|
2009-08-12 18:04:29 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
client2_ptr = find_client(graph_canvas_ptr, client2_id);
|
|
|
|
if (client2_ptr == NULL)
|
|
|
|
{
|
2009-09-20 18:23:42 +03:00
|
|
|
log_error("cannot find client %"PRIu64" of connected port %"PRIu64"", client2_id, port2_id);
|
2009-08-12 18:04:29 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
port2_ptr = find_port(client2_ptr, port2_id);
|
|
|
|
if (client2_ptr == NULL)
|
|
|
|
{
|
2009-09-20 18:23:42 +03:00
|
|
|
log_error("cannot find connected port %"PRIu64" of client %"PRIu64"", port2_id, client2_id);
|
2009-08-12 18:04:29 +03:00
|
|
|
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);
|
2009-08-12 15:41:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
void
|
|
|
|
ports_disconnected(
|
|
|
|
void * graph_canvas,
|
|
|
|
uint64_t client1_id,
|
|
|
|
uint64_t port1_id,
|
|
|
|
uint64_t client2_id,
|
|
|
|
uint64_t port2_id)
|
|
|
|
{
|
2009-08-12 18:04:29 +03:00
|
|
|
struct client * client1_ptr;
|
|
|
|
struct port * port1_ptr;
|
|
|
|
struct client * client2_ptr;
|
|
|
|
struct port * port2_ptr;
|
|
|
|
|
2009-09-20 18:23:42 +03:00
|
|
|
log_info("canvas::ports_disconnected(%"PRIu64", %"PRIu64", %"PRIu64", %"PRIu64")", client1_id, port1_id, client2_id, port2_id);
|
2009-08-12 18:04:29 +03:00
|
|
|
|
|
|
|
client1_ptr = find_client(graph_canvas_ptr, client1_id);
|
|
|
|
if (client1_ptr == NULL)
|
|
|
|
{
|
2009-09-20 18:23:42 +03:00
|
|
|
log_error("cannot find client %"PRIu64" of disconnected port %"PRIu64"", client1_id, port1_id);
|
2009-08-12 18:04:29 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
port1_ptr = find_port(client1_ptr, port1_id);
|
|
|
|
if (client1_ptr == NULL)
|
|
|
|
{
|
2009-09-20 18:23:42 +03:00
|
|
|
log_error("cannot find disconnected port %"PRIu64" of client %"PRIu64"", port1_id, client1_id);
|
2009-08-12 18:04:29 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
client2_ptr = find_client(graph_canvas_ptr, client2_id);
|
|
|
|
if (client2_ptr == NULL)
|
|
|
|
{
|
2009-09-20 18:23:42 +03:00
|
|
|
log_error("cannot find client %"PRIu64" of disconnected port %"PRIu64"", client2_id, port2_id);
|
2009-08-12 18:04:29 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
port2_ptr = find_port(client2_ptr, port2_id);
|
|
|
|
if (client2_ptr == NULL)
|
|
|
|
{
|
2009-09-20 18:23:42 +03:00
|
|
|
log_error("cannot find disconnected port %"PRIu64" of client %"PRIu64"", port2_id, client2_id);
|
2009-08-12 18:04:29 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
canvas_remove_connection(
|
|
|
|
graph_canvas_ptr->canvas,
|
|
|
|
port1_ptr->canvas_port,
|
|
|
|
port2_ptr->canvas_port);
|
2009-08-12 15:41:09 +03:00
|
|
|
}
|
|
|
|
|
2009-08-11 10:13:00 +03:00
|
|
|
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,
|
2009-09-03 05:55:28 +03:00
|
|
|
graph_proxy_handle graph)
|
2009-08-11 10:13:00 +03:00
|
|
|
{
|
2009-09-20 18:48:42 +03:00
|
|
|
ASSERT(graph_canvas_ptr->graph == NULL);
|
2009-08-12 15:41:09 +03:00
|
|
|
|
2009-09-03 05:55:28 +03:00
|
|
|
if (!graph_proxy_attach(
|
2009-08-12 15:41:09 +03:00
|
|
|
graph,
|
|
|
|
graph_canvas,
|
|
|
|
clear,
|
|
|
|
client_appeared,
|
2009-12-26 22:46:20 +02:00
|
|
|
client_renamed,
|
2009-08-12 15:41:09 +03:00
|
|
|
client_disappeared,
|
|
|
|
port_appeared,
|
2009-12-21 20:46:14 +02:00
|
|
|
port_renamed,
|
2009-08-12 15:41:09 +03:00
|
|
|
port_disappeared,
|
|
|
|
ports_connected,
|
|
|
|
ports_disconnected))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
graph_canvas_ptr->graph = graph;
|
|
|
|
|
|
|
|
return true;
|
2009-08-11 10:13:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
graph_canvas_detach(
|
|
|
|
graph_canvas_handle graph_canvas)
|
|
|
|
{
|
2009-09-20 18:48:42 +03:00
|
|
|
ASSERT(graph_canvas_ptr->graph != NULL);
|
2009-09-03 05:55:28 +03:00
|
|
|
graph_proxy_detach(graph_canvas_ptr->graph, graph_canvas);
|
2009-08-12 15:41:09 +03:00
|
|
|
graph_canvas_ptr->graph = NULL;
|
2009-08-11 10:13:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
canvas_handle
|
|
|
|
graph_canvas_get_canvas(
|
|
|
|
graph_canvas_handle graph_canvas)
|
|
|
|
{
|
|
|
|
return graph_canvas_ptr->canvas;
|
|
|
|
}
|