vbscript: Fix memory leak in owned safearray iterator.
[wine.git] / dlls / mstask / task_trigger.c
blobe3f190a315a1bfb0e4e269240b94e6069e35d1bc
1 /*
2 * Copyright (C) 2008 Google (Roy Shea)
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.
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.
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
19 #include <stdarg.h>
21 #define COBJMACROS
23 #include "windef.h"
24 #include "winbase.h"
25 #include "objbase.h"
26 #include "taskschd.h"
27 #include "mstask.h"
28 #include "mstask_private.h"
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(mstask);
33 typedef struct
35 ITaskTrigger ITaskTrigger_iface;
36 LONG ref;
37 ITask *parent_task;
38 WORD trigger_index;
39 } TaskTriggerImpl;
41 static inline TaskTriggerImpl *impl_from_ITaskTrigger(ITaskTrigger *iface)
43 return CONTAINING_RECORD(iface, TaskTriggerImpl, ITaskTrigger_iface);
46 static HRESULT WINAPI MSTASK_ITaskTrigger_QueryInterface(
47 ITaskTrigger* iface,
48 REFIID riid,
49 void **ppvObject)
51 TaskTriggerImpl *This = impl_from_ITaskTrigger(iface);
53 TRACE("IID: %s\n", debugstr_guid(riid));
54 if (ppvObject == NULL)
55 return E_POINTER;
57 if (IsEqualGUID(riid, &IID_IUnknown) ||
58 IsEqualGUID(riid, &IID_ITaskTrigger))
60 *ppvObject = &This->ITaskTrigger_iface;
61 ITaskTrigger_AddRef(iface);
62 return S_OK;
65 WARN("Unknown interface: %s\n", debugstr_guid(riid));
66 *ppvObject = NULL;
67 return E_NOINTERFACE;
70 static ULONG WINAPI MSTASK_ITaskTrigger_AddRef(
71 ITaskTrigger* iface)
73 TaskTriggerImpl *This = impl_from_ITaskTrigger(iface);
74 ULONG ref;
75 TRACE("\n");
76 ref = InterlockedIncrement(&This->ref);
77 return ref;
80 static ULONG WINAPI MSTASK_ITaskTrigger_Release(
81 ITaskTrigger* iface)
83 TaskTriggerImpl *This = impl_from_ITaskTrigger(iface);
84 ULONG ref;
85 TRACE("\n");
86 ref = InterlockedDecrement(&This->ref);
87 if (ref == 0)
89 ITask_Release(This->parent_task);
90 heap_free(This);
91 InterlockedDecrement(&dll_ref);
93 return ref;
96 static HRESULT WINAPI MSTASK_ITaskTrigger_SetTrigger(ITaskTrigger *iface, const PTASK_TRIGGER trigger)
98 TaskTriggerImpl *This = impl_from_ITaskTrigger(iface);
100 TRACE("(%p, %p)\n", iface, trigger);
102 if (!trigger) return E_INVALIDARG;
104 return task_set_trigger(This->parent_task, This->trigger_index, trigger);
107 static HRESULT WINAPI MSTASK_ITaskTrigger_GetTrigger(ITaskTrigger *iface, TASK_TRIGGER *trigger)
109 TaskTriggerImpl *This = impl_from_ITaskTrigger(iface);
111 TRACE("(%p, %p)\n", iface, trigger);
113 if (!trigger) return E_INVALIDARG;
115 return task_get_trigger(This->parent_task, This->trigger_index, trigger);
118 static HRESULT WINAPI MSTASK_ITaskTrigger_GetTriggerString(
119 ITaskTrigger* iface,
120 LPWSTR *ppwszTrigger)
122 FIXME("Not implemented\n");
123 return E_NOTIMPL;
126 static const ITaskTriggerVtbl MSTASK_ITaskTriggerVtbl =
128 MSTASK_ITaskTrigger_QueryInterface,
129 MSTASK_ITaskTrigger_AddRef,
130 MSTASK_ITaskTrigger_Release,
131 MSTASK_ITaskTrigger_SetTrigger,
132 MSTASK_ITaskTrigger_GetTrigger,
133 MSTASK_ITaskTrigger_GetTriggerString
136 HRESULT TaskTriggerConstructor(ITask *task, WORD idx, ITaskTrigger **trigger)
138 TaskTriggerImpl *This;
140 TRACE("(%p, %u, %p)\n", task, idx, trigger);
142 This = heap_alloc(sizeof(*This));
143 if (!This)
144 return E_OUTOFMEMORY;
146 This->ITaskTrigger_iface.lpVtbl = &MSTASK_ITaskTriggerVtbl;
147 This->ref = 1;
149 ITask_AddRef(task);
150 This->parent_task = task;
151 This->trigger_index = idx;
153 *trigger = &This->ITaskTrigger_iface;
154 InterlockedIncrement(&dll_ref);
155 return S_OK;