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 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699
|
/*
* ALSA sequencer Client Manager
* Copyright (c) 1998 by Frank van de Pol <F.K.W.van.de.Pol@inter.nl.net>
*
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#include "driver.h"
#include "minors.h"
#include "seq.h"
#include "seq_clientmgr.h"
#include "seq_memory.h"
#include "seq_queue.h"
#include "seq_timer.h"
#include "seq_info.h"
/* Client Manager
* this module handles the connections of userland and kernel clients
*
*/
snd_mutex_define_static(register);
static client_t clienttab[SND_SEQ_MAX_CLIENTS];
static usage_t client_usage =
{0, 0};
/* return pointer to client structure for specified id */
static client_t *clientptr(int clientid)
{
if (clientid < 0 || clientid >= SND_SEQ_MAX_CLIENTS) {
snd_printk("Seq: oops. Trying to get pointer to client %d\n", clientid);
return NULL;
}
return &clienttab[clientid];
}
static void usage_alloc(usage_t * res, int num)
{
res->cur += num;
if (res->cur > res->peak)
res->peak = res->cur;
}
static void usage_free(usage_t * res, int num)
{
res->cur -= num;
}
/* initialise data structures */
void init_data(void)
{
int c;
client_t *client;
/* zap out the client table */
for (c = 0; c < SND_SEQ_MAX_CLIENTS; c++) {
client = clientptr(c);
client->type = NO_CLIENT;
}
}
static int seq_create_user_client(void)
{
int c;
client_t *client;
/* find free slot in the client table */
c = 0;
while (c < SND_SEQ_MAX_CLIENTS) {
client = clientptr(c);
if (client->type == NO_CLIENT) {
user_client_t *new_client = (user_client_t *) snd_malloc(sizeof(user_client_t));
if (new_client == NULL)
return -ENOMEM;
/* init client data */
snd_mutex_down_static(register);
memset(new_client, 0, sizeof(user_client_t));
new_client->index = c;
new_client->outqueue = snd_seq_fifo_new();
snd_spin_prepare(new_client, input_sleep);
new_client->file = NULL;
strcpy(new_client->name, "");
new_client->ports = NULL;
client->type = USER_CLIENT;
client->ptr.user = new_client;
usage_alloc(&client_usage, 1);
snd_mutex_up_static(register);
return c;
}
c++;
}
return -ENODEV; /* no free slot found, return failure code */
}
static void seq_free_user_client(int c)
{
client_t *client = clientptr(c);
snd_mutex_down_static(register);
if (client->type == USER_CLIENT) {
/* release data from outqueue *//* FIXME: should also release external data */
fifo_t *q = client->ptr.user->outqueue;
while (snd_seq_fifo_avail(q))
snd_seq_cell_free(snd_seq_fifo_cell_out(q));
snd_seq_fifo_delete(&client->ptr.user->outqueue);
snd_free(client->ptr.user, sizeof(user_client_t));
client->type = NO_CLIENT;
usage_free(&client_usage, 1);
} else {
snd_printk("Seq: Trying to free unused user client %d, type = %d\n", c, client->type);
}
snd_mutex_up_static(register);
}
static int seq_create_kernel_client(void)
{
int c;
client_t *client;
/* find free slot in the client table */
c = 0;
while (c < SND_SEQ_MAX_CLIENTS) {
client = clientptr(c);
if (client->type == NO_CLIENT) {
kernel_client_t *new_client = (kernel_client_t *) snd_malloc(sizeof(kernel_client_t));
if (new_client == NULL)
return -ENOMEM;
/* init client data */
snd_mutex_down_static(register);
memset(new_client, 0, sizeof(kernel_client_t));
new_client->outqueue = snd_seq_fifo_new();
strcpy(new_client->name, "");
new_client->input = NULL;
new_client->private_data = NULL;
new_client->ports = NULL;
client->type = KERNEL_CLIENT;
client->ptr.kernel = new_client;
usage_alloc(&client_usage, 1);
snd_mutex_up_static(register);
return c;
}
c++;
}
return -ENODEV; /* no free slot found, return failure code */
}
/*
* FIXME: upon releasing we should also handle cleanup of other client related resources:
* - stop/release timer if client has a timer under control
* - clean events queued from this client (take care about note on/off!)
* - clean events queued for this client
* - remove registered ports
* - remove client from registration lists
*/
static void seq_free_kernel_client(int c)
{
client_t *client = clientptr(c);
snd_mutex_down_static(register);
if (client->type == KERNEL_CLIENT) {
snd_seq_fifo_delete(&client->ptr.kernel->outqueue);
snd_free(client->ptr.kernel, sizeof(kernel_client_t)); /* FIXME: should also drain out queue & release external data */
client->type = NO_CLIENT;
usage_free(&client_usage, 1);
} else {
snd_printk("Seq: Trying to free unused kernel client %d, type = %d\n", c, client->type);
}
snd_mutex_up_static(register);
}
static void seq_free_client(int c)
{
client_t *client = clientptr(c);
switch (client->type) {
case NO_CLIENT:
snd_printk("Seq: Trying to free unused client %d\n", c);
break;
case USER_CLIENT:
seq_free_user_client(c);
break;
case KERNEL_CLIENT:
seq_free_kernel_client(c);
break;
default:
snd_printk("Seq: Trying to free client %d with undefined type = %d\n", c, client->type);
}
}
/* -------------------------------------------------------- */
static int snd_seq_open(unsigned short minor, int cardnum, int device, struct file *file)
{
int c; /* client id */
client_t *client;
c = seq_create_user_client();
if (c < 0)
return c; /* failure code */
/* store pointer to client */
client = clientptr(c);
(user_client_t *) file->private_data = client->ptr.user;
/* fill client data */
client->ptr.user->file = file;
sprintf(client->ptr.user->name, "Client-%d", c);
snd_printk("seq registering user-land client %d\n", c);
MOD_INC_USE_COUNT;
return 0;
}
/*
* FIXME: upon releasing we should also handle cleanup of other client related resources:
* - stop/release timer if client has a timer under control
* - clean events queued from this client (take care about note on/off!)
* - clean events queued for this client
* - remove registered ports
* - remove client from registration lists
*/
static int snd_seq_release(unsigned short minor, int cardnum, int device, struct file *file)
{
user_client_t *clientp = (user_client_t *) file->private_data;
int c = clientp->index;
MOD_DEC_USE_COUNT;
snd_printk("seq releasing user-land client %d\n", c);
clientp = NULL;
seq_free_client(c);
return 0;
}
/* handle client read() */
static long snd_seq_read(struct file *file, char *buf, long count)
{
user_client_t *clientp = (user_client_t *) file->private_data;
long result = 0;
unsigned long flags;
/*snd_printk( ">> snd_seq_read \n>> client=%d, file*=%p, buf*=%p, count=%ld\n",
clientp->index,file,buf,count); */
if (verify_area(VERIFY_WRITE, buf, count))
return -EFAULT;
/* check client structures are in place */
if (clientp == NULL)
return -EIO;
/* while we have room for at least one event */
while (count >= sizeof(snd_seq_event_t)) {
while (snd_seq_fifo_avail(clientp->outqueue) == 0) {
/* no data available in outqueue, block */
if (file->f_flags & O_NONBLOCK)
return result;
snd_spin_lock(clientp, input_sleep, &flags);
clientp->outqueue->flags |= SND_WK_SLEEP;
snd_sleep(clientp->outqueue, input, 10 * HZ);
clientp->outqueue->flags &= ~SND_WK_SLEEP;
snd_spin_unlock(clientp, input_sleep, &flags);
if (snd_sleep_abort(clientp->outqueue, input))
return result;
}
while (snd_seq_fifo_avail(clientp->outqueue)) {
/* data available in queue */
snd_seq_event_cell_t *cell;
int len;
/* check if buffer is big enough for the new event */
cell = snd_seq_fifo_cell_peek(clientp->outqueue);
if (cell == NULL) {
snd_printk("Whoops, snd_seq_read got a NULL from the fifo\n");
return result;
}
switch (cell->event.flags & SND_SEQ_EVENT_LENGTH_MASK) {
case SND_SEQ_EVENT_LENGTH_VARIABLE:
/* handle variable length data */
len = sizeof(snd_seq_event_t) + cell->event.data.ext.len;
break;
case SND_SEQ_EVENT_LENGTH_FIXED:
default:
/* normal event, no special action needed */
len = sizeof(snd_seq_event_t);
}
if (count < len)
return result; /* not enough room for this new event */
/* get event */
cell = snd_seq_fifo_cell_out(clientp->outqueue);
if (cell == NULL) {
snd_printk("Whoops, snd_seq_read got a NULL from the fifo\n");
return result;
}
switch (cell->event.flags & SND_SEQ_EVENT_LENGTH_MASK) {
case SND_SEQ_EVENT_LENGTH_VARIABLE:
/* handle variable length data */
len = sizeof(snd_seq_event_t) + cell->event.data.ext.len;
copy_to_user(buf, &cell->event, sizeof(snd_seq_event_t));
if (cell->event.data.ext.ptr != NULL) {
copy_to_user(buf + sizeof(snd_seq_event_t), cell->event.data.ext.ptr, cell->event.data.ext.len);
snd_seq_ext_free(cell->event.data.ext.ptr, cell->event.data.ext.len);
}
break;
case SND_SEQ_EVENT_LENGTH_FIXED:
default:
/* normal event, no special action needed */
len = sizeof(snd_seq_event_t);
copy_to_user(buf, &cell->event, sizeof(snd_seq_event_t));
}
snd_seq_cell_free(cell);
result += len;
count -= len;
buf += len;
}
}
return result;
}
/* handle write() */
static long snd_seq_write(struct file *file, const char *buf, long count)
{
user_client_t *clientp = (user_client_t *) file->private_data;
snd_seq_event_t *ev = (snd_seq_event_t *) buf;
int rd = 0;
snd_seq_event_cell_t *cell;
//snd_printk( ">> snd_seq_write \n>> client=%d, file*=%p, buf*=%p, count=%ld\n", clientp->index,file,buf,count);
/* check if the data is accessible */
if (verify_area(VERIFY_READ, buf, count))
return -EFAULT;
/* check client structures are in place */
if (clientp == NULL)
return -EIO;
/* only process whole event */
while (count >= sizeof(snd_seq_event_t)) {
/* only start processing if we have enough free cells (>low-water) */
if (snd_seq_unused_cells() < 100) /* FIXME: should be configurable */
break;
/* we got one event, copy it into our own data structure and */
/* feed to the prioQ */
cell = snd_seq_event_dup_from_user(ev);
if (cell) {
cell->event.source.queue = 0;
cell->event.source.client = clientp->index; /* fill in client index */
switch (cell->event.flags & SND_SEQ_EVENT_LENGTH_MASK) {
case SND_SEQ_EVENT_LENGTH_VARIABLE:{
/* handle variable length data */
int msg_len = cell->event.data.ext.len;
unsigned char *org_msg = (char *) ev + sizeof(snd_seq_event_t);
unsigned char *new_msg;
cell->event.data.ext.ptr = new_msg = snd_seq_ext_malloc(msg_len);
if (new_msg != NULL) {
copy_from_user(new_msg, org_msg, msg_len);
} else {
snd_printk("failed to allocate %d bytes for variable length event\n", cell->event.data.ext.len);
}
count -= msg_len;
ev += msg_len;
rd += msg_len;
}
break;
case SND_SEQ_EVENT_LENGTH_FIXED:
default:
/* normal event, no special action needed */
}
snd_seq_enqueue_event(cell);
} else {
/* failure, let client know what we have read */
return rd;
}
/* up to next event */
count -= sizeof(snd_seq_event_t);
ev += sizeof(snd_seq_event_t);
rd += sizeof(snd_seq_event_t);
}
return rd;
}
#ifdef SND_POLL
static unsigned int snd_seq_poll(struct file *file, poll_table * wait)
{
user_client_t *clientp = (user_client_t *) file->private_data;
unsigned int mask = 0;
unsigned long flags;
/* check client structures are in place */
if (clientp == NULL)
return -EIO;
/* should do this only if device is opened for read */
{
snd_spin_lock(clientp, input_sleep, &flags);
clientp->outqueue->flags |= SND_WK_SLEEP;
snd_poll_wait(file, clientp->outqueue, input, wait);
snd_spin_unlock(clientp, input_sleep, &flags);
}
/* check if data is available in the outqueue */
if (snd_seq_fifo_avail(clientp->outqueue) >= 1)
mask |= POLLIN | POLLRDNORM;
/* should have at least 100 free cells in our pool */
/* FIXME: This low-water mark should be configurable */
if (snd_seq_unused_cells() > 100)
mask |= POLLOUT | POLLWRNORM;
return mask;
}
#else
static int snd_seq_select(struct file *file, int sel_type, select_table * wait)
{
user_client_t *clientp = (user_client_t *) file->private_data;
unsigned int mask;
unsigned long flags;
switch (sel_type) {
case SEL_IN: /* check if data is available in the outqueue */
/* FIXME: should check for r/w mode */
snd_spin_lock(client_p, input_sleep, &flags);
if (!(snd_seq_fifo_avail(clientp->outqueue) >= 1)) {
clientp->outqueue->flags |= SND_WK_SLEEP;
snd_select_wait(clientp->outqueue, input, wait);
snd_spin_unlock(client_p, input_sleep, &flags);
return 0;
}
clientp->outqueue->flags &= ~SND_WK_SLEEP;
snd_spin_unlock(client_p, input_sleep, &flags);
return 1;
case SEL_OUT:
if (snd_seq_unused_cells() > 100)
return 1;
return 0;
case SEL_EX:
break;
}
return 0;
}
#endif
/*-----------------------------------------------------*/
/* dispatch a single event to the client */
static void snd_seq_dispatch_single_event(snd_seq_event_cell_t * cell)
{
client_t *dest_client;
int dest = cell->event.dest.client; /* dest client */
dest_client = clientptr(dest);
if (dest_client == NULL) {
snd_printk("snd_seq_dispatch_single_event called with dest_client==NULL\n");
return;
}
switch (dest_client->type) {
case USER_CLIENT:
//snd_printk("seq: event to user client %d\n",dest);
/* write in client's outgoing fifo */
snd_seq_fifo_cell_in(dest_client->ptr.user->outqueue, cell);
break;
case KERNEL_CLIENT:
//snd_printk("seq: event to kernel client %d\n",dest);
if (dest_client->ptr.kernel->input != NULL) {
int result;
/* drain queue if old events are present */
while (snd_seq_fifo_avail(dest_client->ptr.kernel->outqueue)) {
snd_seq_event_cell_t *queued_cell;
queued_cell = snd_seq_fifo_cell_peek(dest_client->ptr.kernel->outqueue);
result = dest_client->ptr.kernel->input(&cell->event, dest_client->ptr.kernel->private_data);
if (result) {
/* event successfully processed, it can mow be removed */
snd_seq_fifo_cell_out(dest_client->ptr.kernel->outqueue);
snd_seq_cell_free(cell);
} else {
snd_printk("seq: kernel client %d refuses to process queued event\n", dest);
break;
}
}
/* directly pass event to client's routine */
result = dest_client->ptr.kernel->input(&cell->event, dest_client->ptr.kernel->private_data);
if (result) {
/* event was successfully processed, it can mow be removed */
snd_seq_cell_free(cell);
} else {
/* client refused the event (shouldn't happen!), queue it */
snd_printk("seq: kernel client %d refuses to process event\n", dest);
snd_seq_fifo_cell_in(dest_client->ptr.kernel->outqueue, cell);
}
} else {
/* no input routine registered, get rid of the event */
snd_printk("seq: kernel client %d has no input processor, event discarded\n", dest);
snd_seq_cell_free(cell);
}
break;
default:
//snd_printk("seq: dispatch_single_event failed, no client with id=%d registered\n", dest);
/* client not found, discard this event... */
snd_seq_cell_free(cell);
break;
}
}
/*
* dispatch event to the client
*
* at this moment we can only send the event to either all clients
* (broadcast) or to a specific client.
* in a later stadium multicast groups will be added
*
*/
void snd_seq_dispatch_event(snd_seq_event_cell_t * cell)
{
client_t *dest_client;
int dest;
if (!cell)
return; /* something screwed up */
dest = cell->event.dest.client; /* dest client */
//snd_printk( "Seq: dispatch event to %d\n",dest);
/* send to specific client */
if ((dest >= 0) && (dest <= 191)) {
snd_seq_dispatch_single_event(cell);
return;
}
/* send to a multicast group */
if ((dest > 191) && (dest < SND_SEQ_ADDRESS_BROADCAST)) {
snd_printk("Seq: multicast groups not supported yet (dest = %d)\n", dest);
/* Idea: multicast groups:
a multicast message is send to a list of destinations:
per list item map: client, port, channel
*/
/* release the original cell */
snd_seq_cell_free(cell);
return;
}
/* handle broadcasts */
if (dest == SND_SEQ_ADDRESS_BROADCAST) {
/* send the event to all clients */
for (dest = 0; dest < SND_SEQ_MAX_CLIENTS; dest++) {
dest_client = clientptr(dest);
if (dest_client->type != NO_CLIENT) {
snd_seq_event_cell_t *new_cell;
/* send duplicates to all the clients */
new_cell = snd_seq_cell_dup(cell);
if (new_cell) {
new_cell->event.dest.client = dest;
snd_seq_dispatch_single_event(new_cell);
}
}
}
/* release the original cell */
snd_seq_cell_free(cell);
return;
}
}
/*-----------------------------------------------------*/
/* fill client_info structure with info on the requested client (passed in client field) */
static int snd_seq_client_get_info(snd_seq_client_info_t * client_info)
{
int c;
client_t *client;
/* requested client number */
c = client_info->client;
if (c < 0 || c >= SND_SEQ_MAX_CLIENTS)
return -EINVAL; /* out of range */
client = clientptr(c);
/* fill the info fields */
client_info->type = client->type;
switch (client_info->type) {
case USER_CLIENT:
strcpy(client_info->name, client->ptr.user->name);
break;
case KERNEL_CLIENT:
strcpy(client_info->name, client->ptr.kernel->name);
break;
default:
strcpy(client_info->name, "???");
}
return 0;
}
/* set info fields for client */
static int snd_seq_client_set_info(int c, snd_seq_client_info_t * client_info)
{
client_t *client;
#if 0
/* check requested client number */
if (c != client_info->client) {
snd_printk("Can only set client info for own client\n");
return -ENXIO;
}
#endif
if (c < 0 || c >= SND_SEQ_MAX_CLIENTS)
return -EINVAL; /* out of range */
client = clientptr(c);
/* fill the info fields */
client_info->type = client->type;
switch (client_info->type) {
case USER_CLIENT:
strcpy(client->ptr.user->name, client_info->name);
break;
case KERNEL_CLIENT:
strcpy(client->ptr.kernel->name, client_info->name);
break;
}
return 0;
}
/* CLIENT_INFO ioctl() */
static int snd_seq_ioctl_get_client_info(int c, snd_seq_client_info_t * _client_info)
{
snd_seq_client_info_t client_info;
client_t *client;
int result;
if (c < 0 || c >= SND_SEQ_MAX_CLIENTS)
return -EINVAL; /* out of range */
client = clientptr(c);
switch (client->type) {
case USER_CLIENT:
if (verify_area(VERIFY_READ, _client_info, sizeof(client_info)))
return -EFAULT;
copy_from_user(&client_info, _client_info, sizeof(client_info));
result = snd_seq_client_get_info(&client_info);
if (result < 0)
return result;
if (verify_area(VERIFY_WRITE, _client_info, sizeof(client_info)))
return -EFAULT;
copy_to_user(_client_info, &client_info, sizeof(client_info));
break;
case KERNEL_CLIENT:
result = snd_seq_client_get_info(_client_info);
if (result < 0)
return result;
break;
default:
return -ENXIO;
}
return 0;
}
/* CLIENT_INFO ioctl() */
static int snd_seq_ioctl_set_client_info(int c, snd_seq_client_info_t * _client_info)
{
snd_seq_client_info_t client_info;
client_t *client;
int result;
if (c < 0 || c >= SND_SEQ_MAX_CLIENTS)
return -EINVAL; /* out of range */
client = clientptr(c);
switch (client->type) {
case USER_CLIENT:
if (verify_area(VERIFY_READ, _client_info, sizeof(client_info)))
return -EFAULT;
copy_from_user(&client_info, _client_info, sizeof(client_info));
result = snd_seq_client_set_info(c, &client_info);
if (result < 0)
return result;
if (verify_area(VERIFY_WRITE, _client_info, sizeof(client_info)))
return -EFAULT;
copy_to_user(_client_info, &client_info, sizeof(client_info));
break;
case KERNEL_CLIENT:
result = snd_seq_client_set_info(c, _client_info);
if (result < 0)
return result;
break;
default:
return -ENXIO;
}
return 0;
}
/*
* get pointer to a client's port
*/
client_port_t *snd_seq_get_client_port_ptr(int client_id, int port_id)
{
client_t *client;
/* lookup requested client */
client = clientptr(client_id);
if (client == NULL)
return NULL;
switch (client->type) {
case USER_CLIENT:
return snd_seq_get_port_ptr(&client->ptr.user->ports, port_id);
break;
case KERNEL_CLIENT:
return snd_seq_get_port_ptr(&client->ptr.kernel->ports, port_id);
break;
default:
return NULL;
}
}
/*
* CREATE PORT ioctl()
*/
static int snd_seq_ioctl_create_port(int c, snd_seq_port_info_t * info)
{
client_t *client;
if (c < 0 || c >= SND_SEQ_MAX_CLIENTS)
return -EINVAL; /* out of range */
client = clientptr(c);
switch (client->type) {
case USER_CLIENT:
{
int p;
client_port_t *port;
snd_seq_port_info_t _info;
p = snd_seq_create_port(&client->ptr.user->ports);
snd_printk("seq registered port %d (user)\n", p);
if ((info != NULL) && (p >= 0)) {
/* set passed parameters */
if (verify_area(VERIFY_READ, info, sizeof(snd_seq_port_info_t)))
return -EFAULT;
copy_from_user(&_info, info, sizeof(snd_seq_port_info_t));
_info.client = c;
_info.port = p;
port = snd_seq_get_port_ptr(&client->ptr.user->ports, _info.port);
if (port != NULL)
snd_seq_set_port_info(port, &_info);
if (verify_area(VERIFY_WRITE, info, sizeof(snd_seq_port_info_t)))
return -EFAULT;
copy_to_user(info, &_info, sizeof(snd_seq_port_info_t));
}
return p;
}
case KERNEL_CLIENT:
{
int p;
client_port_t *port;
p = snd_seq_create_port(&client->ptr.kernel->ports);
snd_printk("seq registered port %d (kernel)\n", p);
if ((info != NULL) && (p >= 0)) {
/* set passed parameters */
info->client = c;
info->port = p;
port = snd_seq_get_port_ptr(&client->ptr.kernel->ports, info->port);
if (port != NULL)
snd_seq_set_port_info(port, info);
}
return p;
}
default:
return -ENXIO;
}
return -ENXIO;
}
/*
* DELETE PORT ioctl()
*/
static int snd_seq_ioctl_delete_port(int c, snd_seq_port_info_t * info)
{
client_t *client;
if (c < 0 || c >= SND_SEQ_MAX_CLIENTS)
return -EINVAL; /* out of range */
client = clientptr(c);
switch (client->type) {
case USER_CLIENT:
{
int ret = -EINVAL;
snd_seq_port_info_t _info;
if (info != NULL) {
/* set passed parameters */
if (verify_area(VERIFY_READ, info, sizeof(snd_seq_port_info_t)))
return -EFAULT;
copy_from_user(&_info, info, sizeof(snd_seq_port_info_t));
ret = snd_seq_delete_port(&client->ptr.user->ports, _info.port);
if (verify_area(VERIFY_WRITE, info, sizeof(snd_seq_port_info_t)))
return -EFAULT;
copy_to_user(info, &_info, sizeof(snd_seq_port_info_t));
}
return ret;
}
case KERNEL_CLIENT:
{
if (info != NULL) {
return snd_seq_delete_port(&client->ptr.kernel->ports, info->port);
}
}
default:
return -ENXIO;
}
return -ENXIO;
}
/*
* GET_PORT_INFO ioctl() (on any client)
*/
static int snd_seq_ioctl_get_port_info(int c, snd_seq_port_info_t * info)
{
client_t *client;
if (c < 0 || c >= SND_SEQ_MAX_CLIENTS)
return -EINVAL; /* out of range */
client = clientptr(c);
switch (client->type) {
case USER_CLIENT:
{
client_port_t *port;
snd_seq_port_info_t _info;
if (verify_area(VERIFY_READ, info, sizeof(snd_seq_port_info_t)))
return -EFAULT;
copy_from_user(&_info, info, sizeof(snd_seq_port_info_t));
port = snd_seq_get_client_port_ptr(_info.client, _info.port);
if (port == NULL)
return -ENXIO;
/* get port info */
snd_seq_get_port_info(port, &_info);
if (verify_area(VERIFY_WRITE, info, sizeof(snd_seq_port_info_t)))
return -EFAULT;
copy_to_user(info, &_info, sizeof(snd_seq_port_info_t));
return 0;
}
case KERNEL_CLIENT:
{
client_port_t *port;
port = snd_seq_get_client_port_ptr(info->client, info->port);
if (port == NULL)
return -ENXIO;
/* get port info */
snd_seq_get_port_info(port, info);
return 0;
}
default:
return -ENXIO;
}
return -ENXIO;
}
/*
* SET_PORT_INFO ioctl() (only ports on this/own client)
*/
static int snd_seq_ioctl_set_port_info(int c, snd_seq_port_info_t * info)
{
client_t *client;
if (c < 0 || c >= SND_SEQ_MAX_CLIENTS)
return -EINVAL; /* out of range */
client = clientptr(c);
switch (client->type) {
case USER_CLIENT:
{
client_port_t *port;
snd_seq_port_info_t _info;
if (verify_area(VERIFY_READ, info, sizeof(snd_seq_port_info_t)))
return -EFAULT;
copy_from_user(&_info, info, sizeof(snd_seq_port_info_t));
_info.client = c; /* only set our own ports ! */
port = snd_seq_get_port_ptr(&client->ptr.user->ports, _info.port);
if (port != NULL)
snd_seq_set_port_info(port, &_info);
if (verify_area(VERIFY_WRITE, info, sizeof(snd_seq_port_info_t)))
return -EFAULT;
copy_to_user(info, &_info, sizeof(snd_seq_port_info_t));
return 0;
}
case KERNEL_CLIENT:
{
client_port_t *port;
port = snd_seq_get_port_ptr(&client->ptr.kernel->ports, info->port);
if (port == NULL)
return -ENXIO;
/* set port info */
info->client = c; /* only set our own ports ! */
snd_seq_set_port_info(port, info);
return 0;
}
default:
return -ENXIO;
}
return -ENXIO;
}
/*
* add a subscriber to a port
*/
static int snd_seq_subscribe_port(snd_seq_port_subscribe_t * subs)
{
client_port_t *port;
port = snd_seq_get_client_port_ptr(subs->sender.client, subs->sender.port);
if (port == NULL)
return -ENXIO;
snd_printk("Add subscription; %d:%d will send to %d:%d via queue %d\n",
subs->sender.client, subs->sender.port,
subs->dest.client, subs->dest.port, subs->dest.queue);
return snd_seq_port_add_subscriber(port, &subs->dest);
}
/*
* add to port's subscription list IOCTL interface
*/
static int snd_seq_ioctl_subscribe_port(int c, snd_seq_port_subscribe_t * subs)
{
client_t *client;
if (c < 0 || c >= SND_SEQ_MAX_CLIENTS)
return -EINVAL; /* out of range */
client = clientptr(c);
switch (client->type) {
case USER_CLIENT:
{
snd_seq_port_subscribe_t _subs;
if (verify_area(VERIFY_READ, subs, sizeof(snd_seq_port_subscribe_t)))
return -EFAULT;
copy_from_user(&_subs, subs, sizeof(snd_seq_port_subscribe_t));
return snd_seq_subscribe_port(&_subs);
}
case KERNEL_CLIENT:
return snd_seq_subscribe_port(subs);
default:
return -ENXIO;
}
return -ENXIO;
}
/*
* remove from port's subscription list
*/
static int snd_seq_ioctl_unsubscribe_port(int c, snd_seq_port_subscribe_t * subs)
{
client_t *client;
if (c < 0 || c >= SND_SEQ_MAX_CLIENTS)
return -EINVAL; /* out of range */
client = clientptr(c);
switch (client->type) {
case USER_CLIENT:
{
snd_printk("unsubscribe_port is not implemented\n"); /* FIXME */
return 0;
}
case KERNEL_CLIENT:
{
snd_printk("unsubscribe_port is not implemented\n"); /* FIXME */
return 0;
}
default:
return -ENXIO;
}
return -ENXIO;
}
static int snd_seq_use_port(snd_seq_port_use_t * use)
{
snd_printk("snd_seq_use_port: not implemented\n");
return 0;
}
/*
* add to port's users list IOCTL interface
*/
static int snd_seq_ioctl_use_port(int c, snd_seq_port_use_t * use)
{
client_t *client;
if (c < 0 || c >= SND_SEQ_MAX_CLIENTS)
return -EINVAL; /* out of range */
client = clientptr(c);
switch (client->type) {
case USER_CLIENT:
{
snd_seq_port_use_t _use;
if (verify_area(VERIFY_READ, use, sizeof(snd_seq_port_use_t)))
return -EFAULT;
copy_from_user(&_use, use, sizeof(snd_seq_port_use_t));
return snd_seq_use_port(&_use);
}
case KERNEL_CLIENT:
return snd_seq_use_port(use);
default:
return -ENXIO;
}
return -ENXIO;
}
/*
* remove from port's users list
*/
static int snd_seq_ioctl_unuse_port(int c, snd_seq_port_use_t * use)
{
client_t *client;
if (c < 0 || c >= SND_SEQ_MAX_CLIENTS)
return -EINVAL; /* out of range */
client = clientptr(c);
switch (client->type) {
case USER_CLIENT:
{
snd_printk("unuse_port is not implemented\n"); /* FIXME */
return 0;
}
case KERNEL_CLIENT:
{
snd_printk("unuse_port is not implemented\n"); /* FIXME */
return 0;
}
default:
return -ENXIO;
}
return -ENXIO;
}
/* fill queue_info structure */
static int snd_seq_get_queue_info(snd_seq_queue_info_t * info)
{
queue_t *queue = queueptr(info->queue);
timer_t *tmr = NULL;
if (queue == NULL)
return -ENXIO;
tmr = queue->timer;
info->tick = tmr->cur_tick;
info->time.tv_sec = tmr->cur_time.tv_sec;
info->time.tv_nsec = tmr->cur_time.tv_nsec;
info->running = tmr->running;
info->tempo = tmr->tempo;
info->ppq = tmr->ppq;
info->flags = 0; /* not yet used... */
info->owner = queue->owner;
info->locked = queue->locked;
return 0; /* goes always ok... */
}
/* set timer information. parameters that are -1 left unchanged */
static int snd_seq_set_queue_info(int client, snd_seq_queue_info_t * info)
{
if (snd_seq_queue_check_access(info->queue, client)) {
if (info->tempo >= 0)
snd_seq_queue_timer_set_tempo(info->queue, client, info->tempo);
if (info->ppq >= 0)
snd_seq_queue_timer_set_ppq(info->queue, client, info->ppq);
if (info->locked >= 0)
snd_seq_queue_set_locked(info->queue, client, info->locked);
if (info->owner >= 0)
snd_seq_queue_set_owner(info->queue, info->owner);
/* return updated queue_info struct */
return snd_seq_get_queue_info(info);
} else {
return -EACCES; /* Permission denied */
}
}
/* SET_QUEUE_INFO ioctl() */
static int snd_seq_ioctl_set_queue_info(int c, snd_seq_queue_info_t * info)
{
client_t *client;
if (c < 0 || c >= SND_SEQ_MAX_CLIENTS)
return -EINVAL; /* out of range */
client = clientptr(c);
switch (client->type) {
case USER_CLIENT:
{
snd_seq_queue_info_t _info;
int result;
if (verify_area(VERIFY_READ, info, sizeof(snd_seq_queue_info_t)))
return -EFAULT;
copy_from_user(&_info, info, sizeof(snd_seq_queue_info_t));
result = snd_seq_set_queue_info(c, &_info);
if (result < 0)
return result;
if (verify_area(VERIFY_WRITE, info, sizeof(snd_seq_queue_info_t)))
return -EFAULT;
copy_to_user(info, &_info, sizeof(snd_seq_queue_info_t));
return 0;
}
case KERNEL_CLIENT:
return snd_seq_set_queue_info(c, info);
default:
return -ENXIO;
}
return -ENXIO;
}
/* GET_QUEUE_INFO ioctl() */
static int snd_seq_ioctl_get_queue_info(int c, snd_seq_queue_info_t * info)
{
client_t *client;
if (c < 0 || c >= SND_SEQ_MAX_CLIENTS)
return -EINVAL; /* out of range */
client = clientptr(c);
switch (client->type) {
case USER_CLIENT:
{
snd_seq_queue_info_t _info;
int result;
if (verify_area(VERIFY_READ, info, sizeof(snd_seq_queue_info_t)))
return -EFAULT;
copy_from_user(&_info, info, sizeof(snd_seq_queue_info_t));
result = snd_seq_get_queue_info(&_info);
if (result < 0)
return result;
if (verify_area(VERIFY_WRITE, info, sizeof(snd_seq_queue_info_t)))
return -EFAULT;
copy_to_user(info, &_info, sizeof(snd_seq_queue_info_t));
return 0;
}
case KERNEL_CLIENT:
return snd_seq_get_queue_info(info);
default:
return -ENXIO;
}
return -ENXIO;
}
static int snd_seq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
user_client_t *clientp = (user_client_t *) file->private_data;
int client = clientp->index;
/*snd_printk(">> seq ioctl - cmd = 0x%x\n", cmd); */
switch (cmd) {
case SND_SEQ_IOCTL_VERSION:
/* return sequencer version number */
return snd_ioctl_out((long *) arg, SND_SEQ_VERSION);
case SND_SEQ_IOCTL_CLIENT_ID:
/* return the id of this client */
return snd_ioctl_out((long *) arg, clientp->index);
case SND_SEQ_IOCTL_GET_CLIENT_INFO:
/* return info on specified client */
return snd_seq_ioctl_get_client_info(client, (snd_seq_client_info_t *) arg);
case SND_SEQ_IOCTL_SET_CLIENT_INFO:
/* set info on specified client */
return snd_seq_ioctl_set_client_info(client, (snd_seq_client_info_t *) arg);
case SND_SEQ_IOCTL_CREATE_PORT:
/* create a port for this client */
return snd_seq_ioctl_create_port(client, (snd_seq_port_info_t *) arg);
case SND_SEQ_IOCTL_DELETE_PORT:
/* remove a port from this client */
return snd_seq_ioctl_delete_port(client, (snd_seq_port_info_t *) arg);
case SND_SEQ_IOCTL_GET_PORT_INFO:
/* get info for specified port */
return snd_seq_ioctl_get_port_info(client, (snd_seq_port_info_t *) arg);
case SND_SEQ_IOCTL_SET_PORT_INFO:
/* set info for specified port in this client */
return snd_seq_ioctl_set_port_info(client, (snd_seq_port_info_t *) arg);
case SND_SEQ_IOCTL_SUBSCRIBE_PORT:
/* add to port's subscription list */
return snd_seq_ioctl_subscribe_port(client, (snd_seq_port_subscribe_t *) arg);
case SND_SEQ_IOCTL_UNSUBSCRIBE_PORT:
/* remove from port's subscription list */
return snd_seq_ioctl_unsubscribe_port(client, (snd_seq_port_subscribe_t *) arg);
case SND_SEQ_IOCTL_USE_PORT:
/* add to port's users list */
return snd_seq_ioctl_use_port(client, (snd_seq_port_use_t *) arg);
case SND_SEQ_IOCTL_UNUSE_PORT:
/* remove from port's users list */
return snd_seq_ioctl_unuse_port(client, (snd_seq_port_use_t *) arg);
case SND_SEQ_IOCTL_GET_QUEUE_INFO:
/* get info for specified queue */
return snd_seq_ioctl_get_queue_info(client, (snd_seq_queue_info_t *) arg);
case SND_SEQ_IOCTL_SET_QUEUE_INFO:
/* set info for specified queue */
return snd_seq_ioctl_set_queue_info(client, (snd_seq_queue_info_t *) arg);
default:
snd_printk("seq unknown ioctl() 0x%x (type='%c', number=0x%2x)\n",
cmd, _IOC_TYPE(cmd), _IOC_NR(cmd));
}
return -ENXIO;
}
/* -------------------------------------------------------- */
/* exported to kernel modules */
int snd_seq_register_kernel_client(snd_seq_client_callback_t * callback, void *private_data)
{
int c; /* client id */
client_t *client;
c = seq_create_kernel_client();
if (c < 0)
return c; /* failure code */
/* fill client data */
client = clientptr(c);
client->ptr.kernel->input = callback->input;
client->ptr.kernel->private_data = private_data;
sprintf(client->ptr.kernel->name, "Client-%d", c);
snd_printk("seq registering kernel client %d\n", c);
/* return client number to caller */
return c;
}
/* exported to kernel modules */
int snd_seq_unregister_kernel_client(int client)
{
snd_printk("seq releasing kernel client %d\n", client);
seq_free_client(client);
return 0;
}
/* exported, called by kernel clients to enqueue events */
int snd_seq_kernel_client_enqueue(int client, snd_seq_event_t * ev)
{
snd_seq_event_cell_t *cell;
/* we got one event, copy it into our own data structure and */
/* feed it to the prioQ */
cell = snd_seq_event_dup(ev);
if (cell) {
cell->event.source.queue = 0;
cell->event.source.client = client; /* fill in client index */
snd_seq_enqueue_event(cell);
return 1; /* success */
} else {
return -1;
}
}
/*
* exported, called by kernel clients to dispatch events directly to other
* clients, bypassing the queues. No processing of time stamps is done.
*/
int snd_seq_kernel_client_dispatch(int client, snd_seq_event_t * ev)
{
snd_seq_event_cell_t *cell;
/* we got one event, copy it into our own data structure and */
/* send it directly to the client */
cell = snd_seq_event_dup(ev);
if (cell) {
snd_seq_dispatch_event(cell);
return 1; /* success */
} else {
return -1;
}
}
/*
* exported, called by kernel clients to perform same functions as with
* userland ioctl()
*/
int snd_seq_kernel_client_ctl(int client, unsigned int cmd, void *arg)
{
//snd_printk(">> seq kernel client ctl - cmd = 0x%x\n", cmd);
switch (cmd) {
case SND_SEQ_IOCTL_GET_CLIENT_INFO:
/* return info on specified client */
return snd_seq_ioctl_get_client_info(client, (snd_seq_client_info_t *) arg);
case SND_SEQ_IOCTL_SET_CLIENT_INFO:
/* set info on specified client */
return snd_seq_ioctl_set_client_info(client, (snd_seq_client_info_t *) arg);
case SND_SEQ_IOCTL_CREATE_PORT:
/* create a port for this client */
return snd_seq_ioctl_create_port(client, (snd_seq_port_info_t *) arg);
case SND_SEQ_IOCTL_DELETE_PORT:
/* remove a port from this client */
return snd_seq_ioctl_delete_port(client, (snd_seq_port_info_t *) arg);
case SND_SEQ_IOCTL_GET_PORT_INFO:
/* get info for specified port */
return snd_seq_ioctl_get_port_info(client, (snd_seq_port_info_t *) arg);
case SND_SEQ_IOCTL_SET_PORT_INFO:
/* set info for specified port */
return snd_seq_ioctl_set_port_info(client, (snd_seq_port_info_t *) arg);
case SND_SEQ_IOCTL_SUBSCRIBE_PORT:
/* add to port's subscription list */
return snd_seq_ioctl_subscribe_port(client, (snd_seq_port_subscribe_t *) arg);
case SND_SEQ_IOCTL_UNSUBSCRIBE_PORT:
/* remove from port's subscription list */
return snd_seq_ioctl_unsubscribe_port(client, (snd_seq_port_subscribe_t *) arg);
case SND_SEQ_IOCTL_USE_PORT:
/* add to port's users list */
return snd_seq_ioctl_use_port(client, (snd_seq_port_use_t *) arg);
case SND_SEQ_IOCTL_UNUSE_PORT:
/* remove from port's users list */
return snd_seq_ioctl_unuse_port(client, (snd_seq_port_use_t *) arg);
case SND_SEQ_IOCTL_GET_QUEUE_INFO:
/* get info for specified queue */
return snd_seq_ioctl_get_queue_info(client, (snd_seq_queue_info_t *) arg);
case SND_SEQ_IOCTL_SET_QUEUE_INFO:
/* set info for specified queue */
return snd_seq_ioctl_set_queue_info(client, (snd_seq_queue_info_t *) arg);
default:
snd_printk("seq unknown ctl() 0x%x (type='%c', number=0x%2x)\n",
cmd, _IOC_TYPE(cmd), _IOC_NR(cmd));
}
return -ENXIO;
}
/*---------------------------------------------------------------------------*/
/*
* /proc interface
*/
static void snd_seq_info_dump_ports(snd_info_buffer_t * buffer, client_port_t * ports)
{
client_port_t *p = ports;
while (p) {
#if SHOW_CAPABILITY
snd_iprintf(buffer, " Port %3d : \"%s\" (%s,%s,%s,%s)\n",
p->port, p->name,
(p->capability & SND_SEQ_PORT_CAP_MIDI_IN ? "MIDI_in" : ""),
(p->capability & SND_SEQ_PORT_CAP_MIDI_OUT ? "MIDI_out" : ""),
(p->capability & SND_SEQ_PORT_CAP_SYNC_IN ? "Sync_in" : ""),
(p->capability & SND_SEQ_PORT_CAP_SYNC_OUT ? "Sync_out" : ""),
(p->capability & SND_SEQ_PORT_CAP_SUBSCRIPTION ? "Subscription" : ""));
#else
snd_iprintf(buffer, " Port %3d : \"%s\"\n",
p->port, p->name);
#endif
/* show subscribers */
if (p->capability & SND_SEQ_PORT_CAP_SUBSCRIPTION) {
subscribers_t *subs;
snd_iprintf(buffer, " Subscribers: ");
for (subs = p->subscribers; subs != NULL; subs = subs->next) {
snd_iprintf(buffer, "%d:%d:%d",
subs->data->dest.queue,
subs->data->dest.client,
subs->data->dest.port);
if (subs->next)
snd_iprintf(buffer, ", ");
}
snd_iprintf(buffer, "\n");
}
/* show users */
if (p->capability & SND_SEQ_PORT_CAP_USE) {
//subscription_t *subs;
snd_iprintf(buffer, " Users: ???");
//for (subs = p->subscribers; subs != NULL; subs = subs->next) {
// snd_iprintf(buffer, "%d:%d:%d",
// subs->dest.queue,
// subs->dest.client,
// subs->dest.port);
// if (subs->next)
// snd_iprintf(buffer, ", ");
//}
snd_iprintf(buffer, "\n");
}
p = p->next;
}
}
/* exported to seq_info.c */
void snd_seq_info_clients_read(snd_info_buffer_t * buffer, void *private_data)
{
int c;
client_t *client;
snd_iprintf(buffer, "Client info.\n");
snd_iprintf(buffer, " cur clients : %d\n", client_usage.cur);
snd_iprintf(buffer, " peak clients : %d\n", client_usage.peak);
snd_iprintf(buffer, " max clients : %d\n", SND_SEQ_MAX_CLIENTS);
snd_iprintf(buffer, "\n");
/* list the client table */
for (c = 0; c < SND_SEQ_MAX_CLIENTS; c++) {
client = clientptr(c);
switch (client->type) {
case NO_CLIENT:
/*snd_iprintf(buffer, "Client %3d : Free\n", c); */
break;
case USER_CLIENT:
snd_iprintf(buffer, "Client %3d : \"%s\" [User]\n", c, client->ptr.user->name);
snd_seq_info_dump_ports(buffer, client->ptr.user->ports);
break;
case KERNEL_CLIENT:
snd_iprintf(buffer, "Client %3d : \"%s\" [Kernel]\n", c, client->ptr.kernel->name);
snd_seq_info_dump_ports(buffer, client->ptr.kernel->ports);
break;
}
}
}
/*---------------------------------------------------------------------------*/
/*
* REGISTRATION PART
*/
static snd_minor_t snd_seq_reg =
{
"sequencer",
NULL, /* unregister */
NULL, /* lseek */
snd_seq_read, /* read */
snd_seq_write, /* write */
snd_seq_open, /* open */
snd_seq_release, /* release */
#ifdef SND_POLL
snd_seq_poll, /* poll */
#else
snd_seq_select, /* select */
#endif
snd_seq_ioctl, /* ioctl */
NULL /* mmap */
};
/*
* register sequencer device
*/
int snd_sequencer_device_init(void)
{
int err;
snd_mutex_down_static(register);
if ((err = snd_register_minor(SND_MINOR_SEQUENCER, &snd_seq_reg)) < 0) {
snd_mutex_up_static(register);
return err;
}
snd_mutex_up_static(register);
return 0;
}
/*
* unregister sequencer device
*/
void snd_sequencer_device_done(void)
{
snd_unregister_minor(SND_MINOR_SEQUENCER);
}
|