Update the address of the Free Software Foundation.
[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 modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (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
14  * GNU Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * 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 HRESULT WINAPI IDirectMusicLoaderCF_QueryInterface (LPCLASSFACTORY iface, REFIID riid, LPVOID *ppobj) {
29         IDirectMusicLoaderCF *This = (IDirectMusicLoaderCF *)iface;
30         
31         TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);
32         if (IsEqualIID (riid, &IID_IUnknown) || 
33             IsEqualIID (riid, &IID_IClassFactory)) {
34                 IDirectMusicLoaderCF_AddRef (iface);
35                 *ppobj = This;
36                 return S_OK;
37         }
38         
39         WARN(": not found\n");
40         return E_NOINTERFACE;
41 }
42
43 ULONG WINAPI IDirectMusicLoaderCF_AddRef (LPCLASSFACTORY iface) {
44         IDirectMusicLoaderCF *This = (IDirectMusicLoaderCF *)iface;
45         TRACE("(%p): AddRef from %ld\n", This, This->dwRef);
46         return InterlockedIncrement (&This->dwRef);
47 }
48
49 ULONG WINAPI IDirectMusicLoaderCF_Release (LPCLASSFACTORY iface) {
50         IDirectMusicLoaderCF *This = (IDirectMusicLoaderCF *)iface;
51         
52         DWORD dwRef = InterlockedDecrement (&This->dwRef);
53         TRACE("(%p): ReleaseRef to %ld\n", This, dwRef);
54         if (dwRef == 0) {
55                 HeapFree(GetProcessHeap (), 0, This);
56                 /* decrease number of instances */
57                 InterlockedDecrement(&dwDirectMusicLoader);
58         }
59         
60         return dwRef;   
61 }
62
63 HRESULT WINAPI IDirectMusicLoaderCF_CreateInstance (LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj) {
64         IDirectMusicLoaderCF *This = (IDirectMusicLoaderCF *)iface;
65         
66         TRACE ("(%p, %p, %s, %p)\n", This, pOuter, debugstr_dmguid(riid), ppobj);
67         if (pOuter) {
68                 ERR(": pOuter should be NULL\n");
69                 return CLASS_E_NOAGGREGATION;
70         }
71         
72         return DMUSIC_CreateDirectMusicLoaderImpl (riid, ppobj, pOuter);
73 }
74
75 HRESULT WINAPI IDirectMusicLoaderCF_LockServer (LPCLASSFACTORY iface, BOOL dolock) {
76         IDirectMusicLoaderCF *This = (IDirectMusicLoaderCF *)iface;
77         TRACE("(%p, %d)\n", This, dolock);
78         if (dolock)
79                 InterlockedIncrement (&dwDirectMusicLoader);
80         else
81                 InterlockedDecrement (&dwDirectMusicLoader);
82         return S_OK;
83 }
84
85 static const IClassFactoryVtbl DirectMusicLoaderCF_Vtbl = {
86         IDirectMusicLoaderCF_QueryInterface,
87         IDirectMusicLoaderCF_AddRef,
88         IDirectMusicLoaderCF_Release,
89         IDirectMusicLoaderCF_CreateInstance,
90         IDirectMusicLoaderCF_LockServer
91 };
92
93 HRESULT WINAPI DMUSIC_CreateDirectMusicLoaderCF (LPCGUID lpcGUID, LPVOID *ppobj, LPUNKNOWN pUnkOuter) {
94         IDirectMusicLoaderCF *obj;
95
96         TRACE("(%s, %p, %p)\n", debugstr_dmguid(lpcGUID), ppobj, pUnkOuter);
97         obj = HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicLoaderCF));
98         if (NULL == obj) {
99                 *ppobj = (LPCLASSFACTORY)NULL;
100                 return E_OUTOFMEMORY;
101         }
102         obj->lpVtbl = &DirectMusicLoaderCF_Vtbl;
103         obj->dwRef = 0; /* will be inited with QueryInterface */
104
105         /* increase number of instances */
106         InterlockedIncrement (&dwDirectMusicLoader);    
107         
108         return IDirectMusicLoaderCF_QueryInterface ((LPCLASSFACTORY)obj, lpcGUID, ppobj);
109 }
110
111
112 /*****************************************************************************
113  * IDirectMusicContainerCF implementation
114  */
115 HRESULT WINAPI IDirectMusicContainerCF_QueryInterface (LPCLASSFACTORY iface, REFIID riid, LPVOID *ppobj) {
116         IDirectMusicContainerCF *This = (IDirectMusicContainerCF *)iface;
117         
118         TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);
119         if (IsEqualIID (riid, &IID_IUnknown) || 
120             IsEqualIID (riid, &IID_IClassFactory)) {
121                 IDirectMusicContainerCF_AddRef (iface);
122                 *ppobj = This;
123                 return S_OK;
124         }
125         
126         WARN(": not found\n");
127         return E_NOINTERFACE;
128 }
129
130 ULONG WINAPI IDirectMusicContainerCF_AddRef (LPCLASSFACTORY iface) {
131         IDirectMusicContainerCF *This = (IDirectMusicContainerCF *)iface;
132         TRACE("(%p): AddRef from %ld\n", This, This->dwRef);
133         return InterlockedIncrement (&This->dwRef);
134 }
135
136 ULONG WINAPI IDirectMusicContainerCF_Release (LPCLASSFACTORY iface) {
137         IDirectMusicContainerCF *This = (IDirectMusicContainerCF *)iface;
138         
139         DWORD dwRef = InterlockedDecrement (&This->dwRef);
140         TRACE("(%p): ReleaseRef to %ld\n", This, dwRef);
141         if (dwRef == 0) {
142                 HeapFree(GetProcessHeap (), 0, This);
143                 /* decrease number of instances */
144                 InterlockedDecrement(&dwDirectMusicContainer);
145         }
146         
147         return dwRef;
148 }
149
150 HRESULT WINAPI IDirectMusicContainerCF_CreateInstance (LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj) {
151         IDirectMusicContainerCF *This = (IDirectMusicContainerCF *)iface;
152
153         TRACE ("(%p, %p, %s, %p)\n", This, pOuter, debugstr_dmguid(riid), ppobj);
154         if (pOuter) {
155                 ERR(": pOuter should be NULL\n");
156                 return CLASS_E_NOAGGREGATION;
157         }
158
159         return DMUSIC_CreateDirectMusicContainerImpl (riid, ppobj, pOuter);
160 }
161
162 HRESULT WINAPI IDirectMusicContainerCF_LockServer (LPCLASSFACTORY iface, BOOL dolock) {
163         IDirectMusicContainerCF *This = (IDirectMusicContainerCF *)iface;
164         TRACE("(%p, %d)\n", This, dolock);
165         if (dolock)
166                 InterlockedIncrement (&dwDirectMusicContainer);
167         else
168                 InterlockedDecrement (&dwDirectMusicContainer);
169         return S_OK;
170 }
171
172 static const IClassFactoryVtbl DirectMusicContainerCF_Vtbl = {
173         IDirectMusicContainerCF_QueryInterface,
174         IDirectMusicContainerCF_AddRef,
175         IDirectMusicContainerCF_Release,
176         IDirectMusicContainerCF_CreateInstance,
177         IDirectMusicContainerCF_LockServer
178 };
179
180 HRESULT WINAPI DMUSIC_CreateDirectMusicContainerCF (LPCGUID lpcGUID, LPVOID *ppobj, LPUNKNOWN pUnkOuter) {
181         IDirectMusicContainerCF *obj;
182
183         TRACE("(%s, %p, %p)\n", debugstr_dmguid(lpcGUID), ppobj, pUnkOuter);
184         obj = HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicContainerCF));
185         if (NULL == obj) {
186                 *ppobj = (LPCLASSFACTORY)NULL;
187                 return E_OUTOFMEMORY;
188         }
189         obj->lpVtbl = &DirectMusicContainerCF_Vtbl;
190         obj->dwRef = 0; /* will be inited with QueryInterface */
191
192         /* increase number of instances */
193         InterlockedIncrement (&dwDirectMusicContainer);
194         
195         return IDirectMusicContainerCF_QueryInterface ((LPCLASSFACTORY)obj, lpcGUID, ppobj);
196 }