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.

385 lines
9.0 KiB

  1. //____________________________________________________________________________
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995 - 1996.
  5. //
  6. // File: jobs.h
  7. //
  8. // Contents: Definition of the shell IDLIST type for Jobs
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 1/5/1996 RaviR Created
  15. //
  16. //____________________________________________________________________________
  17. #include <mstask.h>
  18. #ifndef _JOBIDL_HXX__
  19. #define _JOBIDL_HXX__
  20. #include <common.hxx>
  21. //____________________________________________________________________________
  22. //
  23. // Job folder details view columns enumeration.
  24. //____________________________________________________________________________
  25. enum COLUMNS
  26. {
  27. COLUMN_NAME,
  28. COLUMN_SCHEDULE,
  29. COLUMN_NEXTRUNTIME,
  30. COLUMN_LASTRUNTIME,
  31. COLUMN_STATUS,
  32. #if !defined(_CHICAGO_)
  33. COLUMN_LASTEXITCODE,
  34. COLUMN_CREATOR,
  35. #endif // !defined(_CHICAGO_)
  36. COLUMN_COUNT
  37. };
  38. //____________________________________________________________________________
  39. //
  40. // class: CJobID
  41. //
  42. // synopsis: IDLIST type struct for Jobs
  43. //____________________________________________________________________________
  44. //
  45. #define IDJOB_BUFFER_SIZE (MAX_PATH * 3)
  46. #define MASK_BITS (0xFFF0)
  47. #define VALID_ID (0x00A0)
  48. #define ID_JOB (0x00A1)
  49. #define ID_QUEUE (0x00A2)
  50. #define ID_NEWJOB (0x00A3)
  51. #define ID_NEWQUEUE (0x00A4)
  52. #define ID_TEMPLATE (0x00A5) // create new task template object
  53. enum EJobStatus
  54. {
  55. ejsRunning = 1,
  56. ejsNotScheduled,
  57. ejsMissed,
  58. ejsWouldNotStart,
  59. ejsBadAcct,
  60. ejsResAcct
  61. };
  62. class CJobID
  63. {
  64. public:
  65. CJobID();
  66. HRESULT Load(LPCTSTR pszFolderPath, LPTSTR pszJobPath);
  67. HRESULT Rename(CJobID &jidIn, LPCOLESTR lpszName);
  68. CJobID *Clone(void);
  69. void LoadDummy(LPTSTR pszJobName);
  70. void InitToTemplate();
  71. LPTSTR GetNextRunTimeString(TCHAR tcBuff[], UINT cchBuff,
  72. BOOL fForComparison,
  73. LPSHELLDETAILS lpDetails=NULL);
  74. ULONG GetSize() { return _cb; }
  75. BOOL IsJob() { return _id == ID_JOB; }
  76. BOOL IsTemplate() { return _id == ID_TEMPLATE; }
  77. LPTSTR GetExtension()
  78. {
  79. switch (_id)
  80. {
  81. case ID_JOB: return TSZ_DOTJOB;
  82. // case ID_QUEUE: return g_szDotQue;
  83. default: return TEXT("");
  84. }
  85. }
  86. BOOL IsRunning() { return _status == ejsRunning; }
  87. BOOL IsJobNotScheduled() { return _status == ejsNotScheduled; }
  88. BOOL WasRunMissed() { return _status == ejsMissed; }
  89. BOOL DidJobStartFail() { return _status == ejsWouldNotStart; }
  90. BOOL DidJobBadAcct() { return _status == ejsBadAcct; }
  91. BOOL DidJobRestAcct() { return _status == ejsResAcct; }
  92. ULONG GetJobFlags() { return _ulJobFlags; }
  93. BOOL IsJobFlagOn(ULONG flag) { return (_ulJobFlags & flag) ? TRUE : FALSE; }
  94. TASK_TRIGGER & GetTrigger() { return _sJobTrigger; }
  95. TASK_TRIGGER_TYPE GetTriggerType() { return _sJobTrigger.TriggerType; }
  96. BOOL IsTriggerFlagOn(ULONG flag)
  97. { return (_sJobTrigger.rgFlags & flag) ? TRUE : FALSE; }
  98. USHORT GetTriggerCount() { return _cTriggers; }
  99. SYSTEMTIME & GetLastRunTime() { return _stLastRunTime; }
  100. SYSTEMTIME & GetNextRunTime() { return _stNextRunTime; }
  101. DWORD & GetExitCode() { return _dwExitCode; }
  102. LPTSTR GetAppName() { return _cBuf; }
  103. LPTSTR GetCreator() { return &_cBuf[_oCreator]; }
  104. LPTSTR GetPath() { return &_cBuf[_oPath];; }
  105. LPTSTR GetName() { return &_cBuf[_oName]; }
  106. size_t GetAppNameOffset()
  107. { return offsetof(CJobID, _cBuf); }
  108. size_t GetCreatorOffset()
  109. { return (offsetof(CJobID, _cBuf) + _oCreator * sizeof(TCHAR)); }
  110. size_t GetPathOffset()
  111. { return (offsetof(CJobID, _cBuf) + _oPath * sizeof(TCHAR)); }
  112. size_t GetNameOffset()
  113. { return (offsetof(CJobID, _cBuf) + _oName * sizeof(TCHAR)); }
  114. #if (DBG == 1)
  115. VOID Validate();
  116. #endif // (DBG == 1)
  117. USHORT _cb; // This must be a USHORT & be the first member,
  118. // as dictated by the idlist definition.
  119. USHORT _id; // To validate that the given pidl is indeed
  120. // one of our own. And also to determine
  121. // if it is a Job/NewJob/Queue/NewQueue
  122. USHORT _status; // 1 => running, 0 => idle status
  123. USHORT _oCreator;
  124. USHORT _oPath;
  125. USHORT _oName;
  126. ULONG _ulJobFlags;
  127. SYSTEMTIME _stLastRunTime;
  128. SYSTEMTIME _stNextRunTime;
  129. FILETIME _ftCreation;
  130. FILETIME _ftLastWrite;
  131. DWORD _dwExitCode;
  132. USHORT _cTriggers;
  133. TASK_TRIGGER _sJobTrigger; // structure job trigger
  134. //
  135. // The contents of the buffer are as follows:
  136. // _cBuf[0] = application name
  137. // _cBuf[_oCreator] = creator name
  138. // _cBuf[_oPath] = job object path
  139. // _cBuf[_oName] = job object name
  140. //
  141. TCHAR _cBuf[IDJOB_BUFFER_SIZE];
  142. private:
  143. void
  144. _NullTerminate();
  145. };
  146. typedef CJobID* PJOBID;
  147. //+--------------------------------------------------------------------------
  148. //
  149. // Member: CJobID::CJobID
  150. //
  151. // Synopsis: ctor
  152. //
  153. // History: 12-08-1997 DavidMun Created
  154. //
  155. //---------------------------------------------------------------------------
  156. inline
  157. CJobID::CJobID():
  158. _cb(0)
  159. {
  160. }
  161. //+--------------------------------------------------------------------------
  162. //
  163. // Member: CJobID::_NullTerminate
  164. //
  165. // Synopsis: Ensure that the two bytes just past the declared size of
  166. // this object are zero.
  167. //
  168. // History: 05-30-1997 DavidMun Created
  169. //
  170. //---------------------------------------------------------------------------
  171. inline void
  172. CJobID::_NullTerminate()
  173. {
  174. UNALIGNED USHORT *pusNextCB = (UNALIGNED USHORT *)(((BYTE *)this) + _cb);
  175. *pusNextCB = 0;
  176. // Sanity check that we haven't written outside of this
  177. Win4Assert(_cb + sizeof(USHORT) <= sizeof(CJobID));
  178. }
  179. inline void
  180. CJobID::LoadDummy(
  181. LPTSTR pszJobName)
  182. {
  183. _id = ID_JOB;
  184. _oPath = _oName = 0;
  185. lstrcpy(_cBuf, PathFindFileName(pszJobName));
  186. TCHAR * ptcExtn = PathFindExtension(_cBuf);
  187. if (ptcExtn)
  188. {
  189. *ptcExtn = TEXT('\0');
  190. }
  191. _cb = offsetof(CJobID, _cBuf) + (lstrlen(_cBuf) + 1) * sizeof(TCHAR);
  192. _NullTerminate();
  193. }
  194. #define JOBID_MIN_SIZE (sizeof(CJobID) - IDJOB_BUFFER_SIZE * sizeof(TCHAR))
  195. inline
  196. BOOL
  197. JF_IsValidID(LPCITEMIDLIST pidl)
  198. {
  199. if (pidl)
  200. {
  201. if (pidl->mkid.cb >= JOBID_MIN_SIZE)
  202. {
  203. return ((((CJobID *)pidl)->_id & MASK_BITS) == VALID_ID);
  204. }
  205. }
  206. return FALSE;
  207. }
  208. //____________________________________________________________________________
  209. //
  210. // class: CJob CIDA
  211. //
  212. // synopsis: format of CF_JOBIDLIST
  213. //____________________________________________________________________________
  214. //
  215. typedef HGLOBAL HJOBIDA;
  216. class CJobIDA
  217. {
  218. public:
  219. PJOBID GetItem(UINT i) {
  220. return (i >= cidl) ? NULL : (PJOBID)(((LPBYTE)this) + aoffset[i]);
  221. }
  222. PJOBID operator [](UINT i) {
  223. return (i >= cidl) ? NULL : (PJOBID)(((LPBYTE)this) + aoffset[i]);
  224. }
  225. UINT cidl; // number of CJobIDs
  226. UINT aoffset[1]; // offset to the CJobIDs
  227. };
  228. typedef CJobIDA * PJOBIDA;
  229. HJOBIDA
  230. HJOBIDA_Create(
  231. UINT cidl,
  232. PJOBID * apjidl);
  233. void
  234. HJOBIDA_Free(
  235. HJOBIDA hJobIDA);
  236. HDROP
  237. HDROPFromJobIDList(
  238. LPCTSTR pszFolderPath,
  239. UINT cidl,
  240. PJOBID * apjidl);
  241. HGLOBAL
  242. CreateIDListArray(
  243. LPCITEMIDLIST pidlFolder,
  244. UINT cidl,
  245. PJOBID *apjidl);
  246. //____________________________________________________________________________
  247. //
  248. // Functions to clone and free a LPCITEMIDLIST array.
  249. //____________________________________________________________________________
  250. LPITEMIDLIST*
  251. ILA_Clone(
  252. UINT cidl,
  253. LPCITEMIDLIST* apidl);
  254. VOID
  255. ILA_Free(
  256. UINT cidl,
  257. LPITEMIDLIST* apidl);
  258. //____________________________________________________________________________
  259. //
  260. // Functions to access the CJob & CSchedule
  261. //____________________________________________________________________________
  262. HRESULT
  263. JFGetJobScheduler(
  264. LPTSTR pszMachine,
  265. ITaskScheduler ** ppJobScheduler,
  266. LPCTSTR * ppszFolderPath);
  267. HRESULT
  268. JFCopyJob(
  269. HWND hwndOwner,
  270. TCHAR szFileFrom[],
  271. LPCTSTR pszFolderPath,
  272. BOOL fMove);
  273. HRESULT
  274. GetTriggerStringFromTrigger(
  275. TASK_TRIGGER * pJobTrigger,
  276. LPTSTR psTrigger,
  277. UINT cchTrigger,
  278. LPSHELLDETAILS lpDetails);
  279. BOOL
  280. IsAScheduleObject(
  281. TCHAR szFile[]);
  282. //____________________________________________________________________________
  283. //
  284. // Misc functions.
  285. //____________________________________________________________________________
  286. LPITEMIDLIST *
  287. SHIDLFromJobIDL(
  288. UINT cidl,
  289. PJOBID * apjidl);
  290. #endif // _JOBIDL_HXX__