Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

251 lines
6.9 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // Job Scheduler Service
  4. //
  5. // Microsoft Windows
  6. // Copyright (C) Microsoft Corporation, 1992 - 1996.
  7. //
  8. // File: sch_cls.hxx
  9. //
  10. // Contents: job scheduler service classes header
  11. //
  12. // Classes: CSchedule, CScheduleCF, CEnumJobs
  13. //
  14. // History: 20-Sep-95 EricB created
  15. //
  16. //-----------------------------------------------------------------------------
  17. #ifndef _SCH_CLS_HXX_
  18. #define _SCH_CLS_HXX_
  19. #include "dll.hxx"
  20. #include "job_cls.hxx"
  21. #include <mstask.h>
  22. #include "common.hxx"
  23. // constants
  24. const TCHAR SCH_NEXTATJOBID_VALUE[] = TEXT("NextAtJobId");
  25. const TCHAR SCH_ATTASKMAXHOURS_VALUE[] = TEXT("AtTaskMaxHours");
  26. #define DEFAULT_MAXRUNTIME_HOURS 72
  27. struct DIRSTACK
  28. {
  29. DIRSTACK(void) : pdsNext(NULL) {};
  30. TCHAR tszDir[MAX_PATH];
  31. struct DIRSTACK * pdsNext;
  32. };
  33. typedef struct DIRSTACK * PDIRSTACK;
  34. //
  35. // Helper functions
  36. //
  37. void
  38. GetNextAtID(LPDWORD pdwAtID);
  39. VOID
  40. CalcDomTriggerDates(
  41. DWORD dwDaysOfMonth,
  42. const SYSTEMTIME &stNow,
  43. const SYSTEMTIME &stStart,
  44. SYSTEMTIME *pstStart1,
  45. SYSTEMTIME *pstEnd1,
  46. SYSTEMTIME *pstStart2,
  47. SYSTEMTIME *pstEnd2);
  48. VOID
  49. CalcDowTriggerDate(
  50. const SYSTEMTIME &stNow,
  51. const SYSTEMTIME &stStart,
  52. SYSTEMTIME *pstDowStart,
  53. SYSTEMTIME *pstDowEnd);
  54. // classes
  55. //+----------------------------------------------------------------------------
  56. //
  57. // Class: CEnumJobs
  58. //
  59. // Purpose: OLE job enumerator object class
  60. //
  61. //-----------------------------------------------------------------------------
  62. class CEnumJobs : public IEnumWorkItems
  63. {
  64. public:
  65. CEnumJobs();
  66. ~CEnumJobs();
  67. // IUnknown methods
  68. STDMETHOD(QueryInterface)(REFIID riid, void ** ppvObject);
  69. STDMETHOD_(ULONG, AddRef)(void);
  70. STDMETHOD_(ULONG, Release)(void);
  71. // IEnumJobs methods
  72. STDMETHOD(Next)(ULONG cJobs, LPWSTR ** rgpwszNames,
  73. ULONG * pcNamesFetched);
  74. STDMETHOD(Skip)(ULONG cJobs);
  75. STDMETHOD(Reset)(void);
  76. STDMETHOD(Clone)(IEnumWorkItems ** ppEnumJobs);
  77. HRESULT Init(TCHAR * ptszFolderPath);
  78. private:
  79. HRESULT PushDir(LPCTSTR ptszDir);
  80. HRESULT PopDir(LPTSTR ptszDir);
  81. void ClearDirStack(void);
  82. HRESULT CheckFound(LPWIN32_FIND_DATA pFindData);
  83. HRESULT GetNext(LPTSTR * pptszName);
  84. HANDLE m_hFind;
  85. PDIRSTACK m_pdsHead;
  86. TCHAR * m_ptszFolderPath;
  87. TCHAR m_tszCurDir[MAX_PATH]; // current relative dir path
  88. TCHAR m_tszJobExt[SCH_SMBUF_LEN];
  89. // TCHAR m_tszQueExt[SCH_SMBUF_LEN];
  90. ULONG m_cFound;
  91. BOOL m_fInitialized;
  92. BOOL m_fFindOverrun;
  93. unsigned long m_uRefs;
  94. CDllRef m_DllRef;
  95. };
  96. class CScheduleCF;
  97. class CSchedWorker;
  98. //+----------------------------------------------------------------------------
  99. //
  100. // Class: CSchedule
  101. //
  102. // Purpose: schedule service object class
  103. //
  104. //-----------------------------------------------------------------------------
  105. class CSchedule : public ITaskScheduler
  106. {
  107. public:
  108. friend CScheduleCF;
  109. friend CSchedWorker;
  110. CSchedule();
  111. ~CSchedule();
  112. //
  113. // IUnknown methods
  114. //
  115. STDMETHOD(QueryInterface)(REFIID riid, void ** ppvObject);
  116. STDMETHOD_(ULONG, AddRef)(void);
  117. STDMETHOD_(ULONG, Release)(void);
  118. //
  119. // ITaskScheduler methods
  120. //
  121. STDMETHOD(SetTargetComputer)(LPCWSTR pwszComputer);
  122. STDMETHOD(GetTargetComputer)(LPWSTR * ppwszComputer);
  123. STDMETHOD(Enum)(IEnumWorkItems ** ppEnumWorkItems);
  124. STDMETHOD(Activate)(LPCWSTR pwszName, REFIID riid, IUnknown ** ppunk);
  125. STDMETHOD(Delete)(LPCWSTR pwszName);
  126. STDMETHOD(NewWorkItem)(LPCWSTR pwszJobName, REFCLSID rclsid,
  127. REFIID riid, IUnknown ** ppunk);
  128. STDMETHOD(AddWorkItem)(LPCWSTR pwszWorkItemName,
  129. IScheduledWorkItem * pWorkItem);
  130. STDMETHOD(IsOfType)(LPCWSTR pwszName, REFIID riid);
  131. //
  132. // CSchedule methods
  133. //
  134. #if !defined(_CHICAGO_) // these are not needed for Chicago version
  135. // Client-side API for adding AT jobs (used by mstinit.exe
  136. // to create AT jobs from info in the registry)
  137. STDMETHOD(AddAtJob)(const AT_INFO &At, DWORD * pID);
  138. // Server-side API for adding AT jobs (used by mstask.exe
  139. // for NetJobAdd calls)
  140. STDMETHOD(AddAtJobWithHash)(const AT_INFO &At, DWORD * pID);
  141. STDMETHOD(GetAtJob)(LPCWSTR pwszFileName, AT_INFO * pAt,
  142. LPWSTR pwszCommand, DWORD * pcchCommand);
  143. HRESULT IncrementAndSaveID(void);
  144. HRESULT InitAtID(void);
  145. HRESULT ResetAtID(void);
  146. #endif // #if !defined(_CHICAGO_)
  147. const TCHAR * GetFolderPath(void) {return m_ptszFolderPath;}
  148. const TCHAR * GetTargetMachine(void) { return m_ptszTargetMachine; }
  149. HRESULT Init(void);
  150. HRESULT ActivateJob(LPCTSTR pwszName, CJob ** ppJob,
  151. BOOL fAllData);
  152. private:
  153. //HRESULT ActivateQueue(LPCWSTR pwszName, CQueue ** ppQueue);
  154. //void IsJobOrQueue(LPCWSTR pwszName, LPBOOL pfJob,
  155. // LPBOOL pfQueue);
  156. HRESULT CheckJobName(LPCWSTR pwszPath,
  157. LPTSTR * pptszFullPathName);
  158. HRESULT _AtTaskExists();
  159. HRESULT AddAtJobCommon(const AT_INFO &At,
  160. DWORD *pID,
  161. CJob **ppJob,
  162. WCHAR wszName[],
  163. WCHAR wszID[]);
  164. HRESULT GetAtTaskMaxHours(DWORD* pdwMaxHours);
  165. CRITICAL_SECTION m_CriticalSection;
  166. DWORD m_dwNextID;
  167. TCHAR * m_ptszTargetMachine;
  168. TCHAR * m_ptszFolderPath;
  169. unsigned long m_uRefs;
  170. CDllRef m_DllRef;
  171. };
  172. //+----------------------------------------------------------------------------
  173. //
  174. // Class: CScheduleCF
  175. //
  176. // Purpose: schedule service object class factory
  177. //
  178. //-----------------------------------------------------------------------------
  179. class CScheduleCF : public IClassFactory
  180. {
  181. public:
  182. CScheduleCF();
  183. ~CScheduleCF();
  184. // IUnknown methods
  185. STDMETHOD(QueryInterface)(REFIID riid, void ** ppvObject);
  186. STDMETHOD_(ULONG, AddRef)();
  187. STDMETHOD_(ULONG, Release)();
  188. // IClassFactory methods
  189. STDMETHOD(CreateInstance)(IUnknown * pUnkOuter,
  190. REFIID riid,
  191. void ** ppvObject);
  192. STDMETHOD(LockServer)(BOOL fLock);
  193. static IClassFactory * Create(void);
  194. private:
  195. unsigned long m_uRefs;
  196. CDllRef m_DllRef;
  197. };
  198. // global definitions
  199. extern CScheduleCF g_ScheduleCF;
  200. #endif // _SCH_CLS_HXX_