fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / sound / core / seq / seq_dummy.c
index e05095a..e55488d 100644 (file)
@@ -21,6 +21,7 @@
 #include <sound/driver.h>
 #include <linux/init.h>
 #include <linux/slab.h>
+#include <linux/moduleparam.h>
 #include <sound/core.h>
 #include "seq_clientmgr.h"
 #include <sound/initval.h>
 MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
 MODULE_DESCRIPTION("ALSA sequencer MIDI-through client");
 MODULE_LICENSE("GPL");
-MODULE_CLASSES("{sound}");
-MODULE_SUPPORTED_DEVICE("sound");
-MODULE_PARM(ports, "i");
+MODULE_ALIAS("snd-seq-client-" __stringify(SNDRV_SEQ_CLIENT_DUMMY));
+
+static int ports = 1;
+static int duplex;
+
+module_param(ports, int, 0444);
 MODULE_PARM_DESC(ports, "number of ports to be created");
-MODULE_PARM(duplex, "i");
+module_param(duplex, bool, 0444);
 MODULE_PARM_DESC(duplex, "create DUPLEX ports");
-int ports = 1;
-int duplex = 0;
 
-typedef struct snd_seq_dummy_port {
+struct snd_seq_dummy_port {
        int client;
        int port;
        int duplex;
        int connect;
-} snd_seq_dummy_port_t;
+};
 
 static int my_client = -1;
 
@@ -86,13 +88,13 @@ static int my_client = -1;
  * Note: this callback is called only after all subscribers are removed.
  */
 static int
-dummy_unuse(void *private_data, snd_seq_port_subscribe_t *info)
+dummy_unuse(void *private_data, struct snd_seq_port_subscribe *info)
 {
-       snd_seq_dummy_port_t *p;
+       struct snd_seq_dummy_port *p;
        int i;
-       snd_seq_event_t ev;
+       struct snd_seq_event ev;
 
-       p = snd_magic_cast(snd_seq_dummy_port_t, private_data, return -EINVAL);
+       p = private_data;
        memset(&ev, 0, sizeof(ev));
        if (p->duplex)
                ev.source.port = p->connect;
@@ -114,23 +116,17 @@ dummy_unuse(void *private_data, snd_seq_port_subscribe_t *info)
  * event input callback - just redirect events to subscribers
  */
 static int
-dummy_input(snd_seq_event_t *ev, int direct, void *private_data, int atomic, int hop)
+dummy_input(struct snd_seq_event *ev, int direct, void *private_data,
+           int atomic, int hop)
 {
-       snd_seq_dummy_port_t *p;
-       snd_seq_event_t tmpev;
+       struct snd_seq_dummy_port *p;
+       struct snd_seq_event tmpev;
 
-       p = snd_magic_cast(snd_seq_dummy_port_t, private_data, return -EINVAL);
+       p = private_data;
        if (ev->source.client == SNDRV_SEQ_CLIENT_SYSTEM ||
            ev->type == SNDRV_SEQ_EVENT_KERNEL_ERROR)
                return 0; /* ignore system messages */
-       /* save the original sender */
-       tmpev.type = SNDRV_SEQ_EVENT_KERNEL_QUOTE;
-       tmpev.flags = (ev->flags & ~SNDRV_SEQ_EVENT_LENGTH_MASK)
-               | SNDRV_SEQ_EVENT_LENGTH_FIXED;
-       tmpev.tag = ev->tag;
-       tmpev.time = ev->time;
-       tmpev.data.quote.origin = ev->source;
-       tmpev.data.quote.event = ev;
+       tmpev = *ev;
        if (p->duplex)
                tmpev.source.port = p->connect;
        else
@@ -145,23 +141,20 @@ dummy_input(snd_seq_event_t *ev, int direct, void *private_data, int atomic, int
 static void
 dummy_free(void *private_data)
 {
-       snd_seq_dummy_port_t *p;
-
-       p = snd_magic_cast(snd_seq_dummy_port_t, private_data, return);
-       snd_magic_kfree(p);
+       kfree(private_data);
 }
 
 /*
  * create a port
  */
-static snd_seq_dummy_port_t __init *
+static struct snd_seq_dummy_port __init *
 create_port(int idx, int type)
 {
-       snd_seq_port_info_t pinfo;
-       snd_seq_port_callback_t pcb;
-       snd_seq_dummy_port_t *rec;
+       struct snd_seq_port_info pinfo;
+       struct snd_seq_port_callback pcb;
+       struct snd_seq_dummy_port *rec;
 
-       if ((rec = snd_magic_kcalloc(snd_seq_dummy_port_t, 0, GFP_KERNEL)) == NULL)
+       if ((rec = kzalloc(sizeof(*rec), GFP_KERNEL)) == NULL)
                return NULL;
 
        rec->client = my_client;
@@ -178,7 +171,9 @@ create_port(int idx, int type)
        pinfo.capability |= SNDRV_SEQ_PORT_CAP_WRITE | SNDRV_SEQ_PORT_CAP_SUBS_WRITE;
        if (duplex)
                pinfo.capability |= SNDRV_SEQ_PORT_CAP_DUPLEX;
-       pinfo.type = SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC;
+       pinfo.type = SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC
+               | SNDRV_SEQ_PORT_TYPE_SOFTWARE
+               | SNDRV_SEQ_PORT_TYPE_PORT;
        memset(&pcb, 0, sizeof(pcb));
        pcb.owner = THIS_MODULE;
        pcb.unuse = dummy_unuse;
@@ -187,7 +182,7 @@ create_port(int idx, int type)
        pcb.private_data = rec;
        pinfo.kernel = &pcb;
        if (snd_seq_kernel_client_ctl(my_client, SNDRV_SEQ_IOCTL_CREATE_PORT, &pinfo) < 0) {
-               snd_magic_kfree(rec);
+               kfree(rec);
                return NULL;
        }
        rec->port = pinfo.addr.port;
@@ -200,9 +195,7 @@ create_port(int idx, int type)
 static int __init
 register_client(void)
 {
-       snd_seq_client_callback_t cb;
-       snd_seq_client_info_t cinfo;
-       snd_seq_dummy_port_t *rec1, *rec2;
+       struct snd_seq_dummy_port *rec1, *rec2;
        int i;
 
        if (ports < 1) {
@@ -211,20 +204,11 @@ register_client(void)
        }
 
        /* create client */
-       memset(&cb, 0, sizeof(cb));
-       cb.allow_input = 1;
-       cb.allow_output = 1;
-       my_client = snd_seq_create_kernel_client(NULL, SNDRV_SEQ_CLIENT_DUMMY, &cb);
+       my_client = snd_seq_create_kernel_client(NULL, SNDRV_SEQ_CLIENT_DUMMY,
+                                                "Midi Through");
        if (my_client < 0)
                return my_client;
 
-       /* set client name */
-       memset(&cinfo, 0, sizeof(cinfo));
-       cinfo.client = my_client;
-       cinfo.type = KERNEL_CLIENT;
-       strcpy(cinfo.name, "Midi Through");
-       snd_seq_kernel_client_ctl(my_client, SNDRV_SEQ_IOCTL_SET_CLIENT_INFO, &cinfo);
-
        /* create ports */
        for (i = 0; i < ports; i++) {
                rec1 = create_port(i, 0);
@@ -262,7 +246,11 @@ delete_client(void)
 
 static int __init alsa_seq_dummy_init(void)
 {
-       return register_client();
+       int err;
+       snd_seq_autoload_lock();
+       err = register_client();
+       snd_seq_autoload_unlock();
+       return err;
 }
 
 static void __exit alsa_seq_dummy_exit(void)