* Sync up to trunk head (r64829).
[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 <bits3_0.h>
38
39 #include <wine/list.h>
40 #include <wine/debug.h>
41 #include <wine/unicode.h>
42
43 WINE_DEFAULT_DEBUG_CHANNEL(qmgr);
44
45 /* Background copy job vtbl and related data */
46 typedef struct
47 {
48 IBackgroundCopyJob2 IBackgroundCopyJob2_iface;
49 LONG ref;
50 LPWSTR displayName;
51 LPWSTR description;
52 BG_JOB_TYPE type;
53 GUID jobId;
54 struct list files;
55 BG_JOB_PROGRESS jobProgress;
56 BG_JOB_STATE state;
57 ULONG notify_flags;
58 IBackgroundCopyCallback2 *callback;
59 BOOL callback2; /* IBackgroundCopyCallback2 is supported in addition to IBackgroundCopyCallback */
60 /* Protects file list, and progress */
61 CRITICAL_SECTION cs;
62 struct list entryFromQmgr;
63 } BackgroundCopyJobImpl;
64
65 /* Background copy file vtbl and related data */
66 typedef struct
67 {
68 IBackgroundCopyFile IBackgroundCopyFile_iface;
69 LONG ref;
70 BG_FILE_INFO info;
71 BG_FILE_PROGRESS fileProgress;
72 WCHAR tempFileName[MAX_PATH];
73 struct list entryFromJob;
74 BackgroundCopyJobImpl *owner;
75 } BackgroundCopyFileImpl;
76
77 /* Background copy manager vtbl and related data */
78 typedef struct
79 {
80 IBackgroundCopyManager IBackgroundCopyManager_iface;
81 /* Protects job list, job states, and jobEvent */
82 CRITICAL_SECTION cs;
83 HANDLE jobEvent;
84 struct list jobs;
85 } BackgroundCopyManagerImpl;
86
87 typedef struct
88 {
89 IClassFactory IClassFactory_iface;
90 } ClassFactoryImpl;
91
92 extern HANDLE stop_event DECLSPEC_HIDDEN;
93 extern ClassFactoryImpl BITS_ClassFactory DECLSPEC_HIDDEN;
94 extern BackgroundCopyManagerImpl globalMgr DECLSPEC_HIDDEN;
95
96 HRESULT BackgroundCopyManagerConstructor(LPVOID *ppObj) DECLSPEC_HIDDEN;
97 HRESULT BackgroundCopyJobConstructor(LPCWSTR displayName, BG_JOB_TYPE type,
98 GUID *pJobId, BackgroundCopyJobImpl **job) DECLSPEC_HIDDEN;
99 HRESULT enum_copy_job_create(BackgroundCopyManagerImpl *qmgr,
100 IEnumBackgroundCopyJobs **enumjob) DECLSPEC_HIDDEN;
101 HRESULT BackgroundCopyFileConstructor(BackgroundCopyJobImpl *owner,
102 LPCWSTR remoteName, LPCWSTR localName,
103 BackgroundCopyFileImpl **file) DECLSPEC_HIDDEN;
104 HRESULT EnumBackgroundCopyFilesConstructor(BackgroundCopyJobImpl*, IEnumBackgroundCopyFiles**) DECLSPEC_HIDDEN;
105 DWORD WINAPI fileTransfer(void *param) DECLSPEC_HIDDEN;
106 void processJob(BackgroundCopyJobImpl *job) DECLSPEC_HIDDEN;
107 BOOL processFile(BackgroundCopyFileImpl *file, BackgroundCopyJobImpl *job) DECLSPEC_HIDDEN;
108
109 /* Little helper functions */
110 static inline char *
111 qmgr_strdup(const char *s)
112 {
113 size_t n = strlen(s) + 1;
114 char *d = HeapAlloc(GetProcessHeap(), 0, n);
115 return d ? memcpy(d, s, n) : NULL;
116 }
117
118 static inline HRESULT return_strval(const WCHAR *str, WCHAR **ret)
119 {
120 int len;
121
122 if (!ret) return E_INVALIDARG;
123
124 len = strlenW(str);
125 *ret = CoTaskMemAlloc((len+1)*sizeof(WCHAR));
126 if (!*ret) return E_OUTOFMEMORY;
127 strcpyW(*ret, str);
128 return S_OK;
129 }
130
131 static inline BOOL
132 transitionJobState(BackgroundCopyJobImpl *job, BG_JOB_STATE fromState,
133 BG_JOB_STATE toState)
134 {
135 BOOL rv = FALSE;
136 EnterCriticalSection(&globalMgr.cs);
137 if (job->state == fromState)
138 {
139 job->state = toState;
140 rv = TRUE;
141 }
142 LeaveCriticalSection(&globalMgr.cs);
143 return rv;
144 }
145
146 #endif /* __QMGR_H__ */