add dbus command to allow checking of wether hardware is currently exported
[a2jmidid.git] / port_hash.c
blobd40534531464ae653aac61c4c2452de24ece9b8d
1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*
3 * ALSA SEQ < - > JACK MIDI bridge
5 * Copyright (c) 2006,2007 Dmitry S. Baikov <c0ff@konstruktiv.org>
6 * Copyright (c) 2007,2008,2009 Nedko Arnaudov <nedko@arnaudov.name>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <stdbool.h>
23 #include <semaphore.h>
24 #include <alsa/asoundlib.h>
25 #include <jack/jack.h>
26 #include <jack/ringbuffer.h>
28 #include "list.h"
29 #include "structs.h"
30 #include "port_hash.h"
32 static inline
33 int
34 a2j_port_hash(
35 snd_seq_addr_t addr)
37 return (addr.client + addr.port) % PORT_HASH_SIZE;
40 struct a2j_port *
41 a2j_port_get(
42 a2j_port_hash_t hash,
43 snd_seq_addr_t addr)
45 struct a2j_port **pport = &hash[a2j_port_hash(addr)];
46 while (*pport) {
47 struct a2j_port *port = *pport;
48 if (port->remote.client == addr.client && port->remote.port == addr.port)
49 return port;
50 pport = &port->next;
52 return NULL;
55 void
56 a2j_port_insert(
57 a2j_port_hash_t hash,
58 struct a2j_port * port)
60 struct a2j_port **pport = &hash[a2j_port_hash(port->remote)];
61 port->next = *pport;
62 *pport = port;