Changeset 4f7b78388fa1a85e4868c979c0b8bdbeac685417

Show
Ignore:
Timestamp:
12/27/10 06:16:10 (2 years ago)
Author:
Nedko Arnaudov <nedko@…>
Children:
3a5b7037d88ca19b2003cba39fa7a4ed2bbfae0c
Parents:
1958d74f7cc4036afe4870d55e7fdaadee27f5b9
git-author:
Nedko Arnaudov <nedko@arnaudov.name> / 2010-12-27T06:08:04Z+0200
git-committer:
Nedko Arnaudov <nedko@arnaudov.name> / 2010-12-27T06:16:10Z+0200
Message:

ladish_control: vgraph connection management. #125

Files:
2 modified

Legend:

Unmodified
Added
Removed
  • daemon/graph.c

    r1d029ff r4f7b783  
    196196} 
    197197 
     198static 
     199bool 
     200ladish_graph_find_connection_ports_by_name_internal( 
     201  struct ladish_graph * graph_ptr, 
     202  const char * client1_name, 
     203  const char * port1_name, 
     204  const char * client2_name, 
     205  const char * port2_name, 
     206  struct ladish_graph_port ** port1_ptr_ptr, 
     207  struct ladish_graph_port ** port2_ptr_ptr) 
     208{ 
     209  struct list_head * client1_node_ptr; 
     210  struct ladish_graph_client * client1_ptr; 
     211  struct list_head * port1_node_ptr; 
     212  struct ladish_graph_port * port1_ptr; 
     213  struct list_head * client2_node_ptr; 
     214  struct ladish_graph_client * client2_ptr; 
     215  struct list_head * port2_node_ptr; 
     216  struct ladish_graph_port * port2_ptr; 
     217 
     218  /* 
     219   * Port names are not unique, so in order to find best match, 
     220   * ports are searched with these assumptions: 
     221   * 
     222   *  1. port1 and port2 are of same type (midi or audio) 
     223   *  2. port1 is a source (capture, output) port 
     224   *  3. port2 is a destination (playback, input) port 
     225   * 
     226   * all these conditions have to be met for a port pair to match 
     227   */ 
     228  list_for_each(client1_node_ptr, &graph_ptr->clients) 
     229  { 
     230    client1_ptr = list_entry(client1_node_ptr, struct ladish_graph_client, siblings); 
     231    if (strcmp(client1_ptr->name, client1_name) == 0) 
     232    { 
     233      list_for_each(port1_node_ptr, &client1_ptr->ports) 
     234      { 
     235        port1_ptr = list_entry(port1_node_ptr, struct ladish_graph_port, siblings_client); 
     236        if (JACKDBUS_PORT_IS_OUTPUT(port1_ptr->flags) && 
     237            strcmp(port1_ptr->name, port1_name) == 0) 
     238        { 
     239          list_for_each(client2_node_ptr, &graph_ptr->clients) 
     240          { 
     241            client2_ptr = list_entry(client2_node_ptr, struct ladish_graph_client, siblings); 
     242            if (strcmp(client2_ptr->name, client2_name) == 0) 
     243            { 
     244              list_for_each(port2_node_ptr, &client2_ptr->ports) 
     245              { 
     246                port2_ptr = list_entry(port2_node_ptr, struct ladish_graph_port, siblings_client); 
     247                if (port2_ptr->type == port1_ptr->type && 
     248                    JACKDBUS_PORT_IS_INPUT(port2_ptr->flags) && 
     249                    strcmp(port2_ptr->name, port2_name) == 0) 
     250                { 
     251                  *port1_ptr_ptr = port1_ptr; 
     252                  *port2_ptr_ptr = port2_ptr; 
     253                  return true; 
     254                } 
     255              } 
     256            } 
     257          } 
     258        } 
     259      } 
     260    } 
     261  } 
     262 
     263  return false; 
     264} 
     265 
     266static 
     267bool 
     268ladish_graph_find_connection_ports_by_name( 
     269  struct ladish_graph * graph_ptr, 
     270  const char * client1_name, 
     271  const char * port1_name, 
     272  const char * client2_name, 
     273  const char * port2_name, 
     274  struct ladish_graph_port ** port1_ptr_ptr, 
     275  struct ladish_graph_port ** port2_ptr_ptr) 
     276{ 
     277  if (ladish_graph_find_connection_ports_by_name_internal( 
     278        graph_ptr, 
     279        client1_name, 
     280        port1_name, 
     281        client2_name, 
     282        port2_name, 
     283        port1_ptr_ptr, 
     284        port2_ptr_ptr)) 
     285  { 
     286    return true; 
     287  } 
     288 
     289  if (ladish_graph_find_connection_ports_by_name_internal( 
     290        graph_ptr, 
     291        client2_name, 
     292        port2_name, 
     293        client1_name, 
     294        port1_name, 
     295        port1_ptr_ptr, 
     296        port2_ptr_ptr)) 
     297  { 
     298    return true; 
     299  } 
     300 
     301  return false; 
     302} 
     303 
    198304static struct ladish_graph_port * ladish_graph_find_port_by_id_internal(struct ladish_graph * graph_ptr, uint64_t port_id) 
    199305{ 
     
    614720static void connect_ports_by_name(struct dbus_method_call * call_ptr) 
    615721{ 
    616   log_info("connect_ports_by_name() called."); 
    617   lash_dbus_error(call_ptr, LASH_DBUS_ERROR_GENERIC, "connect by name is not implemented yet"); 
     722  const char * client1_name; 
     723  const char * port1_name; 
     724  const char * client2_name; 
     725  const char * port2_name; 
     726  struct ladish_graph_port * port1; 
     727  struct ladish_graph_port * port2; 
     728 
     729  if (!dbus_message_get_args( 
     730        call_ptr->message, 
     731        &g_dbus_error, 
     732        DBUS_TYPE_STRING, &client1_name, 
     733        DBUS_TYPE_STRING, &port1_name, 
     734        DBUS_TYPE_STRING, &client2_name, 
     735        DBUS_TYPE_STRING, &port2_name, 
     736        DBUS_TYPE_INVALID)) 
     737  { 
     738    lash_dbus_error(call_ptr, LASH_DBUS_ERROR_INVALID_ARGS, "Invalid arguments to method \"%s\": %s", call_ptr->method_name, g_dbus_error.message); 
     739    dbus_error_free(&g_dbus_error); 
     740    return; 
     741  } 
     742 
     743  log_info("connect_ports_by_name(\"%s\", \"%s\", \"%s\", \"%s\") called.", client1_name, port1_name, client2_name, port2_name); 
     744 
     745  if (!ladish_graph_find_connection_ports_by_name(graph_ptr, client1_name, port1_name, client2_name, port2_name, &port1, &port2)) 
     746  { 
     747    lash_dbus_error(call_ptr, LASH_DBUS_ERROR_INVALID_ARGS, "Cannot connect unknown ports"); 
     748    return; 
     749  } 
     750 
     751  if (graph_ptr->connect_handler(graph_ptr->context, (ladish_graph_handle)graph_ptr, port1->port, port2->port)) 
     752  { 
     753    method_return_new_void(call_ptr); 
     754  } 
     755  else 
     756  { 
     757    lash_dbus_error(call_ptr, LASH_DBUS_ERROR_GENERIC, "connect failed"); 
     758  } 
    618759} 
    619760 
     
    689830static void disconnect_ports_by_name(struct dbus_method_call * call_ptr) 
    690831{ 
    691   log_info("disconnect_ports_by_name() called."); 
    692   lash_dbus_error(call_ptr, LASH_DBUS_ERROR_GENERIC, "disconnect by name is not implemented yet"); 
     832  const char * client1_name; 
     833  const char * port1_name; 
     834  const char * client2_name; 
     835  const char * port2_name; 
     836  struct ladish_graph_port * port1; 
     837  struct ladish_graph_port * port2; 
     838  struct ladish_graph_connection * connection_ptr; 
     839 
     840  if (!dbus_message_get_args( 
     841        call_ptr->message, 
     842        &g_dbus_error, 
     843        DBUS_TYPE_STRING, &client1_name, 
     844        DBUS_TYPE_STRING, &port1_name, 
     845        DBUS_TYPE_STRING, &client2_name, 
     846        DBUS_TYPE_STRING, &port2_name, 
     847        DBUS_TYPE_INVALID)) 
     848  { 
     849    lash_dbus_error(call_ptr, LASH_DBUS_ERROR_INVALID_ARGS, "Invalid arguments to method \"%s\": %s", call_ptr->method_name, g_dbus_error.message); 
     850    dbus_error_free(&g_dbus_error); 
     851    return; 
     852  } 
     853 
     854  log_info("disconnect_ports_by_name(\"%s\", \"%s\", \"%s\", \"%s\") called.", client1_name, port1_name, client2_name, port2_name); 
     855 
     856  if (!ladish_graph_find_connection_ports_by_name(graph_ptr, client1_name, port1_name, client2_name, port2_name, &port1, &port2)) 
     857  { 
     858    lash_dbus_error(call_ptr, LASH_DBUS_ERROR_INVALID_ARGS, "Cannot disconnect unknown ports"); 
     859    return; 
     860  } 
     861 
     862  connection_ptr = ladish_graph_find_connection_by_ports(graph_ptr, port1, port2); 
     863  if (connection_ptr == NULL) 
     864  { 
     865    lash_dbus_error(call_ptr, LASH_DBUS_ERROR_INVALID_ARGS, "Cannot disconnect not connected ports"); 
     866    return; 
     867  } 
     868 
     869  disconnect_ports(call_ptr, connection_ptr); 
    693870} 
    694871 
  • ladish_control

    re94e85d r4f7b783  
    3333app_supervisor_interface_name = 'org.ladish.AppSupervisor' 
    3434room_interface_name = 'org.ladish.Room' 
     35patchbay_interface_name = 'org.jackaudio.JackPatchbay' 
    3536 
    3637import sys 
     
    140141        if name == room_name: 
    141142            return bus.get_object(service_name, opath) 
     143 
     144def dump_graph(obj): 
     145    patchbay_iface = dbus.Interface(obj, patchbay_interface_name) 
     146    graph = patchbay_iface.GetGraph(0) 
     147    for client in graph[1]: 
     148        print '"%s"' % client[1] 
     149        for port in client[2]: 
     150            print '  "%s"' % port[1] 
     151    print 
     152    if len(graph[2]): 
     153        if len(graph[2]) == 1: 
     154            print "1 connection:" 
     155        else: 
     156            print "%u connections:" % len(graph[2]) 
     157        for connection in graph[2]: 
     158            print '"%s":"%s" -> "%s":"%s"' % (connection[1], connection[3], connection[5], connection[7]) 
     159    else: 
     160        print "0 connections." 
    142161 
    143162def main(): 
     
    171190        print("    snewapp <appargs>         - add new app to studio (see below for more info)") 
    172191        print("    rnewapp <rname> <appargs> - add new app to room (see below for more info)") 
     192        print("    sgdump                    - studio graph dump") 
     193        print("    rgdump <rname>            - room graph dump") 
     194        print("    sconnect <client1> <port1> <client2> <port2>            - connect ports in studio"); 
     195        print("    sdisconnect <client1> <port1> <client2> <port2>         - disconnect ports in studio"); 
     196        print("    rconnect <rname> <client1> <port1> <client2> <port2>    - connect ports in studio"); 
     197        print("    rdisconnect <rname> <client1> <port1> <client2> <port2> - disconnect ports in room"); 
    173198        print(""); 
    174199        print("Add new app arguments:"); 
     
    416441 
    417442                    add_app(get_room_obj_by_name(bus, studio_iface, arg), cmdline, name, level, term) 
     443                elif arg == "sgdump": 
     444                    print('--- dump studio graph') 
     445                    dump_graph(studio_obj) 
     446                elif arg == "rgdump": 
     447                    if index >= len(sys.argv): 
     448                        print("rconnect command requires rname, client1, port1, client2 and port2 arguments") 
     449                        sys.exit() 
     450                    rname = sys.argv[index] 
     451                    index += 1 
     452                    print('--- dump room "' + rname + '" graph') 
     453                    room_obj = get_room_obj_by_name(bus, studio_obj, rname) 
     454                    dump_graph(room_obj) 
     455                elif arg == "sconnect": 
     456                    if index + 4 > len(sys.argv): 
     457                        print("sconnect command requires client1, port1, client2 and port2 arguments") 
     458                        sys.exit() 
     459                    c1 = sys.argv[index] 
     460                    p1 = sys.argv[index + 1] 
     461                    c2 = sys.argv[index + 2] 
     462                    p2 = sys.argv[index + 3] 
     463                    index += 4 
     464                    print('--- connect studio port "' + c1 + '":"' + p1 + '" to "' + c2 + '":"' + p2 + '"') 
     465                    patchbay_iface = dbus.Interface(studio_obj, patchbay_interface_name) 
     466                    patchbay_iface.ConnectPortsByName(c1, p1, c2, p2) 
     467                elif arg == "sdisconnect": 
     468                    if index + 4 > len(sys.argv): 
     469                        print("sdisconnect command requires client1, port1, client2 and port2 arguments") 
     470                        sys.exit() 
     471                    c1 = sys.argv[index] 
     472                    p1 = sys.argv[index + 1] 
     473                    c2 = sys.argv[index + 2] 
     474                    p2 = sys.argv[index + 3] 
     475                    index += 4 
     476                    print('--- disconnect studio port "' + c2 + '":"' + p2 + '" from "' + c1 + '":"' + p1 + '"') 
     477                    patchbay_iface = dbus.Interface(studio_obj, patchbay_interface_name) 
     478                    patchbay_iface.DisconnectPortsByName(c1, p1, c2, p2) 
     479                elif arg == "rconnect": 
     480                    if index + 5 > len(sys.argv): 
     481                        print("rconnect command requires rname, client1, port1, client2 and port2 arguments") 
     482                        sys.exit() 
     483                    rname = sys.argv[index] 
     484                    c1 = sys.argv[index + 1] 
     485                    p1 = sys.argv[index + 2] 
     486                    c2 = sys.argv[index + 3] 
     487                    p2 = sys.argv[index + 4] 
     488                    index += 5 
     489                    print('--- connect room "' + rname + '" port "' + c1 + '":"' + p1 + '" to "' + c2 + '":"' + p2 + '"') 
     490                    room_obj = get_room_obj_by_name(bus, studio_iface, rname) 
     491                    patchbay_iface = dbus.Interface(room_obj, patchbay_interface_name) 
     492                    patchbay_iface.ConnectPortsByName(c1, p1, c2, p2) 
     493                elif arg == "rdisconnect": 
     494                    if index + 5 > len(sys.argv): 
     495                        print("rdisconnect command requires rname, client1, port1, client2 and port2 arguments") 
     496                        sys.exit() 
     497                    rname = sys.argv[index] 
     498                    c1 = sys.argv[index + 1] 
     499                    p1 = sys.argv[index + 2] 
     500                    c2 = sys.argv[index + 3] 
     501                    p2 = sys.argv[index + 4] 
     502                    index += 5 
     503                    print('--- disconnect room "' + rname + '" port "' + c2 + '":"' + p2 + '" from "' + c1 + '":"' + p1 + '"') 
     504                    room_obj = get_room_obj_by_name(bus, studio_iface, rname) 
     505                    patchbay_iface = dbus.Interface(room_obj, patchbay_interface_name) 
     506                    patchbay_iface.DisconnectPortsByName(c1, p1, c2, p2) 
    418507                else: 
    419508                    print("Unknown command '%s'" % arg)