dmime_main.c 9.14 KB
Newer Older
1 2
/* DirectMusicInteractiveEngine Main
 *
3
 * Copyright (C) 2003-2004 Rok Mandeljc
4
 * Copyright (C) 2003-2004 Raphael Junqueira
5
 *
6 7 8 9
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
10 11 12
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
15
 *
16 17 18
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 20 21
 */

#include "dmime_private.h"
22
#include "rpcproxy.h"
23

24
WINE_DEFAULT_DEBUG_CHANNEL(dmime);
25

26
static HINSTANCE instance;
27 28
LONG DMIME_refCount = 0;

29
typedef struct {
30 31
        IClassFactory IClassFactory_iface;
        HRESULT WINAPI (*fnCreateInstance)(REFIID riid, void **ppv, IUnknown *pUnkOuter);
32 33
} IClassFactoryImpl;

34
/******************************************************************
35
 *      IClassFactory implementation
36
 */
37 38 39
static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
{
        return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
40 41
}

42 43 44 45
static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
{
        if (ppv == NULL)
                return E_POINTER;
46

47 48 49 50 51 52 53 54 55
        if (IsEqualGUID(&IID_IUnknown, riid))
                TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
        else if (IsEqualGUID(&IID_IClassFactory, riid))
                TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
        else {
                FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
                *ppv = NULL;
                return E_NOINTERFACE;
        }
56

57 58 59
        *ppv = iface;
        IUnknown_AddRef((IUnknown*)*ppv);
        return S_OK;
60 61
}

62 63 64
static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
{
        DMIME_LockModule();
65

66
        return 2; /* non-heap based object */
67 68
}

69 70 71
static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
{
        DMIME_UnlockModule();
72

73
        return 1; /* non-heap based object */
74 75
}

76 77 78 79
static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter,
        REFIID riid, void **ppv)
{
        IClassFactoryImpl *This = impl_from_IClassFactory(iface);
80

81
        TRACE ("(%p, %s, %p)\n", pUnkOuter, debugstr_dmguid(riid), ppv);
82

83
        return This->fnCreateInstance(riid, ppv, pUnkOuter);
84 85
}

86 87 88
static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
{
        TRACE("(%d)\n", dolock);
89

90 91 92 93
        if (dolock)
                DMIME_LockModule();
        else
                DMIME_UnlockModule();
94

95
        return S_OK;
96 97
}

98 99 100 101 102 103
static const IClassFactoryVtbl classfactory_vtbl = {
        ClassFactory_QueryInterface,
        ClassFactory_AddRef,
        ClassFactory_Release,
        ClassFactory_CreateInstance,
        ClassFactory_LockServer
104 105
};

106

107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
static IClassFactoryImpl Performance_CF = {{&classfactory_vtbl},
                                           DMUSIC_CreateDirectMusicPerformanceImpl};
static IClassFactoryImpl Segment_CF = {{&classfactory_vtbl}, DMUSIC_CreateDirectMusicSegmentImpl};
static IClassFactoryImpl SegmentState_CF = {{&classfactory_vtbl},
                                            DMUSIC_CreateDirectMusicSegmentStateImpl};
static IClassFactoryImpl Graph_CF = {{&classfactory_vtbl}, DMUSIC_CreateDirectMusicGraphImpl};
static IClassFactoryImpl TempoTrack_CF = {{&classfactory_vtbl}, DMUSIC_CreateDirectMusicTempoTrack};
static IClassFactoryImpl SeqTrack_CF = {{&classfactory_vtbl}, DMUSIC_CreateDirectMusicSeqTrack};
static IClassFactoryImpl SysExTrack_CF = {{&classfactory_vtbl}, DMUSIC_CreateDirectMusicSysExTrack};
static IClassFactoryImpl TimeSigTrack_CF = {{&classfactory_vtbl},
                                            DMUSIC_CreateDirectMusicTimeSigTrack};
static IClassFactoryImpl ParamControlTrack_CF = {{&classfactory_vtbl},
                                                 DMUSIC_CreateDirectMusicParamControlTrack};
static IClassFactoryImpl MarkerTrack_CF = {{&classfactory_vtbl},
                                           DMUSIC_CreateDirectMusicMarkerTrack};
static IClassFactoryImpl LyricsTrack_CF = {{&classfactory_vtbl},
                                           DMUSIC_CreateDirectMusicLyricsTrack};
static IClassFactoryImpl SegTriggerTrack_CF = {{&classfactory_vtbl},
                                               DMUSIC_CreateDirectMusicSegTriggerTrack};
static IClassFactoryImpl AudioPath_CF = {{&classfactory_vtbl},
                                         DMUSIC_CreateDirectMusicAudioPathImpl};
static IClassFactoryImpl WaveTrack_CF = {{&classfactory_vtbl}, DMUSIC_CreateDirectMusicWaveTrack};
129 130 131 132 133 134

/******************************************************************
 *		DllMain
 *
 *
 */
135 136
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
	if (fdwReason == DLL_PROCESS_ATTACH) {
137
                instance = hinstDLL;
138
		DisableThreadLibraryCalls(hinstDLL);
139 140
		/* FIXME: Initialisation */
	}
141
	else if (fdwReason == DLL_PROCESS_DETACH) {
142 143 144 145 146 147 148 149 150 151 152 153
		/* FIXME: Cleanup */
	}

	return TRUE;
}


/******************************************************************
 *		DllCanUnloadNow (DMIME.1)
 *
 *
 */
154 155
HRESULT WINAPI DllCanUnloadNow(void)
{
156
	return DMIME_refCount != 0 ? S_FALSE : S_OK;
157 158 159 160
}


/******************************************************************
161
 *		DllGetClassObject (DMIME.@)
162 163 164
 *
 *
 */
165
HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
166
{
167
    TRACE("(%s, %s, %p)\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
168
    if (IsEqualCLSID (rclsid, &CLSID_DirectMusicPerformance) && IsEqualIID (riid, &IID_IClassFactory)) {
169
                *ppv = &Performance_CF;
170 171 172
		IClassFactory_AddRef((IClassFactory*)*ppv);
		return S_OK;
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicSegment) && IsEqualIID (riid, &IID_IClassFactory)) {
173
                *ppv = &Segment_CF;
174 175 176
		IClassFactory_AddRef((IClassFactory*)*ppv);
		return S_OK;
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicSegmentState) && IsEqualIID (riid, &IID_IClassFactory)) {
177
                *ppv = &SegmentState_CF;
178 179 180
		IClassFactory_AddRef((IClassFactory*)*ppv);
		return S_OK;
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicGraph) && IsEqualIID (riid, &IID_IClassFactory)) {
181
                *ppv = &Graph_CF;
182 183 184
		IClassFactory_AddRef((IClassFactory*)*ppv);
		return S_OK;
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicTempoTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
185
                *ppv = &TempoTrack_CF;
186 187 188
		IClassFactory_AddRef((IClassFactory*)*ppv);
		return S_OK;
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicSeqTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
189
                *ppv = &SeqTrack_CF;
190 191 192
		IClassFactory_AddRef((IClassFactory*)*ppv);
		return S_OK;
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicSysExTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
193
                *ppv = &SysExTrack_CF;
194 195 196
		IClassFactory_AddRef((IClassFactory*)*ppv);
		return S_OK;
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicTimeSigTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
197
                *ppv = &TimeSigTrack_CF;
198 199 200
		IClassFactory_AddRef((IClassFactory*)*ppv);
		return S_OK;
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicParamControlTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
201
                *ppv = &ParamControlTrack_CF;
202 203 204
		IClassFactory_AddRef((IClassFactory*)*ppv);
		return S_OK;
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicMarkerTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
205
                *ppv = &MarkerTrack_CF;
206 207 208
		IClassFactory_AddRef((IClassFactory*)*ppv);
		return S_OK;
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicLyricsTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
209
                *ppv = &LyricsTrack_CF;
210 211 212
		IClassFactory_AddRef((IClassFactory*)*ppv);
		return S_OK;
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicSegTriggerTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
213
                *ppv = &SegTriggerTrack_CF;
214 215 216
		IClassFactory_AddRef((IClassFactory*)*ppv);
		return S_OK;
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicAudioPath) && IsEqualIID (riid, &IID_IClassFactory)) {
217
                *ppv = &AudioPath_CF;
218 219 220
		IClassFactory_AddRef((IClassFactory*)*ppv);
		return S_OK;
	} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicWaveTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
221
                *ppv = &WaveTrack_CF;
222 223 224 225
		IClassFactory_AddRef((IClassFactory*)*ppv);
		return S_OK;
	} 
	
226
    WARN("(%s, %s, %p): no interface found.\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
227 228
    return CLASS_E_CLASSNOTAVAILABLE;
}
229 230 231 232 233 234

/***********************************************************************
 *		DllRegisterServer (DMIME.@)
 */
HRESULT WINAPI DllRegisterServer(void)
{
235
    return __wine_register_resources( instance );
236 237 238 239 240 241 242
}

/***********************************************************************
 *		DllUnregisterServer (DMIME.@)
 */
HRESULT WINAPI DllUnregisterServer(void)
{
243
    return __wine_unregister_resources( instance );
244
}