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