4615e13cddc8c9ae4b2e3c5c2fdaef9bbc7b04e8
[reactos.git] / dll / win32 / qmgr / qmgr.h
1 /*
2 * Queue Manager definitions
3 *
4 * Copyright 2007 Google (Roy Shea)
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #ifndef __QMGR_H__
22 #define __QMGR_H__
23
24 #include <stdarg.h>
25
26 #define WIN32_NO_STATUS
27 #define _INC_WINDOWS
28 #define COM_NO_WINDOWS_H
29
30 #define COBJMACROS
31
32 #include <windef.h>
33 #include <winbase.h>
34 #include <winsvc.h>
35 #include <objbase.h>
36 #include <bits1_5.h>
37 #include <bits2_0.h>
38 #include <bits2_5.h>
39 #include <bits3_0.h>
40
41 #include <wine/list.h>
42 #include <wine/debug.h>
43 #include <wine/unicode.h>
44
45 WINE_DEFAULT_DEBUG_CHANNEL(qmgr);
46
47 /* Background copy job vtbl and related data */
48 typedef struct
49 {
50 IBackgroundCopyJob3 IBackgroundCopyJob3_iface;
51 IBackgroundCopyJobHttpOptions IBackgroundCopyJobHttpOptions_iface;
52 LONG ref;
53 LPWSTR displayName;
54 LPWSTR description;
55 BG_JOB_TYPE type;
56 GUID jobId;
57 struct list files;
58 BG_JOB_PROGRESS jobProgress;
59 BG_JOB_STATE state;
60 ULONG notify_flags;
61 IBackgroundCopyCallback2 *callback;
62 BOOL callback2; /* IBackgroundCopyCallback2 is supported in addition to IBackgroundCopyCallback */
63 /* Protects file list, and progress */
64 CRITICAL_SECTION cs;
65 struct list entryFromQmgr;
66 struct
67 {
68 WCHAR *headers;
69 ULONG flags;
70 BG_AUTH_CREDENTIALS creds[BG_AUTH_TARGET_PROXY][BG_AUTH_SCHEME_PASSPORT];
71 } http_options;
72 struct
73 {
74 BG_ERROR_CONTEXT context;
75 HRESULT code;
76 IBackgroundCopyFile2 *file;
77 } error;
78 HANDLE wait;
79 HANDLE cancel;
80 HANDLE done;
81 } BackgroundCopyJobImpl;
82
83 /* Background copy file vtbl and related data */
84 typedef struct
85 {
86 IBackgroundCopyFile2 IBackgroundCopyFile2_iface;
87 LONG ref;
88 BG_FILE_INFO info;
89 BG_FILE_PROGRESS fileProgress;
90 WCHAR tempFileName[MAX_PATH];
91 struct list entryFromJob;
92 BackgroundCopyJobImpl *owner;
93 DWORD read_size;
94 } BackgroundCopyFileImpl;
95
96 /* Background copy manager vtbl and related data */
97 typedef struct
98 {
99 IBackgroundCopyManager IBackgroundCopyManager_iface;
100 /* Protects job list, job states, and jobEvent */
101 CRITICAL_SECTION cs;
102 HANDLE jobEvent;
103 struct list jobs;
104 } BackgroundCopyManagerImpl;
105
106 typedef struct
107 {
108 IClassFactory IClassFactory_iface;
109 } ClassFactoryImpl;
110
111 extern HANDLE stop_event DECLSPEC_HIDDEN;
112 extern ClassFactoryImpl BITS_ClassFactory DECLSPEC_HIDDEN;
113 extern BackgroundCopyManagerImpl globalMgr DECLSPEC_HIDDEN;
114
115 HRESULT BackgroundCopyManagerConstructor(LPVOID *ppObj) DECLSPEC_HIDDEN;
116 HRESULT BackgroundCopyJobConstructor(LPCWSTR displayName, BG_JOB_TYPE type,
117 GUID *pJobId, BackgroundCopyJobImpl **job) DECLSPEC_HIDDEN;
118 HRESULT enum_copy_job_create(BackgroundCopyManagerImpl *qmgr,
119 IEnumBackgroundCopyJobs **enumjob) DECLSPEC_HIDDEN;
120 HRESULT BackgroundCopyFileConstructor(BackgroundCopyJobImpl *owner,
121 LPCWSTR remoteName, LPCWSTR localName,
122 BackgroundCopyFileImpl **file) DECLSPEC_HIDDEN;
123 HRESULT EnumBackgroundCopyFilesConstructor(BackgroundCopyJobImpl*, IEnumBackgroundCopyFiles**) DECLSPEC_HIDDEN;
124 DWORD WINAPI fileTransfer(void *param) DECLSPEC_HIDDEN;
125 void processJob(BackgroundCopyJobImpl *job) DECLSPEC_HIDDEN;
126 BOOL processFile(BackgroundCopyFileImpl *file, BackgroundCopyJobImpl *job) DECLSPEC_HIDDEN;
127 BOOL transitionJobState(BackgroundCopyJobImpl *job, BG_JOB_STATE from, BG_JOB_STATE to) DECLSPEC_HIDDEN;
128
129 /* Little helper functions */
130 static inline WCHAR *strdupW(const WCHAR *src)
131 {
132 WCHAR *dst = HeapAlloc(GetProcessHeap(), 0, (strlenW(src) + 1) * sizeof(WCHAR));
133 if (dst) strcpyW(dst, src);
134 return dst;
135 }
136
137 static inline WCHAR *co_strdupW(const WCHAR *src)
138 {
139 WCHAR *dst = CoTaskMemAlloc((strlenW(src) + 1) * sizeof(WCHAR));
140 if (dst) strcpyW(dst, src);
141 return dst;
142 }
143
144 static inline HRESULT return_strval(const WCHAR *str, WCHAR **ret)
145 {
146 int len;
147
148 if (!ret) return E_INVALIDARG;
149
150 len = strlenW(str);
151 *ret = CoTaskMemAlloc((len+1)*sizeof(WCHAR));
152 if (!*ret) return E_OUTOFMEMORY;
153 strcpyW(*ret, str);
154 return S_OK;
155 }
156
157 #endif /* __QMGR_H__ */