2 * BeOS audio_module_driver
4 * Copyright (c) 2003, Marcus Overhagen <marcus@overhagen.de>
7 * Redistribution only allowed under the terms of the MIT license.
12 #include <KernelExport.h>
13 #include <directories.h>
22 #include "audio_module.h"
25 int32 api_version
= B_CUR_DRIVER_API_VERSION
;
27 #define DRIVER_NAME "audio_module_driver"
29 #define MODULE_TEST_PATH "media/audio/ich"
32 void republish_devices(void);
34 extern image_id
load_kernel_addon(const char *path
);
35 extern status_t
unload_kernel_addon(image_id imid
);
41 dprintf("audio_module_driver: init_hardware\n");
49 audio_module_info
*audio_module
;
52 void (*print_hello_world
)(void);
54 id
= load_kernel_addon(kUserAddonsDirectory
"/kernel/media/audio/ich");
55 get_image_symbol(id
, "print_hello_world", B_SYMBOL_TYPE_TEXT
,
56 (void **) &print_hello_world
);
58 unload_kernel_addon(id
);
60 dprintf("unload_kernel_addon failed\n");
63 if (B_OK != get_module(MODULE_TEST_PATH, (module_info **)&audio_module)) {
64 dprintf("get_module failed\n");
68 dprintf("calling audio_module->print_hello()\n");
70 audio_module->print_hello();
74 if (B_OK != put_module(MODULE_TEST_PATH)) {
75 dprintf("put_module failed\n");
86 dprintf("audio_module_driver: uninit_driver\n");
91 audio_module_driver_open(const char *name
, uint32 flags
, void **cookie
)
93 dprintf("audio_module_driver: open %s\n", name
);
99 audio_module_driver_close(void *cookie
)
101 dprintf("audio_module_driver: close\n");
107 audio_module_driver_free(void *cookie
)
109 dprintf("audio_module_driver: free\n");
115 audio_module_driver_control(void *cookie
, uint32 op
, void *arg
, size_t len
)
117 dprintf("audio_module_driver: control\n");
126 audio_module_driver_read(void *cookie
, off_t position
, void *buf
,
135 audio_module_driver_write(void *cookie
, off_t position
, const void *buffer
,
138 static int keep_open_fd
= -1;
139 if (*num_bytes
>= 5 && 0 == memcmp("start", buffer
, 5)
140 && keep_open_fd
== -1) {
141 keep_open_fd
= open("/dev/audio/audio_module_driver", O_RDWR
);
144 if (*num_bytes
>= 4 && 0 == memcmp("stop", buffer
, 4)
145 && keep_open_fd
!= -1) {
150 if (*num_bytes
>= 6 && 0 == memcmp("rescan", buffer
, 6)) {
159 static const char *ich_name
[] = {
160 "audio/" DRIVER_NAME
,
161 "audio/modules/foobar/1",
162 "audio/modules/foobar/2",
163 "audio/modules/snafu/1",
164 "audio/modules/snafu/2",
169 device_hooks audio_module_driver_hooks
= {
170 audio_module_driver_open
,
171 audio_module_driver_close
,
172 audio_module_driver_free
,
173 audio_module_driver_control
,
174 audio_module_driver_read
,
175 audio_module_driver_write
,
184 publish_devices(void)
186 dprintf("audio_module_driver: publish_devices\n");
192 find_device(const char *name
)
194 dprintf("audio_module_driver: find_device %s\n", name
);
195 return &audio_module_driver_hooks
;
199 void republish_devices(void)
201 int fd
= open("/dev", O_WRONLY
);
202 write(fd
, DRIVER_NAME
, strlen(DRIVER_NAME
));