Sync with trunk revision 63128.
[reactos.git] / dll / win32 / qmgr / job.c
index c4a2325..911def7 100644 (file)
 
 #include "qmgr.h"
 
+static inline BOOL is_job_done(const BackgroundCopyJobImpl *job)
+{
+    return job->state == BG_JOB_STATE_CANCELLED || job->state == BG_JOB_STATE_ACKNOWLEDGED;
+}
+
 static inline BackgroundCopyJobImpl *impl_from_IBackgroundCopyJob2(IBackgroundCopyJob2 *iface)
 {
     return CONTAINING_RECORD(iface, BackgroundCopyJobImpl, IBackgroundCopyJob2_iface);
 }
 
-static HRESULT WINAPI BITS_IBackgroundCopyJob_QueryInterface(
+static HRESULT WINAPI BackgroundCopyJob_QueryInterface(
     IBackgroundCopyJob2 *iface, REFIID riid, void **obj)
 {
     BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
@@ -45,7 +50,7 @@ static HRESULT WINAPI BITS_IBackgroundCopyJob_QueryInterface(
     return E_NOINTERFACE;
 }
 
-static ULONG WINAPI BITS_IBackgroundCopyJob_AddRef(IBackgroundCopyJob2 *iface)
+static ULONG WINAPI BackgroundCopyJob_AddRef(IBackgroundCopyJob2 *iface)
 {
     BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
     ULONG ref = InterlockedIncrement(&This->ref);
@@ -53,7 +58,7 @@ static ULONG WINAPI BITS_IBackgroundCopyJob_AddRef(IBackgroundCopyJob2 *iface)
     return ref;
 }
 
-static ULONG WINAPI BITS_IBackgroundCopyJob_Release(IBackgroundCopyJob2 *iface)
+static ULONG WINAPI BackgroundCopyJob_Release(IBackgroundCopyJob2 *iface)
 {
     BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
     ULONG ref = InterlockedDecrement(&This->ref);
@@ -64,7 +69,10 @@ static ULONG WINAPI BITS_IBackgroundCopyJob_Release(IBackgroundCopyJob2 *iface)
     {
         This->cs.DebugInfo->Spare[0] = 0;
         DeleteCriticalSection(&This->cs);
+        if (This->callback)
+            IBackgroundCopyCallback2_Release(This->callback);
         HeapFree(GetProcessHeap(), 0, This->displayName);
+        HeapFree(GetProcessHeap(), 0, This->description);
         HeapFree(GetProcessHeap(), 0, This);
     }
 
@@ -73,50 +81,56 @@ static ULONG WINAPI BITS_IBackgroundCopyJob_Release(IBackgroundCopyJob2 *iface)
 
 /*** IBackgroundCopyJob methods ***/
 
-static HRESULT WINAPI BITS_IBackgroundCopyJob_AddFileSet(
+static HRESULT WINAPI BackgroundCopyJob_AddFileSet(
     IBackgroundCopyJob2 *iface,
     ULONG cFileCount,
     BG_FILE_INFO *pFileSet)
 {
+    BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
+    HRESULT hr = S_OK;
     ULONG i;
+
+    TRACE("(%p)->(%d %p)\n", This, cFileCount, pFileSet);
+
+    EnterCriticalSection(&This->cs);
+
     for (i = 0; i < cFileCount; ++i)
     {
-        HRESULT hr = IBackgroundCopyJob2_AddFile(iface, pFileSet[i].RemoteName,
-                                                pFileSet[i].LocalName);
-        if (FAILED(hr))
-            return hr;
+        BackgroundCopyFileImpl *file;
+
+        /* We should return E_INVALIDARG in these cases. */
+        FIXME("Check for valid filenames and supported protocols\n");
+
+        hr = BackgroundCopyFileConstructor(This, pFileSet[i].RemoteName, pFileSet[i].LocalName, &file);
+        if (hr != S_OK) break;
+
+        /* Add a reference to the file to file list */
+        list_add_head(&This->files, &file->entryFromJob);
+        This->jobProgress.BytesTotal = BG_SIZE_UNKNOWN;
+        ++This->jobProgress.FilesTotal;
     }
-    return S_OK;
+
+    LeaveCriticalSection(&This->cs);
+
+    return hr;
 }
 
-static HRESULT WINAPI BITS_IBackgroundCopyJob_AddFile(
+static HRESULT WINAPI BackgroundCopyJob_AddFile(
     IBackgroundCopyJob2 *iface,
     LPCWSTR RemoteUrl,
     LPCWSTR LocalName)
 {
     BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
-    BackgroundCopyFileImpl *file;
-    HRESULT res;
-
-    /* We should return E_INVALIDARG in these cases.  */
-    FIXME("Check for valid filenames and supported protocols\n");
+    BG_FILE_INFO file;
 
-    res = BackgroundCopyFileConstructor(This, RemoteUrl, LocalName, &file);
-    if (res != S_OK)
-        return res;
-
-    /* Add a reference to the file to file list */
-    IBackgroundCopyFile_AddRef(&file->IBackgroundCopyFile_iface);
-    EnterCriticalSection(&This->cs);
-    list_add_head(&This->files, &file->entryFromJob);
-    This->jobProgress.BytesTotal = BG_SIZE_UNKNOWN;
-    ++This->jobProgress.FilesTotal;
-    LeaveCriticalSection(&This->cs);
+    TRACE("(%p)->(%s %s)\n", This, debugstr_w(RemoteUrl), debugstr_w(LocalName));
 
-    return S_OK;
+    file.RemoteName = (LPWSTR)RemoteUrl;
+    file.LocalName = (LPWSTR)LocalName;
+    return IBackgroundCopyJob2_AddFileSet(iface, 1, &file);
 }
 
-static HRESULT WINAPI BITS_IBackgroundCopyJob_EnumFiles(
+static HRESULT WINAPI BackgroundCopyJob_EnumFiles(
     IBackgroundCopyJob2 *iface,
     IEnumBackgroundCopyFiles **enum_files)
 {
@@ -125,22 +139,24 @@ static HRESULT WINAPI BITS_IBackgroundCopyJob_EnumFiles(
     return EnumBackgroundCopyFilesConstructor(This, enum_files);
 }
 
-static HRESULT WINAPI BITS_IBackgroundCopyJob_Suspend(
+static HRESULT WINAPI BackgroundCopyJob_Suspend(
     IBackgroundCopyJob2 *iface)
 {
-    FIXME("Not implemented\n");
+    BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
+    FIXME("(%p): stub\n", This);
     return E_NOTIMPL;
 }
 
-static HRESULT WINAPI BITS_IBackgroundCopyJob_Resume(
+static HRESULT WINAPI BackgroundCopyJob_Resume(
     IBackgroundCopyJob2 *iface)
 {
     BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
     HRESULT rv = S_OK;
 
+    TRACE("(%p)\n", This);
+
     EnterCriticalSection(&globalMgr.cs);
-    if (This->state == BG_JOB_STATE_CANCELLED
-        || This->state == BG_JOB_STATE_ACKNOWLEDGED)
+    if (is_job_done(This))
     {
         rv = BG_E_INVALID_STATE;
     }
@@ -159,23 +175,25 @@ static HRESULT WINAPI BITS_IBackgroundCopyJob_Resume(
     return rv;
 }
 
-static HRESULT WINAPI BITS_IBackgroundCopyJob_Cancel(
+static HRESULT WINAPI BackgroundCopyJob_Cancel(
     IBackgroundCopyJob2 *iface)
 {
-    FIXME("Not implemented\n");
+    BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
+    FIXME("(%p): stub\n", This);
     return E_NOTIMPL;
 }
 
-static HRESULT WINAPI BITS_IBackgroundCopyJob_Complete(
+static HRESULT WINAPI BackgroundCopyJob_Complete(
     IBackgroundCopyJob2 *iface)
 {
     BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
     HRESULT rv = S_OK;
 
+    TRACE("(%p)\n", This);
+
     EnterCriticalSection(&This->cs);
 
-    if (This->state == BG_JOB_STATE_CANCELLED
-        || This->state == BG_JOB_STATE_ACKNOWLEDGED)
+    if (is_job_done(This))
     {
         rv = BG_E_INVALID_STATE;
     }
@@ -208,21 +226,24 @@ static HRESULT WINAPI BITS_IBackgroundCopyJob_Complete(
     return rv;
 }
 
-static HRESULT WINAPI BITS_IBackgroundCopyJob_GetId(
+static HRESULT WINAPI BackgroundCopyJob_GetId(
     IBackgroundCopyJob2 *iface,
     GUID *pVal)
 {
     BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
+    TRACE("(%p)->(%p)\n", This, pVal);
     *pVal = This->jobId;
     return S_OK;
 }
 
-static HRESULT WINAPI BITS_IBackgroundCopyJob_GetType(
+static HRESULT WINAPI BackgroundCopyJob_GetType(
     IBackgroundCopyJob2 *iface,
     BG_JOB_TYPE *pVal)
 {
     BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
 
+    TRACE("(%p)->(%p)\n", This, pVal);
+
     if (!pVal)
         return E_INVALIDARG;
 
@@ -230,12 +251,14 @@ static HRESULT WINAPI BITS_IBackgroundCopyJob_GetType(
     return S_OK;
 }
 
-static HRESULT WINAPI BITS_IBackgroundCopyJob_GetProgress(
+static HRESULT WINAPI BackgroundCopyJob_GetProgress(
     IBackgroundCopyJob2 *iface,
     BG_JOB_PROGRESS *pVal)
 {
     BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
 
+    TRACE("(%p)->(%p)\n", This, pVal);
+
     if (!pVal)
         return E_INVALIDARG;
 
@@ -249,20 +272,23 @@ static HRESULT WINAPI BITS_IBackgroundCopyJob_GetProgress(
     return S_OK;
 }
 
-static HRESULT WINAPI BITS_IBackgroundCopyJob_GetTimes(
+static HRESULT WINAPI BackgroundCopyJob_GetTimes(
     IBackgroundCopyJob2 *iface,
     BG_JOB_TIMES *pVal)
 {
-    FIXME("Not implemented\n");
+    BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
+    FIXME("(%p)->(%p): stub\n", This, pVal);
     return E_NOTIMPL;
 }
 
-static HRESULT WINAPI BITS_IBackgroundCopyJob_GetState(
+static HRESULT WINAPI BackgroundCopyJob_GetState(
     IBackgroundCopyJob2 *iface,
     BG_JOB_STATE *pVal)
 {
     BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
 
+    TRACE("(%p)->(%p)\n", This, pVal);
+
     if (!pVal)
         return E_INVALIDARG;
 
@@ -271,113 +297,191 @@ static HRESULT WINAPI BITS_IBackgroundCopyJob_GetState(
     return S_OK;
 }
 
-static HRESULT WINAPI BITS_IBackgroundCopyJob_GetError(
+static HRESULT WINAPI BackgroundCopyJob_GetError(
     IBackgroundCopyJob2 *iface,
     IBackgroundCopyError **ppError)
 {
-    FIXME("Not implemented\n");
+    BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
+    FIXME("(%p)->(%p): stub\n", This, ppError);
     return E_NOTIMPL;
 }
 
-static HRESULT WINAPI BITS_IBackgroundCopyJob_GetOwner(
+static HRESULT WINAPI BackgroundCopyJob_GetOwner(
     IBackgroundCopyJob2 *iface,
     LPWSTR *pVal)
 {
-    FIXME("Not implemented\n");
+    BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
+    FIXME("(%p)->(%p): stub\n", This, pVal);
     return E_NOTIMPL;
 }
 
-static HRESULT WINAPI BITS_IBackgroundCopyJob_SetDisplayName(
+static HRESULT WINAPI BackgroundCopyJob_SetDisplayName(
     IBackgroundCopyJob2 *iface,
     LPCWSTR Val)
 {
-    FIXME("Not implemented\n");
+    BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
+    FIXME("(%p)->(%s): stub\n", This, debugstr_w(Val));
     return E_NOTIMPL;
 }
 
-static HRESULT WINAPI BITS_IBackgroundCopyJob_GetDisplayName(
+static HRESULT WINAPI BackgroundCopyJob_GetDisplayName(
     IBackgroundCopyJob2 *iface,
     LPWSTR *pVal)
 {
     BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
-    int n;
 
-    if (!pVal)
-        return E_INVALIDARG;
+    TRACE("(%p)->(%p)\n", This, pVal);
 
-    n = (lstrlenW(This->displayName) + 1) * sizeof **pVal;
-    *pVal = CoTaskMemAlloc(n);
-    if (*pVal == NULL)
-        return E_OUTOFMEMORY;
-    memcpy(*pVal, This->displayName, n);
-    return S_OK;
+    return return_strval(This->displayName, pVal);
 }
 
-static HRESULT WINAPI BITS_IBackgroundCopyJob_SetDescription(
+static HRESULT WINAPI BackgroundCopyJob_SetDescription(
     IBackgroundCopyJob2 *iface,
     LPCWSTR Val)
 {
-    FIXME("Not implemented\n");
-    return E_NOTIMPL;
+    BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
+    static const int max_description_len = 1024;
+    HRESULT hr = S_OK;
+    int len;
+
+    TRACE("(%p)->(%s)\n", This, debugstr_w(Val));
+
+    if (!Val) return E_INVALIDARG;
+
+    len = strlenW(Val);
+    if (len > max_description_len) return BG_E_STRING_TOO_LONG;
+
+    EnterCriticalSection(&This->cs);
+
+    if (is_job_done(This))
+    {
+        hr = BG_E_INVALID_STATE;
+    }
+    else
+    {
+        HeapFree(GetProcessHeap(), 0, This->description);
+        if ((This->description = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR))))
+            strcpyW(This->description, Val);
+        else
+            hr = E_OUTOFMEMORY;
+    }
+
+    LeaveCriticalSection(&This->cs);
+
+    return hr;
 }
 
-static HRESULT WINAPI BITS_IBackgroundCopyJob_GetDescription(
+static HRESULT WINAPI BackgroundCopyJob_GetDescription(
     IBackgroundCopyJob2 *iface,
     LPWSTR *pVal)
 {
-    FIXME("Not implemented\n");
-    return E_NOTIMPL;
+    BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
+
+    TRACE("(%p)->(%p)\n", This, pVal);
+
+    return return_strval(This->description, pVal);
 }
 
-static HRESULT WINAPI BITS_IBackgroundCopyJob_SetPriority(
+static HRESULT WINAPI BackgroundCopyJob_SetPriority(
     IBackgroundCopyJob2 *iface,
     BG_JOB_PRIORITY Val)
 {
-    FIXME("(%p,0x%08x) stub\n", iface, Val);
+    BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
+    FIXME("(%p)->(%d): stub\n", This, Val);
     return S_OK;
 }
 
-static HRESULT WINAPI BITS_IBackgroundCopyJob_GetPriority(
+static HRESULT WINAPI BackgroundCopyJob_GetPriority(
     IBackgroundCopyJob2 *iface,
     BG_JOB_PRIORITY *pVal)
 {
-    FIXME("Not implemented\n");
+    BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
+    FIXME("(%p)->(%p): stub\n", This, pVal);
     return E_NOTIMPL;
 }
 
-static HRESULT WINAPI BITS_IBackgroundCopyJob_SetNotifyFlags(
+static HRESULT WINAPI BackgroundCopyJob_SetNotifyFlags(
     IBackgroundCopyJob2 *iface,
     ULONG Val)
 {
-    FIXME("Not implemented\n");
-    return E_NOTIMPL;
+    BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
+    static const ULONG valid_flags = BG_NOTIFY_JOB_TRANSFERRED |
+                                     BG_NOTIFY_JOB_ERROR |
+                                     BG_NOTIFY_DISABLE |
+                                     BG_NOTIFY_JOB_MODIFICATION |
+                                     BG_NOTIFY_FILE_TRANSFERRED;
+
+    TRACE("(%p)->(0x%x)\n", This, Val);
+
+    if (is_job_done(This)) return BG_E_INVALID_STATE;
+    if (Val & ~valid_flags) return E_NOTIMPL;
+    This->notify_flags = Val;
+    return S_OK;
 }
 
-static HRESULT WINAPI BITS_IBackgroundCopyJob_GetNotifyFlags(
+static HRESULT WINAPI BackgroundCopyJob_GetNotifyFlags(
     IBackgroundCopyJob2 *iface,
     ULONG *pVal)
 {
-    FIXME("Not implemented\n");
-    return E_NOTIMPL;
+    BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
+
+    TRACE("(%p)->(%p)\n", This, pVal);
+
+    if (!pVal) return E_INVALIDARG;
+
+    *pVal = This->notify_flags;
+
+    return S_OK;
 }
 
-static HRESULT WINAPI BITS_IBackgroundCopyJob_SetNotifyInterface(
+static HRESULT WINAPI BackgroundCopyJob_SetNotifyInterface(
     IBackgroundCopyJob2 *iface,
     IUnknown *Val)
 {
-    FIXME("Not implemented\n");
-    return E_NOTIMPL;
+    BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
+    HRESULT hr = S_OK;
+
+    TRACE("(%p)->(%p)\n", This, Val);
+
+    if (is_job_done(This)) return BG_E_INVALID_STATE;
+
+    if (This->callback)
+    {
+        IBackgroundCopyCallback2_Release(This->callback);
+        This->callback = NULL;
+        This->callback2 = FALSE;
+    }
+
+    if (Val)
+    {
+        hr = IUnknown_QueryInterface(Val, &IID_IBackgroundCopyCallback2, (void**)&This->callback);
+        if (FAILED(hr))
+            hr = IUnknown_QueryInterface(Val, &IID_IBackgroundCopyCallback, (void**)&This->callback);
+        else
+            This->callback2 = TRUE;
+    }
+
+    return hr;
 }
 
-static HRESULT WINAPI BITS_IBackgroundCopyJob_GetNotifyInterface(
+static HRESULT WINAPI BackgroundCopyJob_GetNotifyInterface(
     IBackgroundCopyJob2 *iface,
     IUnknown **pVal)
 {
-    FIXME("Not implemented\n");
-    return E_NOTIMPL;
+    BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
+
+    TRACE("(%p)->(%p)\n", This, pVal);
+
+    if (!pVal) return E_INVALIDARG;
+
+    *pVal = (IUnknown*)This->callback;
+    if (*pVal)
+        IUnknown_AddRef(*pVal);
+
+    return S_OK;
 }
 
-static HRESULT WINAPI BITS_IBackgroundCopyJob_SetMinimumRetryDelay(
+static HRESULT WINAPI BackgroundCopyJob_SetMinimumRetryDelay(
     IBackgroundCopyJob2 *iface,
     ULONG Seconds)
 {
@@ -385,180 +489,195 @@ static HRESULT WINAPI BITS_IBackgroundCopyJob_SetMinimumRetryDelay(
     return S_OK;
 }
 
-static HRESULT WINAPI BITS_IBackgroundCopyJob_GetMinimumRetryDelay(
+static HRESULT WINAPI BackgroundCopyJob_GetMinimumRetryDelay(
     IBackgroundCopyJob2 *iface,
     ULONG *Seconds)
 {
-    FIXME("%p\n", Seconds);
+    BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
+    FIXME("(%p)->(%p): stub\n", This, Seconds);
     *Seconds = 30;
     return S_OK;
 }
 
-static HRESULT WINAPI BITS_IBackgroundCopyJob_SetNoProgressTimeout(
+static HRESULT WINAPI BackgroundCopyJob_SetNoProgressTimeout(
     IBackgroundCopyJob2 *iface,
     ULONG Seconds)
 {
-    FIXME("%u\n", Seconds);
+    BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
+    FIXME("(%p)->(%d): stub\n", This, Seconds);
     return S_OK;
 }
 
-static HRESULT WINAPI BITS_IBackgroundCopyJob_GetNoProgressTimeout(
+static HRESULT WINAPI BackgroundCopyJob_GetNoProgressTimeout(
     IBackgroundCopyJob2 *iface,
     ULONG *Seconds)
 {
-    FIXME("%p\n", Seconds);
+    BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
+    FIXME("(%p)->(%p): stub\n", This, Seconds);
     *Seconds = 900;
     return S_OK;
 }
 
-static HRESULT WINAPI BITS_IBackgroundCopyJob_GetErrorCount(
+static HRESULT WINAPI BackgroundCopyJob_GetErrorCount(
     IBackgroundCopyJob2 *iface,
     ULONG *Errors)
 {
-    FIXME("Not implemented\n");
+    BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
+    FIXME("(%p)->(%p): stub\n", This, Errors);
     return E_NOTIMPL;
 }
 
-static HRESULT WINAPI BITS_IBackgroundCopyJob_SetProxySettings(
+static HRESULT WINAPI BackgroundCopyJob_SetProxySettings(
     IBackgroundCopyJob2 *iface,
     BG_JOB_PROXY_USAGE ProxyUsage,
     const WCHAR *ProxyList,
     const WCHAR *ProxyBypassList)
 {
-    FIXME("Not implemented\n");
+    BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
+    FIXME("(%p)->(%d %s %s): stub\n", This, ProxyUsage, debugstr_w(ProxyList), debugstr_w(ProxyBypassList));
     return E_NOTIMPL;
 }
 
-static HRESULT WINAPI BITS_IBackgroundCopyJob_GetProxySettings(
+static HRESULT WINAPI BackgroundCopyJob_GetProxySettings(
     IBackgroundCopyJob2 *iface,
     BG_JOB_PROXY_USAGE *pProxyUsage,
     LPWSTR *pProxyList,
     LPWSTR *pProxyBypassList)
 {
-    FIXME("Not implemented\n");
+    BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
+    FIXME("(%p)->(%p %p %p): stub\n", This, pProxyUsage, pProxyList, pProxyBypassList);
     return E_NOTIMPL;
 }
 
-static HRESULT WINAPI BITS_IBackgroundCopyJob_TakeOwnership(
+static HRESULT WINAPI BackgroundCopyJob_TakeOwnership(
     IBackgroundCopyJob2 *iface)
 {
-    FIXME("Not implemented\n");
+    BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
+    FIXME("(%p): stub\n", This);
     return E_NOTIMPL;
 }
 
-static HRESULT WINAPI BITS_IBackgroundCopyJob_SetNotifyCmdLine(
+static HRESULT WINAPI BackgroundCopyJob_SetNotifyCmdLine(
     IBackgroundCopyJob2 *iface,
     LPCWSTR prog,
     LPCWSTR params)
 {
-    FIXME("Not implemented\n");
+    BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
+    FIXME("(%p)->(%s %s): stub\n", This, debugstr_w(prog), debugstr_w(params));
     return E_NOTIMPL;
 }
 
-static HRESULT WINAPI BITS_IBackgroundCopyJob_GetNotifyCmdLine(
+static HRESULT WINAPI BackgroundCopyJob_GetNotifyCmdLine(
     IBackgroundCopyJob2 *iface,
     LPWSTR *prog,
     LPWSTR *params)
 {
-    FIXME("Not implemented\n");
+    BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
+    FIXME("(%p)->(%p %p): stub\n", This, prog, params);
     return E_NOTIMPL;
 }
 
-static HRESULT WINAPI BITS_IBackgroundCopyJob_GetReplyProgress(
+static HRESULT WINAPI BackgroundCopyJob_GetReplyProgress(
     IBackgroundCopyJob2 *iface,
     BG_JOB_REPLY_PROGRESS *progress)
 {
-    FIXME("Not implemented\n");
+    BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
+    FIXME("(%p)->(%p): stub\n", This, progress);
     return E_NOTIMPL;
 }
 
-static HRESULT WINAPI BITS_IBackgroundCopyJob_GetReplyData(
+static HRESULT WINAPI BackgroundCopyJob_GetReplyData(
     IBackgroundCopyJob2 *iface,
     byte **pBuffer,
     UINT64 *pLength)
 {
-    FIXME("Not implemented\n");
+    BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
+    FIXME("(%p)->(%p %p): stub\n", This, pBuffer, pLength);
     return E_NOTIMPL;
 }
 
-static HRESULT WINAPI BITS_IBackgroundCopyJob_SetReplyFileName(
+static HRESULT WINAPI BackgroundCopyJob_SetReplyFileName(
     IBackgroundCopyJob2 *iface,
     LPCWSTR filename)
 {
-    FIXME("Not implemented\n");
+    BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
+    FIXME("(%p)->(%s): stub\n", This, debugstr_w(filename));
     return E_NOTIMPL;
 }
 
-static HRESULT WINAPI BITS_IBackgroundCopyJob_GetReplyFileName(
+static HRESULT WINAPI BackgroundCopyJob_GetReplyFileName(
     IBackgroundCopyJob2 *iface,
     LPWSTR *pFilename)
 {
-    FIXME("Not implemented\n");
+    BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
+    FIXME("(%p)->(%p): stub\n", This, pFilename);
     return E_NOTIMPL;
 }
 
-static HRESULT WINAPI BITS_IBackgroundCopyJob_SetCredentials(
+static HRESULT WINAPI BackgroundCopyJob_SetCredentials(
     IBackgroundCopyJob2 *iface,
     BG_AUTH_CREDENTIALS *cred)
 {
-    FIXME("Not implemented\n");
+    BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
+    FIXME("(%p)->(%p): stub\n", This, cred);
     return S_OK;
 }
 
-static HRESULT WINAPI BITS_IBackgroundCopyJob_RemoveCredentials(
+static HRESULT WINAPI BackgroundCopyJob_RemoveCredentials(
     IBackgroundCopyJob2 *iface,
     BG_AUTH_TARGET target,
     BG_AUTH_SCHEME scheme)
 {
-    FIXME("Not implemented\n");
+    BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
+    FIXME("(%p)->(%d %d): stub\n", This, target, scheme);
     return S_OK;
 }
 
-static const IBackgroundCopyJob2Vtbl BITS_IBackgroundCopyJob_Vtbl =
-{
-    BITS_IBackgroundCopyJob_QueryInterface,
-    BITS_IBackgroundCopyJob_AddRef,
-    BITS_IBackgroundCopyJob_Release,
-    BITS_IBackgroundCopyJob_AddFileSet,
-    BITS_IBackgroundCopyJob_AddFile,
-    BITS_IBackgroundCopyJob_EnumFiles,
-    BITS_IBackgroundCopyJob_Suspend,
-    BITS_IBackgroundCopyJob_Resume,
-    BITS_IBackgroundCopyJob_Cancel,
-    BITS_IBackgroundCopyJob_Complete,
-    BITS_IBackgroundCopyJob_GetId,
-    BITS_IBackgroundCopyJob_GetType,
-    BITS_IBackgroundCopyJob_GetProgress,
-    BITS_IBackgroundCopyJob_GetTimes,
-    BITS_IBackgroundCopyJob_GetState,
-    BITS_IBackgroundCopyJob_GetError,
-    BITS_IBackgroundCopyJob_GetOwner,
-    BITS_IBackgroundCopyJob_SetDisplayName,
-    BITS_IBackgroundCopyJob_GetDisplayName,
-    BITS_IBackgroundCopyJob_SetDescription,
-    BITS_IBackgroundCopyJob_GetDescription,
-    BITS_IBackgroundCopyJob_SetPriority,
-    BITS_IBackgroundCopyJob_GetPriority,
-    BITS_IBackgroundCopyJob_SetNotifyFlags,
-    BITS_IBackgroundCopyJob_GetNotifyFlags,
-    BITS_IBackgroundCopyJob_SetNotifyInterface,
-    BITS_IBackgroundCopyJob_GetNotifyInterface,
-    BITS_IBackgroundCopyJob_SetMinimumRetryDelay,
-    BITS_IBackgroundCopyJob_GetMinimumRetryDelay,
-    BITS_IBackgroundCopyJob_SetNoProgressTimeout,
-    BITS_IBackgroundCopyJob_GetNoProgressTimeout,
-    BITS_IBackgroundCopyJob_GetErrorCount,
-    BITS_IBackgroundCopyJob_SetProxySettings,
-    BITS_IBackgroundCopyJob_GetProxySettings,
-    BITS_IBackgroundCopyJob_TakeOwnership,
-    BITS_IBackgroundCopyJob_SetNotifyCmdLine,
-    BITS_IBackgroundCopyJob_GetNotifyCmdLine,
-    BITS_IBackgroundCopyJob_GetReplyProgress,
-    BITS_IBackgroundCopyJob_GetReplyData,
-    BITS_IBackgroundCopyJob_SetReplyFileName,
-    BITS_IBackgroundCopyJob_GetReplyFileName,
-    BITS_IBackgroundCopyJob_SetCredentials,
-    BITS_IBackgroundCopyJob_RemoveCredentials
+static const IBackgroundCopyJob2Vtbl BackgroundCopyJobVtbl =
+{
+    BackgroundCopyJob_QueryInterface,
+    BackgroundCopyJob_AddRef,
+    BackgroundCopyJob_Release,
+    BackgroundCopyJob_AddFileSet,
+    BackgroundCopyJob_AddFile,
+    BackgroundCopyJob_EnumFiles,
+    BackgroundCopyJob_Suspend,
+    BackgroundCopyJob_Resume,
+    BackgroundCopyJob_Cancel,
+    BackgroundCopyJob_Complete,
+    BackgroundCopyJob_GetId,
+    BackgroundCopyJob_GetType,
+    BackgroundCopyJob_GetProgress,
+    BackgroundCopyJob_GetTimes,
+    BackgroundCopyJob_GetState,
+    BackgroundCopyJob_GetError,
+    BackgroundCopyJob_GetOwner,
+    BackgroundCopyJob_SetDisplayName,
+    BackgroundCopyJob_GetDisplayName,
+    BackgroundCopyJob_SetDescription,
+    BackgroundCopyJob_GetDescription,
+    BackgroundCopyJob_SetPriority,
+    BackgroundCopyJob_GetPriority,
+    BackgroundCopyJob_SetNotifyFlags,
+    BackgroundCopyJob_GetNotifyFlags,
+    BackgroundCopyJob_SetNotifyInterface,
+    BackgroundCopyJob_GetNotifyInterface,
+    BackgroundCopyJob_SetMinimumRetryDelay,
+    BackgroundCopyJob_GetMinimumRetryDelay,
+    BackgroundCopyJob_SetNoProgressTimeout,
+    BackgroundCopyJob_GetNoProgressTimeout,
+    BackgroundCopyJob_GetErrorCount,
+    BackgroundCopyJob_SetProxySettings,
+    BackgroundCopyJob_GetProxySettings,
+    BackgroundCopyJob_TakeOwnership,
+    BackgroundCopyJob_SetNotifyCmdLine,
+    BackgroundCopyJob_GetNotifyCmdLine,
+    BackgroundCopyJob_GetReplyProgress,
+    BackgroundCopyJob_GetReplyData,
+    BackgroundCopyJob_SetReplyFileName,
+    BackgroundCopyJob_GetReplyFileName,
+    BackgroundCopyJob_SetCredentials,
+    BackgroundCopyJob_RemoveCredentials
 };
 
 HRESULT BackgroundCopyJobConstructor(LPCWSTR displayName, BG_JOB_TYPE type, GUID *job_id, BackgroundCopyJobImpl **job)
@@ -573,14 +692,14 @@ HRESULT BackgroundCopyJobConstructor(LPCWSTR displayName, BG_JOB_TYPE type, GUID
     if (!This)
         return E_OUTOFMEMORY;
 
-    This->IBackgroundCopyJob2_iface.lpVtbl = &BITS_IBackgroundCopyJob_Vtbl;
+    This->IBackgroundCopyJob2_iface.lpVtbl = &BackgroundCopyJobVtbl;
     InitializeCriticalSection(&This->cs);
     This->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": BackgroundCopyJobImpl.cs");
 
     This->ref = 1;
     This->type = type;
 
-    n = (lstrlenW(displayName) + 1) *  sizeof *displayName;
+    n = (strlenW(displayName) + 1) *  sizeof *displayName;
     This->displayName = HeapAlloc(GetProcessHeap(), 0, n);
     if (!This->displayName)
     {
@@ -609,8 +728,15 @@ HRESULT BackgroundCopyJobConstructor(LPCWSTR displayName, BG_JOB_TYPE type, GUID
     This->jobProgress.FilesTransferred = 0;
 
     This->state = BG_JOB_STATE_SUSPENDED;
+    This->description = NULL;
+    This->notify_flags = BG_NOTIFY_JOB_ERROR | BG_NOTIFY_JOB_TRANSFERRED;
+    This->callback = NULL;
+    This->callback2 = FALSE;
 
     *job = This;
+
+    TRACE("created job %s:%p\n", debugstr_guid(&This->jobId), This);
+
     return S_OK;
 }