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.

795 lines
17 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. task.cxx
  5. Abstract:
  6. Routines implementing the Task object
  7. Author:
  8. Cliff Van Dyke (cliffv) 11-Apr-2001
  9. --*/
  10. #include "pch.hxx"
  11. DWORD
  12. AzpTaskInit(
  13. IN PGENERIC_OBJECT ParentGenericObject,
  14. IN PGENERIC_OBJECT ChildGenericObject
  15. )
  16. /*++
  17. Routine Description:
  18. This routine is a worker routine for AzTaskCreate. It does any object specific
  19. initialization that needs to be done.
  20. On entry, AzGlResource must be locked exclusively.
  21. Arguments:
  22. ParentGenericObject - Specifies the parent object to add the child object onto.
  23. The reference count has been incremented on this object.
  24. ChildGenericObject - Specifies the newly allocated child object.
  25. The reference count has been incremented on this object.
  26. Return Value:
  27. NO_ERROR - The operation was successful
  28. ERROR_NOT_ENOUGH_MEMORY - not enough memory
  29. Other exception status codes
  30. --*/
  31. {
  32. PAZP_TASK Task = (PAZP_TASK) ChildGenericObject;
  33. PAZP_APPLICATION Application = (PAZP_APPLICATION) ParentGenericObject;
  34. //
  35. // Initialization
  36. //
  37. ASSERT( AzpIsLockedExclusive( &AzGlResource ) );
  38. //
  39. // Sanity check the parent
  40. //
  41. ASSERT( ParentGenericObject->ObjectType == OBJECT_TYPE_APPLICATION );
  42. //
  43. // Tasks reference 'Operations' that are children of the same 'Application' as the Task object
  44. // Let the generic object manager know all of the lists we support
  45. //
  46. ChildGenericObject->GenericObjectLists = &Task->Operations,
  47. ObInitObjectList( &Task->Operations,
  48. NULL,
  49. FALSE, // Forward link
  50. 0, // No link pair id
  51. &Application->Operations,
  52. NULL,
  53. NULL );
  54. return NO_ERROR;
  55. }
  56. VOID
  57. AzpTaskFree(
  58. IN PGENERIC_OBJECT GenericObject
  59. )
  60. /*++
  61. Routine Description:
  62. This routine is a worker routine for Task object free. It does any object specific
  63. cleanup that needs to be done.
  64. On entry, AzGlResource must be locked exclusively.
  65. Arguments:
  66. GenericObject - Specifies a pointer to the object to be deleted.
  67. Return Value:
  68. None
  69. --*/
  70. {
  71. PAZP_TASK Task = (PAZP_TASK) GenericObject;
  72. //
  73. // Initialization
  74. //
  75. ASSERT( AzpIsLockedExclusive( &AzGlResource ) );
  76. //
  77. // Free any local strings
  78. //
  79. AzpFreeString( &Task->BizRule );
  80. AzpFreeString( &Task->BizRuleLanguage );
  81. }
  82. DWORD
  83. AzpTaskGetProperty(
  84. IN PGENERIC_OBJECT GenericObject,
  85. IN ULONG PropertyId,
  86. OUT PVOID *PropertyValue
  87. )
  88. /*++
  89. Routine Description:
  90. This routine is a worker routine for AzTaskGetProperty. It does any object specific
  91. property gets.
  92. On entry, AzGlResource must be locked shared.
  93. Arguments:
  94. GenericObject - Specifies a pointer to the object to be queried
  95. PropertyId - Specifies which property to return.
  96. PropertyValue - Specifies a pointer to return the property in.
  97. The returned pointer must be freed using AzFreeMemory.
  98. The returned value and type depends in PropertyId. The valid values are:
  99. AZ_PROP_TASK_BIZRULE LPWSTR - Biz rule for the task
  100. AZ_PROP_TASK_BIZRULE_LANGUAGE LPWSTR - Biz language rule for the task
  101. AZ_PROP_TASK_OPERATIONS AZ_STRING_ARRAY - Operations granted by this task
  102. Return Value:
  103. Status of the operation
  104. --*/
  105. {
  106. DWORD WinStatus = NO_ERROR;
  107. PAZP_TASK Task = (PAZP_TASK) GenericObject;
  108. //
  109. // Initialization
  110. //
  111. ASSERT( AzpIsLockedShared( &AzGlResource ) );
  112. //
  113. // Return any object specific attribute
  114. //
  115. switch ( PropertyId ) {
  116. //
  117. // Return BizRule to the caller
  118. //
  119. case AZ_PROP_TASK_BIZRULE:
  120. *PropertyValue = AzpGetStringProperty( &Task->BizRule );
  121. if ( *PropertyValue == NULL ) {
  122. WinStatus = ERROR_NOT_ENOUGH_MEMORY;
  123. }
  124. break;
  125. //
  126. // Return BizRule language to the caller
  127. //
  128. case AZ_PROP_TASK_BIZRULE_LANGUAGE:
  129. *PropertyValue = AzpGetStringProperty( &Task->BizRuleLanguage );
  130. if ( *PropertyValue == NULL ) {
  131. WinStatus = ERROR_NOT_ENOUGH_MEMORY;
  132. }
  133. break;
  134. //
  135. // Return the set of operations to the caller
  136. //
  137. case AZ_PROP_TASK_OPERATIONS:
  138. *PropertyValue = ObGetPropertyItems( &Task->Operations );
  139. if ( *PropertyValue == NULL ) {
  140. WinStatus = ERROR_NOT_ENOUGH_MEMORY;
  141. }
  142. break;
  143. default:
  144. AzPrint(( AZD_INVPARM, "AzTaskGetProperty: invalid prop id %ld\n", PropertyId ));
  145. WinStatus = ERROR_INVALID_PARAMETER;
  146. break;
  147. }
  148. return WinStatus;
  149. }
  150. DWORD
  151. AzpTaskSetProperty(
  152. IN PGENERIC_OBJECT GenericObject,
  153. IN ULONG PropertyId,
  154. IN PVOID PropertyValue
  155. )
  156. /*++
  157. Routine Description:
  158. This routine is a worker routine for AzTaskSetProperty. It does any object specific
  159. property sets.
  160. On entry, AzGlResource must be locked exclusive.
  161. Arguments:
  162. GenericObject - Specifies a pointer to the object to be modified
  163. PropertyId - Specifies which property to set.
  164. PropertyValue - Specifies a pointer to the property.
  165. The specified value and type depends in PropertyId. The valid values are:
  166. AZ_PROP_TASK_BIZRULE LPWSTR - Biz rule for the task
  167. AZ_PROP_TASK_BIZRULE_LANGUAGE LPWSTR - Biz language rule for the task
  168. Return Value:
  169. Status of the operation
  170. --*/
  171. {
  172. DWORD WinStatus = NO_ERROR;
  173. PAZP_TASK Task = (PAZP_TASK) GenericObject;
  174. AZP_STRING CapturedString;
  175. AZP_STRING ValidValue1;
  176. AZP_STRING ValidValue2;
  177. //
  178. // Initialization
  179. //
  180. ASSERT( AzpIsLockedExclusive( &AzGlResource ) );
  181. AzpInitString( &CapturedString, NULL );
  182. //
  183. // Set any object specific attribute
  184. //
  185. switch ( PropertyId ) {
  186. //
  187. // Set BizRule on the object
  188. //
  189. case AZ_PROP_TASK_BIZRULE:
  190. //
  191. // Capture the input string
  192. //
  193. WinStatus = AzpCaptureString( &CapturedString,
  194. (LPWSTR) PropertyValue,
  195. AZ_MAX_TASK_BIZRULE_LENGTH,
  196. TRUE ); // NULL is OK
  197. if ( WinStatus != NO_ERROR ) {
  198. goto Cleanup;
  199. }
  200. //
  201. // Swap the old/new names
  202. //
  203. AzpSwapStrings( &CapturedString, &Task->BizRule );
  204. break;
  205. //
  206. // Set BizRule language on the object
  207. //
  208. case AZ_PROP_TASK_BIZRULE_LANGUAGE:
  209. //
  210. // Capture the input string
  211. //
  212. WinStatus = AzpCaptureString( &CapturedString,
  213. (LPWSTR) PropertyValue,
  214. AZ_MAX_TASK_BIZRULE_LANGUAGE_LENGTH,
  215. TRUE ); // NULL is OK
  216. if ( WinStatus != NO_ERROR ) {
  217. goto Cleanup;
  218. }
  219. //
  220. // Ensure it is one of the valid values
  221. //
  222. AzpInitString( &ValidValue1, L"VBScript" );
  223. AzpInitString( &ValidValue2, L"JScript" );
  224. if ( !AzpEqualStrings( &CapturedString, &ValidValue1) &&
  225. !AzpEqualStrings( &CapturedString, &ValidValue2) ) {
  226. AzPrint(( AZD_INVPARM, "AzTaskSetProperty: invalid language %ws\n", CapturedString.String ));
  227. WinStatus = ERROR_INVALID_PARAMETER;
  228. goto Cleanup;
  229. }
  230. //
  231. // Swap the old/new names
  232. //
  233. AzpSwapStrings( &CapturedString, &Task->BizRuleLanguage );
  234. break;
  235. default:
  236. AzPrint(( AZD_INVPARM, "AzTaskSetProperty: invalid prop id %ld\n", PropertyId ));
  237. WinStatus = ERROR_INVALID_PARAMETER;
  238. goto Cleanup;
  239. }
  240. //
  241. // Free any local resources
  242. //
  243. Cleanup:
  244. AzpFreeString( &CapturedString );
  245. return WinStatus;
  246. }
  247. DWORD
  248. WINAPI
  249. AzTaskCreate(
  250. IN AZ_HANDLE ApplicationHandle,
  251. IN LPCWSTR TaskName,
  252. IN DWORD Reserved,
  253. OUT PAZ_HANDLE TaskHandle
  254. )
  255. /*++
  256. Routine Description:
  257. This routine adds a task into the scope of the specified application.
  258. Arguments:
  259. ApplicationHandle - Specifies a handle to the application.
  260. TaskName - Specifies the name of the task to add.
  261. Reserved - Reserved. Must by zero.
  262. TaskHandle - Return a handle to the task.
  263. The caller must close this handle by calling AzCloseHandle.
  264. Return Value:
  265. NO_ERROR - The operation was successful
  266. ERROR_ALREADY_EXISTS - An object by that name already exists
  267. --*/
  268. {
  269. //
  270. // Call the common routine to do most of the work
  271. //
  272. return ObCommonCreateObject(
  273. (PGENERIC_OBJECT) ApplicationHandle,
  274. OBJECT_TYPE_APPLICATION,
  275. &(((PAZP_APPLICATION)ApplicationHandle)->Tasks),
  276. OBJECT_TYPE_TASK,
  277. TaskName,
  278. Reserved,
  279. (PGENERIC_OBJECT *) TaskHandle );
  280. }
  281. DWORD
  282. WINAPI
  283. AzTaskOpen(
  284. IN AZ_HANDLE ApplicationHandle,
  285. IN LPCWSTR TaskName,
  286. IN DWORD Reserved,
  287. OUT PAZ_HANDLE TaskHandle
  288. )
  289. /*++
  290. Routine Description:
  291. This routine opens a task into the scope of the specified application.
  292. Arguments:
  293. ApplicationHandle - Specifies a handle to the application.
  294. TaskName - Specifies the name of the task to open
  295. Reserved - Reserved. Must by zero.
  296. TaskHandle - Return a handle to the task.
  297. The caller must close this handle by calling AzCloseHandle.
  298. Return Value:
  299. NO_ERROR - The operation was successful
  300. ERROR_NOT_FOUND - There is no task by that name
  301. --*/
  302. {
  303. //
  304. // Call the common routine to do most of the work
  305. //
  306. return ObCommonOpenObject(
  307. (PGENERIC_OBJECT) ApplicationHandle,
  308. OBJECT_TYPE_APPLICATION,
  309. &(((PAZP_APPLICATION)ApplicationHandle)->Tasks),
  310. OBJECT_TYPE_TASK,
  311. TaskName,
  312. Reserved,
  313. (PGENERIC_OBJECT *) TaskHandle );
  314. }
  315. DWORD
  316. WINAPI
  317. AzTaskEnum(
  318. IN AZ_HANDLE ApplicationHandle,
  319. IN DWORD Reserved,
  320. IN OUT PULONG EnumerationContext,
  321. OUT PAZ_HANDLE TaskHandle
  322. )
  323. /*++
  324. Routine Description:
  325. Enumerates all of the tasks for the specified application.
  326. Arguments:
  327. ApplicationHandle - Specifies a handle to the application.
  328. Reserved - Reserved. Must by zero.
  329. EnumerationContext - Specifies a context indicating the next task to return
  330. On input for the first call, should point to zero.
  331. On input for subsequent calls, should point to the value returned on the previous call.
  332. On output, returns a value to be passed on the next call.
  333. TaskHandle - Returns a handle to the next task object.
  334. The caller must close this handle by calling AzCloseHandle.
  335. Return Value:
  336. NO_ERROR - The operation was successful (a handle was returned)
  337. ERROR_NO_MORE_ITEMS - No more items were available for enumeration
  338. --*/
  339. {
  340. //
  341. // Call the common routine to do most of the work
  342. //
  343. return ObCommonEnumObjects(
  344. (PGENERIC_OBJECT) ApplicationHandle,
  345. OBJECT_TYPE_APPLICATION,
  346. &(((PAZP_APPLICATION)ApplicationHandle)->Tasks),
  347. EnumerationContext,
  348. Reserved,
  349. (PGENERIC_OBJECT *) TaskHandle );
  350. }
  351. DWORD
  352. WINAPI
  353. AzTaskGetProperty(
  354. IN AZ_HANDLE TaskHandle,
  355. IN ULONG PropertyId,
  356. IN DWORD Reserved,
  357. OUT PVOID *PropertyValue
  358. )
  359. /*++
  360. Routine Description:
  361. Returns the specified property for a task.
  362. Arguments:
  363. TaskHandle - Specifies a handle to the task
  364. PropertyId - Specifies which property to return.
  365. Reserved - Reserved. Must by zero.
  366. PropertyValue - Specifies a pointer to return the property in.
  367. The returned pointer must be freed using AzFreeMemory.
  368. The returned value and type depends in PropertyId. The valid values are:
  369. AZ_PROP_NAME LPWSTR - Object name of the object
  370. AZ_PROP_DESCRIPTION LPWSTR - Description of the object
  371. AZ_PROP_TASK_BIZRULE LPWSTR - Biz rule for the task
  372. AZ_PROP_TASK_BIZRULE_LANGUAGE LPWSTR - Biz language rule for the task
  373. Return Value:
  374. NO_ERROR - The operation was successful
  375. ERROR_INVALID_PARAMETER - PropertyId isn't valid
  376. --*/
  377. {
  378. //
  379. // Call the common routine to do most of the work
  380. //
  381. return ObCommonGetProperty(
  382. (PGENERIC_OBJECT) TaskHandle,
  383. OBJECT_TYPE_TASK,
  384. PropertyId,
  385. Reserved,
  386. PropertyValue );
  387. }
  388. DWORD
  389. WINAPI
  390. AzTaskSetProperty(
  391. IN AZ_HANDLE TaskHandle,
  392. IN ULONG PropertyId,
  393. IN DWORD Reserved,
  394. IN PVOID PropertyValue
  395. )
  396. /*++
  397. Routine Description:
  398. Sets the specified property for a task.
  399. Arguments:
  400. TaskHandle - Specifies a handle to the task
  401. PropertyId - Specifies which property to set
  402. Reserved - Reserved. Must by zero.
  403. PropertyValue - Specifies a pointer to the property.
  404. The specified value and type depends in PropertyId. The valid values are:
  405. AZ_PROP_NAME LPWSTR - Object name of the object
  406. AZ_PROP_DESCRIPTION LPWSTR - Description of the object
  407. Return Value:
  408. NO_ERROR - The operation was successful
  409. ERROR_INVALID_PARAMETER - PropertyId isn't valid
  410. --*/
  411. {
  412. //
  413. // Call the common routine to do most of the work
  414. //
  415. return ObCommonSetProperty(
  416. (PGENERIC_OBJECT) TaskHandle,
  417. OBJECT_TYPE_TASK,
  418. PropertyId,
  419. Reserved,
  420. PropertyValue );
  421. }
  422. DWORD
  423. WINAPI
  424. AzTaskAddPropertyItem(
  425. IN AZ_HANDLE TaskHandle,
  426. IN ULONG PropertyId,
  427. IN DWORD Reserved,
  428. IN PVOID PropertyValue
  429. )
  430. /*++
  431. Routine Description:
  432. Adds an item to the list of items specified by PropertyId.
  433. Arguments:
  434. TaskHandle - Specifies a handle to the task
  435. PropertyId - Specifies which property to modify
  436. Reserved - Reserved. Must by zero.
  437. PropertyValue - Specifies a pointer to item to add.
  438. The specified value and type depends on PropertyId. The valid values are:
  439. AZ_PROP_TASK_OPERATIONS LPWSTR - Operation granted by this task
  440. Return Value:
  441. NO_ERROR - The operation was successful
  442. ERROR_INVALID_PARAMETER - PropertyId isn't valid
  443. ERROR_NOT_FOUND - There is no object by that name
  444. ERROR_ALREADY_EXISTS - An item by that name already exists in the list
  445. --*/
  446. {
  447. PGENERIC_OBJECT_LIST GenericObjectList;
  448. //
  449. // Validate the Property ID
  450. //
  451. switch ( PropertyId ) {
  452. case AZ_PROP_TASK_OPERATIONS:
  453. GenericObjectList = &((PAZP_TASK)TaskHandle)->Operations;
  454. break;
  455. default:
  456. AzPrint(( AZD_INVPARM, "AzTaskAddPropertyItem: invalid prop id %ld\n", PropertyId ));
  457. return ERROR_INVALID_PARAMETER;
  458. }
  459. //
  460. // Call the common routine to do most of the work
  461. //
  462. return ObCommonAddPropertyItem(
  463. (PGENERIC_OBJECT) TaskHandle,
  464. OBJECT_TYPE_TASK,
  465. GenericObjectList,
  466. Reserved,
  467. (LPWSTR) PropertyValue );
  468. }
  469. DWORD
  470. WINAPI
  471. AzTaskRemovePropertyItem(
  472. IN AZ_HANDLE TaskHandle,
  473. IN ULONG PropertyId,
  474. IN DWORD Reserved,
  475. IN PVOID PropertyValue
  476. )
  477. /*++
  478. Routine Description:
  479. Remove an item from the list of items specified by PropertyId.
  480. Arguments:
  481. TaskHandle - Specifies a handle to the task
  482. PropertyId - Specifies which property to modify
  483. Reserved - Reserved. Must by zero.
  484. PropertyValue - Specifies a pointer to item to remove.
  485. The specified value and type depends on PropertyId. The valid values are:
  486. AZ_PROP_TASK_OPERATIONS LPWSTR - Operation granted by this task
  487. Return Value:
  488. NO_ERROR - The operation was successful
  489. ERROR_INVALID_PARAMETER - PropertyId isn't valid
  490. ERROR_NOT_FOUND - There is no item by that name in the list
  491. --*/
  492. {
  493. PGENERIC_OBJECT_LIST GenericObjectList;
  494. //
  495. // Validate the Property ID
  496. //
  497. switch ( PropertyId ) {
  498. case AZ_PROP_TASK_OPERATIONS:
  499. GenericObjectList = &((PAZP_TASK)TaskHandle)->Operations;
  500. break;
  501. default:
  502. AzPrint(( AZD_INVPARM, "AzTaskRemovePropertyItem: invalid prop id %ld\n", PropertyId ));
  503. return ERROR_INVALID_PARAMETER;
  504. }
  505. //
  506. // Call the common routine to do most of the work
  507. //
  508. return ObCommonRemovePropertyItem (
  509. (PGENERIC_OBJECT) TaskHandle,
  510. OBJECT_TYPE_TASK,
  511. GenericObjectList,
  512. Reserved,
  513. (LPWSTR) PropertyValue );
  514. }
  515. DWORD
  516. WINAPI
  517. AzTaskDelete(
  518. IN AZ_HANDLE ApplicationHandle,
  519. IN LPCWSTR TaskName,
  520. IN DWORD Reserved
  521. )
  522. /*++
  523. Routine Description:
  524. This routine deletes a task from the scope of the specified application.
  525. Also deletes any child objects of TaskName.
  526. Arguments:
  527. ApplicationHandle - Specifies a handle to the application.
  528. TaskName - Specifies the name of the task to delete.
  529. Reserved - Reserved. Must by zero.
  530. Return Value:
  531. NO_ERROR - The operation was successful
  532. ERROR_NOT_FOUND - An object by that name cannot be found
  533. --*/
  534. {
  535. //
  536. // Call the common routine to do most of the work
  537. //
  538. return ObCommonDeleteObject(
  539. (PGENERIC_OBJECT) ApplicationHandle,
  540. OBJECT_TYPE_APPLICATION,
  541. &(((PAZP_APPLICATION)ApplicationHandle)->Tasks),
  542. OBJECT_TYPE_TASK,
  543. TaskName,
  544. Reserved );
  545. }