dmusic: Fix license headers that mistakenly use GPL instead of LGPL.
[wine] / dlls / dmloader / classfactory.c
1  /* IDirectMusicLoaderCF
2  *  IDirectMusicContainerCF
3  *
4  * Copyright (C) 2004 Rok Mandeljc
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include "dmloader_private.h"
22
23 WINE_DEFAULT_DEBUG_CHANNEL(dmloader);
24
25 /*****************************************************************************
26  * IDirectMusicLoaderCF implementation
27  */
28 static ULONG WINAPI IDirectMusicLoaderCF_AddRef (LPCLASSFACTORY iface);
29
30 static HRESULT WINAPI IDirectMusicLoaderCF_QueryInterface (LPCLASSFACTORY iface, REFIID riid, LPVOID *ppobj) {
31         IDirectMusicLoaderCF *This = (IDirectMusicLoaderCF *)iface;
32         
33         TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);
34         if (IsEqualIID (riid, &IID_IUnknown) || 
35             IsEqualIID (riid, &IID_IClassFactory)) {
36                 IDirectMusicLoaderCF_AddRef (iface);
37                 *ppobj = This;
38                 return S_OK;
39         }
40         
41         WARN(": not found\n");
42         return E_NOINTERFACE;
43 }
44
45 static ULONG WINAPI IDirectMusicLoaderCF_AddRef (LPCLASSFACTORY iface) {
46         IDirectMusicLoaderCF *This = (IDirectMusicLoaderCF *)iface;
47         TRACE("(%p): AddRef from %d\n", This, This->dwRef);
48         return InterlockedIncrement (&This->dwRef);
49 }
50
51 static ULONG WINAPI IDirectMusicLoaderCF_Release (LPCLASSFACTORY iface) {
52         IDirectMusicLoaderCF *This = (IDirectMusicLoaderCF *)iface;
53         
54         DWORD dwRef = InterlockedDecrement (&This->dwRef);
55         TRACE("(%p): ReleaseRef to %d\n", This, dwRef);
56         if (dwRef == 0) {
57                 HeapFree(GetProcessHeap (), 0, This);
58                 /* decrease number of instances */
59                 InterlockedDecrement(&dwDirectMusicLoader);
60         }
61         
62         return dwRef;   
63 }
64
65 static HRESULT WINAPI IDirectMusicLoaderCF_CreateInstance (LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj) {
66         IDirectMusicLoaderCF *This = (IDirectMusicLoaderCF *)iface;
67         
68         TRACE ("(%p, %p, %s, %p)\n", This, pOuter, debugstr_dmguid(riid), ppobj);
69         if (pOuter) {
70                 ERR(": pOuter should be NULL\n");
71                 return CLASS_E_NOAGGREGATION;
72         }
73         
74         return DMUSIC_CreateDirectMusicLoaderImpl (riid, ppobj, pOuter);
75 }
76
77 static HRESULT WINAPI IDirectMusicLoaderCF_LockServer (LPCLASSFACTORY iface, BOOL dolock) {
78         IDirectMusicLoaderCF *This = (IDirectMusicLoaderCF *)iface;
79         TRACE("(%p, %d)\n", This, dolock);
80         if (dolock)
81                 InterlockedIncrement (&dwDirectMusicLoader);
82         else
83                 InterlockedDecrement (&dwDirectMusicLoader);
84         return S_OK;
85 }
86
87 static const IClassFactoryVtbl DirectMusicLoaderCF_Vtbl = {
88         IDirectMusicLoaderCF_QueryInterface,
89         IDirectMusicLoaderCF_AddRef,
90         IDirectMusicLoaderCF_Release,
91         IDirectMusicLoaderCF_CreateInstance,
92         IDirectMusicLoaderCF_LockServer
93 };
94
95 HRESULT WINAPI DMUSIC_CreateDirectMusicLoaderCF (LPCGUID lpcGUID, LPVOID *ppobj, LPUNKNOWN pUnkOuter) {
96         IDirectMusicLoaderCF *obj;
97
98         TRACE("(%s, %p, %p)\n", debugstr_dmguid(lpcGUID), ppobj, pUnkOuter);
99         obj = HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicLoaderCF));
100         if (NULL == obj) {
101                 *ppobj = (LPCLASSFACTORY)NULL;
102                 return E_OUTOFMEMORY;
103         }
104         obj->lpVtbl = &DirectMusicLoaderCF_Vtbl;
105         obj->dwRef = 0; /* will be inited with QueryInterface */
106
107         /* increase number of instances */
108         InterlockedIncrement (&dwDirectMusicLoader);    
109         
110         return IDirectMusicLoaderCF_QueryInterface ((LPCLASSFACTORY)obj, lpcGUID, ppobj);
111 }
112
113
114 /*****************************************************************************
115  * IDirectMusicContainerCF implementation
116  */
117 static ULONG WINAPI IDirectMusicContainerCF_AddRef (LPCLASSFACTORY iface);
118
119 static HRESULT WINAPI IDirectMusicContainerCF_QueryInterface (LPCLASSFACTORY iface, REFIID riid, LPVOID *ppobj) {
120         IDirectMusicContainerCF *This = (IDirectMusicContainerCF *)iface;
121         
122         TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);
123         if (IsEqualIID (riid, &IID_IUnknown) || 
124             IsEqualIID (riid, &IID_IClassFactory)) {
125                 IDirectMusicContainerCF_AddRef (iface);
126                 *ppobj = This;
127                 return S_OK;
128         }
129         
130         WARN(": not found\n");
131         return E_NOINTERFACE;
132 }
133
134 static ULONG WINAPI IDirectMusicContainerCF_AddRef (LPCLASSFACTORY iface) {
135         IDirectMusicContainerCF *This = (IDirectMusicContainerCF *)iface;
136         TRACE("(%p): AddRef from %d\n", This, This->dwRef);
137         return InterlockedIncrement (&This->dwRef);
138 }
139
140 static ULONG WINAPI IDirectMusicContainerCF_Release (LPCLASSFACTORY iface) {
141         IDirectMusicContainerCF *This = (IDirectMusicContainerCF *)iface;
142         
143         DWORD dwRef = InterlockedDecrement (&This->dwRef);
144         TRACE("(%p): ReleaseRef to %d\n", This, dwRef);
145         if (dwRef == 0) {
146                 HeapFree(GetProcessHeap (), 0, This);
147                 /* decrease number of instances */
148                 InterlockedDecrement(&dwDirectMusicContainer);
149         }
150         
151         return dwRef;
152 }
153
154 static HRESULT WINAPI IDirectMusicContainerCF_CreateInstance (LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj) {
155         IDirectMusicContainerCF *This = (IDirectMusicContainerCF *)iface;
156
157         TRACE ("(%p, %p, %s, %p)\n", This, pOuter, debugstr_dmguid(riid), ppobj);
158         if (pOuter) {
159                 ERR(": pOuter should be NULL\n");
160                 return CLASS_E_NOAGGREGATION;
161         }
162
163         return DMUSIC_CreateDirectMusicContainerImpl (riid, ppobj, pOuter);
164 }
165
166 static HRESULT WINAPI IDirectMusicContainerCF_LockServer (LPCLASSFACTORY iface, BOOL dolock) {
167         IDirectMusicContainerCF *This = (IDirectMusicContainerCF *)iface;
168         TRACE("(%p, %d)\n", This, dolock);
169         if (dolock)
170                 InterlockedIncrement (&dwDirectMusicContainer);
171         else
172                 InterlockedDecrement (&dwDirectMusicContainer);
173         return S_OK;
174 }
175
176 static const IClassFactoryVtbl DirectMusicContainerCF_Vtbl = {
177         IDirectMusicContainerCF_QueryInterface,
178         IDirectMusicContainerCF_AddRef,
179         IDirectMusicContainerCF_Release,
180         IDirectMusicContainerCF_CreateInstance,
181         IDirectMusicContainerCF_LockServer
182 };
183
184 HRESULT WINAPI DMUSIC_CreateDirectMusicContainerCF (LPCGUID lpcGUID, LPVOID *ppobj, LPUNKNOWN pUnkOuter) {
185         IDirectMusicContainerCF *obj;
186
187         TRACE("(%s, %p, %p)\n", debugstr_dmguid(lpcGUID), ppobj, pUnkOuter);
188         obj = HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicContainerCF));
189         if (NULL == obj) {
190                 *ppobj = (LPCLASSFACTORY)NULL;
191                 return E_OUTOFMEMORY;
192         }
193         obj->lpVtbl = &DirectMusicContainerCF_Vtbl;
194         obj->dwRef = 0; /* will be inited with QueryInterface */
195
196         /* increase number of instances */
197         InterlockedIncrement (&dwDirectMusicContainer);
198         
199         return IDirectMusicContainerCF_QueryInterface ((LPCLASSFACTORY)obj, lpcGUID, ppobj);
200 }