Some "cast to pointer from integer of different size" warnings removed.
[AROS-Contrib.git] / MultiMedia / playcdda / diskchange.c
blob24f1580ce5ed134e9ffbfc76c299ea268fc302cc
1 /* Copyright 2010-2011 Fredrik Wikstrom. All rights reserved.
2 **
3 ** Redistribution and use in source and binary forms, with or without
4 ** modification, are permitted provided that the following conditions
5 ** are met:
6 **
7 ** 1. Redistributions of source code must retain the above copyright
8 ** notice, this list of conditions and the following disclaimer.
9 **
10 ** 2. Redistributions in binary form must reproduce the above copyright
11 ** notice, this list of conditions and the following disclaimer in the
12 ** documentation and/or other materials provided with the distribution.
14 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
15 ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
18 ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 ** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 ** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 ** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 ** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 ** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 ** POSSIBILITY OF SUCH DAMAGE.
27 #include <exec/exec.h>
28 #include <proto/exec.h>
29 #include <proto/dos.h>
30 #include "diskchange.h"
31 #include <SDI_compiler.h>
33 struct DiskChangeHandler {
34 struct ExecBase *exec;
35 struct Task *task;
36 ULONG sigmask;
37 struct IOStdReq *io;
38 struct Interrupt *interrupt;
41 AROS_UFH3(void, DiskChangeFunction,
42 AROS_UFHA(APTR, data, A1),
43 AROS_UFHA(APTR, code, A5),
44 AROS_UFHA(struct ExecBase *, SysBase, A6))
46 AROS_USERFUNC_INIT
47 struct DiskChangeHandler *handler = data;
48 Signal(handler->task, handler->sigmask);
49 AROS_USERFUNC_EXIT
52 struct IORequest *DuplicateIORequest (struct IORequest *old) {
53 struct IORequest *new;
54 new = CreateIORequest(old->io_Message.mn_ReplyPort, old->io_Message.mn_Length);
55 if (new) {
56 CopyMem(old, new, old->io_Message.mn_Length);
58 return new;
61 APTR AddDiskChangeHandler (struct IOStdReq *ref_io, ULONG sigmask) {
62 struct DiskChangeHandler *handler;
63 struct IOStdReq *io;
64 struct Interrupt *interrupt;
65 handler = AllocVec(sizeof(struct DiskChangeHandler), MEMF_PUBLIC);
66 io = (struct IOStdReq *)DuplicateIORequest((struct IORequest *)ref_io);
67 interrupt = AllocVec(sizeof(struct Interrupt), MEMF_PUBLIC|MEMF_CLEAR);
68 if (handler && io && interrupt) {
69 handler->exec = SysBase;
70 handler->task = FindTask(NULL);
71 handler->sigmask = sigmask;
72 handler->io = io;
73 handler->interrupt = interrupt;
75 interrupt->is_Node.ln_Succ = NULL;
76 interrupt->is_Node.ln_Pred = NULL;
77 interrupt->is_Node.ln_Type = NT_INTERRUPT;
78 interrupt->is_Node.ln_Pri = 0;
79 interrupt->is_Node.ln_Name = "PlayCDDA disk change interrupt";
80 interrupt->is_Data = handler;
81 interrupt->is_Code = (APTR)DiskChangeFunction;
83 io->io_Command = TD_ADDCHANGEINT;
84 io->io_Data = interrupt;
85 io->io_Length = sizeof(struct Interrupt);
86 SendIO((struct IORequest *)io);
88 return handler;
89 } else {
90 FreeVec(interrupt);
91 DeleteIORequest((struct IORequest *)io);
92 FreeVec(handler);
94 return NULL;
97 void RemDiskChangeHandler (APTR handler_ptr) {
98 struct DiskChangeHandler *handler = handler_ptr;
99 if (handler) {
100 struct IOStdReq *io = handler->io;
101 struct Interrupt *interrupt = handler->interrupt;
103 io->io_Command = TD_REMCHANGEINT;
104 DoIO((struct IORequest *)io);
106 FreeVec(interrupt);
107 DeleteIORequest((struct IORequest *)io);
108 FreeVec(handler);