1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#include <linux/init.h>
23#include <linux/export.h>
24#include <linux/slab.h>
25#include <sound/core.h>
26#include "seq_system.h"
27#include "seq_timer.h"
28#include "seq_queue.h"
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
62static int sysclient = -1;
63
64
65static int announce_port = -1;
66
67
68
69
70static int setheader(struct snd_seq_event * ev, int client, int port)
71{
72 if (announce_port < 0)
73 return -ENODEV;
74
75 memset(ev, 0, sizeof(struct snd_seq_event));
76
77 ev->flags &= ~SNDRV_SEQ_EVENT_LENGTH_MASK;
78 ev->flags |= SNDRV_SEQ_EVENT_LENGTH_FIXED;
79
80 ev->source.client = sysclient;
81 ev->source.port = announce_port;
82 ev->dest.client = SNDRV_SEQ_ADDRESS_SUBSCRIBERS;
83
84
85
86 ev->data.addr.client = client;
87 ev->data.addr.port = port;
88
89 return 0;
90}
91
92
93
94void snd_seq_system_broadcast(int client, int port, int type)
95{
96 struct snd_seq_event ev;
97
98 if (setheader(&ev, client, port) < 0)
99 return;
100 ev.type = type;
101 snd_seq_kernel_client_dispatch(sysclient, &ev, 0, 0);
102}
103
104
105int snd_seq_system_notify(int client, int port, struct snd_seq_event *ev)
106{
107 ev->flags = SNDRV_SEQ_EVENT_LENGTH_FIXED;
108 ev->source.client = sysclient;
109 ev->source.port = announce_port;
110 ev->dest.client = client;
111 ev->dest.port = port;
112 return snd_seq_kernel_client_dispatch(sysclient, ev, 0, 0);
113}
114
115
116static int event_input_timer(struct snd_seq_event * ev, int direct, void *private_data, int atomic, int hop)
117{
118 return snd_seq_control_queue(ev, atomic, hop);
119}
120
121
122int __init snd_seq_system_client_init(void)
123{
124 struct snd_seq_port_callback pcallbacks;
125 struct snd_seq_port_info *port;
126 int err;
127
128 port = kzalloc(sizeof(*port), GFP_KERNEL);
129 if (!port)
130 return -ENOMEM;
131
132 memset(&pcallbacks, 0, sizeof(pcallbacks));
133 pcallbacks.owner = THIS_MODULE;
134 pcallbacks.event_input = event_input_timer;
135
136
137 sysclient = snd_seq_create_kernel_client(NULL, 0, "System");
138 if (sysclient < 0) {
139 kfree(port);
140 return sysclient;
141 }
142
143
144 strcpy(port->name, "Timer");
145 port->capability = SNDRV_SEQ_PORT_CAP_WRITE;
146 port->capability |= SNDRV_SEQ_PORT_CAP_READ|SNDRV_SEQ_PORT_CAP_SUBS_READ;
147 port->kernel = &pcallbacks;
148 port->type = 0;
149 port->flags = SNDRV_SEQ_PORT_FLG_GIVEN_PORT;
150 port->addr.client = sysclient;
151 port->addr.port = SNDRV_SEQ_PORT_SYSTEM_TIMER;
152 err = snd_seq_kernel_client_ctl(sysclient, SNDRV_SEQ_IOCTL_CREATE_PORT,
153 port);
154 if (err < 0)
155 goto error_port;
156
157
158 strcpy(port->name, "Announce");
159 port->capability = SNDRV_SEQ_PORT_CAP_READ|SNDRV_SEQ_PORT_CAP_SUBS_READ;
160 port->kernel = NULL;
161 port->type = 0;
162 port->flags = SNDRV_SEQ_PORT_FLG_GIVEN_PORT;
163 port->addr.client = sysclient;
164 port->addr.port = SNDRV_SEQ_PORT_SYSTEM_ANNOUNCE;
165 err = snd_seq_kernel_client_ctl(sysclient, SNDRV_SEQ_IOCTL_CREATE_PORT,
166 port);
167 if (err < 0)
168 goto error_port;
169 announce_port = port->addr.port;
170
171 kfree(port);
172 return 0;
173
174 error_port:
175 snd_seq_system_client_done();
176 kfree(port);
177 return err;
178}
179
180
181
182void snd_seq_system_client_done(void)
183{
184 int oldsysclient = sysclient;
185
186 if (oldsysclient >= 0) {
187 sysclient = -1;
188 announce_port = -1;
189 snd_seq_delete_kernel_client(oldsysclient);
190 }
191}
192