factory.c 3.03 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * Copyright (C) 2008 Google (Roy Shea)
 *
 * This library 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.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#include "mstask_private.h"
#include "wine/debug.h"

WINE_DEFAULT_DEBUG_CHANNEL(mstask);

24 25 26 27 28 29 30 31 32 33 34
struct ClassFactoryImpl
{
    IClassFactory IClassFactory_iface;
    LONG ref;
};

static inline ClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
{
    return CONTAINING_RECORD(iface, ClassFactoryImpl, IClassFactory_iface);
}

35 36 37 38 39
static HRESULT WINAPI MSTASK_IClassFactory_QueryInterface(
        LPCLASSFACTORY iface,
        REFIID riid,
        LPVOID *ppvObj)
{
40
    ClassFactoryImpl *This = impl_from_IClassFactory(iface);
41 42 43 44 45 46 47 48

    TRACE("IID: %s\n",debugstr_guid(riid));
    if (ppvObj == NULL)
        return E_POINTER;

    if (IsEqualGUID(riid, &IID_IUnknown) ||
            IsEqualGUID(riid, &IID_IClassFactory))
    {
49
        *ppvObj = &This->IClassFactory_iface;
50 51 52 53 54 55 56 57 58
        IClassFactory_AddRef(iface);
        return S_OK;
    }

    WARN("Unknown interface: %s\n", debugstr_guid(riid));
    *ppvObj = NULL;
    return E_NOINTERFACE;
}

59
static ULONG WINAPI MSTASK_IClassFactory_AddRef(IClassFactory *face)
60 61 62 63 64 65
{
    TRACE("\n");
    InterlockedIncrement(&dll_ref);
    return 2;
}

66
static ULONG WINAPI MSTASK_IClassFactory_Release(IClassFactory *iface)
67 68 69 70 71 72 73
{
    TRACE("\n");
    InterlockedDecrement(&dll_ref);
    return 1;
}

static HRESULT WINAPI MSTASK_IClassFactory_CreateInstance(
74 75
        IClassFactory *iface,
        IUnknown *pUnkOuter,
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
        REFIID riid,
        LPVOID *ppvObj)
{
    HRESULT res;
    IUnknown *punk = NULL;
    *ppvObj = NULL;

    TRACE("IID: %s\n",debugstr_guid(riid));

    if (pUnkOuter)
        return CLASS_E_NOAGGREGATION;

    res = TaskSchedulerConstructor((LPVOID*) &punk);
    if (FAILED(res))
        return res;

92 93
    res = IUnknown_QueryInterface(punk, riid, ppvObj);
    IUnknown_Release(punk);
94 95 96 97
    return res;
}

static HRESULT WINAPI MSTASK_IClassFactory_LockServer(
98
        IClassFactory *iface,
99 100 101 102
        BOOL fLock)
{
    TRACE("\n");

103 104
    if (fLock)
        IClassFactory_AddRef(iface);
105
    else
106
        IClassFactory_Release(iface);
107 108 109 110 111 112 113 114 115 116 117 118
    return S_OK;
}

static const IClassFactoryVtbl IClassFactory_Vtbl =
{
    MSTASK_IClassFactory_QueryInterface,
    MSTASK_IClassFactory_AddRef,
    MSTASK_IClassFactory_Release,
    MSTASK_IClassFactory_CreateInstance,
    MSTASK_IClassFactory_LockServer
};

119
ClassFactoryImpl MSTASK_ClassFactory = { { &IClassFactory_Vtbl } };