Leaked source code of windows server 2003
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.

253 lines
7.2 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 + 1];
  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 PopDir(LPTSTR ptszDir, size_t cchBuff);
  80. void ClearDirStack(void);
  81. HRESULT CheckFound(LPWIN32_FIND_DATA pFindData);
  82. HRESULT GetNext(LPTSTR * pptszName);
  83. HANDLE m_hFind;
  84. PDIRSTACK m_pdsHead;
  85. TCHAR * m_ptszFolderPath;
  86. TCHAR m_tszCurDir[MAX_PATH + 1]; // current relative dir path
  87. TCHAR m_tszJobExt[SCH_SMBUF_LEN];
  88. // TCHAR m_tszQueExt[SCH_SMBUF_LEN];
  89. ULONG m_cFound;
  90. BOOL m_fInitialized;
  91. BOOL m_fFindOverrun;
  92. unsigned long m_uRefs;
  93. CDllRef m_DllRef;
  94. };
  95. class CScheduleCF;
  96. class CSchedWorker;
  97. //+----------------------------------------------------------------------------
  98. //
  99. // Class: CSchedule
  100. //
  101. // Purpose: schedule service object class
  102. //
  103. //-----------------------------------------------------------------------------
  104. class CSchedule : public ITaskScheduler
  105. {
  106. public:
  107. friend CScheduleCF;
  108. friend CSchedWorker;
  109. CSchedule();
  110. ~CSchedule();
  111. //
  112. // IUnknown methods
  113. //
  114. STDMETHOD(QueryInterface)(REFIID riid, void ** ppvObject);
  115. STDMETHOD_(ULONG, AddRef)(void);
  116. STDMETHOD_(ULONG, Release)(void);
  117. //
  118. // ITaskScheduler methods
  119. //
  120. STDMETHOD(SetTargetComputer)(LPCWSTR pwszComputer);
  121. STDMETHOD(GetTargetComputer)(LPWSTR * ppwszComputer);
  122. STDMETHOD(Enum)(IEnumWorkItems ** ppEnumWorkItems);
  123. STDMETHOD(Activate)(LPCWSTR pwszName, REFIID riid, IUnknown ** ppunk);
  124. STDMETHOD(Delete)(LPCWSTR pwszName);
  125. STDMETHOD(NewWorkItem)(LPCWSTR pwszJobName, REFCLSID rclsid,
  126. REFIID riid, IUnknown ** ppunk);
  127. STDMETHOD(AddWorkItem)(LPCWSTR pwszWorkItemName,
  128. IScheduledWorkItem * pWorkItem);
  129. STDMETHOD(IsOfType)(LPCWSTR pwszName, REFIID riid);
  130. //
  131. // CSchedule methods
  132. //
  133. // Client-side API for adding AT jobs (used by mstinit.exe
  134. // to create AT jobs from info in the registry)
  135. STDMETHOD(AddAtJob)(const AT_INFO &At, DWORD * pID);
  136. // non COM-based Enum function. (uses thread token for access check rather thann CoGetCallContext)
  137. STDMETHOD(EnumInternal)(IEnumWorkItems ** ppEnumWorkItems);
  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. const TCHAR * GetFolderPath(void) {return m_ptszFolderPath;}
  147. const TCHAR * GetTargetMachine(void) { return m_ptszTargetMachine; }
  148. HRESULT Init(void);
  149. HRESULT ActivateJob(LPCTSTR pwszName, CJob ** ppJob,
  150. BOOL fAllData);
  151. private:
  152. //HRESULT ActivateQueue(LPCWSTR pwszName, CQueue ** ppQueue);
  153. //void IsJobOrQueue(LPCWSTR pwszName, LPBOOL pfJob,
  154. // LPBOOL pfQueue);
  155. HRESULT CheckJobName(LPCWSTR pwszPath,
  156. LPTSTR * pptszFullPathName);
  157. HRESULT _AtTaskExists();
  158. HRESULT AddAtJobCommon(const AT_INFO &At,
  159. DWORD *pID,
  160. CJob **ppJob,
  161. WCHAR wszName[],
  162. size_t cchBuff,
  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_