All sound drivers need -ldxguid.
[wine] / dlls / winmm / winejack / jack.c
1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
2 /*
3  * Wine Driver for jack Sound Server
4  *   http://jackit.sourceforge.net
5  *
6  * Copyright 2002 Chris Morgan
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 #include "config.h"
24 #include "wine/port.h"
25
26 #include <stdarg.h>
27 #include <stdio.h>
28
29 #include "windef.h"
30 #include "winbase.h"
31 #include "wingdi.h"
32 #include "winuser.h"
33 #include "mmddk.h"
34 #include "jack.h"
35 #include "wine/library.h"
36 #include "wine/debug.h"
37
38 WINE_DEFAULT_DEBUG_CHANNEL(jack);
39
40 #ifdef HAVE_JACK_JACK_H
41 static int jack = 0;
42
43 /* set this to zero or one to enable or disable tracing in here */
44
45 #ifndef SONAME_LIBJACK
46 #define SONAME_LIBJACK "libjack.so"
47 #endif
48
49 void *jackhandle = NULL;
50
51 /**************************************************************************
52  *                              JACK_drvLoad                    [internal]      
53  */
54 static DWORD JACK_drvLoad(void)
55 {
56   TRACE("JACK_drvLoad()\n");
57
58   /* dynamically load the jack library if not already loaded */
59   if(!jackhandle)
60   {
61     jackhandle = wine_dlopen(SONAME_LIBJACK, RTLD_NOW, NULL, 0);
62     TRACE("JACK_drvLoad: SONAME_LIBJACK == %s\n", SONAME_LIBJACK);
63     TRACE("JACK_drvLoad: jackhandle == 0x%x\n", jackhandle);
64     if(!jackhandle)
65     {
66       FIXME("JACK_drvLoad: error loading the jack library %s, please install this library to use jack\n", SONAME_LIBJACK);
67       jackhandle = (void*)-1;
68       return 0;
69     }
70   }
71
72   return 1;
73 }
74
75 /**************************************************************************
76  *                              JACK_drvFree                    [internal]      
77  */
78 /* unload the jack library on driver free */
79 static DWORD JACK_drvFree(void)
80 {
81   TRACE("JACK_drvFree()\n");
82
83   if(jackhandle && (jackhandle != (void*)-1))
84   {
85     TRACE("JACK_drvFree: calling wine_dlclose() on jackhandle\n");
86     wine_dlclose(jackhandle, NULL, 0);
87     jackhandle = NULL;
88   }
89
90   return 1;
91 }
92
93 /**************************************************************************
94  *                              JACK_drvOpen                    [internal]      
95  */
96 static  DWORD   JACK_drvOpen(LPSTR str)
97 {
98   /* if we were unable to load the jack library then fail the */
99   /* driver open */
100   if(!jackhandle)
101   {
102     FIXME("JACK_drvOpen: unable to open the jack library, returning 0\n");
103     return 0;
104   }
105
106   if (jack)
107   {
108     FIXME("JACK_drvOpen: jack != 0 (already open), returning 0\n");
109     return 0;
110   }
111     
112   /* I know, this is ugly, but who cares... */
113   TRACE("JACK_drvOpen: opened jack(set jack = 1), returning 1\n");
114   jack = 1;
115   return 1;
116 }
117
118 /**************************************************************************
119  *                              JACK_drvClose                   [internal]      
120  */
121 static  DWORD   JACK_drvClose(DWORD dwDevID)
122 {
123   if (jack)
124   {
125     TRACE("JACK_drvClose: jack is nonzero, setting jack to 0 and returning 1\n");
126     jack = 0;
127     return 1;
128   }
129
130   TRACE("JACK_drvClose: jack is zero(closed), returning 0\n");
131   return 0;
132 }
133 #endif /* #ifdef HAVE_JACK_JACK_H */
134
135
136 /**************************************************************************
137  *                              DriverProc (WINEJACK.1)
138  */
139 LONG CALLBACK   JACK_DriverProc(DWORD dwDevID, HDRVR hDriv, DWORD wMsg, 
140                                DWORD dwParam1, DWORD dwParam2)
141 {
142 /* EPP     TRACE("(%08lX, %04X, %08lX, %08lX, %08lX)\n",  */
143 /* EPP    dwDevID, hDriv, wMsg, dwParam1, dwParam2); */
144     
145     switch(wMsg) {
146 #ifdef HAVE_JACK_JACK_H
147     case DRV_LOAD:
148         TRACE("JACK_DriverProc: DRV_LOAD\n");
149         return JACK_drvLoad();
150     case DRV_FREE:
151         TRACE("JACK_DriverProc: DRV_FREE\n");
152         return JACK_drvFree();
153     case DRV_OPEN:
154         TRACE("JACK_DriverProc: DRV_OPEN\n");
155         return JACK_drvOpen((LPSTR)dwParam1);
156     case DRV_CLOSE:
157         TRACE("JACK_DriverProc: DRV_CLOSE\n");
158         return JACK_drvClose(dwDevID);
159     case DRV_ENABLE:
160         TRACE("JACK_DriverProc: DRV_ENABLE\n");
161         return 1;
162     case DRV_DISABLE:
163         TRACE("JACK_DriverProc: DRV_DISABLE\n");
164         return 1;
165     case DRV_QUERYCONFIGURE:    return 1;
166     case DRV_CONFIGURE:         MessageBoxA(0, "jack audio driver!", "jack driver", MB_OK);     return 1;
167     case DRV_INSTALL:           
168       TRACE("JACK_DriverProc: DRV_INSTALL\n");
169       return DRVCNF_RESTART;
170     case DRV_REMOVE:
171       TRACE("JACK_DriverProc: DRV_REMOVE\n");
172       return DRVCNF_RESTART;
173 #endif
174     default:
175         return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
176     }
177 }