Full support for Ginger Console
[linux-ginger.git] / sound / core / seq / seq_system.c
blob77884e62b6483216981c0d2a9da553ac86b9f138
1 /*
2 * ALSA sequencer System services Client
3 * Copyright (c) 1998-1999 by Frank van de Pol <fvdpol@coil.demon.nl>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <linux/init.h>
23 #include <sound/core.h>
24 #include "seq_system.h"
25 #include "seq_timer.h"
26 #include "seq_queue.h"
28 /* internal client that provide system services, access to timer etc. */
31 * Port "Timer"
32 * - send tempo /start/stop etc. events to this port to manipulate the
33 * queue's timer. The queue address is specified in
34 * data.queue.queue.
35 * - this port supports subscription. The received timer events are
36 * broadcasted to all subscribed clients. The modified tempo
37 * value is stored on data.queue.value.
38 * The modifier client/port is not send.
40 * Port "Announce"
41 * - does not receive message
42 * - supports supscription. For each client or port attaching to or
43 * detaching from the system an announcement is send to the subscribed
44 * clients.
46 * Idea: the subscription mechanism might also work handy for distributing
47 * synchronisation and timing information. In this case we would ideally have
48 * a list of subscribers for each type of sync (time, tick), for each timing
49 * queue.
51 * NOTE: the queue to be started, stopped, etc. must be specified
52 * in data.queue.addr.queue field. queue is used only for
53 * scheduling, and no longer referred as affected queue.
54 * They are used only for timer broadcast (see above).
55 * -- iwai
59 /* client id of our system client */
60 static int sysclient = -1;
62 /* port id numbers for this client */
63 static int announce_port = -1;
67 /* fill standard header data, source port & channel are filled in */
68 static int setheader(struct snd_seq_event * ev, int client, int port)
70 if (announce_port < 0)
71 return -ENODEV;
73 memset(ev, 0, sizeof(struct snd_seq_event));
75 ev->flags &= ~SNDRV_SEQ_EVENT_LENGTH_MASK;
76 ev->flags |= SNDRV_SEQ_EVENT_LENGTH_FIXED;
78 ev->source.client = sysclient;
79 ev->source.port = announce_port;
80 ev->dest.client = SNDRV_SEQ_ADDRESS_SUBSCRIBERS;
82 /* fill data */
83 /*ev->data.addr.queue = SNDRV_SEQ_ADDRESS_UNKNOWN;*/
84 ev->data.addr.client = client;
85 ev->data.addr.port = port;
87 return 0;
91 /* entry points for broadcasting system events */
92 void snd_seq_system_broadcast(int client, int port, int type)
94 struct snd_seq_event ev;
96 if (setheader(&ev, client, port) < 0)
97 return;
98 ev.type = type;
99 snd_seq_kernel_client_dispatch(sysclient, &ev, 0, 0);
102 /* entry points for broadcasting system events */
103 int snd_seq_system_notify(int client, int port, struct snd_seq_event *ev)
105 ev->flags = SNDRV_SEQ_EVENT_LENGTH_FIXED;
106 ev->source.client = sysclient;
107 ev->source.port = announce_port;
108 ev->dest.client = client;
109 ev->dest.port = port;
110 return snd_seq_kernel_client_dispatch(sysclient, ev, 0, 0);
113 /* call-back handler for timer events */
114 static int event_input_timer(struct snd_seq_event * ev, int direct, void *private_data, int atomic, int hop)
116 return snd_seq_control_queue(ev, atomic, hop);
119 /* register our internal client */
120 int __init snd_seq_system_client_init(void)
122 struct snd_seq_port_callback pcallbacks;
123 struct snd_seq_port_info *port;
125 port = kzalloc(sizeof(*port), GFP_KERNEL);
126 if (!port)
127 return -ENOMEM;
129 memset(&pcallbacks, 0, sizeof(pcallbacks));
130 pcallbacks.owner = THIS_MODULE;
131 pcallbacks.event_input = event_input_timer;
133 /* register client */
134 sysclient = snd_seq_create_kernel_client(NULL, 0, "System");
136 /* register timer */
137 strcpy(port->name, "Timer");
138 port->capability = SNDRV_SEQ_PORT_CAP_WRITE; /* accept queue control */
139 port->capability |= SNDRV_SEQ_PORT_CAP_READ|SNDRV_SEQ_PORT_CAP_SUBS_READ; /* for broadcast */
140 port->kernel = &pcallbacks;
141 port->type = 0;
142 port->flags = SNDRV_SEQ_PORT_FLG_GIVEN_PORT;
143 port->addr.client = sysclient;
144 port->addr.port = SNDRV_SEQ_PORT_SYSTEM_TIMER;
145 snd_seq_kernel_client_ctl(sysclient, SNDRV_SEQ_IOCTL_CREATE_PORT, port);
147 /* register announcement port */
148 strcpy(port->name, "Announce");
149 port->capability = SNDRV_SEQ_PORT_CAP_READ|SNDRV_SEQ_PORT_CAP_SUBS_READ; /* for broadcast only */
150 port->kernel = NULL;
151 port->type = 0;
152 port->flags = SNDRV_SEQ_PORT_FLG_GIVEN_PORT;
153 port->addr.client = sysclient;
154 port->addr.port = SNDRV_SEQ_PORT_SYSTEM_ANNOUNCE;
155 snd_seq_kernel_client_ctl(sysclient, SNDRV_SEQ_IOCTL_CREATE_PORT, port);
156 announce_port = port->addr.port;
158 kfree(port);
159 return 0;
163 /* unregister our internal client */
164 void __exit snd_seq_system_client_done(void)
166 int oldsysclient = sysclient;
168 if (oldsysclient >= 0) {
169 sysclient = -1;
170 announce_port = -1;
171 snd_seq_delete_kernel_client(oldsysclient);