Sync with trunk r63502.
[reactos.git] / dll / win32 / mstask / factory.c
1 /*
2 * Copyright (C) 2008 Google (Roy Shea)
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19 #include "mstask_private.h"
20
21 struct ClassFactoryImpl
22 {
23 IClassFactory IClassFactory_iface;
24 LONG ref;
25 };
26
27 static inline ClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
28 {
29 return CONTAINING_RECORD(iface, ClassFactoryImpl, IClassFactory_iface);
30 }
31
32 static HRESULT WINAPI MSTASK_IClassFactory_QueryInterface(
33 LPCLASSFACTORY iface,
34 REFIID riid,
35 LPVOID *ppvObj)
36 {
37 ClassFactoryImpl *This = impl_from_IClassFactory(iface);
38
39 TRACE("IID: %s\n",debugstr_guid(riid));
40 if (ppvObj == NULL)
41 return E_POINTER;
42
43 if (IsEqualGUID(riid, &IID_IUnknown) ||
44 IsEqualGUID(riid, &IID_IClassFactory))
45 {
46 *ppvObj = &This->IClassFactory_iface;
47 IClassFactory_AddRef(iface);
48 return S_OK;
49 }
50
51 WARN("Unknown interface: %s\n", debugstr_guid(riid));
52 *ppvObj = NULL;
53 return E_NOINTERFACE;
54 }
55
56 static ULONG WINAPI MSTASK_IClassFactory_AddRef(IClassFactory *face)
57 {
58 TRACE("\n");
59 InterlockedIncrement(&dll_ref);
60 return 2;
61 }
62
63 static ULONG WINAPI MSTASK_IClassFactory_Release(IClassFactory *iface)
64 {
65 TRACE("\n");
66 InterlockedDecrement(&dll_ref);
67 return 1;
68 }
69
70 static HRESULT WINAPI MSTASK_IClassFactory_CreateInstance(
71 IClassFactory *iface,
72 IUnknown *pUnkOuter,
73 REFIID riid,
74 LPVOID *ppvObj)
75 {
76 HRESULT res;
77 IUnknown *punk = NULL;
78 *ppvObj = NULL;
79
80 TRACE("IID: %s\n",debugstr_guid(riid));
81
82 if (pUnkOuter)
83 return CLASS_E_NOAGGREGATION;
84
85 res = TaskSchedulerConstructor((LPVOID*) &punk);
86 if (FAILED(res))
87 return res;
88
89 res = IUnknown_QueryInterface(punk, riid, ppvObj);
90 IUnknown_Release(punk);
91 return res;
92 }
93
94 static HRESULT WINAPI MSTASK_IClassFactory_LockServer(
95 IClassFactory *iface,
96 BOOL fLock)
97 {
98 TRACE("\n");
99
100 if (fLock)
101 IClassFactory_AddRef(iface);
102 else
103 IClassFactory_Release(iface);
104 return S_OK;
105 }
106
107 static const IClassFactoryVtbl IClassFactory_Vtbl =
108 {
109 MSTASK_IClassFactory_QueryInterface,
110 MSTASK_IClassFactory_AddRef,
111 MSTASK_IClassFactory_Release,
112 MSTASK_IClassFactory_CreateInstance,
113 MSTASK_IClassFactory_LockServer
114 };
115
116 ClassFactoryImpl MSTASK_ClassFactory = { { &IClassFactory_Vtbl } };