qmgr.h 3.94 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 24 25 26 27
/*
 * Queue Manager definitions
 *
 * Copyright 2007 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
 */

#ifndef __QMGR_H__
#define __QMGR_H__

#include "windef.h"
#include "objbase.h"

#define COBJMACROS
28
#include "bits1_5.h"
29

30
#include <string.h>
31
#include "wine/list.h"
32

33 34 35
/* Background copy job vtbl and related data */
typedef struct
{
36
    const IBackgroundCopyJob2Vtbl *lpVtbl;
37
    LONG ref;
38 39 40
    LPWSTR displayName;
    BG_JOB_TYPE type;
    GUID jobId;
41 42
    struct list files;
    BG_JOB_PROGRESS jobProgress;
43
    BG_JOB_STATE state;
44 45
    /* Protects file list, and progress */
    CRITICAL_SECTION cs;
46
    struct list entryFromQmgr;
47 48
} BackgroundCopyJobImpl;

49 50 51 52 53
/* Enum background copy jobs vtbl and related data */
typedef struct
{
    const IEnumBackgroundCopyJobsVtbl *lpVtbl;
    LONG ref;
54 55 56
    IBackgroundCopyJob **jobs;
    ULONG numJobs;
    ULONG indexJobs;
57 58
} EnumBackgroundCopyJobsImpl;

59 60 61 62 63 64 65 66 67 68
/* Enum background copy files vtbl and related data */
typedef struct
{
    const IEnumBackgroundCopyFilesVtbl *lpVtbl;
    LONG ref;
    IBackgroundCopyFile **files;
    ULONG numFiles;
    ULONG indexFiles;
} EnumBackgroundCopyFilesImpl;

69 70 71 72 73 74
/* Background copy file vtbl and related data */
typedef struct
{
    const IBackgroundCopyFileVtbl *lpVtbl;
    LONG ref;
    BG_FILE_INFO info;
75
    BG_FILE_PROGRESS fileProgress;
76
    WCHAR tempFileName[MAX_PATH];
77
    struct list entryFromJob;
78
    BackgroundCopyJobImpl *owner;
79 80
} BackgroundCopyFileImpl;

81 82 83 84
/* Background copy manager vtbl and related data */
typedef struct
{
    const IBackgroundCopyManagerVtbl *lpVtbl;
85
    /* Protects job list, job states, and jobEvent  */
86
    CRITICAL_SECTION cs;
87
    HANDLE jobEvent;
88
    struct list jobs;
89 90
} BackgroundCopyManagerImpl;

91 92 93 94 95
typedef struct
{
    const IClassFactoryVtbl *lpVtbl;
} ClassFactoryImpl;

96
extern HANDLE stop_event;
97
extern ClassFactoryImpl BITS_ClassFactory;
98
extern BackgroundCopyManagerImpl globalMgr;
99

100
HRESULT BackgroundCopyManagerConstructor(IUnknown *pUnkOuter, LPVOID *ppObj);
101 102
HRESULT BackgroundCopyJobConstructor(LPCWSTR displayName, BG_JOB_TYPE type,
                                     GUID *pJobId, LPVOID *ppObj);
103 104
HRESULT EnumBackgroundCopyJobsConstructor(LPVOID *ppObj,
                                          IBackgroundCopyManager* copyManager);
105 106 107
HRESULT BackgroundCopyFileConstructor(BackgroundCopyJobImpl *owner,
                                      LPCWSTR remoteName, LPCWSTR localName,
                                      LPVOID *ppObj);
108
HRESULT EnumBackgroundCopyFilesConstructor(LPVOID *ppObj,
109
                                           IBackgroundCopyJob2 *copyJob);
110
DWORD WINAPI fileTransfer(void *param);
111 112
void processJob(BackgroundCopyJobImpl *job);
BOOL processFile(BackgroundCopyFileImpl *file, BackgroundCopyJobImpl *job);
113

114 115 116 117 118 119 120 121 122
/* Little helper functions */
static inline char *
qmgr_strdup(const char *s)
{
    size_t n = strlen(s) + 1;
    char *d = HeapAlloc(GetProcessHeap(), 0, n);
    return d ? memcpy(d, s, n) : NULL;
}

123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
static inline BOOL
transitionJobState(BackgroundCopyJobImpl *job, BG_JOB_STATE fromState,
                   BG_JOB_STATE toState)
{
    BOOL rv = FALSE;
    EnterCriticalSection(&globalMgr.cs);
    if (job->state == fromState)
    {
        job->state = toState;
        rv = TRUE;
    }
    LeaveCriticalSection(&globalMgr.cs);
    return rv;
}

138
#endif /* __QMGR_H__ */