Added version information.
[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 #include "wine/library.h"
26
27 #include "windef.h"
28 #include "winbase.h"
29 #include "wingdi.h"
30 #include "winuser.h"
31 #include "mmddk.h"
32 #include "jack.h"
33
34 #ifdef HAVE_JACK_JACK_H
35 static int jack = 0;
36
37 /* set this to zero or one to enable or disable tracing in here */
38 #define TRACING                 0
39
40 #if TRACING
41 #define PRINTF(...) printf(...)
42 #else
43 #define PRINTF(...)
44 #endif
45
46 #ifndef JACK_SONAME
47 #define JACK_SONAME "libjack.so"
48 #endif
49
50 void *jackhandle = NULL;
51
52 /**************************************************************************
53  *                              JACK_drvLoad                    [internal]      
54  */
55 static DWORD JACK_drvLoad(void)
56 {
57   PRINTF("JACK_drvLoad()\n");
58
59   /* dynamically load the jack library if not already loaded */
60   if(!jackhandle)
61   {
62     jackhandle = wine_dlopen(JACK_SONAME, RTLD_NOW, NULL, 0);
63     PRINTF("JACK_drvLoad: JACK_SONAME == %s\n", JACK_SONAME);
64     PRINTF("JACK_drvLoad: jackhandle == 0x%x\n", jackhandle);
65     if(!jackhandle)
66     {
67       PRINTF("JACK_drvLoad: error loading the jack library %s, please install this library to use jack\n", JACK_SONAME);
68       jackhandle = (void*)-1;
69       return 0;
70     }
71   }
72
73   return 1;
74 }
75
76 /**************************************************************************
77  *                              JACK_drvFree                    [internal]      
78  */
79 /* unload the jack library on driver free */
80 static DWORD JACK_drvFree(void)
81 {
82   PRINTF("JACK_drvFree()\n");
83
84   if(jackhandle && (jackhandle != (void*)-1))
85   {
86     PRINTF("JACK_drvFree: calling wine_dlclose() on jackhandle\n");
87     wine_dlclose(jackhandle, NULL, 0);
88     jackhandle = NULL;
89   }
90
91   return 1;
92 }
93
94 /**************************************************************************
95  *                              JACK_drvOpen                    [internal]      
96  */
97 static  DWORD   JACK_drvOpen(LPSTR str)
98 {
99   /* if we were unable to load the jack library then fail the */
100   /* driver open */
101   if(!jackhandle)
102   {
103     PRINTF("JACK_drvOpen: unable to open the jack library, returning 0\n");
104     return 0;
105   }
106
107   if (jack)
108   {
109     PRINTF("JACK_drvOpen: jack != 0 (already open), returning 0\n");
110     return 0;
111   }
112     
113   /* I know, this is ugly, but who cares... */
114   PRINTF("JACK_drvOpen: opened jack(set jack = 1), returning 1\n");
115   jack = 1;
116   return 1;
117 }
118
119 /**************************************************************************
120  *                              JACK_drvClose                   [internal]      
121  */
122 static  DWORD   JACK_drvClose(DWORD dwDevID)
123 {
124   if (jack)
125   {
126     PRINTF("JACK_drvClose: jack is nonzero, setting jack to 0 and returning 1\n");
127     jack = 0;
128     return 1;
129   }
130
131   PRINTF("JACK_drvClose: jack is zero(closed), returning 0\n");
132   return 0;
133 }
134 #endif /* #ifdef HAVE_JACK_JACK_H */
135
136
137 /**************************************************************************
138  *                              DriverProc (WINEJACK.1)
139  */
140 LONG CALLBACK   JACK_DriverProc(DWORD dwDevID, HDRVR hDriv, DWORD wMsg, 
141                                DWORD dwParam1, DWORD dwParam2)
142 {
143 /* EPP     TRACE("(%08lX, %04X, %08lX, %08lX, %08lX)\n",  */
144 /* EPP    dwDevID, hDriv, wMsg, dwParam1, dwParam2); */
145     
146     switch(wMsg) {
147 #ifdef HAVE_JACK_JACK_H
148     case DRV_LOAD:
149         PRINTF("JACK_DriverProc: DRV_LOAD\n");
150         return JACK_drvLoad();
151     case DRV_FREE:
152         PRINTF("JACK_DriverProc: DRV_FREE\n");
153         return JACK_drvFree();
154     case DRV_OPEN:
155         PRINTF("JACK_DriverProc: DRV_OPEN\n");
156         return JACK_drvOpen((LPSTR)dwParam1);
157     case DRV_CLOSE:
158         PRINTF("JACK_DriverProc: DRV_CLOSE\n");
159         return JACK_drvClose(dwDevID);
160     case DRV_ENABLE:
161         PRINTF("JACK_DriverProc: DRV_ENABLE\n");
162         return 1;
163     case DRV_DISABLE:
164         PRINTF("JACK_DriverProc: DRV_DISABLE\n");
165         return 1;
166     case DRV_QUERYCONFIGURE:    return 1;
167     case DRV_CONFIGURE:         MessageBoxA(0, "jack audio driver!", "jack driver", MB_OK);     return 1;
168     case DRV_INSTALL:           
169       PRINTF("JACK_DriverProc: DRV_INSTALL\n");
170       return DRVCNF_RESTART;
171     case DRV_REMOVE:
172       PRINTF("JACK_DriverProc: DRV_REMOVE\n");
173       return DRVCNF_RESTART;
174 #endif
175     default:
176         return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
177     }
178 }